mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-02-07 17:55:54 +01:00
Added new helper methods to MLPPMatrix and MLPPVector.
This commit is contained in:
parent
e5810cda01
commit
f59b092d10
@ -24,6 +24,9 @@ String MLPPMatrix::to_string() {
|
|||||||
|
|
||||||
void MLPPMatrix::_bind_methods() {
|
void MLPPMatrix::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("add_row", "row"), &MLPPMatrix::add_row_pool_vector);
|
ClassDB::bind_method(D_METHOD("add_row", "row"), &MLPPMatrix::add_row_pool_vector);
|
||||||
|
ClassDB::bind_method(D_METHOD("add_row_mlpp_vector", "row"), &MLPPMatrix::add_row_mlpp_vector);
|
||||||
|
ClassDB::bind_method(D_METHOD("add_rows_mlpp_matrix", "other"), &MLPPMatrix::add_rows_mlpp_matrix);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("remove_row", "index"), &MLPPMatrix::remove_row);
|
ClassDB::bind_method(D_METHOD("remove_row", "index"), &MLPPMatrix::remove_row);
|
||||||
ClassDB::bind_method(D_METHOD("remove_row_unordered", "index"), &MLPPMatrix::remove_row_unordered);
|
ClassDB::bind_method(D_METHOD("remove_row_unordered", "index"), &MLPPMatrix::remove_row_unordered);
|
||||||
ClassDB::bind_method(D_METHOD("swap_row", "index_1", "index_2"), &MLPPMatrix::swap_row);
|
ClassDB::bind_method(D_METHOD("swap_row", "index_1", "index_2"), &MLPPMatrix::swap_row);
|
||||||
|
@ -30,6 +30,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ void add_row(const Vector<real_t> &p_row) {
|
_FORCE_INLINE_ void add_row(const Vector<real_t> &p_row) {
|
||||||
|
if (p_row.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_size.x == 0) {
|
if (_size.x == 0) {
|
||||||
_size.x = p_row.size();
|
_size.x = p_row.size();
|
||||||
}
|
}
|
||||||
@ -51,6 +55,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ void add_row_pool_vector(const PoolRealArray &p_row) {
|
_FORCE_INLINE_ void add_row_pool_vector(const PoolRealArray &p_row) {
|
||||||
|
if (p_row.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_size.x == 0) {
|
if (_size.x == 0) {
|
||||||
_size.x = p_row.size();
|
_size.x = p_row.size();
|
||||||
}
|
}
|
||||||
@ -72,6 +80,66 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void add_row_mlpp_vector(const Ref<MLPPVector> &p_row) {
|
||||||
|
ERR_FAIL_COND(!p_row.is_valid());
|
||||||
|
|
||||||
|
int p_row_size = p_row->size();
|
||||||
|
|
||||||
|
if (p_row_size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_size.x == 0) {
|
||||||
|
_size.x = p_row_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
ERR_FAIL_COND(_size.x != p_row_size);
|
||||||
|
|
||||||
|
int ci = data_size();
|
||||||
|
|
||||||
|
++_size.y;
|
||||||
|
|
||||||
|
_data = (real_t *)memrealloc(_data, data_size() * sizeof(real_t));
|
||||||
|
CRASH_COND_MSG(!_data, "Out of memory");
|
||||||
|
|
||||||
|
const real_t *row_ptr = p_row->ptr();
|
||||||
|
|
||||||
|
for (int i = 0; i < p_row_size; ++i) {
|
||||||
|
_data[ci + i] = row_ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void add_rows_mlpp_matrix(const Ref<MLPPMatrix> &p_other) {
|
||||||
|
ERR_FAIL_COND(!p_other.is_valid());
|
||||||
|
|
||||||
|
int other_data_size = p_other->data_size();
|
||||||
|
|
||||||
|
if (other_data_size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size2i other_size = p_other->size();
|
||||||
|
|
||||||
|
if (_size.x == 0) {
|
||||||
|
_size.x = other_size.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
ERR_FAIL_COND(other_size.x != _size.x);
|
||||||
|
|
||||||
|
int start_offset = data_size();
|
||||||
|
|
||||||
|
_size.y += other_size.y;
|
||||||
|
|
||||||
|
_data = (real_t *)memrealloc(_data, data_size() * sizeof(real_t));
|
||||||
|
CRASH_COND_MSG(!_data, "Out of memory");
|
||||||
|
|
||||||
|
const real_t *other_ptr = p_other->ptr();
|
||||||
|
|
||||||
|
for (int i = 0; i < other_data_size; ++i) {
|
||||||
|
_data[start_offset + i] = other_ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void remove_row(real_t p_index) {
|
void remove_row(real_t p_index) {
|
||||||
ERR_FAIL_INDEX(p_index, _size.y);
|
ERR_FAIL_INDEX(p_index, _size.y);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ String MLPPVector::to_string() {
|
|||||||
|
|
||||||
void MLPPVector::_bind_methods() {
|
void MLPPVector::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("push_back", "elem"), &MLPPVector::push_back);
|
ClassDB::bind_method(D_METHOD("push_back", "elem"), &MLPPVector::push_back);
|
||||||
|
ClassDB::bind_method(D_METHOD("add_mlpp_vector", "other"), &MLPPVector::push_back);
|
||||||
ClassDB::bind_method(D_METHOD("remove", "index"), &MLPPVector::remove);
|
ClassDB::bind_method(D_METHOD("remove", "index"), &MLPPVector::remove);
|
||||||
ClassDB::bind_method(D_METHOD("remove_unordered", "index"), &MLPPVector::remove_unordered);
|
ClassDB::bind_method(D_METHOD("remove_unordered", "index"), &MLPPVector::remove_unordered);
|
||||||
ClassDB::bind_method(D_METHOD("erase", "val"), &MLPPVector::erase);
|
ClassDB::bind_method(D_METHOD("erase", "val"), &MLPPVector::erase);
|
||||||
|
@ -36,6 +36,29 @@ public:
|
|||||||
_data[_size - 1] = p_elem;
|
_data[_size - 1] = p_elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_FORCE_INLINE_ void add_mlpp_vector(const Ref<MLPPVector> &p_other) {
|
||||||
|
ERR_FAIL_COND(!p_other.is_valid());
|
||||||
|
|
||||||
|
int other_size = p_other->size();
|
||||||
|
|
||||||
|
if (other_size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int start_offset = _size;
|
||||||
|
|
||||||
|
_size += other_size;
|
||||||
|
|
||||||
|
_data = (real_t *)memrealloc(_data, _size * sizeof(real_t));
|
||||||
|
CRASH_COND_MSG(!_data, "Out of memory");
|
||||||
|
|
||||||
|
const real_t *other_ptr = p_other->ptr();
|
||||||
|
|
||||||
|
for (int i = 0; i < other_size; ++i) {
|
||||||
|
_data[start_offset + i] = other_ptr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void remove(real_t p_index) {
|
void remove(real_t p_index) {
|
||||||
ERR_FAIL_INDEX(p_index, _size);
|
ERR_FAIL_INDEX(p_index, _size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user