GithubHelp home page GithubHelp logo

matrix-rs's Introduction

Matrix-rs

A (very) small, reasonably ergonomic matrix library.

Why?

I didn't like the ergonomics of nalgebra or ndarray. This was a quick attempt to put together a matrix library that would let me do all the things I wanted with minimal fuss. It's not as feature complete or fast as either of the others, but I've found it nicer to use and more understandable when I just want to do something fast and quick. It something akin to a child's drawing of Python's Numpy -- affectionate and well intended, if utterly terrible.

Samples

// Create a new row matrix with values 1, 2, 3.
let m = Matrix::<u32>::from_data(1, 3, vec![1, 2, 3]);

// Create a column matrix with values 1.0, 3.1415, and 1.626
let n = Matrix::<f32>::from_data(3, 1, vec![1.0, 3.1415, 1.626]);

// Create the mandelbrot set:
let mandelbrot = Matrix::<u8>::from_fn(600, 800, |i|{
    let x = ((i % 800) as f32 - 400.0) / 200.0; // Go from -2 to 2.
    let y = ((i / 800) as f32 - 400.0) / 200.0; // Also -2 to 2.

    let c = (x, y);
    let mut z = (0f32, 0f32);

    let mut iter = 0u8;
    for t in 0..255u8 {
        if z.0*z.0 + z.1*z.1 > 4.0 {
            break;
        }
        z = ((z.0 * z.0) - (z.1 * z.1), 2*(z.0 * z.1));
        z = (z.0 + c.0, z.1 + c.1);
        iter = t;
    }

    iter
});

// Multiply a 3x3 matrix with the identity matrix.
let a = Matrix::<f32>::ones(3, 3);
let ident = Matirx::<f32>::ident(3, 3);
let res = a.matmul(ident);

matrix-rs's People

Contributors

josephcatrambone avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.