From cd5d84733c812e8111e075077c5e5fd50730400c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 29 Apr 2023 12:31:57 +0200 Subject: [PATCH] Now Vector, Matrix, and Tensor3 are resources. Renamed their duplicate() method to duplicate_fast(). --- mlpp/activation/activation.cpp | 8 ++++---- mlpp/lin_alg/lin_alg.cpp | 10 +++++----- mlpp/lin_alg/mlpp_matrix.cpp | 24 ++++++++++++------------ mlpp/lin_alg/mlpp_matrix.h | 8 ++++---- mlpp/lin_alg/mlpp_tensor3.cpp | 8 ++++---- mlpp/lin_alg/mlpp_tensor3.h | 8 ++++---- mlpp/lin_alg/mlpp_vector.cpp | 6 +++--- mlpp/lin_alg/mlpp_vector.h | 8 ++++---- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/mlpp/activation/activation.cpp b/mlpp/activation/activation.cpp index a480122..5645999 100644 --- a/mlpp/activation/activation.cpp +++ b/mlpp/activation/activation.cpp @@ -830,10 +830,10 @@ real_t MLPPActivation::linear_normr(real_t z) { return z; } Ref MLPPActivation::linear_normv(const Ref &z) { - return z->duplicate(); + return z->duplicate_fast(); } Ref MLPPActivation::linear_normm(const Ref &z) { - return z->duplicate(); + return z->duplicate_fast(); } real_t MLPPActivation::linear_derivr(real_t z) { @@ -1012,7 +1012,7 @@ Ref MLPPActivation::adj_softmax_normv(const Ref &z) { return softmax_normv(n); } Ref MLPPActivation::adj_softmax_normm(const Ref &z) { - Ref n = z->duplicate(); + Ref n = z->duplicate_fast(); Size2i size = z->size(); @@ -1057,7 +1057,7 @@ Ref MLPPActivation::adj_softmax_derivv(const Ref &z) { return adj_softmax_normv(n); } Ref MLPPActivation::adj_softmax_derivm(const Ref &z) { - Ref n = z->duplicate(); + Ref n = z->duplicate_fast(); Size2i size = z->size(); diff --git a/mlpp/lin_alg/lin_alg.cpp b/mlpp/lin_alg/lin_alg.cpp index 66346ef..79cdbef 100644 --- a/mlpp/lin_alg/lin_alg.cpp +++ b/mlpp/lin_alg/lin_alg.cpp @@ -235,7 +235,7 @@ Ref MLPPLinAlg::transposenm(const Ref &A) { return AT; } Ref MLPPLinAlg::scalar_multiplynm(real_t scalar, const Ref &A) { - Ref AN = A->duplicate(); + Ref AN = A->duplicate_fast(); Size2i a_size = AN->size(); real_t *an_ptr = AN->ptrw(); @@ -249,7 +249,7 @@ Ref MLPPLinAlg::scalar_multiplynm(real_t scalar, const Ref MLPPLinAlg::scalar_addnm(real_t scalar, const Ref &A) { - Ref AN = A->duplicate(); + Ref AN = A->duplicate_fast(); Size2i a_size = AN->size(); real_t *an_ptr = AN->ptrw(); @@ -802,7 +802,7 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(Ref A) { } while (!diagonal); - Ref a_new_prior = a_new->duplicate(); + Ref a_new_prior = a_new->duplicate_fast(); Size2i a_new_size = a_new->size(); @@ -825,7 +825,7 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(Ref A) { } } - Ref eigen_temp = eigenvectors->duplicate(); + Ref eigen_temp = eigenvectors->duplicate_fast(); Size2i eigenvectors_size = eigenvectors->size(); @@ -1689,7 +1689,7 @@ Ref MLPPLinAlg::mat_vec_multnv(const Ref &A, const Ref MLPPLinAlg::subtract_matrix_rowsnv(const Ref &a, const Ref &B) { - Ref c = a->duplicate(); + Ref c = a->duplicate_fast(); Size2i b_size = B->size(); diff --git a/mlpp/lin_alg/mlpp_matrix.cpp b/mlpp/lin_alg/mlpp_matrix.cpp index dfb1690..c143ea3 100644 --- a/mlpp/lin_alg/mlpp_matrix.cpp +++ b/mlpp/lin_alg/mlpp_matrix.cpp @@ -363,7 +363,7 @@ Vector MLPPMatrix::to_flat_byte_array() const { return ret; } -Ref MLPPMatrix::duplicate() const { +Ref MLPPMatrix::duplicate_fast() const { Ref ret; ret.instance(); @@ -673,7 +673,7 @@ void MLPPMatrix::mult(const Ref &B) { ERR_FAIL_COND(_size.x != b_size.y || _size.y != b_size.x); - Ref A = duplicate(); + Ref 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 &B) { Size2i a_size = size(); Size2i b_size = B->size(); - Ref A = duplicate(); + Ref 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 &A, const Ref A = duplicate(); + Ref 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::scalar_multiplyn(const real_t scalar) const { - Ref AN = duplicate(); + Ref 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::scalar_addn(const real_t scalar) const { - Ref AN = duplicate(); + Ref 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 a_new_prior = a_new->duplicate(); + Ref a_new_prior = a_new->duplicate_fast(); Size2i a_new_size = a_new->size(); @@ -2080,7 +2080,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigen() const { } } - Ref eigen_temp = eigenvectors->duplicate(); + Ref eigen_temp = eigenvectors->duplicate_fast(); Size2i eigenvectors_size = eigenvectors->size(); @@ -2197,7 +2197,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref &A) const { } while (!diagonal); - Ref a_new_prior = a_new->duplicate(); + Ref a_new_prior = a_new->duplicate_fast(); Size2i a_new_size = a_new->size(); @@ -2220,7 +2220,7 @@ MLPPMatrix::EigenResult MLPPMatrix::eigenb(const Ref &A) const { } } - Ref eigen_temp = eigenvectors->duplicate(); + Ref eigen_temp = eigenvectors->duplicate_fast(); Size2i eigenvectors_size = eigenvectors->size(); @@ -2682,7 +2682,7 @@ void MLPPMatrix::set_diagonal(const Ref &a) { Ref MLPPMatrix::set_diagonaln(const Ref &a) const { ERR_FAIL_COND_V(!a.is_valid(), Ref()); - Ref B = duplicate(); + Ref 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); diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 7242c76..c916fc7 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -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 to_flat_byte_array() const; - Ref duplicate() const; + Ref duplicate_fast() const; void set_from_mlpp_matrix(const Ref &p_from); void set_from_mlpp_matrixr(const MLPPMatrix &p_from); diff --git a/mlpp/lin_alg/mlpp_tensor3.cpp b/mlpp/lin_alg/mlpp_tensor3.cpp index 7c08c26..ecf418c 100644 --- a/mlpp/lin_alg/mlpp_tensor3.cpp +++ b/mlpp/lin_alg/mlpp_tensor3.cpp @@ -1541,7 +1541,7 @@ void MLPPTensor3::scalar_multiply(const real_t scalar) { } } Ref MLPPTensor3::scalar_multiplyn(const real_t scalar) const { - Ref AN = duplicate(); + Ref 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::scalar_addn(const real_t scalar) const { - Ref AN = duplicate(); + Ref AN = duplicate_fast(); int ds = AN->data_size(); real_t *an_ptr = AN->ptrw(); @@ -1878,7 +1878,7 @@ Vector MLPPTensor3::to_flat_byte_array() const { return ret; } -Ref MLPPTensor3::duplicate() const { +Ref MLPPTensor3::duplicate_fast() const { Ref 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); diff --git a/mlpp/lin_alg/mlpp_tensor3.h b/mlpp/lin_alg/mlpp_tensor3.h index 2f11813..53e8170 100644 --- a/mlpp/lin_alg/mlpp_tensor3.h +++ b/mlpp/lin_alg/mlpp_tensor3.h @@ -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 to_flat_byte_array() const; - Ref duplicate() const; + Ref duplicate_fast() const; void set_from_mlpp_tensor3(const Ref &p_from); void set_from_mlpp_tensor3r(const MLPPTensor3 &p_from); diff --git a/mlpp/lin_alg/mlpp_vector.cpp b/mlpp/lin_alg/mlpp_vector.cpp index 779d912..3e113b6 100644 --- a/mlpp/lin_alg/mlpp_vector.cpp +++ b/mlpp/lin_alg/mlpp_vector.cpp @@ -184,7 +184,7 @@ Vector MLPPVector::to_byte_array() const { return ret; } -Ref MLPPVector::duplicate() const { +Ref MLPPVector::duplicate_fast() const { Ref ret; ret.instance(); @@ -1178,7 +1178,7 @@ void MLPPVector::subtract_matrix_rows(const Ref &B) { } } Ref MLPPVector::subtract_matrix_rowsn(const Ref &B) const { - Ref c = duplicate(); + Ref 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); diff --git a/mlpp/lin_alg/mlpp_vector.h b/mlpp/lin_alg/mlpp_vector.h index 9f0f97b..3dc1ce3 100644 --- a/mlpp/lin_alg/mlpp_vector.h +++ b/mlpp/lin_alg/mlpp_vector.h @@ -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 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 to_byte_array() const; - Ref duplicate() const; + Ref duplicate_fast() const; void set_from_mlpp_vectorr(const MLPPVector &p_from); void set_from_mlpp_vector(const Ref &p_from);