Git Product home page Git Product logo

sparse-matrix's Introduction

Sparse Matrix

Project's specifications are taken from the 2020 C++ exam of the course "Programming C++" and can be found in the file assignment.pdf in italian languages. The file report.pdf describe all the information and all my choices on the project in italian languages.

A sparse matrix is a matrix in which only the elements explicitly inserted are physically stored, all other elements have the default value. I choose to save in the matrix also elements equal to the default value if they are explicitly inserted! I use a ordered linked-list to represent the sparse matrix efficiently. Each new element is inserted in order according to its coordinates.

SparseMatrix.h

Is a template class that implement the sparse matrix. T: type of the values stored in the matrix.

Variable type implemented

value_type: value of type T, is the value of a single cell of the matrix.

sm_size: coordinate value for the matrix.

Class member

Struct element: implemented an element of the matrix. Each element contains the value (value_type) and const coordinates (i,j).

Public method

SparseMatrix(const sm_size r,const sm_size c, const value_type &dv): Initialize a sparse matrix with r number of rows, c number of columns and dv default value

SparseMatrix& operator=(const SparseMatrix &other): redefinition of operator=

SparseMatrix(const SparseMatrix &other): copy constructor

template <typename Q>
SparseMatrix(const SparseMatrix<Q> &other): copy constructor with other sparse matrix of type Q. Leave the conversion Q->T to the compiler
  
add(const sm_size ii, const sm_size jj, const value_type& value): add an element at (ii, jj) coordinates with the specifed value.
    
const value_type& operator()(const sm_size ii,const sm_size jj) const: *redefinition of operator(). Return constant value of the element at (ii,jj) coordinates.
    
sm_size getNumRows() const: return the number of rows.
    
sm_size getNumCols() const: return the number of columns.
    
sm_size getNumElement() const: return the number of element explicit inserted.
    
sm_size getDefaultValue() const: return the default value.

Iterator

I have implemented forward iterator for reading (const_iterator) and writing (iterator).

iterator begin(): return the iterator at the start of the matrix

iterator end(): return the iterator at the end of the matrix

const_iterator begin() const: *return the const_iterator at the start of the matrix

const_iterator end() const: return the const_iterator at the end of the matrix

Main.cpp

Contains examples of class use. I used this file as a test file for the class.

sparse-matrix's People

Contributors

rconfa avatar

Watchers

 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.