Compare commits
No commits in common. "main" and "main" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,2 @@
|
|||||||
build/*
|
build/*
|
||||||
.vscode/*
|
.vscode/*
|
||||||
main.cpp
|
|
||||||
main.exe
|
|
12
main.cpp
Normal file
12
main.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "matrices.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Matrix a(3, 3);
|
||||||
|
Matrix b(3, 1); // Let's multiply by a vector
|
||||||
|
|
||||||
|
Matrix result = a * &b;
|
||||||
|
|
||||||
|
result.Print("A x B"); // Result is a 3 by 1 vector
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
42
matrices.h
42
matrices.h
@ -16,7 +16,7 @@ class Matrix{
|
|||||||
|
|
||||||
inline Matrix Swap(const Matrix*);
|
inline Matrix Swap(const Matrix*);
|
||||||
|
|
||||||
inline Matrix Multiply(float);
|
inline void Multiply(float); // TODO : Make this return a Matrix
|
||||||
inline Matrix Multiply(const Matrix*);
|
inline Matrix Multiply(const Matrix*);
|
||||||
|
|
||||||
inline void Hadamard(const Matrix*);
|
inline void Hadamard(const Matrix*);
|
||||||
@ -27,8 +27,6 @@ class Matrix{
|
|||||||
inline Matrix Substract(float);
|
inline Matrix Substract(float);
|
||||||
inline Matrix Substract(const Matrix*);
|
inline Matrix Substract(const Matrix*);
|
||||||
|
|
||||||
inline Matrix Function(float (*f)(float));
|
|
||||||
|
|
||||||
inline void Print(std::string_view);
|
inline void Print(std::string_view);
|
||||||
|
|
||||||
inline Matrix Transpose();
|
inline Matrix Transpose();
|
||||||
@ -38,10 +36,7 @@ class Matrix{
|
|||||||
inline Matrix operator+(const Matrix*);
|
inline Matrix operator+(const Matrix*);
|
||||||
inline Matrix operator-(const Matrix*);
|
inline Matrix operator-(const Matrix*);
|
||||||
inline Matrix operator*(const Matrix*);
|
inline Matrix operator*(const Matrix*);
|
||||||
|
// TODO : Add float parameters for these
|
||||||
inline Matrix operator+(float);
|
|
||||||
inline Matrix operator-(float);
|
|
||||||
inline Matrix operator*(float);
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
inline Matrix(int, int);
|
inline Matrix(int, int);
|
||||||
@ -64,29 +59,6 @@ Matrix Matrix::operator*(const Matrix* other){
|
|||||||
return this->Multiply(other);
|
return this->Multiply(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix Matrix::operator+(float value){
|
|
||||||
return this->Add(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Matrix::operator-(float value){
|
|
||||||
return this->Substract(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Matrix::operator*(float value){
|
|
||||||
return this->Multiply(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Matrix::Function(float (*f)(float)){
|
|
||||||
Matrix result = this;
|
|
||||||
for(int m = 0; m < result.values.size(); m++){
|
|
||||||
for(int n = 0; n < result.values[m].size(); n++){
|
|
||||||
// Execute function on every value
|
|
||||||
result.values[m][n] = f(result.values[m][n]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructs a zero matrix
|
// Constructs a zero matrix
|
||||||
Matrix::Matrix(int rows, int cols){
|
Matrix::Matrix(int rows, int cols){
|
||||||
for(int m = 0; m < rows; m++){
|
for(int m = 0; m < rows; m++){
|
||||||
@ -208,14 +180,12 @@ Matrix Matrix::Substract(float value){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Multiply every matrix case by a given factor
|
// Multiply every matrix case by a given factor
|
||||||
Matrix Matrix::Multiply(float value){
|
void Matrix::Multiply(float value){
|
||||||
Matrix result = this;
|
for(int m = 0; m < this->values.size(); m++){
|
||||||
for(int m = 0; m < result.values.size(); m++){
|
for(int n = 0; n < this->values[m].size(); n++){
|
||||||
for(int n = 0; n < result.values[m].size(); n++){
|
this->values[m][n] *= value;
|
||||||
result.values[m][n] *= value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a matrix to a given value
|
// Set a matrix to a given value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user