testvec.h File Reference


Detailed Description

Test vector generation and checking.

Todo:
testmat_ChooseDim and ChooseDivisible do not actually need to be build-type dependent.

#include <stdlib.h>
#include <oski/common.h>
#include <oski/matrix.h>
#include <oski/matcreate.h>
#include <oski/vecview.h>

Go to the source code of this file.

Name mangling.

#define testvec_Create   MANGLE_(testvec_Create)
#define testvec_CalcDataSize   MANGLE_(testvec_CalcDataSize)
#define testvec_Clone   MANGLE_(testvec_Clone)
#define testvec_Destroy   MANGLE_(testvec_Destroy)
#define testmat_ChangeSizeDenseCSR   MANGLE_(testmat_ChangeSizeDenseCSR)
#define testmat_ChangeSizeDenseTriCSR   MANGLE_(testmat_ChangeSizeDenseTriCSR)
#define testmat_GenDenseCSR   MANGLE_(testmat_GenDenseCSR)
#define testmat_GenRandomCSR   MANGLE_(testmat_GenRandomCSR)
#define testmat_GenTriCSR   MANGLE_(testmat_GenTriCSR)
#define testmat_GenTriCSC   MANGLE_(testmat_GenTriCSC)
#define testmat_GenBlockedBandedCSR   MANGLE_(testmat_GenBlockedBandedCSR)
#define check_MatMult_instance   MANGLE_(check_MatMult_instance)
#define check_MatTrisolve_instance   MANGLE_(check_MatTrisolve_instance)
#define check_MatTransMatMult_instance   MANGLE_(check_MatTransMatMult_instance)
#define check_MatMultAndMatTransMult_instance   MANGLE_(check_MatMultAndMatTransMult_instance)
#define testmat_ChooseDim   MANGLE_(testmat_ChooseDim)
#define ChooseDivisible   MANGLE_(ChooseDivisible)

Defines

#define INC_UTIL_TESTVEC_H
 tests/test_util.h included.

Functions

oski_vecview_t testvec_Create (oski_index_t len, oski_index_t num_vecs, oski_storage_t orient, int use_minstride)
 Allocate a dense 2-D array, fill it with random values, and return it wrapped in a newly allocated vector view object.
size_t testvec_CalcDataSize (const oski_vecview_t x)
 Based on its storage orientation and stride, returns the minimum size (in elements) of the underlying storage array.
oski_vecview_t testvec_Clone (const oski_vecview_t x)
 Clone an object created using testvec_Create().
void testvec_Destroy (oski_vecview_t x)
 Destroy a test vector created via testvec_Create().
size_t testmat_ChooseDim (size_t nz_volume, size_t elem_size)
 Select the dimension for a square, dense matrix whose size in Bytes exceeds nz_volume.
size_t ChooseDivisible (size_t n, size_t d)
 Returns the smallest integer $n' >= n$ such that $d | n'$.
void testmat_GenDenseCSR (oski_index_t m, oski_index_t n, oski_index_t **p_ptr, oski_index_t **p_ind, oski_value_t **p_val)
 Generates a dense, non-symmetric matrix in sparse CSR format.
void testmat_ChangeSizeDenseCSR (oski_index_t m_new, oski_index_t n_new, oski_index_t *ptr, oski_index_t *ind)
 Changes the dimensions (and pattern) of a previously allocated dense CSR test matrix.
void testmat_ChangeSizeDenseTriCSR (oski_index_t n_new, int make_lower, int cond_for_trisolve, oski_index_t *ptr, oski_index_t *ind, oski_value_t *val)
 Changes the pattern of a previously allocated dense CSR test matrix to a dense triangular pattern.
void testmat_GenTriCSR (oski_index_t m, oski_index_t max_nnz_row, oski_inmatprop_t shape, int is_unitdiag, int is_sorted, int indbase, oski_index_t **p_ptr, oski_index_t **p_ind, oski_value_t **p_val)
 Generates a random, well-conditioned sparse triangular matrix in CSR format with the prescribed attributes for testing triangular solve.
