Giter VIP home page Giter VIP logo

mymatrix's Introduction

MyMatrix

My simple matrix library that can perform fraction operations.

1. Attribute

  • Name: MyMatrix.
  • Language: Rust, requires version rustc >= 1.75.0.
  • Goal: Write a simple matrix library that can perform fraction operations.
  • Module: Vector, Matrix
  • Style: Follow Rust's official recommended style.
  • Test: Using rstest for unit testing and ensure that all tests passed.
  • Security: There is no unsafe code block.
  • Document: Using cargo doc --open to open documents.

2. Usage

To use it, add the following lines to your Cargo.toml file:

[dependencies]
mymatrix = "0"

Some simple examples:

use mymatrix::*;

// Vector dot product
print!("{}", Vector::from([1, 2, 3]) * Vector::from([4, 5, 6])); // 32
// Vector cross product
print!("{}", Vector::cross(&[1, 2, 3].into(), &[4, 5, 6].into())); // [-3 6 -3]
// Vector scalar product
print!("{}", Vector::from([1, 2]) * pyinrs::Fraction::from((2, 5))); // [2/5 4/5]

// Matrix rank
print!("{}", Matrix::from([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).rank()); // 2
// Matrix determinant
print!("{}", Matrix::from([[1, 2, 3], [4, 5, 6], [7, 8, 0]]).det().unwrap()); // 27
// Matrix inversion
print!("{}", Matrix::from([[1, 2, 3], [4, 5, 6], [7, 8, 0]]).inv().unwrap());
/*
[[
-16/9 8/9 -1/9;
14/9 -7/9 2/9;
-1/9 2/9 -1/9;
]]
*/

let a = Matrix::from([[1, 2], [3, 4]]);
let b = Matrix::create(2, 2, 0.into());
let c = Matrix::create(2, 2, 1.into());
let d = Matrix::eye(2);

print!("{}", ((a + b) * (c + d)).inv().unwrap());
/*
[[
-11/6 5/6;
5/3 -2/3;
]]
*/

mymatrix's People

Contributors

chen-qingyu avatar szabgab avatar

Watchers

Lucian avatar  avatar

Forkers

szabgab

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.