IVSparse  v1.0
A sparse matrix compression library.
CSC_Iterator_Methods.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 namespace IVSparse {
12 
13  //* Constructors *//
14 
15  // CSC Matrix Constructor
16  template <typename T, typename indexT, bool columnMajor>
18  this->outer = vec;
19 
20  // check if the vector is empty
21  if (mat.getOuterPointers()[vec] == mat.getOuterPointers()[vec + 1]) {
22  vals = nullptr;
23  indices = nullptr;
24  endPtr = nullptr;
25  return;
26  }
27 
28  // set the pointers to the correct locations
29  vals = &mat.vals[mat.outerPtr[vec]];
30  indices = &mat.innerIdx[mat.outerPtr[vec]];
31  endPtr = &mat.innerIdx[mat.outerPtr[vec + 1]];
32 
33  // set the values of the iterator
34  val = vals;
35  index = indices[0];
36  }
37 
38  // CSC Vector Constructor
39  template <typename T, typename indexT, bool columnMajor>
41  this->outer = 0;
42 
43  // set the pointers to the correct locations
44  vals = vec.values();
45  indices = vec.indexPtr();
46  endPtr = vec.indexPtr() + vec.nonZeros();
47 
48  // set the values of the iterator
49  val = vals;
50  index = indices[0];
51  }
52 
53  //* Overloaded Operators *//
54 
55  // Increment Operator
56  template <typename T, typename indexT, bool columnMajor>
58  vals++;
59  indices++;
60 
61  // check if the iterator is at the end of the vector
62  if (indices == endPtr) { return; }
63 
64  // set the values of the iterator
65  val = vals;
66  index = *indices;
67  }
68 
69  // Equality Operator
70  template <typename T, typename indexT, bool columnMajor>
71  bool SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator::operator==(const InnerIterator &other) { return (vals == other.vals && indices == other.index); }
72 
73  // Inequality Operator
74  template <typename T, typename indexT, bool columnMajor>
75  bool SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator::operator!=(const InnerIterator &other) { return (vals != other.vals || indices != other.index); }
76 
77  // Less Than Operator
78  template <typename T, typename indexT, bool columnMajor>
79  bool SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator::operator<(const InnerIterator &other) { return (vals < other.vals && indices < other.index); }
80 
81  // Greater Than Operator
82  template <typename T, typename indexT, bool columnMajor>
83  bool SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator::operator>(const InnerIterator &other) { return (vals > other.vals && indices > other.index); }
84 
85  // Dereference Operator
86  template <typename T, typename indexT, bool columnMajor>
87  T &SparseMatrix<T, indexT, 1, columnMajor>::InnerIterator::operator*() { return val; }
88 
89  //* Getters & Setters *//
90 
91  // Get the current index of the iterator
92  template <typename T, typename indexT, bool columnMajor>
94 
95  // Get the current outer dimension of the iterator
96  template <typename T, typename indexT, bool columnMajor>
98 
99  // Get the current row of the iterator
100  template <typename T, typename indexT, bool columnMajor>
102  if (columnMajor) { return index; }
103  else { return outer; }
104  }
105 
106  // Get the current column of the iterator
107  template <typename T, typename indexT, bool columnMajor>
109  if (columnMajor) { return outer; }
110  else { return index; }
111  }
112 
113  // Get the current value of the iterator
114  template <typename T, typename indexT, bool columnMajor>
116 
117  // coefficent access method
118  template <typename T, typename indexT, bool columnMajor>
120 
121 } // namespace IVSparse
void coeff(T newValue)
Definition: IVCSC_Iterator_Methods.hpp:97
T value()
Definition: IVCSC_Iterator_Methods.hpp:89
indexT row()
Definition: IVCSC_Iterator_Methods.hpp:101
indexT col()
Definition: IVCSC_Iterator_Methods.hpp:108
indexT outerDim()
Definition: IVCSC_Iterator_Methods.hpp:85
indexT getIndex()
Definition: IVCSC_Iterator_Methods.hpp:93
InnerIterator()
Definition: IVCSC_Iterator.hpp:58
Definition: IVCSC_Vector.hpp:27
uint32_t nonZeros()
Definition: IVCSC_Vector_Methods.hpp:163
Definition: CSC_SparseMatrix.hpp:24
indexT * getOuterPointers() const
Definition: CSC_Methods.hpp:33
Definition: IVCSC_SparseMatrix.hpp:27