mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-12-21 14:56:47 +01:00
Added lots of const qualifiers to MLPPVector, MLPPMatrix, MLPPTensor3.
This commit is contained in:
parent
61227dd641
commit
f849155159
@ -19,7 +19,7 @@ bool MLPPMatrix::linearIndependenceChecker(std::vector<std::vector<real_t>> A) {
|
||||
}
|
||||
*/
|
||||
|
||||
Ref<MLPPMatrix> MLPPMatrix::gaussian_noise(int n, int m) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::gaussian_noise(int n, int m) const {
|
||||
std::random_device rd;
|
||||
std::default_random_engine generator(rd());
|
||||
std::normal_distribution<real_t> distribution(0, 1); // Standard normal distribution. Mean of 0, std of 1.
|
||||
@ -64,7 +64,7 @@ void MLPPMatrix::add(const Ref<MLPPMatrix> &B) {
|
||||
c_ptr[i] += b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::addn(const Ref<MLPPMatrix> &B) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::addn(const Ref<MLPPMatrix> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPMatrix>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPMatrix>());
|
||||
|
||||
@ -117,7 +117,7 @@ void MLPPMatrix::sub(const Ref<MLPPMatrix> &B) {
|
||||
c_ptr[i] -= b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::subn(const Ref<MLPPMatrix> &B) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::subn(const Ref<MLPPMatrix> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPMatrix>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPMatrix>());
|
||||
|
||||
@ -1269,7 +1269,7 @@ void MLPPMatrix::max(const Ref<MLPPMatrix> &B) {
|
||||
c_ptr[i] = MAX(c_ptr[i], b_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::maxn(const Ref<MLPPMatrix> &B) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::maxn(const Ref<MLPPMatrix> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPMatrix>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPMatrix>());
|
||||
|
||||
@ -1435,7 +1435,7 @@ void MLPPMatrix::covo(Ref<MLPPMatrix> out) const {
|
||||
}
|
||||
}
|
||||
|
||||
MLPPMatrix::EigenResult MLPPMatrix::eigen() {
|
||||
MLPPMatrix::EigenResult MLPPMatrix::eigen() const {
|
||||
EigenResult res;
|
||||
|
||||
/*
|
||||
@ -1573,7 +1573,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigen() {
|
||||
|
||||
return res;
|
||||
}
|
||||
MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref<MLPPMatrix> &A) {
|
||||
MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref<MLPPMatrix> &A) const {
|
||||
EigenResult res;
|
||||
|
||||
ERR_FAIL_COND_V(!A.is_valid(), res);
|
||||
@ -1736,7 +1736,7 @@ Array MLPPMatrix::eigenb_bind(const Ref<MLPPMatrix> &A) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
MLPPMatrix::SVDResult MLPPMatrix::svd() {
|
||||
MLPPMatrix::SVDResult MLPPMatrix::svd() const {
|
||||
SVDResult res;
|
||||
|
||||
EigenResult left_eigen = multn(transposen())->eigen();
|
||||
@ -1760,7 +1760,7 @@ MLPPMatrix::SVDResult MLPPMatrix::svd() {
|
||||
return res;
|
||||
}
|
||||
|
||||
MLPPMatrix::SVDResult MLPPMatrix::svdb(const Ref<MLPPMatrix> &A) {
|
||||
MLPPMatrix::SVDResult MLPPMatrix::svdb(const Ref<MLPPMatrix> &A) const {
|
||||
SVDResult res;
|
||||
|
||||
ERR_FAIL_COND_V(!A.is_valid(), res);
|
||||
@ -1984,7 +1984,7 @@ bool MLPPMatrix::zeroEigenvalue(std::vector<std::vector<real_t>> A) {
|
||||
}
|
||||
*/
|
||||
|
||||
Ref<MLPPVector> MLPPMatrix::mult_vec(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPMatrix::mult_vec(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPMatrix>());
|
||||
|
||||
int b_size = b->size();
|
||||
@ -2052,7 +2052,7 @@ void MLPPMatrix::add_vec(const Ref<MLPPVector> &b) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::add_vecn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::add_vecn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPMatrix>());
|
||||
ERR_FAIL_COND_V(_size.x != b->size(), Ref<MLPPMatrix>());
|
||||
|
||||
@ -2116,7 +2116,7 @@ void MLPPMatrix::outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &
|
||||
}
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!a.is_valid() || !b.is_valid(), Ref<MLPPMatrix>());
|
||||
|
||||
Ref<MLPPMatrix> C;
|
||||
@ -2157,7 +2157,7 @@ void MLPPMatrix::set_diagonal(const Ref<MLPPVector> &a) {
|
||||
b_ptr[calculate_index(i, i)] = a_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::set_diagonaln(const Ref<MLPPVector> &a) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::set_diagonaln(const Ref<MLPPVector> &a) const {
|
||||
ERR_FAIL_COND_V(!a.is_valid(), Ref<MLPPMatrix>());
|
||||
|
||||
Ref<MLPPMatrix> B = duplicate();
|
||||
@ -2200,7 +2200,7 @@ void MLPPMatrix::diagonal_zeroed(const Ref<MLPPVector> &a) {
|
||||
b_ptr[calculate_index(i, i)] = a_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::diagonal_zeroedn(const Ref<MLPPVector> &a) {
|
||||
Ref<MLPPMatrix> MLPPMatrix::diagonal_zeroedn(const Ref<MLPPVector> &a) const {
|
||||
ERR_FAIL_COND_V(!a.is_valid(), Ref<MLPPMatrix>());
|
||||
|
||||
Ref<MLPPMatrix> B;
|
||||
|
@ -266,7 +266,7 @@ public:
|
||||
_data[p_index_y * _size.x + p_index_x] = p_val;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Vector<real_t> get_row_vector(int p_index_y) {
|
||||
_FORCE_INLINE_ Vector<real_t> get_row_vector(int p_index_y) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, Vector<real_t>());
|
||||
|
||||
Vector<real_t> ret;
|
||||
@ -288,7 +288,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y) {
|
||||
_FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, PoolRealArray());
|
||||
|
||||
PoolRealArray ret;
|
||||
@ -311,7 +311,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_row_mlpp_vector(int p_index_y) {
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_row_mlpp_vector(int p_index_y) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, Ref<MLPPVector>());
|
||||
|
||||
Ref<MLPPVector> ret;
|
||||
@ -586,15 +586,15 @@ public:
|
||||
//std::vector<std::vector<real_t>> gramMatrix(std::vector<std::vector<real_t>> A);
|
||||
//bool linearIndependenceChecker(std::vector<std::vector<real_t>> A);
|
||||
|
||||
Ref<MLPPMatrix> gaussian_noise(int n, int m);
|
||||
Ref<MLPPMatrix> gaussian_noise(int n, int m) const;
|
||||
void gaussian_noise_fill();
|
||||
|
||||
void add(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> addn(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> addn(const Ref<MLPPMatrix> &B) const;
|
||||
void addb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void sub(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> subn(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> subn(const Ref<MLPPMatrix> &B) const;
|
||||
void subb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void mult(const Ref<MLPPMatrix> &B);
|
||||
@ -691,7 +691,7 @@ public:
|
||||
//std::vector<std::vector<real_t>> rotate(std::vector<std::vector<real_t>> A, real_t theta, int axis = -1);
|
||||
|
||||
void max(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B) const;
|
||||
void maxb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
//real_t max(std::vector<std::vector<real_t>> A);
|
||||
@ -713,8 +713,8 @@ public:
|
||||
Ref<MLPPMatrix> eigen_values;
|
||||
};
|
||||
|
||||
EigenResult eigen();
|
||||
EigenResult eigenb(const Ref<MLPPMatrix> &A);
|
||||
EigenResult eigen() const;
|
||||
EigenResult eigenb(const Ref<MLPPMatrix> &A) const;
|
||||
Array eigen_bind();
|
||||
Array eigenb_bind(const Ref<MLPPMatrix> &A);
|
||||
|
||||
@ -724,8 +724,8 @@ public:
|
||||
Ref<MLPPMatrix> Vt;
|
||||
};
|
||||
|
||||
SVDResult svd();
|
||||
SVDResult svdb(const Ref<MLPPMatrix> &A);
|
||||
SVDResult svd() const;
|
||||
SVDResult svdb(const Ref<MLPPMatrix> &A) const;
|
||||
Array svd_bind();
|
||||
Array svdb_bind(const Ref<MLPPMatrix> &A);
|
||||
|
||||
@ -766,24 +766,24 @@ public:
|
||||
bool zeroEigenvalue(std::vector<std::vector<real_t>> A);
|
||||
*/
|
||||
|
||||
Ref<MLPPVector> mult_vec(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> mult_vec(const Ref<MLPPVector> &b) const;
|
||||
void mult_veco(const Ref<MLPPVector> &b, Ref<MLPPVector> out);
|
||||
|
||||
void add_vec(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> add_vecn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> add_vecn(const Ref<MLPPVector> &b) const;
|
||||
void add_vecb(const Ref<MLPPMatrix> &A, const Ref<MLPPVector> &b);
|
||||
|
||||
// This multiplies a, bT
|
||||
void outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) const;
|
||||
|
||||
// Just sets the diagonal
|
||||
void set_diagonal(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> set_diagonaln(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> set_diagonaln(const Ref<MLPPVector> &a) const;
|
||||
|
||||
// Sets the diagonals, everythign else will get zeroed
|
||||
void diagonal_zeroed(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a) const;
|
||||
|
||||
_FORCE_INLINE_ bool is_equal_approx(const Ref<MLPPMatrix> &p_with, real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const {
|
||||
ERR_FAIL_COND_V(!p_with.is_valid(), false);
|
||||
|
@ -64,7 +64,7 @@ void MLPPTensor3::add_feature_maps_image(const Ref<Image> &p_img, const int p_ch
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
Ref<Image> MLPPTensor3::get_feature_map_image(const int p_index_z) {
|
||||
Ref<Image> MLPPTensor3::get_feature_map_image(const int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<Image>());
|
||||
|
||||
Ref<Image> image;
|
||||
@ -92,7 +92,7 @@ Ref<Image> MLPPTensor3::get_feature_map_image(const int p_index_z) {
|
||||
|
||||
return image;
|
||||
}
|
||||
Ref<Image> MLPPTensor3::get_feature_maps_image(const int p_index_r, const int p_index_g, const int p_index_b, const int p_index_a) {
|
||||
Ref<Image> MLPPTensor3::get_feature_maps_image(const int p_index_r, const int p_index_g, const int p_index_b, const int p_index_a) const {
|
||||
if (p_index_r != -1) {
|
||||
ERR_FAIL_INDEX_V(p_index_r, _size.z, Ref<Image>());
|
||||
}
|
||||
@ -437,7 +437,7 @@ void MLPPTensor3::add(const Ref<MLPPTensor3> &B) {
|
||||
c_ptr[i] += b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPTensor3> MLPPTensor3::addn(const Ref<MLPPTensor3> &B) {
|
||||
Ref<MLPPTensor3> MLPPTensor3::addn(const Ref<MLPPTensor3> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>());
|
||||
|
||||
@ -490,7 +490,7 @@ void MLPPTensor3::sub(const Ref<MLPPTensor3> &B) {
|
||||
c_ptr[i] -= b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPTensor3> MLPPTensor3::subn(const Ref<MLPPTensor3> &B) {
|
||||
Ref<MLPPTensor3> MLPPTensor3::subn(const Ref<MLPPTensor3> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>());
|
||||
|
||||
@ -803,7 +803,7 @@ void MLPPTensor3::max(const Ref<MLPPTensor3> &B) {
|
||||
c_ptr[i] = MAX(c_ptr[i], b_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPTensor3> MLPPTensor3::maxn(const Ref<MLPPTensor3> &B) {
|
||||
Ref<MLPPTensor3> MLPPTensor3::maxn(const Ref<MLPPTensor3> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPTensor3>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPTensor3>());
|
||||
|
||||
|
@ -287,7 +287,7 @@ public:
|
||||
_data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z] = p_val;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Vector<real_t> get_row_vector(int p_index_y, int p_index_z) {
|
||||
_FORCE_INLINE_ Vector<real_t> get_row_vector(int p_index_y, int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, Vector<real_t>());
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Vector<real_t>());
|
||||
|
||||
@ -310,7 +310,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y, int p_index_z) {
|
||||
_FORCE_INLINE_ PoolRealArray get_row_pool_vector(int p_index_y, int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, PoolRealArray());
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, PoolRealArray());
|
||||
|
||||
@ -334,7 +334,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_row_mlpp_vector(int p_index_y, int p_index_z) {
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_row_mlpp_vector(int p_index_y, int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, Ref<MLPPVector>());
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<MLPPVector>());
|
||||
|
||||
@ -420,7 +420,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Vector<real_t> get_feature_map_vector(int p_index_z) {
|
||||
_FORCE_INLINE_ Vector<real_t> get_feature_map_vector(int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Vector<real_t>());
|
||||
|
||||
Vector<real_t> ret;
|
||||
@ -444,7 +444,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ PoolRealArray get_feature_map_pool_vector(int p_index_z) {
|
||||
_FORCE_INLINE_ PoolRealArray get_feature_map_pool_vector(int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, PoolRealArray());
|
||||
|
||||
PoolRealArray ret;
|
||||
@ -469,7 +469,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_feature_map_mlpp_vector(int p_index_z) {
|
||||
_FORCE_INLINE_ Ref<MLPPVector> get_feature_map_mlpp_vector(int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<MLPPVector>());
|
||||
|
||||
Ref<MLPPVector> ret;
|
||||
@ -512,7 +512,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Ref<MLPPMatrix> get_feature_map_mlpp_matrix(int p_index_z) {
|
||||
_FORCE_INLINE_ Ref<MLPPMatrix> get_feature_map_mlpp_matrix(int p_index_z) const {
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref<MLPPMatrix>());
|
||||
|
||||
Ref<MLPPMatrix> ret;
|
||||
@ -643,8 +643,8 @@ public:
|
||||
|
||||
void add_feature_maps_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
|
||||
Ref<Image> get_feature_map_image(const int p_index_z);
|
||||
Ref<Image> get_feature_maps_image(const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1);
|
||||
Ref<Image> get_feature_map_image(const int p_index_z) const;
|
||||
Ref<Image> get_feature_maps_image(const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const;
|
||||
|
||||
void get_feature_map_into_image(Ref<Image> p_target, const int p_index_z, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void get_feature_maps_into_image(Ref<Image> p_target, const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const;
|
||||
@ -658,11 +658,11 @@ public:
|
||||
//math api
|
||||
|
||||
void add(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B) const;
|
||||
void addb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void sub(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> subn(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> subn(const Ref<MLPPTensor3> &B) const;
|
||||
void subb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void element_wise_division(const Ref<MLPPTensor3> &B);
|
||||
@ -690,7 +690,7 @@ public:
|
||||
void hadamard_productb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void max(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> maxn(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> maxn(const Ref<MLPPTensor3> &B) const;
|
||||
void maxb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void abs();
|
||||
|
@ -27,7 +27,7 @@ void MLPPVector::flatten_vectors(const Vector<Ref<MLPPVector>> &A) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPVector::flatten_vectorsn(const Vector<Ref<MLPPVector>> &A) {
|
||||
Ref<MLPPVector> MLPPVector::flatten_vectorsn(const Vector<Ref<MLPPVector>> &A) const {
|
||||
Ref<MLPPVector> a;
|
||||
a.instance();
|
||||
|
||||
@ -69,7 +69,7 @@ void MLPPVector::hadamard_product(const Ref<MLPPVector> &b) {
|
||||
out_ptr[i] = a_ptr[i] * b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::hadamard_productn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPVector::hadamard_productn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPVector>());
|
||||
|
||||
Ref<MLPPVector> out;
|
||||
@ -126,7 +126,7 @@ void MLPPVector::element_wise_division(const Ref<MLPPVector> &b) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPVector::element_wise_divisionn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPVector::element_wise_divisionn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPVector>());
|
||||
|
||||
Ref<MLPPVector> out;
|
||||
@ -172,7 +172,7 @@ void MLPPVector::scalar_multiply(real_t scalar) {
|
||||
out_ptr[i] = out_ptr[i] * scalar;
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::scalar_multiplyn(real_t scalar) {
|
||||
Ref<MLPPVector> MLPPVector::scalar_multiplyn(real_t scalar) const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -208,7 +208,7 @@ void MLPPVector::scalar_add(real_t scalar) {
|
||||
out_ptr[i] = out_ptr[i] + scalar;
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::scalar_addn(real_t scalar) {
|
||||
Ref<MLPPVector> MLPPVector::scalar_addn(real_t scalar) const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
|
||||
@ -251,7 +251,7 @@ void MLPPVector::add(const Ref<MLPPVector> &b) {
|
||||
out_ptr[i] += b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::addn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPVector::addn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPVector>());
|
||||
ERR_FAIL_COND_V(_size != b->size(), Ref<MLPPVector>());
|
||||
|
||||
@ -300,7 +300,7 @@ void MLPPVector::sub(const Ref<MLPPVector> &b) {
|
||||
out_ptr[i] -= b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::subn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPVector::subn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPVector>());
|
||||
ERR_FAIL_COND_V(_size != b->size(), Ref<MLPPVector>());
|
||||
|
||||
@ -345,7 +345,7 @@ void MLPPVector::log() {
|
||||
out_ptr[i] = Math::log(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::logn() {
|
||||
Ref<MLPPVector> MLPPVector::logn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -380,7 +380,7 @@ void MLPPVector::log10() {
|
||||
out_ptr[i] = Math::log10(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::log10n() {
|
||||
Ref<MLPPVector> MLPPVector::log10n() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -415,7 +415,7 @@ void MLPPVector::exp() {
|
||||
out_ptr[i] = Math::exp(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::expn() {
|
||||
Ref<MLPPVector> MLPPVector::expn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -450,7 +450,7 @@ void MLPPVector::erf() {
|
||||
out_ptr[i] = Math::erf(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::erfn() {
|
||||
Ref<MLPPVector> MLPPVector::erfn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -485,7 +485,7 @@ void MLPPVector::exponentiate(real_t p) {
|
||||
out_ptr[i] = Math::pow(out_ptr[i], p);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::exponentiaten(real_t p) {
|
||||
Ref<MLPPVector> MLPPVector::exponentiaten(real_t p) const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -520,7 +520,7 @@ void MLPPVector::sqrt() {
|
||||
out_ptr[i] = Math::sqrt(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::sqrtn() {
|
||||
Ref<MLPPVector> MLPPVector::sqrtn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -551,14 +551,14 @@ void MLPPVector::sqrtb(const Ref<MLPPVector> &a) {
|
||||
void MLPPVector::cbrt() {
|
||||
return exponentiate(static_cast<real_t>(1) / static_cast<real_t>(3));
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::cbrtn() {
|
||||
Ref<MLPPVector> MLPPVector::cbrtn() const {
|
||||
return exponentiaten(static_cast<real_t>(1) / static_cast<real_t>(3));
|
||||
}
|
||||
void MLPPVector::cbrtb(const Ref<MLPPVector> &a) {
|
||||
return exponentiateb(a, static_cast<real_t>(1) / static_cast<real_t>(3));
|
||||
}
|
||||
|
||||
real_t MLPPVector::dot(const Ref<MLPPVector> &b) {
|
||||
real_t MLPPVector::dot(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), 0);
|
||||
|
||||
ERR_FAIL_COND_V(_size != b->size(), 0);
|
||||
@ -593,7 +593,7 @@ void MLPPVector::abs() {
|
||||
out_ptr[i] = ABS(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::absn() {
|
||||
Ref<MLPPVector> MLPPVector::absn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -621,7 +621,7 @@ void MLPPVector::absb(const Ref<MLPPVector> &a) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPVector::zero_vec(int n) {
|
||||
Ref<MLPPVector> MLPPVector::zero_vec(int n) const {
|
||||
Ref<MLPPVector> vec;
|
||||
vec.instance();
|
||||
|
||||
@ -630,7 +630,7 @@ Ref<MLPPVector> MLPPVector::zero_vec(int n) {
|
||||
|
||||
return vec;
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::one_vec(int n) {
|
||||
Ref<MLPPVector> MLPPVector::one_vec(int n) const {
|
||||
Ref<MLPPVector> vec;
|
||||
vec.instance();
|
||||
|
||||
@ -639,7 +639,7 @@ Ref<MLPPVector> MLPPVector::one_vec(int n) {
|
||||
|
||||
return vec;
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::full_vec(int n, int k) {
|
||||
Ref<MLPPVector> MLPPVector::full_vec(int n, int k) const {
|
||||
Ref<MLPPVector> vec;
|
||||
vec.instance();
|
||||
|
||||
@ -656,7 +656,7 @@ void MLPPVector::sin() {
|
||||
out_ptr[i] = Math::sin(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::sinn() {
|
||||
Ref<MLPPVector> MLPPVector::sinn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -691,7 +691,7 @@ void MLPPVector::cos() {
|
||||
out_ptr[i] = Math::sqrt(out_ptr[i]);
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::cosn() {
|
||||
Ref<MLPPVector> MLPPVector::cosn() const {
|
||||
Ref<MLPPVector> out;
|
||||
out.instance();
|
||||
out->resize(_size);
|
||||
@ -738,7 +738,7 @@ void MLPPVector::maxv(const Ref<MLPPVector> &b) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::maxvn(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPVector> MLPPVector::maxvn(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), Ref<MLPPVector>());
|
||||
ERR_FAIL_COND_V(_size != b->size(), Ref<MLPPVector>());
|
||||
|
||||
@ -790,7 +790,7 @@ void MLPPVector::maxvb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) {
|
||||
}
|
||||
}
|
||||
|
||||
real_t MLPPVector::max_element() {
|
||||
real_t MLPPVector::max_element() const {
|
||||
const real_t *aa = ptr();
|
||||
|
||||
real_t max_element = -Math_INF;
|
||||
@ -805,7 +805,7 @@ real_t MLPPVector::max_element() {
|
||||
|
||||
return max_element;
|
||||
}
|
||||
real_t MLPPVector::min_element() {
|
||||
real_t MLPPVector::min_element() const {
|
||||
const real_t *aa = ptr();
|
||||
|
||||
real_t min_element = Math_INF;
|
||||
@ -838,7 +838,7 @@ std::vector<std::vector<real_t>> MLPPVector::round(std::vector<std::vector<real_
|
||||
}
|
||||
*/
|
||||
|
||||
real_t MLPPVector::euclidean_distance(const Ref<MLPPVector> &b) {
|
||||
real_t MLPPVector::euclidean_distance(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), 0);
|
||||
|
||||
ERR_FAIL_COND_V(_size != b->size(), 0);
|
||||
@ -854,7 +854,7 @@ real_t MLPPVector::euclidean_distance(const Ref<MLPPVector> &b) {
|
||||
|
||||
return Math::sqrt(dist);
|
||||
}
|
||||
real_t MLPPVector::euclidean_distance_squared(const Ref<MLPPVector> &b) {
|
||||
real_t MLPPVector::euclidean_distance_squared(const Ref<MLPPVector> &b) const {
|
||||
ERR_FAIL_COND_V(!b.is_valid(), 0);
|
||||
|
||||
ERR_FAIL_COND_V(_size != b->size(), 0);
|
||||
@ -883,7 +883,7 @@ real_t MLPPVector::norm_2(std::vector<std::vector<real_t>> A) {
|
||||
}
|
||||
*/
|
||||
|
||||
real_t MLPPVector::norm_sq() {
|
||||
real_t MLPPVector::norm_sq() const {
|
||||
const real_t *a_ptr = ptr();
|
||||
|
||||
real_t n_sq = 0;
|
||||
@ -893,7 +893,7 @@ real_t MLPPVector::norm_sq() {
|
||||
return n_sq;
|
||||
}
|
||||
|
||||
real_t MLPPVector::sum_elements() {
|
||||
real_t MLPPVector::sum_elements() const {
|
||||
const real_t *a_ptr = ptr();
|
||||
|
||||
real_t sum = 0;
|
||||
@ -923,7 +923,7 @@ void MLPPVector::subtract_matrix_rows(const Ref<MLPPMatrix> &B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ref<MLPPVector> MLPPVector::subtract_matrix_rowsn(const Ref<MLPPMatrix> &B) {
|
||||
Ref<MLPPVector> MLPPVector::subtract_matrix_rowsn(const Ref<MLPPMatrix> &B) const {
|
||||
Ref<MLPPVector> c = duplicate();
|
||||
|
||||
Size2i b_size = B->size();
|
||||
@ -958,7 +958,7 @@ void MLPPVector::subtract_matrix_rowsb(const Ref<MLPPVector> &a, const Ref<MLPPM
|
||||
}
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPVector::outer_product(const Ref<MLPPVector> &b) {
|
||||
Ref<MLPPMatrix> MLPPVector::outer_product(const Ref<MLPPVector> &b) const {
|
||||
Ref<MLPPMatrix> C;
|
||||
C.instance();
|
||||
Size2i sm = Size2i(b->size(), size());
|
||||
@ -978,7 +978,7 @@ Ref<MLPPMatrix> MLPPVector::outer_product(const Ref<MLPPVector> &b) {
|
||||
return C;
|
||||
}
|
||||
|
||||
Ref<MLPPMatrix> MLPPVector::diagnm() {
|
||||
Ref<MLPPMatrix> MLPPVector::diagnm() const {
|
||||
Ref<MLPPMatrix> B;
|
||||
B.instance();
|
||||
|
||||
|
@ -329,122 +329,112 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
// New apis should look like this:
|
||||
//void substract(const Ref<MLPPVector> &b); <- this should be the simplest / most obvious method
|
||||
//Ref<MLPPVector> substractn(const Ref<MLPPVector> &b);
|
||||
//void substractb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b); -> result is in this (subtractionv like)
|
||||
|
||||
// Or:
|
||||
//void hadamard_product(const Ref<MLPPVector> &b); <- this should be the simplest / most obvious method
|
||||
//Ref<MLPPVector> hadamard_productn(const Ref<MLPPVector> &b); <- n -> new
|
||||
//void hadamard_productb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b); <- b -> between, result is stored in *this
|
||||
|
||||
void flatten_vectors(const Vector<Ref<MLPPVector>> &A);
|
||||
Ref<MLPPVector> flatten_vectorsn(const Vector<Ref<MLPPVector>> &A);
|
||||
Ref<MLPPVector> flatten_vectorsn(const Vector<Ref<MLPPVector>> &A) const;
|
||||
|
||||
void hadamard_product(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> hadamard_productn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> hadamard_productn(const Ref<MLPPVector> &b) const;
|
||||
void hadamard_productb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
|
||||
void element_wise_division(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> element_wise_divisionn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> element_wise_divisionn(const Ref<MLPPVector> &b) const;
|
||||
void element_wise_divisionb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
|
||||
void scalar_multiply(real_t scalar);
|
||||
Ref<MLPPVector> scalar_multiplyn(real_t scalar);
|
||||
Ref<MLPPVector> scalar_multiplyn(real_t scalar) const;
|
||||
void scalar_multiplyb(real_t scalar, const Ref<MLPPVector> &a);
|
||||
|
||||
void scalar_add(real_t scalar);
|
||||
Ref<MLPPVector> scalar_addn(real_t scalar);
|
||||
Ref<MLPPVector> scalar_addn(real_t scalar) const;
|
||||
void scalar_addb(real_t scalar, const Ref<MLPPVector> &a);
|
||||
|
||||
void add(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> addn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> addn(const Ref<MLPPVector> &b) const;
|
||||
void addb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
|
||||
void sub(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> subn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> subn(const Ref<MLPPVector> &b) const;
|
||||
void subb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
|
||||
void log();
|
||||
Ref<MLPPVector> logn();
|
||||
Ref<MLPPVector> logn() const;
|
||||
void logb(const Ref<MLPPVector> &a);
|
||||
|
||||
void log10();
|
||||
Ref<MLPPVector> log10n();
|
||||
Ref<MLPPVector> log10n() const;
|
||||
void log10b(const Ref<MLPPVector> &a);
|
||||
|
||||
void exp();
|
||||
Ref<MLPPVector> expn();
|
||||
Ref<MLPPVector> expn() const;
|
||||
void expb(const Ref<MLPPVector> &a);
|
||||
|
||||
void erf();
|
||||
Ref<MLPPVector> erfn();
|
||||
Ref<MLPPVector> erfn() const;
|
||||
void erfb(const Ref<MLPPVector> &a);
|
||||
|
||||
void exponentiate(real_t p);
|
||||
Ref<MLPPVector> exponentiaten(real_t p);
|
||||
Ref<MLPPVector> exponentiaten(real_t p) const;
|
||||
void exponentiateb(const Ref<MLPPVector> &a, real_t p);
|
||||
|
||||
void sqrt();
|
||||
Ref<MLPPVector> sqrtn();
|
||||
Ref<MLPPVector> sqrtn() const;
|
||||
void sqrtb(const Ref<MLPPVector> &a);
|
||||
|
||||
void cbrt();
|
||||
Ref<MLPPVector> cbrtn();
|
||||
Ref<MLPPVector> cbrtn() const;
|
||||
void cbrtb(const Ref<MLPPVector> &a);
|
||||
|
||||
real_t dot(const Ref<MLPPVector> &b);
|
||||
real_t dot(const Ref<MLPPVector> &b) const;
|
||||
|
||||
//std::vector<real_t> cross(std::vector<real_t> a, std::vector<real_t> b);
|
||||
|
||||
void abs();
|
||||
Ref<MLPPVector> absn();
|
||||
Ref<MLPPVector> absn() const;
|
||||
void absb(const Ref<MLPPVector> &a);
|
||||
|
||||
Ref<MLPPVector> zero_vec(int n);
|
||||
Ref<MLPPVector> one_vec(int n);
|
||||
Ref<MLPPVector> full_vec(int n, int k);
|
||||
Ref<MLPPVector> zero_vec(int n) const;
|
||||
Ref<MLPPVector> one_vec(int n) const;
|
||||
Ref<MLPPVector> full_vec(int n, int k) const;
|
||||
|
||||
void sin();
|
||||
Ref<MLPPVector> sinn();
|
||||
Ref<MLPPVector> sinn() const;
|
||||
void sinb(const Ref<MLPPVector> &a);
|
||||
|
||||
void cos();
|
||||
Ref<MLPPVector> cosn();
|
||||
Ref<MLPPVector> cosn() const;
|
||||
void cosb(const Ref<MLPPVector> &a);
|
||||
|
||||
void maxv(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> maxvn(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPVector> maxvn(const Ref<MLPPVector> &b) const;
|
||||
void maxvb(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
|
||||
real_t max_element();
|
||||
real_t min_element();
|
||||
real_t max_element() const;
|
||||
real_t min_element() const;
|
||||
|
||||
//std::vector<real_t> round(std::vector<real_t> a);
|
||||
|
||||
real_t euclidean_distance(const Ref<MLPPVector> &b);
|
||||
real_t euclidean_distance_squared(const Ref<MLPPVector> &b);
|
||||
real_t euclidean_distance(const Ref<MLPPVector> &b) const;
|
||||
real_t euclidean_distance_squared(const Ref<MLPPVector> &b) const;
|
||||
|
||||
/*
|
||||
real_t norm_2(std::vector<real_t> a);
|
||||
*/
|
||||
|
||||
real_t norm_sq();
|
||||
real_t norm_sq() const;
|
||||
|
||||
real_t sum_elements();
|
||||
real_t sum_elements() const;
|
||||
|
||||
//real_t cosineSimilarity(std::vector<real_t> a, std::vector<real_t> b);
|
||||
|
||||
void subtract_matrix_rows(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPVector> subtract_matrix_rowsn(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPVector> subtract_matrix_rowsn(const Ref<MLPPMatrix> &B) const;
|
||||
void subtract_matrix_rowsb(const Ref<MLPPVector> &a, const Ref<MLPPMatrix> &B);
|
||||
|
||||
// This multiplies a, bT
|
||||
Ref<MLPPMatrix> outer_product(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> outer_product(const Ref<MLPPVector> &b) const;
|
||||
|
||||
// as_diagonal_matrix / to_diagonal_matrix
|
||||
Ref<MLPPMatrix> diagnm();
|
||||
Ref<MLPPMatrix> diagnm() const;
|
||||
|
||||
String to_string();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user