void testmat_GenTriCSC (oski_index_t m, oski_index_t max_nnz_row, oski_inmatprop_t shape, int is_unitdiag, int is_sorted, int indbase, oski_index_t **p_ptr, oski_index_t **p_ind, oski_value_t **p_val)
 Generates a random, well-conditioned sparse triangular matrix in CSC format with the prescribed attributes for testing triangular solve.
void testmat_GenBlockedBandedCSR (oski_index_t k_min, oski_index_t row_min, oski_index_t r, oski_index_t c, oski_index_t *p_n, oski_index_t **p_ptr, oski_index_t **p_ind, oski_value_t **p_val)
 Generates a matrix with a banded shape, where each row contains dense blocks of a given size.
int check_MatMult_instance (const oski_matrix_t A0, const oski_matrix_t A1, oski_matop_t opA, oski_value_t alpha, const oski_vecview_t x, oski_value_t beta, oski_vecview_t y0)
 Check an instance of matrix-vector multiply.
int check_MatTrisolve_instance (const oski_matrix_t T0, const oski_matrix_t T1, oski_matop_t opT, oski_value_t alpha, const oski_vecview_t b)
 Check an instance of sparse triangular solve.
int check_MatTransMatMult_instance (const oski_matrix_t A0, const oski_matrix_t A1, oski_ataop_t opA, oski_value_t alpha, const oski_vecview_t x, oski_value_t beta, oski_vecview_t y0, oski_vecview_t t0)
 Check an instance of sparse $A^TAx$.
int check_MatMultAndMatTransMult_instance (const oski_matrix_t A0, const oski_matrix_t A1, oski_value_t alpha, const oski_vecview_t x, oski_value_t beta, oski_vecview_t y, oski_matop_t opA, oski_value_t omega, const oski_vecview_t w, oski_value_t zeta, oski_vecview_t z)
 Check and instance of simultaneous multiplication by sparse $A$ and $\mathrm{op}(A)$.
oski_matrix_t testmat_GenRandomCSR (oski_index_t m, oski_index_t n, oski_index_t min_nnz_row, oski_index_t max_nnz_row, oski_inmatprop_t shape, int implicit_diag, int index_base, oski_copymode_t copymode, oski_index_t **p_ptr, oski_index_t **p_ind, oski_value_t **p_val)
 Create a raw matrix pattern and matrix object corresponding to the caller-specified dimensions and shape.


Function Documentation

int check_MatMult_instance const oski_matrix_t  A0,
const oski_matrix_t  A1,
oski_matop_t  opA,
oski_value_t  alpha,
const oski_vecview_t  x,
oski_value_t  beta,
oski_vecview_t  y0
 

Check an instance of matrix-vector multiply.

If the calculation is merely incorrect, then this routine prints a message and returns ERR_WRONG_ANS.

int check_MatMultAndMatTransMult_instance const oski_matrix_t  A0,
const oski_matrix_t  A1,
oski_value_t  alpha,
const oski_vecview_t  x,
oski_value_t  beta,
oski_vecview_t  y0,
oski_matop_t  opA,
oski_value_t  omega,
const oski_vecview_t  w,
oski_value_t  zeta,
oski_vecview_t  z0
 

Check and instance of simultaneous multiplication by sparse $A$ and $\mathrm{op}(A)$.

If the calculation is merely incorrect, then this routine prints a message and returns ERR_WRONG_ANS.

int check_MatTransMatMult_instance const oski_matrix_t  A0,
const oski_matrix_t  A1,
oski_ataop_t  opA,
oski_value_t  alpha,
const oski_vecview_t  x,
oski_value_t  beta,
oski_vecview_t  y0,
oski_vecview_t  t0
 

Check an instance of sparse $A^TAx$.

If the calculation is merely incorrect, then this routine prints a message and returns ERR_WRONG_ANS.

int check_MatTrisolve_instance const oski_matrix_t  A0,
const oski_matrix_t  A1,
oski_matop_t  opA,
oski_value_t  alpha,
const oski_vecview_t  b
 

