mirror of
https://github.com/nasa/trick.git
synced 2025-03-23 04:25:28 +00:00
Add tweaks that speed up matrix multiplication routines. ref #386
This commit is contained in:
parent
86add82e35
commit
eef5b14fbf
trick_source/trick_utils/math/src
@ -1,25 +1,27 @@
|
||||
/*
|
||||
PURPOSE: (Matrix times Matrix)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))) */
|
||||
* PURPOSE: (Matrix times Matrix)
|
||||
* ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
* PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))
|
||||
* ((Robert McPhail) (CACI) (Feb 2017) (Updated algorithm)))
|
||||
*/
|
||||
|
||||
#include "trick/trick_math.h"
|
||||
|
||||
void matxmat(double **prod, /* Out: Product of the two matrices */
|
||||
double **mat1, /* In: Matrix 1 */
|
||||
double **mat2, /* In: Matrix 2 */
|
||||
int n)
|
||||
{ /* In: Array size */
|
||||
int n) { /* In: Array size */
|
||||
int i, j, k;
|
||||
double temp;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
prod[i][j] = 0.0;
|
||||
temp = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
prod[i][j] += mat1[i][k] * mat2[k][j];
|
||||
temp += mat1[i][k] * mat2[k][j];
|
||||
}
|
||||
prod[i][j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
/*
|
||||
PURPOSE: (Matrix times Matrix transpose)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))) */
|
||||
PURPOSE: (Matrix times Matrix transpose)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))
|
||||
((Robert McPhail) (CACI) (Feb 2017) (Updated algorithm))) */
|
||||
|
||||
#include "trick/trick_math.h"
|
||||
|
||||
void matxtrans(double **prod, /* Out: product of the two matrices */
|
||||
double **mat1, /* In: matrix 1 */
|
||||
double **mat2, /* In: matrix 2 */
|
||||
int n)
|
||||
{ /* In: array size */
|
||||
int n) { /* In: array size */
|
||||
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
prod[i][j] = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
prod[i][j] += mat1[i][k] * mat2[j][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
int i, j, k;
|
||||
double temp;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
temp = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
temp += mat1[i][k] * mat2[j][k];
|
||||
}
|
||||
prod[i][j] = temp;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1,28 +1,29 @@
|
||||
/*
|
||||
PURPOSE: (Matrix transpose times Matrix)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release)))
|
||||
*/
|
||||
PURPOSE: (Matrix transpose times Matrix)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))
|
||||
((Robert McPhail) (CACI) (Feb 2017) (Updated algorithm)))
|
||||
*/
|
||||
|
||||
#include "trick/trick_math.h"
|
||||
|
||||
void transxmat(double **prod, /* Out: Product of the two matrices */
|
||||
void transxmat(double **prod, /* Out: Product of the two matrices */
|
||||
double **mat1, /* In: Matrix 1 */
|
||||
double **mat2, /* In: Matrix 2 */
|
||||
int n)
|
||||
{ /* In: Array size */
|
||||
int n) { /* In: Array size */
|
||||
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
prod[i][j] = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
prod[i][j] += mat1[k][i] * mat2[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
int i, j, k;
|
||||
double temp;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
temp = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
temp += mat1[k][i] * mat2[k][j];
|
||||
}
|
||||
prod[i][j] = temp;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,28 +1,28 @@
|
||||
/*
|
||||
PURPOSE: (Matrix transpose times Matrix transpose)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release)))
|
||||
*/
|
||||
PURPOSE: (Matrix transpose times Matrix transpose)
|
||||
ASSUMPTIONS AND LIMITATIONS: ((Square matrix))
|
||||
PROGRAMMERS: (((Les Quiocho) (NASA/JSC) (Jan 1993) (v1.0) (Init Release))
|
||||
((Robert McPhail) (CACI) (Feb 2017) (Updated algorithm)))
|
||||
*/
|
||||
|
||||
#include "trick/trick_math.h"
|
||||
|
||||
void transxtrans(double **prod, /* Out: product of the two matrices */
|
||||
double **mat1, /* In: matrix 1 */
|
||||
double **mat2, /* In: matrix 2 */
|
||||
int n)
|
||||
{ /* In: array size */
|
||||
int n) { /* In: array size */
|
||||
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
prod[i][j] = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
prod[i][j] += mat1[k][i] * mat2[j][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
int i, j, k;
|
||||
double temp;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
temp = 0.0;
|
||||
for (k = 0; k < n; k++) {
|
||||
temp += mat1[k][i] * mat2[j][k];
|
||||
}
|
||||
prod[i][j] = temp;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user