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.

Date
Tue Jul 15 15:10:44 2003

Add more tests here as necessary...

Definition in file test_sparse.cc.

◆ main()

 int main ( void )

Definition at line 1111 of file test_sparse.cc.

◆ 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 ( )

Definition at line 296 of file test_sparse.cc.

◆ test46()

 void test46 ( )

Definition at line 329 of file test_sparse.cc.

◆ 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.

◆ 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
 m The number of rows of the dense matrix C. n The number of cols ot the sparse matrix B. ntests The number of tests to be performed. verbose If 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
 ntest The number of tests to perform. verbose If 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.

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
 ntests Number of test to perform. verbose If 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.

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
 m The number of rows of C n The number of columns of C ntests The number of test to be performed verbose If 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
 m The number of rows of the sparse matrix. n The number of columns of the sparse matrix. ntests The number of test to be performed. verbose If 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
 m The number of rows of the dense matrix C. n The number of cols ot the sparse matrix B. ntests The number of tests to be performed. verbose If 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
 m Number of rows of A. n Number of columns of A. ntests Number of tests to perform. verbose If 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.

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
 m The number of rows of the sparse matrix. n The number of colums of the sparse matrix. ntests The number of tests to be performed. verbose If 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 )

Definition at line 411 of file test_sparse.cc.

Referenced by main().