From dfee5107786a839396943e73dff26a16fe8837a5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 25 Oct 2023 00:53:41 +0200 Subject: [PATCH] Added a new helper method to MLPPMatrix. --- mlpp/lin_alg/mlpp_matrix.cpp | 24 ++++++++++++++++++++++++ mlpp/lin_alg/mlpp_matrix.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/mlpp/lin_alg/mlpp_matrix.cpp b/mlpp/lin_alg/mlpp_matrix.cpp index fcc4941..f7a09e4 100644 --- a/mlpp/lin_alg/mlpp_matrix.cpp +++ b/mlpp/lin_alg/mlpp_matrix.cpp @@ -558,6 +558,18 @@ void MLPPMatrix::set_from_arrays(const Array &p_from) { } } +void MLPPMatrix::set_from_ptr(const real_t *p_from, const int p_size_y, const int p_size_x) { + _data = NULL; + + ERR_FAIL_COND(!p_from); + + resize(Size2i(p_size_x, p_size_y)); + int ds = data_size(); + for (int i = 0; i < ds; ++i) { + _data[i] = p_from[i]; + } +} + /* std::vector> MLPPMatrix::gramMatrix(std::vector> A) { return matmult(transpose(A), A); // AtA @@ -3005,6 +3017,18 @@ MLPPMatrix::MLPPMatrix(const Array &p_from) { set_from_arrays(p_from); } +MLPPMatrix::MLPPMatrix(const real_t *p_from, const int p_size_y, const int p_size_x) { + _data = NULL; + + ERR_FAIL_COND(!p_from); + + resize(Size2i(p_size_x, p_size_y)); + int ds = data_size(); + for (int i = 0; i < ds; ++i) { + _data[i] = p_from[i]; + } +} + MLPPMatrix::~MLPPMatrix() { if (_data) { reset(); diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 0e257d0..3c87b24 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -136,6 +136,7 @@ public: void set_from_mlpp_vectors_array(const Array &p_from); void set_from_vectors(const Vector> &p_from); void set_from_arrays(const Array &p_from); + void set_from_ptr(const real_t *p_from, const int p_size_y, const int p_size_x); //std::vector> gramMatrix(std::vector> A); //bool linearIndependenceChecker(std::vector> A); @@ -359,6 +360,7 @@ public: MLPPMatrix(const MLPPMatrix &p_from); MLPPMatrix(const Vector> &p_from); MLPPMatrix(const Array &p_from); + MLPPMatrix(const real_t *p_from, const int p_size_y, const int p_size_x); ~MLPPMatrix();