Check an instance of sparse triangular solve.

If the calculation is merely incorrect, then this routine prints a message and returns ERR_WRONG_ANS.

void testmat_ChangeSizeDenseCSR oski_index_t  m_new,
oski_index_t  n_new,
oski_index_t *  ptr,
oski_index_t *  ind
 

Changes the dimensions (and pattern) of a previously allocated dense CSR test matrix.

Parameters:
[in] m_new New number of rows.
[in] n_new New number of columns.
[in,out] ptr Prior row pointers.
[in,out] ind Prior index values.
Returns:
A new pattern for a dense m_new x n_new matrix in sparse CSR format, conforming to the following specifications:
  • It is stored in CSR format.
  • It uses 0-based indexing.
  • Indices are sorted and unique.
This routine assumes that ptr, ind were previously allocated to be sufficiently large to store a dense matrix of the requested size. The previous contents of (ptr, ind) are ignored.

void testmat_ChangeSizeDenseTriCSR oski_index_t  n_new,
int  make_lower,
int  cond_for_trisolve,
oski_index_t *  ptr,
oski_index_t *  ind,
oski_value_t *  val
 

Changes the pattern of a previously allocated dense CSR test matrix to a dense triangular pattern.

Parameters:
[in] n_new New dimension.
[in] make_lower Set to any non-zero value to generate a lower triangular matrix; otherwise, this routine generates an upper-triangular pattern.
[in] cond_for_trisolve Set to any non-zero value to generate random values that lead to a well-conditioned triangular system solve; otherwise, put all values in the range [0, 1].
[in,out] ptr Prior row pointers.
[in,out] ind Prior index values.
[in,out] val Prior non-zero values.
Returns:
A new pattern for a dense triangular n_new x n_new matrix in sparse CSR format, conforming to the following specifications:
  • It is stored in CSR format.
  • It uses 0-based indexing.
  • Indices are sorted and unique.
  • The value of all diagonal elements is O(1), pure real, and all off-diagonal elements are O(1/n_new).
This routine assumes that ptr, ind were previously allocated to be sufficiently large to store a dense matrix of the requested size. The previous contents of (ptr, ind, val) are ignored.

size_t testmat_ChooseDim size_t  nz_volume,
size_t  elem_size
 

Select the dimension for a square, dense matrix whose size in Bytes exceeds nz_volume.

Parameters:
[in] nz_volume Minimum desired size of matrix data array, in Bytes.
[in] elem_size Size of each matrix element value.
Returns:
The dimension of a square dense matrix whose size (volume, in bytes) is at least nz_volume.

void testmat_GenBlockedBandedCSR oski_index_t  k_min,
oski_index_t  row_min,
oski_index_t  r,
oski_index_t  c,
oski_index_t *  p_n,
oski_index_t **  p_ptr,
oski_index_t **  p_ind,
oski_value_t **  p_val
 

Generates a matrix with a banded shape, where each row contains dense blocks of a given size.

Parameters:
[in] k_min Minimum number of non-zeros.
[in] row_min Minimum number of non-zeros per row.
[in] r Row block size.
[in] c Column block size.
[in,out] p_m Pointer to scalar in which to store the number of rows.
[in,out] p_n Pointer to scalar in which to store the number of columns.
[in,out] p_ptr Pointer to row pointers.
[in,out] p_ind Pointer to column indices.
[in,out] p_val Pointer to values.

void testmat_GenDenseCSR oski_index_t  m,
oski_index_t  n,
oski_index_t **  p_ptr,
oski_index_t **  p_ind,
oski_value_t **  p_val
 

Generates a dense, non-symmetric matrix in sparse CSR format.

