Now Vector, Matrix, and Tensor3 are resources. Renamed their duplicate() method to duplicate_fast().

This commit is contained in:
Relintai 2023-04-29 12:31:57 +02:00
parent 149bf14094
commit cd5d84733c
8 changed files with 40 additions and 40 deletions

View File

@ -830,10 +830,10 @@ real_t MLPPActivation::linear_normr(real_t z) {
return z;
}
Ref<MLPPVector> MLPPActivation::linear_normv(const Ref<MLPPVector> &z) {
return z->duplicate();
return z->duplicate_fast();
}
Ref<MLPPMatrix> MLPPActivation::linear_normm(const Ref<MLPPMatrix> &z) {
return z->duplicate();
return z->duplicate_fast();
}
real_t MLPPActivation::linear_derivr(real_t z) {
@ -1012,7 +1012,7 @@ Ref<MLPPVector> MLPPActivation::adj_softmax_normv(const Ref<MLPPVector> &z) {
return softmax_normv(n);
}
Ref<MLPPMatrix> MLPPActivation::adj_softmax_normm(const Ref<MLPPMatrix> &z) {
Ref<MLPPMatrix> n = z->duplicate();
Ref<MLPPMatrix> n = z->duplicate_fast();
Size2i size = z->size();
@ -1057,7 +1057,7 @@ Ref<MLPPVector> MLPPActivation::adj_softmax_derivv(const Ref<MLPPVector> &z) {
return adj_softmax_normv(n);
}
Ref<MLPPMatrix> MLPPActivation::adj_softmax_derivm(const Ref<MLPPMatrix> &z) {
Ref<MLPPMatrix> n = z->duplicate();
Ref<MLPPMatrix> n = z->duplicate_fast();
Size2i size = z->size();

View File

@ -235,7 +235,7 @@ Ref<MLPPMatrix> MLPPLinAlg::transposenm(const Ref<MLPPMatrix> &A) {
return AT;
}
Ref<MLPPMatrix> MLPPLinAlg::scalar_multiplynm(real_t scalar, const Ref<MLPPMatrix> &A) {
Ref<MLPPMatrix> AN = A->duplicate();
Ref<MLPPMatrix> AN = A->duplicate_fast();
Size2i a_size = AN->size();
real_t *an_ptr = AN->ptrw();
@ -249,7 +249,7 @@ Ref<MLPPMatrix> MLPPLinAlg::scalar_multiplynm(real_t scalar, const Ref<MLPPMatri
}
Ref<MLPPMatrix> MLPPLinAlg::scalar_addnm(real_t scalar, const Ref<MLPPMatrix> &A) {
Ref<MLPPMatrix> AN = A->duplicate();
Ref<MLPPMatrix> AN = A->duplicate_fast();
Size2i a_size = AN->size();
real_t *an_ptr = AN->ptrw();
@ -802,7 +802,7 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(Ref<MLPPMatrix> A) {
} while (!diagonal);
Ref<MLPPMatrix> a_new_prior = a_new->duplicate();
Ref<MLPPMatrix> a_new_prior = a_new->duplicate_fast();
Size2i a_new_size = a_new->size();
@ -825,7 +825,7 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(Ref<MLPPMatrix> A) {
}
}
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate();
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate_fast();
Size2i eigenvectors_size = eigenvectors->size();
@ -1689,7 +1689,7 @@ Ref<MLPPVector> MLPPLinAlg::mat_vec_multnv(const Ref<MLPPMatrix> &A, const Ref<M
}
Ref<MLPPVector> MLPPLinAlg::subtract_matrix_rowsnv(const Ref<MLPPVector> &a, const Ref<MLPPMatrix> &B) {
Ref<MLPPVector> c = a->duplicate();
Ref<MLPPVector> c = a->duplicate_fast();
Size2i b_size = B->size();

View File

@ -363,7 +363,7 @@ Vector<uint8_t> MLPPMatrix::to_flat_byte_array() const {
return ret;
}
Ref<MLPPMatrix> MLPPMatrix::duplicate() const {
Ref<MLPPMatrix> MLPPMatrix::duplicate_fast() const {
Ref<MLPPMatrix> ret;
ret.instance();
@ -673,7 +673,7 @@ void MLPPMatrix::mult(const Ref<MLPPMatrix> &B) {
ERR_FAIL_COND(_size.x != b_size.y || _size.y != b_size.x);
Ref<MLPPMatrix> A = duplicate();
Ref<MLPPMatrix> A = duplicate_fast();
Size2i a_size = A->size();
Size2i rs = Size2i(b_size.x, a_size.y);
@ -840,7 +840,7 @@ void MLPPMatrix::kronecker_product(const Ref<MLPPMatrix> &B) {
Size2i a_size = size();
Size2i b_size = B->size();
Ref<MLPPMatrix> A = duplicate();
Ref<MLPPMatrix> A = duplicate_fast();
resize(Size2i(b_size.x * a_size.x, b_size.y * a_size.y));
@ -1008,7 +1008,7 @@ void MLPPMatrix::element_wise_divisionb(const Ref<MLPPMatrix> &A, const Ref<MLPP
}
void MLPPMatrix::transpose() {
Ref<MLPPMatrix> A = duplicate();
Ref<MLPPMatrix> A = duplicate_fast();
Size2i a_size = A->size();
resize(Size2i(a_size.y, a_size.x));
@ -1067,7 +1067,7 @@ void MLPPMatrix::scalar_multiply(const real_t scalar) {
}
}
Ref<MLPPMatrix> MLPPMatrix::scalar_multiplyn(const real_t scalar) const {
Ref<MLPPMatrix> AN = duplicate();
Ref<MLPPMatrix> AN = duplicate_fast();
int ds = AN->data_size();
real_t *an_ptr = AN->ptrw();
@ -1100,7 +1100,7 @@ void MLPPMatrix::scalar_add(const real_t scalar) {
}
}
Ref<MLPPMatrix> MLPPMatrix::scalar_addn(const real_t scalar) const {
Ref<MLPPMatrix> AN = duplicate();
Ref<MLPPMatrix> AN = duplicate_fast();
int ds = AN->data_size();
real_t *an_ptr = AN->ptrw();
@ -2057,7 +2057,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigen() const {
} while (!diagonal);
Ref<MLPPMatrix> a_new_prior = a_new->duplicate();
Ref<MLPPMatrix> a_new_prior = a_new->duplicate_fast();
Size2i a_new_size = a_new->size();
@ -2080,7 +2080,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigen() const {
}
}
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate();
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate_fast();
Size2i eigenvectors_size = eigenvectors->size();
@ -2197,7 +2197,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref<MLPPMatrix> &A) const {
} while (!diagonal);
Ref<MLPPMatrix> a_new_prior = a_new->duplicate();
Ref<MLPPMatrix> a_new_prior = a_new->duplicate_fast();
Size2i a_new_size = a_new->size();
@ -2220,7 +2220,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref<MLPPMatrix> &A) const {
}
}
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate();
Ref<MLPPMatrix> eigen_temp = eigenvectors->duplicate_fast();
Size2i eigenvectors_size = eigenvectors->size();
@ -2682,7 +2682,7 @@ void MLPPMatrix::set_diagonal(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();
Ref<MLPPMatrix> B = duplicate_fast();
int a_size = a->size();
int ms = MIN(_size.x, _size.y);
@ -2987,7 +2987,7 @@ void MLPPMatrix::_bind_methods() {
ClassDB::bind_method(D_METHOD("to_flat_pool_vector"), &MLPPMatrix::to_flat_pool_vector);
ClassDB::bind_method(D_METHOD("to_flat_byte_array"), &MLPPMatrix::to_flat_byte_array);
ClassDB::bind_method(D_METHOD("duplicate"), &MLPPMatrix::duplicate);
ClassDB::bind_method(D_METHOD("duplicate_fast"), &MLPPMatrix::duplicate_fast);
ClassDB::bind_method(D_METHOD("set_from_mlpp_vectors_array", "from"), &MLPPMatrix::set_from_mlpp_vectors_array);
ClassDB::bind_method(D_METHOD("set_from_arrays", "from"), &MLPPMatrix::set_from_arrays);

View File

@ -10,14 +10,14 @@
#include "core/math/vector2i.h"
#include "core/os/memory.h"
#include "core/object/reference.h"
#include "core/object/resource.h"
#include "mlpp_vector.h"
class Image;
class MLPPMatrix : public Reference {
GDCLASS(MLPPMatrix, Reference);
class MLPPMatrix : public Resource {
GDCLASS(MLPPMatrix, Resource);
public:
_FORCE_INLINE_ real_t *ptrw() {
@ -110,7 +110,7 @@ public:
PoolRealArray to_flat_pool_vector() const;
Vector<uint8_t> to_flat_byte_array() const;
Ref<MLPPMatrix> duplicate() const;
Ref<MLPPMatrix> duplicate_fast() const;
void set_from_mlpp_matrix(const Ref<MLPPMatrix> &p_from);
void set_from_mlpp_matrixr(const MLPPMatrix &p_from);

View File

@ -1541,7 +1541,7 @@ void MLPPTensor3::scalar_multiply(const real_t scalar) {
}
}
Ref<MLPPTensor3> MLPPTensor3::scalar_multiplyn(const real_t scalar) const {
Ref<MLPPTensor3> AN = duplicate();
Ref<MLPPTensor3> AN = duplicate_fast();
int ds = AN->data_size();
real_t *an_ptr = AN->ptrw();
@ -1574,7 +1574,7 @@ void MLPPTensor3::scalar_add(const real_t scalar) {
}
}
Ref<MLPPTensor3> MLPPTensor3::scalar_addn(const real_t scalar) const {
Ref<MLPPTensor3> AN = duplicate();
Ref<MLPPTensor3> AN = duplicate_fast();
int ds = AN->data_size();
real_t *an_ptr = AN->ptrw();
@ -1878,7 +1878,7 @@ Vector<uint8_t> MLPPTensor3::to_flat_byte_array() const {
return ret;
}
Ref<MLPPTensor3> MLPPTensor3::duplicate() const {
Ref<MLPPTensor3> MLPPTensor3::duplicate_fast() const {
Ref<MLPPTensor3> ret;
ret.instance();
@ -2311,7 +2311,7 @@ void MLPPTensor3::_bind_methods() {
ClassDB::bind_method(D_METHOD("to_flat_pool_vector"), &MLPPTensor3::to_flat_pool_vector);
ClassDB::bind_method(D_METHOD("to_flat_byte_array"), &MLPPTensor3::to_flat_byte_array);
ClassDB::bind_method(D_METHOD("duplicate"), &MLPPTensor3::duplicate);
ClassDB::bind_method(D_METHOD("duplicate_fast"), &MLPPTensor3::duplicate_fast);
ClassDB::bind_method(D_METHOD("set_from_mlpp_tensor3", "from"), &MLPPTensor3::set_from_mlpp_tensor3);
ClassDB::bind_method(D_METHOD("set_from_mlpp_matrix", "from"), &MLPPTensor3::set_from_mlpp_matrix);

View File

@ -10,15 +10,15 @@
#include "core/math/vector2i.h"
#include "core/os/memory.h"
#include "core/object/reference.h"
#include "core/object/resource.h"
#include "mlpp_matrix.h"
#include "mlpp_vector.h"
class Image;
class MLPPTensor3 : public Reference {
GDCLASS(MLPPTensor3, Reference);
class MLPPTensor3 : public Resource {
GDCLASS(MLPPTensor3, Resource);
public:
_FORCE_INLINE_ real_t *ptrw() {
@ -237,7 +237,7 @@ public:
PoolRealArray to_flat_pool_vector() const;
Vector<uint8_t> to_flat_byte_array() const;
Ref<MLPPTensor3> duplicate() const;
Ref<MLPPTensor3> duplicate_fast() const;
void set_from_mlpp_tensor3(const Ref<MLPPTensor3> &p_from);
void set_from_mlpp_tensor3r(const MLPPTensor3 &p_from);

View File

@ -184,7 +184,7 @@ Vector<uint8_t> MLPPVector::to_byte_array() const {
return ret;
}
Ref<MLPPVector> MLPPVector::duplicate() const {
Ref<MLPPVector> MLPPVector::duplicate_fast() const {
Ref<MLPPVector> ret;
ret.instance();
@ -1178,7 +1178,7 @@ void MLPPVector::subtract_matrix_rows(const Ref<MLPPMatrix> &B) {
}
}
Ref<MLPPVector> MLPPVector::subtract_matrix_rowsn(const Ref<MLPPMatrix> &B) const {
Ref<MLPPVector> c = duplicate();
Ref<MLPPVector> c = duplicate_fast();
Size2i b_size = B->size();
@ -1357,7 +1357,7 @@ void MLPPVector::_bind_methods() {
ClassDB::bind_method(D_METHOD("to_pool_vector"), &MLPPVector::to_pool_vector);
ClassDB::bind_method(D_METHOD("to_byte_array"), &MLPPVector::to_byte_array);
ClassDB::bind_method(D_METHOD("duplicate"), &MLPPVector::duplicate);
ClassDB::bind_method(D_METHOD("duplicate_fast"), &MLPPVector::duplicate_fast);
ClassDB::bind_method(D_METHOD("set_from_mlpp_vector", "from"), &MLPPVector::set_from_mlpp_vector);
ClassDB::bind_method(D_METHOD("set_from_pool_vector", "from"), &MLPPVector::set_from_pool_vector);

View File

@ -10,15 +10,15 @@
#include "core/error/error_macros.h"
#include "core/os/memory.h"
#include "core/object/reference.h"
#include "core/object/resource.h"
//REMOVE
#include <vector>
class MLPPMatrix;
class MLPPVector : public Reference {
GDCLASS(MLPPVector, Reference);
class MLPPVector : public Resource {
GDCLASS(MLPPVector, Resource);
public:
_FORCE_INLINE_ real_t *ptrw() {
@ -102,7 +102,7 @@ public:
PoolRealArray to_pool_vector() const;
Vector<uint8_t> to_byte_array() const;
Ref<MLPPVector> duplicate() const;
Ref<MLPPVector> duplicate_fast() const;
void set_from_mlpp_vectorr(const MLPPVector &p_from);
void set_from_mlpp_vector(const Ref<MLPPVector> &p_from);