ARTS 2.5.4 (git: 31ce4f0e)
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()

◆ test3()

void test3 ( )

Definition at line 43 of file test_sparse.cc.

References M.

Referenced by test_transmat_from_propmat().

◆ test40()

void test40 ( )

Definition at line 183 of file test_sparse.cc.

References b, c, joker, mult(), and Sparse::rw().

◆ test41()

void test41 ( )

Definition at line 211 of file test_sparse.cc.

References c, Sparse::rw(), and transpose().

◆ test42()

void test42 ( )

Definition at line 239 of file test_sparse.cc.

References c, mult(), Sparse::rw(), and transpose().

◆ test43()

void test43 ( )

Definition at line 254 of file test_sparse.cc.

References c, and Sparse::rw().

◆ test44()

void test44 ( )

Definition at line 278 of file test_sparse.cc.

References c, Sparse::insert_row(), Sparse::ncols(), Sparse::nrows(), Sparse::rw(), and v.

◆ test45()

void test45 ( )

◆ test46()

◆ 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 abs, c, and Sparse::rw().

◆ test49()

void test49 ( )

Definition at line 384 of file test_sparse.cc.

References add(), 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 get_maximum_error(), joker, min, mult(), random_fill_matrix(), Matrix::resize(), and transpose().

Referenced by main().

◆ 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(), id_mat(), Sparse::ncols(), Sparse::nrows(), Matrix::resize(), and Sparse::resize().

Referenced by main().

◆ 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(), Sparse::insert_row(), joker, Sparse::ncols(), Sparse::nrows(), random_fill_vector(), Matrix::resize(), Sparse::resize(), and v.

Referenced by main().

◆ 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(), get_maximum_error(), 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(), 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 get_maximum_error(), joker, min, mult(), random_fill_matrix(), Matrix::resize(), and transpose().

Referenced by main().

◆ 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 get_maximum_error(), Constant::k, mult(), random_fill_matrix(), random_fill_vector(), transpose(), and transpose_mult().

Referenced by main().

◆ 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 abs, get_maximum_error(), Constant::k, random_fill_matrix(), and transpose().

Referenced by main().

◆ test_xml_io()

Numeric test_xml_io ( Index  ntests,
bool  verbose 
)