General use matrix class NxM dimensions

General use matrix class NxM dimensions

Released 7 years ago , Last update 7 years ago

A general and extensible matrix class made to handle any dimensions with speed yet providing flexibility, ease of use and portability.

The class is meant to be light-weight, efficient and portable so only basic matrix operations were implemented needed for graphic processing, game development or similar. Typical math and rarely used operations like finding the inverse , determinant or eigenvalues of the matrix have been omitted not to clog up the class. It's built to be compiler and platform agnostic to be portable. The focus was set on ease of use and therefore features a rich function list.

Example usage:

//Multiple declarations made for easy usage
matrix a;//Declares a matrix
matrix a(5,10);//Declares a matrix and sets it to the provided dimensions
matrix a(2.5,3,3.5,4);//Declares a 2x2 matrix with initial values
matrix a(2.5,3,3.5,2.5,3,3.5,2.5,3,3.5);//Declares a 3x3 matrix with initial values

//If you want to change or initialize a matrix to some dimensions
matrix a;
//If you want to clear the matrix and free memory

//Given an already declared matrix , you can populate it with data in various ways
matrix a;
a.populate(2.5,3,3.5,4);//Creates a 2x2 matrix and populates it
a.populate(2.5,3,3.5,2.5,3,3.5,2.5,3,3.5);//Creates a 3x3 matrix and initializes it

double data[2*3]={1.2,2.3,3.4,4.5,5.6,6.7};
a.populate(2,3,data);//Populates a NxM matrix with the provided data

a.populate(data);//Populates an already formed matrix with the provided data

//Getting and setting individual data is just as simple
a.num_rows();//Returns the number of rows
a.num_columns();//Returns the number of columns
a.get_element(2,3);//Gets the element at the specified location , note that indexes go [0,n-1] and not [1,n]
a.set_element(2,3,3.5);//Sets the element at the specified location to the provided value

//Operations with matrixes using overloaded operators
matrix a,b,c;
a=b*5.3;//Multiplication by scalar
a=b/5.3;//Division by scalar
a=b+5;//Add a constant to all elements
a=b-5;//Subtract a constant from all elements
a.identity();//if the matrix is square it gets set to an identity matrix
a.identity(5);//Sets an identity matrix of dimensions NxN;//Zeroes out the current matrix,10);//Creates a matrix of size 5,10 set with 0 for each element
a.transpose();//Transposes the current matrix
a.return_transpose();//Returns the transposed matrix leaving the original matrix unchanged

//Logic operations
matrix a,b;
a==b;//Returns true on equality otherwise false
a!=b;//Returns false on equality otherwise true

To use the matrix simply include the header file and use it. It isn't suggested to use matrices with sizes larger of 5000x5000 since it requires about 190 MB of RAM and for some operations double that amount.


14 day 14-day money-back guarantee


Developer License

  • Perpetual license

  • Unlimited projects

  • Can distribute code and binary products

  • Commercial use

1 license From » $5.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email
No comments have been posted yet.