- What's This? Behold: The Scratch Matrix Engine (SME)! This isn't just another Scratch project; it's a full-blown, highly optimized Linear Algebra library cooked up entirely in visual blocks. Forget those "hello world" scripts; this monster is designed to power real, complex AI applications and numerical simulations that Scratch was definitely NOT meant for. Spoiler: it works. Prepare for advanced math, Scratch-style. - How to Use (Unleash the Matrix Power): 1. Import the Engine: Grab the MatrixEngine sprite from this project, backpack it, and drag it into your own Scratch project. Easy peasy. 2. Fire It Up: Always click the green flag! This awakens the engine, registers all its internal functions (like the mythical sigmoid), and gets everything prepped for action. Without this, it's just inert block spaghetti. 3. Matrix Mindset: * Internal Storage: Matrices here aren't simple lists. They're stored as complex, custom-formatted strings (e.g., shape=RxC;1x1=value;...). Don't worry about the raw string; just use the custom blocks! * 1-Based Indexing: Just like in real math (and unlike most programming languages), all matrix indexing is 1-based. So, the top-left element is 1x1, not 0x0. Embrace the elegance. 4. Core Custom Blocks (Your New Superpowers): All the magic happens via custom blocks found on the MatrixEngine sprite, prefixed with MatrixEngine:. Here are some key ones: * MatrixEngine:create (name) (rows) (cols): Births a new matrix named name with your chosen rows and cols. Currently initializes with zeros, because order. * MatrixEngine:set (name) at (row) x (col) to (value): Updates a single element. Precision, Scratch-style. * MatrixEngine:access (name) at (row) x (col): Fetches an element's value. The result appears in the global variable MatrixEngine:return_value. * MatrixEngine:get rows of (name) / MatrixEngine:get cols of (name): Snags the dimensions of any matrix (result in MatrixEngine:return_value). * MatrixEngine:transpose (matrix_A) to (matrix_C): Flips rows and columns. Essential for geometry and, surprisingly, for making dot products easier (conceptually, anyway!). * MatrixEngine:dot product (matrix_A) and (matrix_B) to (matrix_C): The mighty matrix multiplication (dot product) of matrix_A and matrix_B, storing the result in matrix_C. (Remember: columns of A must match rows of B!). * MatrixEngine:add (matrix_A) and (matrix_B) to (matrix_C): Element-wise addition of matrix_A and matrix_B, storing the result in matrix_C. (Requires identical dimensions). * MatrixEngine:subtract (matrix_A) and (matrix_B) to (matrix_C): Element-wise subtraction of matrix_A and matrix_B, storing the result in matrix_C. (Requires identical dimensions). * MatrixEngine:hadamard product (matrix_A) and (matrix_B) to (matrix_C): Element-wise multiplication (Hadamard product) of matrix_A and matrix_B, storing the result in matrix_C. (Requires identical dimensions). * MatrixEngine:scalar multiply (matrix_A) by (scalar_value) to (matrix_C): Multiplies every element of matrix_A by scalar_value, storing in matrix_C. Scale up (or down)! * MatrixEngine:map (matrix_A) with (function_name_text) to (matrix_C): Applies a mathematical function (like Sigmoid!) to every single element in a matrix, storing results in matrix_C. * Current Functions: Use "sigmoid" (as a text input). More on the way if the mood strikes! 5. Debugging (Because Debuggers Are for Wimps): * Incompatible dimensions? Expect (hopefully) clear error messages. * For serious debugging, pair this engine with my xterm sprite (available in my other projects: Check my profile!). It's your personal terminal right inside Scratch, perfect for printing matrix values and tracing the chaos. 6. Versioning: This module adheres to Semantic Versioning (SemVer) guidelines (MAJOR.MINOR.PATCH). This helps you know how updates work: Major version changes (e.g., v1 to v2) might have breaking changes. Minor changes (e.g., v1.0 to v1.1) add features but are backward-compatible. Patch changes (e.g., v1.0.0 to v1.0.1) are for bug fixes. --- USAGE NOTE: Usage of this module is prohibited unless cited in the "Notes and Credits" section of your project.
Built by: @ScratchCat_000 (dev-kas) Powered by: The sheer, unadulterated pain of manually wiring neural network weights and biases in my "Watch an AI learn to play Flappy Bird" and "XOR AI Test" projects. Never again. A ludicrously complex, custom string-based matrix data structure. Scratch gives you "janky lists," so I built my own multi-dimensional, pseudo-array format. A hand-rolled lexer (tokenizer) and detokenizer (unlexer) that I built from scratch because Scratch, bless its heart, doesn't have basic string split or replace functions. Yes, I parsed my own text files. A highly optimized system for applying functions to matrix elements. Initially, I tried a "dynamic dispatch" system using broadcasts, but it was too slow. I refactored to use direct custom block calls for dramatic performance gains, ensuring rapid application of functions like Sigmoid. My own "mutexes" (mutual exclusion locks) – inspired by Golang's concurrency patterns – to prevent data corruption during frantic concurrent reads/writes to shared matrix data. Because even single-threaded Scratch can have "race conditions," apparently. An absolutely insane performance optimization journey: This thing initially took 8.27 seconds to sigmoid a 4x4 matrix using broadcasts. After realizing how much that sucked, I rewrote the core using direct custom block calls, dropping the time to a glorious 0.3 seconds! Learn from my pain, enjoy the speed. My history of building entire programming languages (lexer, parser, evaluator, debugger, LSP, DAP, CLI) in TypeScript and Golang. Turns out, forcing high-level CS concepts into Scratch is my new hobby. The audacity of trying to build a fundamental linear algebra library where cats dance and sprites jump. Caffeine. Still lots and lots of caffeine. Inspired by: The desire to transcend Scratch's inherent limitations and build truly complex AI and computational models. The elegance (and pain) of low-level systems design and compiler construction. The sheer frustration of manual computation. Basically, anything that makes me think, "Can I do that in Scratch? ...Probably not. Okay, I'm doing it." Acknowledgements: Scratch was never, ever, EVER built for this. Still did it. Thanks to the Scratch Team for creating such a versatile (and endlessly abusable) platform that it can be bent to such… unusual purposes. This project is not affiliated with or endorsed by any actual AI research lab or math textbook. It's just me. Trademarks & Stuff: "Scratch" is a trademark of the Lifelong Kindergarten Group at the MIT Media Lab. "Go" (or "Golang") is a trademark of Google LLC. Any mathematical terms (like "Matrix," "Sigmoid," "Dot Product," "Hadamard Product") are concepts, not trademarks. Thankfully. All copyrights belong to their respective owners. I just copy the vibes, and now my Matrix Engine copies the vibes. Fun fact: This entire Matrix Engine, all its complex mathematical operations, its custom data parsing, and its pseudo-concurrency features run on 100% pure visual block spaghetti, the glorious chaos of global variables, and the sheer audacity of trying to build a supercomputer in a cat-themed coding environment. For the curious gremlins: Want to see how I process millions of data points for my "GPT2-like Generative Model" or how I built a full terminal in Scratch? Check out those projects on my profile! --- USAGE NOTE: This module adheres to Semantic Versioning (SemVer) guidelines (MAJOR.MINOR.PATCH). Usage of this module is prohibited unless cited in the "Notes and Credits" section of your project.