A lite library for operations in linear algebra

Committer:
benson516
Date:
Fri Feb 10 18:31:32 2017 +0000
Revision:
0:33b75d52d2a7
Speed up the library by using constant references

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benson516 0:33b75d52d2a7 1 #ifndef MATRIX_PRIMITIVE_H
benson516 0:33b75d52d2a7 2 #define MATRIX_PRIMITIVE_H
benson516 0:33b75d52d2a7 3 //
benson516 0:33b75d52d2a7 4 #include <vector>
benson516 0:33b75d52d2a7 5 #include <math.h>
benson516 0:33b75d52d2a7 6
benson516 0:33b75d52d2a7 7 using std::vector;
benson516 0:33b75d52d2a7 8
benson516 0:33b75d52d2a7 9 // Namespace MATRIX_PRIMITIVE
benson516 0:33b75d52d2a7 10 //////////////////////////
benson516 0:33b75d52d2a7 11 namespace MATRIX_PRIMITIVE
benson516 0:33b75d52d2a7 12 {
benson516 0:33b75d52d2a7 13
benson516 0:33b75d52d2a7 14 // Utilities
benson516 0:33b75d52d2a7 15 ///////////////////////////
benson516 0:33b75d52d2a7 16 void Mat_multiply_Vec(vector<float> &v_out, vector<vector<float> > &m_left, vector<float> &v_right); // v_out = m_left*v_right
benson516 0:33b75d52d2a7 17 vector<float> Mat_multiply_Vec(vector<vector<float> > &m_left, vector<float> &v_right); // v_out = m_left*v_right
benson516 0:33b75d52d2a7 18
benson516 0:33b75d52d2a7 19 // New function for matrix multiply matrix
benson516 0:33b75d52d2a7 20 vector<vector<float> > Mat_multiply_Mat(vector<vector<float> > &m_left, vector<vector<float> > &m_right); // m_out = m_left*m_right
benson516 0:33b75d52d2a7 21 vector<float> Get_VectorPlus(const vector<float> &v_a, const vector<float> &v_b, bool is_minus); // v_a + (or -) v_b
benson516 0:33b75d52d2a7 22 vector<float> Get_VectorScalarMultiply(const vector<float> &v_a, float scale); // scale*v_a
benson516 0:33b75d52d2a7 23
benson516 0:33b75d52d2a7 24 // Important!
benson516 0:33b75d52d2a7 25 // New function for scale-up a vector
benson516 0:33b75d52d2a7 26 // v_a *= scale
benson516 0:33b75d52d2a7 27 void Get_VectorScaleUp(vector<float> &v_a, float scale); // v_a *= scale
benson516 0:33b75d52d2a7 28
benson516 0:33b75d52d2a7 29 // Increment
benson516 0:33b75d52d2a7 30 void Get_VectorIncrement(vector<float> &v_a, const vector<float> &v_b, bool is_minus); // v_a += (or -=) v_b
benson516 0:33b75d52d2a7 31 /////////////////////////// end Utilities
benson516 0:33b75d52d2a7 32
benson516 0:33b75d52d2a7 33
benson516 0:33b75d52d2a7 34 // Matrix inversion, using Gauss method
benson516 0:33b75d52d2a7 35 /////////////////////////////////////////
benson516 0:33b75d52d2a7 36 bool SolveSingularityOnDiag(vector<vector<float> > &M, vector<vector<float> > &M_inv, size_t i);
benson516 0:33b75d52d2a7 37
benson516 0:33b75d52d2a7 38 vector<vector<float> > MatrixInversion(vector<vector<float> > M); // Note: we need a copy of M, don't use reference
benson516 0:33b75d52d2a7 39 ///////////////////////////////////////// end Matrix inversion, using Gauss method
benson516 0:33b75d52d2a7 40
benson516 0:33b75d52d2a7 41 }
benson516 0:33b75d52d2a7 42 ////////////////////////// end Namespace MATRIX_PRIMITIVE
benson516 0:33b75d52d2a7 43
benson516 0:33b75d52d2a7 44
benson516 0:33b75d52d2a7 45 #endif