philsupertramp/game-math
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1
17#pragma once
18#include "../Matrix.h"
19#include "../sorting.h"
20#include <vector>
21
22#ifndef EPS
24 #define EPS 1e-8
25#endif
26
27
35Matrix<double> linspace(double start, double end, unsigned long num_elements);
36
44Matrix<double> zeros(size_t rows, size_t columns, size_t elements = 1);
45
52
60Matrix<double> ones(size_t rows, size_t columns = 1, size_t elements = 1);
61
68Matrix<double> eye(size_t rows, size_t columns = 0);
69
79Matrix<double> tridiag(size_t rows, size_t columns, double left, double center, double right);
80
93double norm(const Matrix<double>& in);
94
102Matrix<double> norm(const Matrix<double>& in, int axis);
103
112
113
124Matrix<size_t> nonzero(const std::function<bool(const double&)>& validation, const Matrix<double>& x);
125
126
134template<typename T>
136 bool isRows = in.rows() > in.columns();
137 auto k = isRows ? in.rows() : in.columns();
138 auto result = eye(k);
139 for(size_t i = 0; i < k; ++i) { result(i, i) = in(isRows ? i : 0, isRows ? 0 : i); }
140 return result;
141}
142
Definition: Matrix.h:42
size_t rows() const
Definition: Matrix.h:193
size_t columns() const
Definition: Matrix.h:198
Matrix< T > diag(const Matrix< T > &in)
Definition: utils.h:135
Matrix< size_t > argsort(const Matrix< double > &in)
Matrix< size_t > nonzero(const std::function< bool(const double &)> &validation, const Matrix< double > &x)
Matrix< double > eye(size_t rows, size_t columns=0)
double norm(const Matrix< double > &in)
Matrix< double > tridiag(size_t rows, size_t columns, double left, double center, double right)
Matrix< double > ones(size_t rows, size_t columns=1, size_t elements=1)
Matrix< double > zerosV(size_t rows)
Matrix< double > zeros(size_t rows, size_t columns, size_t elements=1)
Matrix< double > linspace(double start, double end, unsigned long num_elements)