Compare commits
4 Commits
e8f843a420
...
main
Author | SHA1 | Date | |
---|---|---|---|
fba09a5c40 | |||
7a2b42e06d | |||
91348e7c09 | |||
2d2d6afcfb |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
build/*
|
build/*
|
||||||
.vscode/*
|
.vscode/*
|
||||||
main.cpp
|
main.cpp
|
||||||
|
main.exe
|
13
main.cpp
13
main.cpp
@ -1,13 +0,0 @@
|
|||||||
#include "matrices.h"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Matrix a(3, 3);
|
|
||||||
|
|
||||||
a.Print("A");
|
|
||||||
|
|
||||||
a = a.Add(0.5F);
|
|
||||||
|
|
||||||
a.Print("A + 0.5F");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
30
matrices.h
30
matrices.h
@ -27,6 +27,8 @@ 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();
|
||||||
@ -36,7 +38,10 @@ 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);
|
||||||
@ -59,6 +64,29 @@ 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++){
|
||||||
|
Reference in New Issue
Block a user