ARTS  2.3.1285(git:92a29ea9-dirty)
test_sparse.cc File Reference

Tests for sparse matrices. More...

#include <iostream>
#include <stdexcept>
#include "lin_alg.h"
#include "matpackI.h"
#include "matpackII.h"
#include "test_utils.h"
#include "xml_io.h"

Go to the source code of this file.

Functions

void test3 ()
 
void test40 ()
 
void test41 ()
 
void test42 ()
 
void test43 ()
 
void test44 ()
 
void test45 ()
 
void test46 ()
 
void test47 ()
 
void test48 ()
 
void test49 ()
 
Numeric test_xml_io (Index ntests, bool verbose)
 
Numeric test_insert_row (Index ntests, bool verbose)
 Test sparse insert_row function. More...
 
Numeric test_identity (Index ntests, bool verbose)
 Test sparse identity matrix. More...
 
Numeric test_sparse_construction (Index m, Index n, Index ntests, bool verbose)
 Test sparse matrix construction. More...
 
Numeric test_sparse_unary_operations (Index m, Index n, Index ntests, bool verbose)
 Test unary operation on sparse matrices. More...
 
Numeric test_dense_sparse_multiplication (Index m, Index n, Index ntests, bool verbose)
 Test dense-sparse multiplication. More...
 
Numeric test_sparse_dense_multiplication (Index m, Index n, Index ntests, bool verbose)
 Test sparse-dense multiplication. More...
 
Numeric test_sparse_multiplication (Index m, Index n, Index ntests, bool verbose)
 Test sparse multiplication. More...
 
Numeric test_sparse_arithmetic (Index m, Index n, Index ntests, bool verbose)
 Test sparse matrix arithmetic. More...
 
int main ()
 

Detailed Description

Tests for sparse matrices.

Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:10:44 2003

Add more tests here as necessary...

Definition in file test_sparse.cc.

Function Documentation

◆ main()

int main ( void  )

Definition at line 1111 of file test_sparse.cc.

References test_sparse_arithmetic().

◆ test3()

void test3 ( )

Definition at line 43 of file test_sparse.cc.

References i, M, and Sparse::rw().

◆ test40()

void test40 ( )

Definition at line 183 of file test_sparse.cc.

References Sparse::rw().

◆ test41()

void test41 ( )

Definition at line 211 of file test_sparse.cc.

References r.

◆ test42()

void test42 ( )

Definition at line 239 of file test_sparse.cc.

References r.

◆ test43()

void test43 ( )

Definition at line 254 of file test_sparse.cc.

References r.

◆ test44()

void test44 ( )

Definition at line 278 of file test_sparse.cc.

References r.

◆ test45()

void test45 ( )

Definition at line 296 of file test_sparse.cc.

References xml_read_from_file().

◆ test46()

void test46 ( )

Definition at line 329 of file test_sparse.cc.

References xml_read_from_file().

◆ test47()

void test47 ( )

Definition at line 358 of file test_sparse.cc.

References id_mat(), and Sparse::resize().

◆ test48()

void test48 ( )

Definition at line 369 of file test_sparse.cc.

References r.

◆ test49()

void test49 ( )

Definition at line 384 of file test_sparse.cc.

References add(), C, i, Sparse::rw(), and sub().

◆ test_dense_sparse_multiplication()

Numeric test_dense_sparse_multiplication ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test dense-sparse multiplication.

Test multiplication B x C of a dense matrix B with a sparse matrix C. Takes a random submatrix of a m-times-n matrix B and multiplies it with a randomly generated sparse matrix C. The operation is simultaneously performed using dense arithmetic and the results are compared. Also tests the multiplication of transposed matrices.

Parameters
mThe number of rows of the dense matrix C.
nThe number of cols ot the sparse matrix B.
ntestsThe number of tests to be performed.
verboseIf true, the test results of each test are printed to stdout.
Returns
Returns the maximum relative error between the sparse and the dense operation taken over all tests.

Definition at line 685 of file test_sparse.cc.

References C, get_maximum_error(), i, joker, min, mult(), random_fill_matrix(), Matrix::resize(), and transpose().

◆ test_identity()

Numeric test_identity ( Index  ntests,
bool  verbose 
)

Test sparse identity matrix.

Test the creation of sparse identity matrices using Sparse::make_I(...). For each test, a randomly sized sparse matrix is created and set to the identity matrix. The result is compared to the result of the dense couterpart identity(...). ntests sets the number of tests to be performed. Also tests if the matrix was correctly resized. If the resize fails the function returns 1.0.

Parameters
ntestThe number of tests to perform.
verboseIf true, test results for each test are printed to stdout.
Returns
The maximum relative error between the sparse identity matrix and the dense identity matrix taken over all tests. Return 1.0 if the resize operation fails.

Definition at line 519 of file test_sparse.cc.

References get_maximum_error(), i, id_mat(), n, Sparse::ncols(), Sparse::nrows(), Sparse::resize(), and Matrix::resize().

