From 711009b02df4835b5f921f7f00115cda9897c90c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 23 Apr 2023 11:53:57 +0200 Subject: [PATCH] Added matrix based getters and setters to Tensor3. --- mlpp/lin_alg/mlpp_tensor3.h | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/mlpp/lin_alg/mlpp_tensor3.h b/mlpp/lin_alg/mlpp_tensor3.h index 7df0fc9..f8b9e07 100644 --- a/mlpp/lin_alg/mlpp_tensor3.h +++ b/mlpp/lin_alg/mlpp_tensor3.h @@ -504,6 +504,50 @@ public: } } + _FORCE_INLINE_ Ref get_feature_map_mlpp_matrix(int p_index_z) { + ERR_FAIL_INDEX_V(p_index_z, _size.z, Ref()); + + Ref ret; + ret.instance(); + + int fmds = feature_map_data_size(); + + if (unlikely(fmds == 0)) { + return ret; + } + + ret->resize(feature_map_size()); + + int ind_start = calculate_feature_map_index(p_index_z); + + real_t *row_ptr = ret->ptrw(); + + for (int i = 0; i < fmds; ++i) { + row_ptr[i] = _data[ind_start + i]; + } + + return ret; + } + + _FORCE_INLINE_ void get_feature_map_into_mlpp_vector(int p_index_z, Ref target) const { + ERR_FAIL_INDEX(p_index_z, _size.z); + + int fmds = feature_map_data_size(); + Size2i fms = feature_map_size(); + + if (unlikely(target->size() != fms)) { + target->resize(fms); + } + + int ind_start = calculate_feature_map_index(p_index_z); + + real_t *row_ptr = target->ptrw(); + + for (int i = 0; i < fmds; ++i) { + row_ptr[i] = _data[ind_start + i]; + } + } + _FORCE_INLINE_ void set_feature_map_vector(int p_index_z, const Vector &p_row) { ERR_FAIL_INDEX(p_index_z, _size.z); @@ -554,6 +598,23 @@ public: } } + _FORCE_INLINE_ void set_feature_map_mlpp_matrix(int p_index_z, const Ref &p_mat) { + ERR_FAIL_INDEX(p_index_z, _size.z); + ERR_FAIL_COND(!p_mat.is_valid()); + + int fmds = feature_map_data_size(); + + ERR_FAIL_COND(p_mat->size() != feature_map_size()); + + int ind_start = calculate_feature_map_index(p_index_z); + + const real_t *row_ptr = p_mat->ptr(); + + for (int i = 0; i < fmds; ++i) { + _data[ind_start + i] = row_ptr[i]; + } + } + void fill(real_t p_val) { if (!_data) { return;