| 
        
#include <stddef.h>
 #include <stdio.h>
 Go to the source code of this file. 
|  |  | struct CSRMatrix * | csrmatrix_new_count_nnz (size_t m) |  |  |  | struct CSRMatrix * | csrmatrix_new_known_nnz (size_t m, size_t nnz) |  |  |  | size_t | csrmatrix_new_elms_pushback (struct CSRMatrix *A) |  |  |  | size_t | csrmatrix_elm_index (int i, int j, const struct CSRMatrix *A) |  |  |  | void | csrmatrix_sortrows (struct CSRMatrix *A) |  |  |  | void | csrmatrix_delete (struct CSRMatrix *A) |  |  |  | void | csrmatrix_zero (struct CSRMatrix *A) |  |  |  | void | vector_zero (size_t n, double *v) |  |  |  | void | csrmatrix_write (const struct CSRMatrix *A, const char *fn) |  |  |  | void | csrmatrix_write_stream (const struct CSRMatrix *A, FILE *fp) |  |  |  | void | vector_write (size_t n, const double *v, const char *fn) |  |  |  | void | vector_write_stream (size_t n, const double *v, FILE *fp) |  |  |  Data structure and operations to manage sparse matrices in CSR formats. 
      
        
          | void csrmatrix_delete | ( | struct CSRMatrix * | A | ) |  |  
Dispose of memory resources obtained through prior calls to allocation routines. Parameters
  
  
 The pointer Ais invalid following a call to csrmatrix_delete(). 
      
        
          | size_t csrmatrix_elm_index | ( | int | i, |  
          |  |  | int | j, |  
          |  |  | const struct CSRMatrix * | A |  
          |  | ) |  |  |  
      
        
          | struct CSRMatrix* csrmatrix_new_count_nnz | ( | size_t | m | ) |  |  
Allocate a matrix structure and corresponding row pointers, ia, sufficiently initialised to support "count and push-back" construction scheme. The matrix will be fully formed in csrmatrix_new_elms_pushback(). Parameters
  
    | [in] | m | Number of matrix rows. | 
 ReturnsAllocated matrix structure with allocated row pointers and valid mfield. The row pointer elements are initialised all zero to simplify the non-zero element counting procedure. Thejaandsafields areNULL. This function returnsNULLin case of allocation failure.
 
      
        
          | size_t csrmatrix_new_elms_pushback | ( | struct CSRMatrix * | A | ) |  |  
Set row pointers and allocate column index and matrix element arrays of a matrix previous obtained from csrmatrix_new_count_nnz(). The memory resources should be released through the csrmatrix_delete() function. This function assumes that, on input, the total number of structurally non-zero elements of row iare stored inA->ia[i+1]for alli = 0, ..., A->m - 1and thatA->ia[0] == 0. If successful, then on output the row end pointersA->ia[i+1]are positioned at the start of the corresponding rows. If not, then theA->jaandA->saarrays remain unallocated. Parameters
  
  
 ReturnsTotal number of allocated non-zeros, A->nnz == A->ia[A->m]if successful and zero in case of allocation failure.
 
      
        
          | struct CSRMatrix* csrmatrix_new_known_nnz | ( | size_t | m, |  
          |  |  | size_t | nnz |  
          |  | ) |  |  |  
Allocate a matrix structure and all constituent fields to hold a sparse matrix with a specified number of (structural) non-zero elements. The contents of the individual matrix arrays is undefined. In particular, the sparsity pattern must be constructed through some other, external, means prior to using the matrix in (e.g.,) a global system assembly process. The memory resources should be released through the csrmatrix_delete() function. Parameters
  
    | [in] | m | Number of matrix rows. |  | [in] | nnz | Number of structural non-zeros. | 
 ReturnsAllocated matrix structure and constituent element arrays. NULLin case of allocation failure.
 
      
        
          | void csrmatrix_sortrows | ( | struct CSRMatrix * | A | ) |  |  
Sort column indices within each matrix row in ascending order. The corresponding matrix elements (i.e., sa) are not referenced. Consequently, following a call to csrmatrix_sortrows(), all relations to any pre-existing matrix elements are lost and must be rebuilt. After a call to csrmatrix_sortrows(), the following relation holds A->ja[k] < A->ja[k+1]for allk = A->ia[i], ..., A->ia[i+1]-2in each rowi = 0, ..., A->m - 1. Parameters
  
  
 
      
        
          | void csrmatrix_write | ( | const struct CSRMatrix * | A, |  
          |  |  | const char * | fn |  
          |  | ) |  |  |  
Print matrix to file. The matrix content is printed in coordinate format with row and column indices ranging from 1toA->m. This output format facilitates simple processing through thespconvertfunction in MATLABĀ© or Octave. This function is implemented in terms of csrmatrix_write_stream(). Parameters
  
    | [in] | A | Matrix. |  | [in] | fn | Name of file to which matrix contents will be output. | 
 
      
        
          | void csrmatrix_write_stream | ( | const struct CSRMatrix * | A, |  
          |  |  | FILE * | fp |  
          |  | ) |  |  |  
Print matrix to stream. The matrix content is printed in coordinate format with row and column indices ranging from 1toA->m. This output format facilitates simple processing through thespconvertfunction in MATLABĀ© or Octave. Parameters
  
    | [in] | A | Matrix. |  | [in,out] | fp | Open (text) stream to which matrix contents will be output. | 
 
      
        
          | void vector_write | ( | size_t | n, |  
          |  |  | const double * | v, |  
          |  |  | const char * | fn |  
          |  | ) |  |  |  
Print vector to file. Elements are printed with one line (separated by ') per vector element.'
 This function is implemented in terms of vector_write_stream(). Parameters
  
    | [in] | n | Number of vector elements. |  | [in] | v | Vector. |  | [in] | fn | Name of file to which vector contents will be output. | 
 
      
        
          | void vector_write_stream | ( | size_t | n, |  
          |  |  | const double * | v, |  
          |  |  | FILE * | fp |  
          |  | ) |  |  |  
Print vector to stream. Elements are printed with one line (separated by ') per vector element.'
 Parameters
  
    | [in] | n | Number of vector elements. |  | [in] | v | Vector. |  | [in,out] | fp | Open (text) stream to which vector contents will be output. | 
 
      
        
          | void vector_zero | ( | size_t | n, |  
          |  |  | double * | v |  
          |  | ) |  |  |  
Zero all vector elements. Parameters
  
    | [in] | n | Number of vector elements. |  | [out] | v | Vector for which to zero the elements. | 
   |