◆ test_insert_row()

Numeric test_insert_row ( Index  ntests,
bool  verbose 
)

Test sparse insert_row function.

Performs ntests randomized tests of the Sparse::insert_row(...) function. For each test a random vector is inserted as row r into a sparse matrix. The sparse matrix is then transformed into a dense matrix and the row r compared to the vector. Return the maximum error between the rth row in the sparse matrix and the inserted vector, which should be 0.

Parameters
ntestsNumber of test to perform.
verboseIf verbose == true, the error for each test is printed to stdout.
Returns
The maximum error between the inserted vector and the corresponding row of the matrix.

Definition at line 457 of file test_sparse.cc.

References get_maximum_error(), i, Sparse::insert_row(), joker, n, Sparse::ncols(), Sparse::nrows(), r, random_fill_vector(), Sparse::resize(), Vector::resize(), and Matrix::resize().

◆ test_sparse_arithmetic()

Numeric test_sparse_arithmetic ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test sparse matrix arithmetic.

Test multiplication, addition and subtraction of sparse matrices using the corresponding dense operations. The operations performed are

A x B, C + D, C - D

for a m-times-n matrix C, a m-times-m matrix A, a m-times-n matrix B and a m-times-n matrix D.

Parameters
mThe number of rows of C
nThe number of columns of C
ntestsThe number of test to be performed
verboseIf true, the results of each test are printed to stdout.
Returns
The maximum relative error taken over all tests and operations.

Definition at line 1028 of file test_sparse.cc.

References add(), C, get_maximum_error(), i, mult(), random_fill_matrix(), and sub().

Referenced by main().

◆ test_sparse_construction()

Numeric test_sparse_construction ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test sparse matrix construction.

Performs ntests of the construction and conversion of sparse matrices to dense matrices. In each test a sparse m-times-n matrix is created and filled with random values. The matrix is then converted to a dense matrix and the error between the two matrices is computed.

Parameters
mThe number of rows of the sparse matrix.
nThe number of columns of the sparse matrix.
ntestsThe number of test to be performed.
verboseIf true, the results of each test are printed to stdout.
Returns
Returns the maximum relative error between the sparse matrix and the converted, dense matrix taken over all ntests tests.

Definition at line 570 of file test_sparse.cc.

References get_maximum_error(), i, and random_fill_matrix().

◆ test_sparse_dense_multiplication()

Numeric test_sparse_dense_multiplication ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test sparse-dense multiplication.

Test multiplication B x C of a sparse matrix B with a dense matrix C. Takes a random submatrix of a m-times-n matrix C and multiplies it with a randomly generated sparse matrix B. The operation is simultaneously performed using dense arithmetic and the results are compared. Also test the multiplication of transposed matrices.

Parameters
mThe number of rows of the dense matrix C.
nThe number of cols ot the sparse matrix B.
ntestsThe number of tests to be performed.
verboseIf true, the test results of each test are printed to stdout.
Returns
Returns the maximum relative error between the sparse and the dense operation taken over all tests.

Definition at line 805 of file test_sparse.cc.

References C, get_maximum_error(), i, joker, min, mult(), random_fill_matrix(), Matrix::resize(), and transpose().

◆ test_sparse_multiplication()

Numeric test_sparse_multiplication ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test sparse multiplication.

Test multiplication of sparse matrices with sparse and dense matrices as well as vectors. Performs ntests test, where in each test the product of two sparse matrices, of a sparse and a dense matrix and of a sparse matrix and a vector are computed:

Matrix-matrix product: A = B x C
Matrix-vector product: y = B * x

Where A is a m-times-n matrix and B a m-times-k matrix, where k is picked randomly for each test from the range [1,999]. The results are compared to the results obtained using dense arithmetic and the maximum relative error taken over all tests is returned.

Parameters
mNumber of rows of A.
nNumber of columns of A.
ntestsNumber of tests to perform.
verboseIf true, the results of each test are printed to stdout.
Returns
The maximum relative error taken over all operations and number of tests performed.

Definition at line 932 of file test_sparse.cc.

References i.

◆ test_sparse_unary_operations()

Numeric test_sparse_unary_operations ( Index  m,
Index  n,
Index  ntests,
bool  verbose 
)

Test unary operation on sparse matrices.

Perform ntests tests of the unary operation on sparse matrices (abs(...), transpose(...)) as well as construction of sparse matrices using rw, ro. The test of the construction of sparse matrix is done by filling a dense matrix with identical random values at the same positions and comparing the dense and the sparse matrices.

Parameters
mThe number of rows of the sparse matrix.
nThe number of colums of the sparse matrix.
ntestsThe number of tests to be performed.
verboseIf true, results for each test are printed to stdout.
Returns
The maximum relative error between the sparse matrix and the dense counterpart taken over all tests.

Definition at line 613 of file test_sparse.cc.

References get_maximum_error(), i, and random_fill_matrix().

◆ test_xml_io()

Numeric test_xml_io ( Index  ntests,
bool  verbose 
)