Arithmetic Matrix Operations



Zero Matrix / Identity Matrix

Zero Matrix and Identity Matrix.

It is convenient to have routines to initialize a matrix either to a zero matrix or the identity matrix.

The function for setting a real matrix to the zero matrix is Zero_Matrix( ) and the function for setting a complex matrix to the zero matrix is Zero_CMatrix( ). The function for setting a square n×n real matrix to the identity matrix is Identity_Matrix( ) and the function or setting a square n×n complex matrix to the identity matrix is Identity_CMatrix( ). There are also special routines for setting a matrix to a identity matrix stored in upper triangular form or lower triangular form.

Function List

  • void Zero_Matrix( double *A, int nrows, int ncols )

    Set the nrows×ncols matrix A to the zero matrix, i.e. A[i] [j] = 0 for all i, j.

  • void Identity_Matrix( double *A, int n )

    Set the square n×n matrix A to the identity matrix, i.e. A[i][j] = 0 if i ≠ j and A[i][i] = 1 otherwise.

  • void Identity_Matrix_ut( double *A, int n )

    Set the square n×n matrix A stored in upper triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

  • void Identity_Matrix_lt( double *A, int n )

    Set the square n×n matrix A stored in lower triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

  • void Zero_CMatrix( double complex *A, int nrows, int ncols )

    Set the nrows×ncols complex matrix A to the zero matrix, i.e. A[i] [j] = 0+0i for all i, j.

  • void Identity_CMatrix( double complex *A, int n )

    Set the square n×n complex matrix A to the identity matrix, i.e. A[i][j] = 0+0i if i ≠ j and A[i][i] = 1+0i otherwise.

  • void Identity_CMatrix_ut( double complex *A, int n )

    Set the square n×n complex matrix A stored in upper triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

  • void Identity_CMatrix_lt( double complex *A, int n )

    Set the square n×n complex matrix A stored in lower triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

C Source Code

C Test Code, Test Results, and Build Shell Script

  • The file, testzeromatrix_C.c, contains a test program of Zero_Matrix( ). This test program requires the file zero_matrix.c listed above.

  • The file, ZeroMatrix_CTest.txt, contains the results of the test program testzeromatrix_C.c.

  • The file, testzeromatrix_C.sh, contains the shell script used to compile, link, and execute the test program testzeromatrix_C.c.


  • The file, testidentity_C.c, contains a test program of Identity_Matrix( ). This test program requires the file identity_matrix.c listed above.

  • The file, IdentityMatrixTests_C.txt, contains the results of the test program testidentity_C.c.

  • The file, testidentity_C.sh, contains the shell script used to compile, link, and execute the test program testidentity_C.c.


  • The file, testidentity_ut_C.c, contains a test program of Identity_Matrix_ut( ). This test program requires the file identity_matrix_ut.c listed above.

  • The file, IdentityMatrixUTTests_C.txt, contains the results of the test program testidentity_ut_C.c.

  • The file, testidentity_ut_C.sh, contains the shell script used to compile, link, and execute the test program testidentity_ut_C.c.


  • The file, testidentity_lt_C.c, contains a test program of Identity_Matrix_lt( ). This test program requires the file identity_matrix_lt.c listed above.

  • The file, IdentityMatrixLTTests_C.txt, contains the results of the test program testidentity_lt_C.c.

  • The file, testidentity_lt_C.sh, contains the shell script used to compile, link, and execute the test program testidentity_lt_C.c.


  • The file, testzerocmatrix.c, contains a test program of Zero_CMatrix( ). This test program requires the file zero_cmatrix.c listed above.

  • The file, ZeroCMatrixTest.txt, contains the results of the test program ttestzerocmatrix.c.

  • The file, testzerocmatrix.sh, contains the shell script used to compile, link, and execute the test program testzerocmatrix.c.


  • The file, testidentitycmatrix.c, contains a test program of Identity_CMatrix( ). This test program requires the file identity_cmatrix.c listed above.

  • The file, IdentityCMatrixTests.txt, contains the results of the test program testidentitycmatrix.c.

  • The file, testidentitycmatrix.sh, contains the shell script used to compile, link, and execute the test program testidentitycmatrix.c.


  • The file, testidentitycmatrixut.c, contains a test program of Identity_CMatrix_ut( ). This test program requires the file identity_cmatrix_ut.c listed above.

  • The file, IdentityCMatrixUTTests.txt, contains the results of the test program testidentitycmatrixut.c.

  • The file, testidentitycmatrixut.sh, contains the shell script used to compile, link, and execute the test program testidentitycmatrixut.c.


  • The file, testidentitycmatrixlt.c, contains a test program of Identity_CMatrix_lt( ). This test program requires the file identity_cmatrix_lt.c listed above.

  • The file, IdentityCMatrixLTTests.txt, contains the results of the test program testidentitycmatrixlt.c.

  • The file, testidentitycmatrixlt.sh, contains the shell script used to compile, link, and execute the test program testidentitycmatrixlt.c.

NASM Source Code
For Linux gcc Users

NASM Test Code, Test Results, and Build Shell Script

  • The file, testzeromatrix_A.c, contains a test program of Zero_Matrix( ). This test program requires the file zero_matrix.asm listed above.

  • The file, ZeroMatrix_ATest.txt, contains the results of the test program testzeromatrix_A.c.

  • The file, testzeromatrix_A.sh, contains the shell script used to compile, link, and execute the test program testzeromatrix_A.c.


  • The file, testidentity_A.c, contains a test program of Identity_Matrix( ). This test program requires the file identity_matrix.asm listed above.

  • The file, IdentityMatrixTests_A.txt, contains the results of the test program testidentity_A.c.

  • The file, testidentity_A.sh, contains the shell script used to compile, link, and execute the test program testidentity_A.c.


  • The file, testidentity_ut_A.c, contains a test program of Identity_Matrix_ut( ). This test program requires the file identity_matrix_ut.asm listed above.

  • The file, IdentityMatrixUTTests_A.txt, contains the results of the test program testidentity_ut_A.c.

  • The file, testidentity_ut_A.sh, contains the shell script used to compile, link, and execute the test program testidentity_ut_A.c.


  • The file, testidentity_lt_A.c, contains a test program of Identity_Matrix_lt( ). This test program requires the file identity_matrix_lt.asm listed above.

  • The file, IdentityMatrixLTTests_A.txt, contains the results of the test program testidentity_lt_A.c.

  • The file, testidentity_lt_A.sh, contains the shell script used to compile, link, and execute the test program testidentity_lt_A.c.

Timing For Zero_Matrix
Number of Clock Cycles

Routine3 × 4
Matrix
zero_matrix.c105
zero_matrix.asm38

Timing For Identity_Matrix
Number of Clock Cycles

Routine3 × 3
Matrix
identity_matrix.c66
identity_matrix.asm28

Timing For Identity_Matrix_ut
Number of Clock Cycles

Routine2 × 2
Matrix
3 × 3
Matrix
4 × 4
Matrix
identity_matrix_ut.c194785
identity_matrix_ut.asm0*1938
*Time within time variation of calling time stamp.

Timing For Identity_Matrix_lt
Number of Clock Cycles

Routine2 × 2
Matrix
3 × 3
Matrix
4 × 4
Matrix
identity_matrix_lt.c194785
identity_matrix_lt.asm0*1938
*Time within time variation of calling time stamp.