Code Monkey home page Code Monkey logo

tortoise-matrix's Introduction

TortoiseMatrix is a simple, slow and header only matrix implementation in C++ language.

Examples

// element wise matrix multiplication example
// create 3x4 matrix with 2.0 
TortoiseMatrix<double> m1(3, 4, 2.0);
// create 3x4 matrix with 3.0 
TortoiseMatrix<double> m2(3, 4, 3.0);
// result 3x4 matrix with 6.0 
TortoiseMatrix<double> m3 = m1 * m2;
// Matrix multiplication example
// create 1x2 matrix with 2.0 
TortoiseMatrix<double> m1(1, 2, 2.0);
// create 2x1 matrix with 3.0 
TortoiseMatrix<double> m2(2, 1, 3.0);
// result 1x1 matrix with 12 
TortoiseMatrix<double> m3 = m1.dot(m2);
std::valarray<std::valarray<int>> mock_data = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
};

// Matrix transpose example
// create 3x3 matrix with mock data 
TortoiseMatrix<int> mat(3, 3, mock_data);
auto result = mat.transpose();
/*
Result is now:
    {1, 4, 7},
    {2, 5, 8},
    {3, 6, 9},
*/
std::valarray<std::valarray<int>> mock_data = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
};

// min example
// create 3x3 matrix with mock data 
TortoiseMatrix<int> mat(3, 3, mock_data);
// min is 1
auto min = mat.min();
std::valarray<std::valarray<int>> mock_data = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9},
};

// max example
// create 3x3 matrix with mock data 
TortoiseMatrix<int> mat(3, 3, mock_data);
// min is 9
auto max = mat.max();
// pow example
// create 3x3 matrix with 2 
TortoiseMatrix<int> mat(3, 3, 2);
auto square = mat.pow(2);
// Extract 
// create 3x3 matrix with 2 
TortoiseMatrix<int> mat(3, 3, 2);
// 3x1 matrix (row1)
auto row1 = mat.extract(0, 3);
// 3x1 matrix (row2)
auto row2 = mat.extract(1, 3);

Things to implement

Matrix multiplication is O^3. Optimization required.

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.