# Arithmetic Matrix Operations

 Home Matrix Home Arithmetic Matrix Routines Home Matrix Addition / Subtraction Matrix Diagonal Add / Subract Scalar Matrix Multiply / Divide by Scalar Matrix Multiplication ATB, ABT, ATA, AAT [A,B] and {A, B} Row / Column Transform Row Sum / Column Sum / Trace Zero Matrix / Identity Matrix Direct Sum Bilinear Function / Kronecker

## Direct Sum.

The direct sum of the matrices A1,...,An is the matrix C = A1 ⊕ ... ⊕ An given by the matrix
C =
 ⌈ A1 0 ··· 0 ⌉ | 0 A2 ··· 0 | | ··· ··· ··· ··· | ⌊ 0 0 ··· An ⌋

### Function List

• void Direct_Sum( double *C, int nrows, int ncols, int number_of_summands, double *A1, int nrows1, int ncols1, ... , double *Am, int nrowsm, int ncolsm, double *Alast )

This routine initializes the nrows×ncols matrix C as the direct sum of number_of_summands matrices A1, … , Alast, where last = number_of_summands. The number of rows of C, nrows, is equal to the sum of the number of rows of the individual summands:
nrows = nrows1 + … + nrowsm + nrowslast,
and the number of columns of C, ncols, is equal to the sum of the number of columns of the individual summands:
ncols = ncols1 + … + ncolsm + ncolslast.

Note that the number of rows and columns of the last summand, Alast, are not arguments, but rather are calculated internally.

• void CDirect_Sum( double complex *C, int nrows, int ncols, int number_of_summands, double complex*A1, int nrows1, int ncols1, ... , double complex *Am, int nrowsm, int ncolsm, double complex *Alast )

This routine initializes the nrows×ncols matrix C as the direct sum of number_of_summands matrices A1, … , Alast, where last = number_of_summands. The number of rows of C, nrows, is equal to the sum of the number of rows of the individual summands:
nrows = nrows1 + … + nrowsm + nrowslast,
and the number of columns of C, ncols, is equal to the sum of the number of columns of the individual summands:
ncols = ncols1 + … + ncolsm + ncolslast.

Note that the number of rows and columns of the last summand, Alast, are not arguments, but rather are calculated internally.

#### C Source Code

• The file, direct_sum.c, contains the version of Direct_Sum( ) written in C.

• The file, cdirect_sum.c, contains the version of CDirect_Sum( ) written in C.

#### C Test Code, Test Results, and Build Shell Script

• The file, testdirectsum_C.c, contains a test program of Direct_Sum( ). This test program requires the file direct_sum.c listed above.

• The file, DirectSumTests_C.txt, contains the results of the test program testdirectsum_C.c.

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

• The file, testcdirectsum.c, contains a test program of CDirect_Sum( ). This test program requires the file cdirect_sum.c listed above.

• The file, CDirectSumTests.txt, contains the results of the test program testcdirectsum.c.

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

#### NASM Source CodeFor Linux gcc Users

• The file, direct_sum.asm, contains the version of Direct_Sum( ) written in NASM.

#### Nasm Test Code, Test Results, and Build Shell Script

• The file, testdirectsum_A.c, contains a test program of Zero_Vector( ). This test program requires the file zero_vector.asm listed above.

• The file, DirectSumTests_A.txt, contains the results of the test program testdirectsum_A.c.

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

#### Timing For Direct_SumNumber of Clock Cycles

 Routine 3 ×3 ⊕ 3×3 direct_sum.c 1016 direct_sum.asm 494