Giter Club home page Giter Club logo

graphmat's Introduction

GraphMat

Header-only Library

Matrix implemented as a graph, specially for the use case when it should be auto expanding at custom rate, specially in simulations. A matrix header-only library, uses graphs internally, helpful when your matrix is part of a simulation where it needs to grow many times (or just automatically keep growing).

Tip: Can directly go to the documentaion in the wiki section for usage

This was originally a subproject for the worldline project

Purpose -

I needed a matrix like data structure, that can have

  1. Expansion and deletetion capabilities like that of a list (ie. no need to copy again and again for expansion as in std::vector (and i am not talking about the capacity vs size here, that would not work for my purpose))

  2. access as a vector 2x2 matrix, or atleast fast access

Then, i had read somewhere, A matrix is inherently a graph, each node connected to 4 adjacent nodes, though it maybe very simple, but quite intutive it seems.

So, now the point of it, So i created a matrix data structure, based on a graph, that completes the requirements for point 1 above, though it doesn't have constant time lookups like std::vector, but for my case, i chose to create it like this.

Basic Usage

...
#include <graphMat/graph_mat.hpp>

int main(){
    Graph_Matrix_3D<int> matrix;            // primitive type
    Graph_Matrix_3D<std::string> smat;      // objects
    Graph_Matrix_3D<DataClass> dmat({5, 5, 5}); // initial size
    Graph_Matrix_3D<DataClass> dmat({5, 5, 5}, [n=1](DataClass& data, int x, int y, int z) mutable {    // size with INITIALISIZER function (other variants exist too)
        data.my_data_member = 100*x + 10*y + z;
        std::cout << "Adding box: " << n++ << '\n';
    });
}

Documentation

Documentation is being maintained in wiki section of this repo.

https://github.com/adi-g15/graphMat/wiki/Graph-Matrix-3D

Note -

You can likely just use a std::list<std::list<std::list>>, though then memory allocations will be for each node individually, and also i wanted a better structure according to the needs of worldLine Simulation project, auto expansion being one.

Also, in case of vector<vector<vector<>>>, you will likely have it grow in ONLY TWO DIRECTIONS, and I WANTED IT TO GROW EQUALLY IN ALL FOUR DIRECTIONS, now this would, almost always mean, that even for a simple expansion, the vector<vector<vector<>>> has to completely allocate to a whole new place

Created by Aditya Gupta :D, it follows the Unlicense license, no restrictions for you :-)

graphmat's People

Contributors

adi-g15 avatar silentwatcher3 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

silentwatcher3

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.