From 1718f33c842267ead2ffbfbe3c78a02ce6ed70b6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 26 Jan 2023 17:16:16 +0100 Subject: [PATCH] Rename _size to _data_size in MLPPMatrix. --- mlpp/lin_alg/mlpp_matrix.h | 105 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 6562a81..a39e847 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -6,6 +6,7 @@ #include "core/containers/vector.h" #include "core/error/error_macros.h" #include "core/os/memory.h" +#include "core/math/vector2i.h" #include "core/object/reference.h" @@ -24,38 +25,38 @@ public: } _FORCE_INLINE_ void push_back(double p_elem) { - ++_size; + ++_data_size; - _data = (double *)memrealloc(_data, _size * sizeof(double)); + _data = (double *)memrealloc(_data, _data_size * sizeof(double)); CRASH_COND_MSG(!_data, "Out of memory"); - _data[_size - 1] = p_elem; + _data[_data_size - 1] = p_elem; } void remove(double p_index) { - ERR_FAIL_INDEX(p_index, _size); + ERR_FAIL_INDEX(p_index, _data_size); - --_size; + --_data_size; - for (int i = p_index; i < _size; i++) { + for (int i = p_index; i < _data_size; i++) { _data[i] = _data[i + 1]; } - _data = (double *)memrealloc(_data, _size * sizeof(double)); + _data = (double *)memrealloc(_data, _data_size * sizeof(double)); CRASH_COND_MSG(!_data, "Out of memory"); } // Removes the item copying the last value into the position of the one to // remove. It's generally faster than `remove`. void remove_unordered(int p_index) { - ERR_FAIL_INDEX(p_index, _size); - _size--; + ERR_FAIL_INDEX(p_index, _data_size); + _data_size--; - if (_size > p_index) { - _data[p_index] = _data[_size]; + if (_data_size > p_index) { + _data[p_index] = _data[_data_size]; } - _data = (double *)memrealloc(_data, _size * sizeof(double)); + _data = (double *)memrealloc(_data, _data_size * sizeof(double)); CRASH_COND_MSG(!_data, "Out of memory"); } @@ -83,8 +84,8 @@ public: } void invert() { - for (int i = 0; i < _size / 2; i++) { - SWAP(_data[i], _data[_size - i - 1]); + for (int i = 0; i < _data_size / 2; i++) { + SWAP(_data[i], _data[_data_size - i - 1]); } } @@ -94,66 +95,66 @@ public: if (_data) { memfree(_data); _data = NULL; - _size = 0; + _data_size = 0; } } - _FORCE_INLINE_ bool empty() const { return _size == 0; } - _FORCE_INLINE_ int size() const { return _size; } + _FORCE_INLINE_ bool empty() const { return _data_size == 0; } + _FORCE_INLINE_ int size() const { return _data_size; } void resize(int p_size) { - _size = p_size; + _data_size = p_size; - _data = (double *)memrealloc(_data, _size * sizeof(double)); + _data = (double *)memrealloc(_data, _data_size * sizeof(double)); CRASH_COND_MSG(!_data, "Out of memory"); } _FORCE_INLINE_ const double &operator[](int p_index) const { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); return _data[p_index]; } _FORCE_INLINE_ double &operator[](int p_index) { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); return _data[p_index]; } _FORCE_INLINE_ double get_element(int p_index) const { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); return _data[p_index]; } _FORCE_INLINE_ double get_element(int p_index) { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); return _data[p_index]; } _FORCE_INLINE_ real_t get_element_bind(int p_index) const { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); return static_cast(_data[p_index]); } _FORCE_INLINE_ void set_element(int p_index, double p_val) { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); _data[p_index] = p_val; } _FORCE_INLINE_ void set_element_bind(int p_index, real_t p_val) { - CRASH_BAD_UNSIGNED_INDEX(p_index, _size); + CRASH_BAD_UNSIGNED_INDEX(p_index, _data_size); _data[p_index] = p_val; } void fill(double p_val) { - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = p_val; } } void insert(int p_pos, double p_val) { - ERR_FAIL_INDEX(p_pos, _size + 1); - if (p_pos == _size) { + ERR_FAIL_INDEX(p_pos, _data_size + 1); + if (p_pos == _data_size) { push_back(p_val); } else { - resize(_size + 1); - for (int i = _size - 1; i > p_pos; i--) { + resize(_data_size + 1); + for (int i = _data_size - 1; i > p_pos; i--) { _data[i] = _data[i - 1]; } _data[p_pos] = p_val; @@ -161,7 +162,7 @@ public: } int find(const double &p_val, int p_from = 0) const { - for (int i = p_from; i < _size; i++) { + for (int i = p_from; i < _data_size; i++) { if (_data[i] == p_val) { return i; } @@ -171,7 +172,7 @@ public: template void sort_custom() { - int len = _size; + int len = _data_size; if (len == 0) { return; } @@ -186,7 +187,7 @@ public: void ordered_insert(double p_val) { int i; - for (i = 0; i < _size; i++) { + for (i = 0; i < _data_size; i++) { if (p_val < _data[i]) { break; } @@ -198,7 +199,7 @@ public: Vector ret; ret.resize(size()); double *w = ret.ptrw(); - memcpy(w, _data, sizeof(double) * _size); + memcpy(w, _data, sizeof(double) * _data_size); return ret; } @@ -218,9 +219,9 @@ public: Vector to_byte_array() const { Vector ret; - ret.resize(_size * sizeof(double)); + ret.resize(_data_size * sizeof(double)); uint8_t *w = ret.ptrw(); - memcpy(w, _data, sizeof(double) * _size); + memcpy(w, _data, sizeof(double) * _data_size); return ret; } @@ -235,7 +236,7 @@ public: _FORCE_INLINE_ void set_from_mlpp_matrixr(const MLPPMatrix &p_from) { resize(p_from.size()); - for (int i = 0; i < p_from._size; i++) { + for (int i = 0; i < p_from._data_size; i++) { _data[i] = p_from._data[i]; } } @@ -259,7 +260,7 @@ public: _FORCE_INLINE_ void set_from_vector(const Vector &p_from) { resize(p_from.size()); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = p_from[i]; } } @@ -267,42 +268,42 @@ public: _FORCE_INLINE_ void set_from_pool_vector(const PoolRealArray &p_from) { resize(p_from.size()); typename PoolRealArray::Read r = p_from.read(); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = r[i]; } } _FORCE_INLINE_ MLPPMatrix() { - _size = 0; + _data_size = 0; _data = NULL; } _FORCE_INLINE_ MLPPMatrix(const MLPPMatrix &p_from) { - _size = 0; + _data_size = 0; _data = NULL; resize(p_from.size()); - for (int i = 0; i < p_from._size; i++) { + for (int i = 0; i < p_from._data_size; i++) { _data[i] = p_from._data[i]; } } MLPPMatrix(const Vector &p_from) { - _size = 0; + _data_size = 0; _data = NULL; resize(p_from.size()); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = p_from[i]; } } MLPPMatrix(const PoolRealArray &p_from) { - _size = 0; + _data_size = 0; _data = NULL; resize(p_from.size()); typename PoolRealArray::Read r = p_from.read(); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = r[i]; } } @@ -318,23 +319,23 @@ public: std::vector ret; ret.resize(size()); double *w = &ret[0]; - memcpy(w, _data, sizeof(double) * _size); + memcpy(w, _data, sizeof(double) * _data_size); return ret; } _FORCE_INLINE_ void set_from_std_vector(const std::vector &p_from) { resize(p_from.size()); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = p_from[i]; } } MLPPMatrix(const std::vector &p_from) { - _size = 0; + _data_size = 0; _data = NULL; resize(p_from.size()); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < _data_size; i++) { _data[i] = p_from[i]; } } @@ -343,7 +344,7 @@ protected: static void _bind_methods(); protected: - int _size; + int _data_size; double *_data; };