Contains macros and function definitions for common matrix operations.
More...
#include <stdio.h>
Go to the source code of this file.
|
#define | _MatrixZero_(A, N) |
|
#define | _MatrixMultiply_(A, B, C, N) |
|
#define | _MatrixMultiplyNonSquare_(A, B, C, NRowA, NColA, NColB) |
|
#define | _MatrixMultiplySubtract_(C, A, B, N) |
|
#define | _MatVecMultiply_(A, x, y, N) |
|
#define | _MatVecMultiplySubtract_(y, A, x, N) |
|
#define | _MatrixInvert_(A, B, N) |
|
Contains macros and function definitions for common matrix operations.
- Author
- Debojyoti Ghosh
Definition in file matops.h.
#define _MatrixZero_ |
( |
|
A, |
|
|
|
N |
|
) |
| |
Value:{ \
int arraycounter; \
for (arraycounter=0; arraycounter<(N)*(N); arraycounter++) *((A)+arraycounter) = 0.0; \
}
Set all elements of the square matrix A of size N to 0, stored as a 1D array in row-major format.
Definition at line 12 of file matops.h.
#define _MatrixMultiply_ |
( |
|
A, |
|
|
|
B, |
|
|
|
C, |
|
|
|
N |
|
) |
| |
Value:{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(N); matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) { \
*((C)+matopsi*(N)+matopsj) = 0; \
for (matopsk=0; matopsk<(N); matopsk++) *((C)+matopsi*(N)+matopsj) += ((*((A)+matopsi*(N)+matopsk)) * (*((B)+matopsk*(N)+matopsj))); \
} \
}
C = A B, where A, B, C are square matrices of size N, stored as 1D arrays in row major format.
Definition at line 22 of file matops.h.
#define _MatrixMultiplyNonSquare_ |
( |
|
A, |
|
|
|
B, |
|
|
|
C, |
|
|
|
NRowA, |
|
|
|
NColA, |
|
|
|
NColB |
|
) |
| |
Value:{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(NRowA); matopsi++) \
for (matopsj=0; matopsj<(NColB); matopsj++) { \
*((C)+matopsi*(NColB)+matopsj) = 0; \
for (matopsk=0; matopsk<(NColA); matopsk++) *((C)+matopsi*(NColB)+matopsj) += ((*((A)+matopsi*(NColA)+matopsk)) * (*((B)+matopsk*(NColB)+matopsj))); \
} \
}
C = A B where A is a NRowA X NColA matrix, B is a NColA X NColB matrix, and C is a NRowA X NColB matrix. All matrices are stored as 1D arrays in row-major format.
Definition at line 37 of file matops.h.
#define _MatrixMultiplySubtract_ |
( |
|
C, |
|
|
|
A, |
|
|
|
B, |
|
|
|
N |
|
) |
| |
Value:{ \
int matopsi,matopsj,matopsk; \
for (matopsi=0; matopsi<(N); matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) \
for (matopsk=0; matopsk<(N); matopsk++) *((C)+matopsi*(N)+matopsj) -= ((*((A)+matopsi*(N)+matopsk)) * (*((B)+matopsk*(N)+matopsj))); \
} \
C = C - A B, where A, B, C are square matrices of size N, saved as 1D arrays in row-major format.
Definition at line 51 of file matops.h.
#define _MatVecMultiply_ |
( |
|
A, |
|
|
|
x, |
|
|
|
y, |
|
|
|
N |
|
) |
| |
Value:{ \
int matopsi,matopsj; \
for (matopsi=0; matopsi<(N); matopsi++) { \
*((y)+matopsi) = 0; \
for (matopsj=0; matopsj<(N); matopsj++) *((y)+matopsi) += (*((A)+matopsi*N+matopsj) * *((x)+matopsj)); \
} \
}
y = A x, where x, y are vectors of size N, and A is a square matrix of size N stored as a 1D array in row major format.
Definition at line 64 of file matops.h.
#define _MatVecMultiplySubtract_ |
( |
|
y, |
|
|
|
A, |
|
|
|
x, |
|
|
|
N |
|
) |
| |
Value:{ \
int matopsi,matopsj; \
for (matopsi=0; matopsi<N; matopsi++) \
for (matopsj=0; matopsj<(N); matopsj++) *((y)+matopsi) -= (*((A)+matopsi*N+matopsj) * *((x)+matopsj)); \
}
y = y - A x, where x, y are vectors of size N, and A is a square matrix of size N stored as a 1D array in row major format.
Definition at line 78 of file matops.h.
#define _MatrixInvert_ |
( |
|
A, |
|
|
|
B, |
|
|
|
N |
|
) |
| |
B =A^{-1} (Inverse of A), where A, B are square matrices of size N stored as 1D arrays in row-major format. Uses LU decomposition. If A is singular, B will contain NaN or Inf.
Definition at line 90 of file matops.h.