Parameters:
[in] m Logical number of matrix rows. Must be positive.
[in] n Logical number of matrix columns. Must be positive.
[in,out] p_ptr Pointer to a pointer in which to return the newly allocated row pointers.
[in,out] p_ind Pointer to a pointer in which to return the newly allocated column indices.
[in,out] p_val Pointer to a pointer in which to return the newly allocated non-zero values.
Returns:
Newly allocated 3-array storage in (*p_ptr, *p_ind, *p_val). On error, aborts the application with an error message.
The newly created matrix has the properties specified in testmat_ChangeSizeDenseCSR().

Todo:
What is the best way to initialize the dense matrix? For benchmarking, it seems sufficient to initialize all entries to 'tiny' values (here, $\frac{1}{\max{m}{n}}$), which is faster than calling the random number generator.

oski_matrix_t testmat_GenRandomCSR oski_index_t  m,
oski_index_t  n,
oski_index_t  min_nnz_row,
oski_index_t  max_nnz_row,
oski_inmatprop_t  shape,
int  implicit_diag,
int  index_base,
oski_copymode_t  copymode,
oski_index_t **  p_ptr,
oski_index_t **  p_ind,
oski_value_t **  p_val
 

Create a raw matrix pattern and matrix object corresponding to the caller-specified dimensions and shape.

Parameters:
[in] m Number of rows.
[in] n Number of columns.
[in] min_nnz_row Minimum # of non-zeros per row.
[in] max_nnz_row Maximum # of non-zeros per row. If max_nnz_row is less than min_nnz_row, then it is taken to be n.
[in] shape Matrix shape (MAT_GENERAL ... MAT_HERM_FULL).
[in] implicit_diag Set to 1 if the diagonal should be unit and implicit, or 0 otherwise.
[in] index_base Set to 1 or 0 to set the base index.
[in,out] p_ptr Pointer to buffer to hold the row pointers, or NULL if none is desired.
[in,out] p_ind Pointer to buffer to hold the column indices, or NULL if none is desired.
[in,out] p_val Pointer to buffer to hold the stored non-zero values, or NULL if none is desired.
Returns:
On success, returns a valid matrix handle and sets (*p_ptr, *p_ind, *p_val) to point to the raw CSR representation. Otherwise, aborts the program.
Note:
If p_ptr, p_ind, or p_val are NULL but the copy mode is set to SHARE_INPUTMAT, then there is the potential for a memory leak.

void testmat_GenTriCSR oski_index_t  m,
oski_index_t  max_nnz_row,
oski_inmatprop_t  shape,
int  is_unitdiag,
int  is_sorted,
int  indbase,
oski_index_t **  p_ptr,
oski_index_t **  p_ind,
oski_value_t **  p_val
 

Generates a random, well-conditioned sparse triangular matrix in CSR format with the prescribed attributes for testing triangular solve.

Parameters:
[in] m Dimension of the desired matrix.
[in] max_nnz_row Maximum desired number of non-zeros per row.
[in] shape MAT_TRI_LOWER or MAT_TRI_UPPER.
[in] is_unitdiag Set to 0 if the matrix should have
[in] indbase Index base, 0 or 1. an implicit unit diagonal, or non-zero otherwise.
[in] is_sorted Set to any non-zero value if the column indices should be sorted in increasing order.
[in,out] p_ptr Pointer in which to store a newly allocated array of row pointers for the matrix, or NULL if not desired.
[in,out] p_ind Pointer in which to store a newly allocated array of column indices for the matrix, or NULL if not desired.
[in,out] p_val Pointer in which to store a newly allocated array of non-zero values, or NULL if not desired.

oski_vecview_t testvec_Create oski_index_t  len,
oski_index_t  num_vecs,
oski_storage_t  orient,
int  use_minstride
 

Allocate a dense 2-D array, fill it with random values, and return it wrapped in a newly allocated vector view object.

Parameters:
[in] len Length of a column vector.
[in] num_vecs Number of column vectors.
[in] orient Storage orientation.
[in] use_minstride Set to 0 to choose the minimum possible stride for the specified orientation, or 1 to choose a slightly larger stride with perturbation chosen at random.
Returns:
A test vector conforming to the caller's request.


Generated on Wed Sep 19 16:41:23 2007 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.4.6