Ice Sheet System Model  4.18
Code documentation
Public Member Functions | Data Fields
SparseRow< doubletype > Class Template Reference

#include <SparseRow.h>

Public Member Functions

 SparseRow ()
 
 SparseRow (int in_M)
 
 ~SparseRow ()
 
void Echo ()
 
void SetValues (int numvalues, int *cols, doubletype *vals, int *mods)
 
doubletype Norm (NormMode mode)
 
doubletype Mult (doubletype *X)
 
int Nnz (void)
 
void SetIrnJcnA (int *irn_loc, int *jcn_loc, doubletype *a_loc, int i_index, int count)
 

Data Fields

int M
 
int ncols
 
int * indices
 
doubletype * values
 

Detailed Description

template<class doubletype>
class SparseRow< doubletype >

Definition at line 13 of file SparseRow.h.

Constructor & Destructor Documentation

◆ SparseRow() [1/2]

template<class doubletype >
SparseRow< doubletype >::SparseRow ( )
inline

Definition at line 23 of file SparseRow.h.

23  { /*{{{*/
24  M=0;
25  ncols=0;
26  indices=NULL;
27  values=NULL;
28  } /*}}}*/

◆ SparseRow() [2/2]

template<class doubletype >
SparseRow< doubletype >::SparseRow ( int  in_M)
inline

Definition at line 29 of file SparseRow.h.

29  {/*{{{*/
30 
31  M=in_M;
32  ncols=0;
33  indices=NULL;
34  values=NULL;
35 
36  } /*}}}*/

◆ ~SparseRow()

template<class doubletype >
SparseRow< doubletype >::~SparseRow ( )
inline

Definition at line 37 of file SparseRow.h.

37  {/*{{{*/
38  if(ncols){
39  xDelete<int>(indices);
40  xDelete<doubletype>(values);
41  }
42  } /*}}}*/

Member Function Documentation

◆ Echo()

template<class doubletype >
void SparseRow< doubletype >::Echo ( void  )
inline

Definition at line 45 of file SparseRow.h.

45  { /*{{{*/
46  int i;
47 
48  for(i=0;i<ncols;i++){
49  _printf_("(" << indices[i] << "," << values[i] << ") ");
50  }
51  } /*}}}*/

◆ SetValues()

template<class doubletype >
void SparseRow< doubletype >::SetValues ( int  numvalues,
int *  cols,
doubletype *  vals,
int *  mods 
)
inline

Definition at line 52 of file SparseRow.h.

52  { /*{{{*/
53 
54  int count;
55  int i,j;
56 
57  if(!M)_error_("unknow dimension for this sparse row!");
58 
59  /*Deallocate if already allocated: */
60  if(ncols){
61  xDelete<int>(indices);
62  xDelete<doubletype>(values);
63  }
64 
65  /*check numvalues: */
66  if(!numvalues)return;
67 
68  /*Go through cols and resolve duplicates: */
69  for(i=0;i<numvalues;i++){
70  for(j=i+1;j<numvalues;j++){
71  if (cols[j]==cols[i]){
72  if (mods[j]==ADD_VAL){
73  vals[i]+=vals[j];
74  }
75  else vals[i]=vals[j];
76  cols[j]=-1;
77  }
78  /*Ensure that this value will not be used anymore: */
79  }
80  }
81 
82  /*Now go through cols once more, and retrieve only what we need: */
83  ncols=0;
84  for(i=0;i<numvalues;i++)if(cols[i]>=0)ncols++;
85 
86  /*Allocate and fill: */
87  indices=xNew<int>(ncols); _assert_(indices);
88  values=xNewZeroInit<doubletype>(ncols); _assert_(values);
89 
90  count=0;
91  for(i=0;i<numvalues;i++){
92  if(cols[i]>=0){
93  indices[count]=cols[i];
94  values[count]=vals[i];
95  count++;
96  }
97  }
98 
99  if(count!=ncols)_error_("counter problem during set values operations");
100  } /*}}}*/

◆ Norm()

template<class doubletype >
doubletype SparseRow< doubletype >::Norm ( NormMode  mode)
inline

Definition at line 101 of file SparseRow.h.

101  { /*{{{*/
102 
103  int i;
104  doubletype norm=0.;
105 
106  switch(mode){
107  case NORM_INF:
108  for(i=0;i<ncols;i++){
109  norm+=fabs(values[i]);
110  }
111  return norm;
112  break;
113  case NORM_FROB:
114  for(i=0;i<ncols;i++){
115  norm+=values[i]*values[i];
116  }
117  return norm;
118  break;
119 
120  default:
121  _error_("unknown norm !");
122  break;
123  }
124  }

◆ Mult()

template<class doubletype >
doubletype SparseRow< doubletype >::Mult ( doubletype *  X)
inline

Definition at line 126 of file SparseRow.h.

126  { /*{{{*/
127 
128  int i;
129  doubletype mult=0;
130 
131  for(i=0;i<ncols;i++){
132  mult+=values[i]*X[indices[i]];
133  }
134 
135  return mult;
136  }

◆ Nnz()

template<class doubletype >
int SparseRow< doubletype >::Nnz ( void  )
inline

Definition at line 138 of file SparseRow.h.

138  { /*{{{*/
139 
140  return ncols;
141  }

◆ SetIrnJcnA()

template<class doubletype >
void SparseRow< doubletype >::SetIrnJcnA ( int *  irn_loc,
int *  jcn_loc,
doubletype *  a_loc,
int  i_index,
int  count 
)
inline

Definition at line 143 of file SparseRow.h.

143  {/*{{{*/
144  int i;
145 
146  for(i=0;i<ncols;i++){
147  irn_loc[count+i]=i_index;
148  jcn_loc[count+i]=indices[i]+1; //fortran indexing
149  a_loc[count+i]=values[i];
150  }
151  }

Field Documentation

◆ M

template<class doubletype >
int SparseRow< doubletype >::M

Definition at line 17 of file SparseRow.h.

◆ ncols

template<class doubletype >
int SparseRow< doubletype >::ncols

Definition at line 18 of file SparseRow.h.

◆ indices

template<class doubletype >
int* SparseRow< doubletype >::indices

Definition at line 19 of file SparseRow.h.

◆ values

template<class doubletype >
doubletype* SparseRow< doubletype >::values

Definition at line 20 of file SparseRow.h.


The documentation for this class was generated from the following file:
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
ADD_VAL
@ ADD_VAL
Definition: toolkitsenums.h:14
NORM_INF
@ NORM_INF
Definition: toolkitsenums.h:15
NORM_FROB
@ NORM_FROB
Definition: toolkitsenums.h:15
SparseRow::ncols
int ncols
Definition: SparseRow.h:18
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
SparseRow::values
doubletype * values
Definition: SparseRow.h:20
SparseRow::M
int M
Definition: SparseRow.h:17
SparseRow::indices
int * indices
Definition: SparseRow.h:19