Added operator = overload
This commit is contained in:
parent
96cea58568
commit
6eb4b00c12
9
main.cpp
9
main.cpp
@ -6,16 +6,13 @@ int main()
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
Matrix a(2,1);
|
||||
Matrix b(1,2);
|
||||
|
||||
Matrix a(3,1);
|
||||
a.Randomize();
|
||||
b.Randomize();
|
||||
|
||||
Matrix b = a;
|
||||
|
||||
a.Print("A");
|
||||
b.Print("B");
|
||||
|
||||
a.Multiply(&b).Print("A x B");
|
||||
|
||||
return 0;
|
||||
}
|
38
matrices.h
38
matrices.h
@ -1,6 +1,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#define assertm(exp, msg) assert((void(msg), exp))
|
||||
|
||||
@ -8,31 +9,40 @@ class Matrix{
|
||||
private:
|
||||
std::vector<std::vector<float>> values;
|
||||
public:
|
||||
void Randomize();
|
||||
void Randomize(float, float);
|
||||
inline void Randomize();
|
||||
inline void Randomize(float, float);
|
||||
|
||||
void Set(float);
|
||||
inline void Set(float);
|
||||
|
||||
void Multiply(float);
|
||||
Matrix Multiply(Matrix*);
|
||||
inline void Multiply(float);
|
||||
inline Matrix Multiply(Matrix*);
|
||||
|
||||
void Hadamard(Matrix*);
|
||||
inline void Hadamard(Matrix*);
|
||||
|
||||
void Add(float);
|
||||
void Add(Matrix*);
|
||||
inline void Add(float);
|
||||
inline void Add(Matrix*);
|
||||
|
||||
void Substract(float);
|
||||
void Substract(Matrix*);
|
||||
inline void Substract(float);
|
||||
inline void Substract(Matrix*);
|
||||
|
||||
void Print(std::string_view);
|
||||
inline void Print(std::string_view);
|
||||
|
||||
void Transpose();
|
||||
inline void Transpose();
|
||||
|
||||
// --- Operators
|
||||
// Assign
|
||||
inline Matrix operator=(const Matrix*);
|
||||
|
||||
// Constructors
|
||||
Matrix(int, int);
|
||||
Matrix(Matrix*);
|
||||
inline Matrix(int, int);
|
||||
inline Matrix(Matrix*);
|
||||
};
|
||||
|
||||
Matrix Matrix::operator=(const Matrix* other){
|
||||
this->values = other->values;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Constructs a zero matrix
|
||||
Matrix::Matrix(int rows, int cols){
|
||||
for(int m = 0; m < rows; m++){
|
||||
|
Loading…
x
Reference in New Issue
Block a user