Added an index based getter and setter to Tensor3 and Matrix.

This commit is contained in:
Relintai 2023-04-16 20:38:50 +02:00
parent 90dbd6657e
commit 33ac510e6f
4 changed files with 30 additions and 0 deletions

View File

@ -112,6 +112,9 @@ void MLPPMatrix::_bind_methods() {
ClassDB::bind_method(D_METHOD("resize", "size"), &MLPPMatrix::resize);
ClassDB::bind_method(D_METHOD("get_element_index", "index"), &MLPPMatrix::get_element_index);
ClassDB::bind_method(D_METHOD("set_element_index", "index", "val"), &MLPPMatrix::set_element_index);
ClassDB::bind_method(D_METHOD("get_element", "index_x", "index_y"), &MLPPMatrix::get_element);
ClassDB::bind_method(D_METHOD("set_element", "index_x", "index_y", "val"), &MLPPMatrix::set_element);

View File

@ -240,6 +240,18 @@ public:
return _data[p_index];
}
_FORCE_INLINE_ real_t get_element_index(int p_index) const {
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
return _data[p_index];
}
_FORCE_INLINE_ void set_element_index(int p_index, real_t p_val) {
ERR_FAIL_INDEX(p_index, data_size());
_data[p_index] = p_val;
}
_FORCE_INLINE_ real_t get_element(int p_index_y, int p_index_x) const {
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);

View File

@ -129,6 +129,9 @@ void MLPPTensor3::_bind_methods() {
ClassDB::bind_method(D_METHOD("resize", "size"), &MLPPTensor3::resize);
ClassDB::bind_method(D_METHOD("get_element_index", "index"), &MLPPTensor3::get_element_index);
ClassDB::bind_method(D_METHOD("set_element_index", "index", "val"), &MLPPTensor3::set_element_index);
ClassDB::bind_method(D_METHOD("get_element", "index_x", "index_y"), &MLPPTensor3::get_element);
ClassDB::bind_method(D_METHOD("set_element", "index_x", "index_y", "val"), &MLPPTensor3::set_element);

View File

@ -243,6 +243,18 @@ public:
return _data[p_index];
}
_FORCE_INLINE_ real_t get_element_index(int p_index) const {
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
return _data[p_index];
}
_FORCE_INLINE_ void set_element_index(int p_index, real_t p_val) {
ERR_FAIL_INDEX(p_index, data_size());
_data[p_index] = p_val;
}
_FORCE_INLINE_ real_t get_element(int p_index_y, int p_index_x, int p_index_z) const {
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);