mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-12-21 14:56:47 +01:00
Simplified hadamard_product in MLPPMatrix.
This commit is contained in:
parent
9df031e10c
commit
81744cc460
@ -250,20 +250,21 @@ void MLPPMatrix::hadamard_product(const Ref<MLPPMatrix> &B) {
|
||||
ERR_FAIL_COND(!B.is_valid());
|
||||
ERR_FAIL_COND(_size != B->size());
|
||||
|
||||
int ds = data_size();
|
||||
|
||||
const real_t *b_ptr = B->ptr();
|
||||
real_t *c_ptr = ptrw();
|
||||
|
||||
for (int i = 0; i < _size.y; i++) {
|
||||
for (int j = 0; j < _size.x; j++) {
|
||||
int ind_i_j = calculate_index(i, j);
|
||||
c_ptr[ind_i_j] = c_ptr[ind_i_j] * b_ptr[ind_i_j];
|
||||
}
|
||||
for (int i = 0; i < ds; i++) {
|
||||
c_ptr[i] = c_ptr[i] * b_ptr[i];
|
||||
}
|
||||
}
|
||||
Ref<MLPPMatrix> MLPPMatrix::hadamard_productn(const Ref<MLPPMatrix> &B) const {
|
||||
ERR_FAIL_COND_V(!B.is_valid(), Ref<MLPPMatrix>());
|
||||
ERR_FAIL_COND_V(_size != B->size(), Ref<MLPPMatrix>());
|
||||
|
||||
int ds = data_size();
|
||||
|
||||
Ref<MLPPMatrix> C;
|
||||
C.instance();
|
||||
C->resize(_size);
|
||||
@ -272,11 +273,8 @@ Ref<MLPPMatrix> MLPPMatrix::hadamard_productn(const Ref<MLPPMatrix> &B) const {
|
||||
const real_t *b_ptr = B->ptr();
|
||||
real_t *c_ptr = C->ptrw();
|
||||
|
||||
for (int i = 0; i < _size.y; i++) {
|
||||
for (int j = 0; j < _size.x; j++) {
|
||||
int ind_i_j = calculate_index(i, j);
|
||||
c_ptr[ind_i_j] = a_ptr[ind_i_j] * b_ptr[ind_i_j];
|
||||
}
|
||||
for (int i = 0; i < ds; i++) {
|
||||
c_ptr[i] = a_ptr[i] * b_ptr[i];
|
||||
}
|
||||
|
||||
return C;
|
||||
@ -290,15 +288,14 @@ void MLPPMatrix::hadamard_productb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatri
|
||||
resize(a_size);
|
||||
}
|
||||
|
||||
int ds = data_size();
|
||||
|
||||
const real_t *a_ptr = A->ptr();
|
||||
const real_t *b_ptr = B->ptr();
|
||||
real_t *c_ptr = ptrw();
|
||||
|
||||
for (int i = 0; i < a_size.y; i++) {
|
||||
for (int j = 0; j < a_size.x; j++) {
|
||||
int ind_i_j = A->calculate_index(i, j);
|
||||
c_ptr[ind_i_j] = a_ptr[ind_i_j] * b_ptr[ind_i_j];
|
||||
}
|
||||
for (int i = 0; i < ds; i++) {
|
||||
c_ptr[i] = a_ptr[i] * b_ptr[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user