414 |
} |
} |
415 |
} |
} |
416 |
} |
} |
417 |
|
|
418 |
|
// General tensor product: arg_2(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR) |
419 |
|
// SM is the product of the last axis_offset entries in arg_0.getShape(). |
420 |
|
inline |
421 |
|
void matrix_matrix_product(const int SL, const int SM, const int SR, const double* A, const double* B, double* C, int transpose) |
422 |
|
{ |
423 |
|
if (transpose == 0) { |
424 |
|
for (int i=0; i<SL; i++) { |
425 |
|
for (int j=0; j<SR; j++) { |
426 |
|
double sum = 0.0; |
427 |
|
for (int l=0; l<SM; l++) { |
428 |
|
sum += A[i+SL*l] * B[l+SM*j]; |
429 |
|
} |
430 |
|
C[i+SL*j] = sum; |
431 |
|
} |
432 |
|
} |
433 |
|
} |
434 |
|
else if (transpose == 1) { |
435 |
|
for (int i=0; i<SL; i++) { |
436 |
|
for (int j=0; j<SR; j++) { |
437 |
|
double sum = 0.0; |
438 |
|
for (int l=0; l<SM; l++) { |
439 |
|
sum += A[i*SM+l] * B[l+SM*j]; |
440 |
|
} |
441 |
|
C[i+SL*j] = sum; |
442 |
|
} |
443 |
|
} |
444 |
|
} |
445 |
|
else if (transpose == 2) { |
446 |
|
for (int i=0; i<SL; i++) { |
447 |
|
for (int j=0; j<SR; j++) { |
448 |
|
double sum = 0.0; |
449 |
|
for (int l=0; l<SM; l++) { |
450 |
|
sum += A[i+SL*l] * B[l*SR+j]; |
451 |
|
} |
452 |
|
C[i+SL*j] = sum; |
453 |
|
} |
454 |
|
} |
455 |
|
} |
456 |
|
} |
457 |
|
|
458 |
} // end of namespace |
} // end of namespace |
459 |
#endif |
#endif |