1 #ifndef flexMatrixLogical_H 2 #define flexMatrixLogical_H 4 #include "flexLinearOperator.h" 14 typedef thrust::device_vector<T> Tdata;
16 typedef std::vector<T> Tdata;
23 std::vector<int> rowToIndexList;
24 std::vector<int> indexList;
34 flexMatrixLogical(
int aNumRows,
int aNumCols,
bool aMinus) : rowToIndexList(aNumRows + 1, static_cast<int>(0)), indexList(0, 0),
flexLinearOperator<T>(aNumRows, aNumCols, matrixOp, aMinus){};
40 A->rowToIndexList = indexList;
41 A->indexList = rowToIndexList;
47 void times(
bool transposed,
const Tdata &input, Tdata &output)
52 void timesPlus(
bool transposed,
const Tdata &input, Tdata &output)
56 doTimesCPU(transposed, input, output,MINUS);
60 doTimesCPU(transposed, input, output,PLUS);
64 void timesMinus(
bool transposed,
const Tdata &input, Tdata &output)
68 doTimesCPU(transposed, input, output,PLUS);
72 doTimesCPU(transposed, input, output,MINUS);
82 void blockInsert(
const std::vector<int> &indexI,
const std::vector<int> &indexJ)
87 int numberListElements = (int)indexI.size();
90 std::vector<int> emptyBucket(0, 0);
91 std::vector < std::vector<int> > buckets(this->
getNumRows(), emptyBucket);
94 for (
int indexInput = 0; indexInput < numberListElements; indexInput++)
96 buckets[indexI[indexInput]].push_back(indexInput);
100 for (
int indexRow = 0; indexRow < this->
getNumRows(); indexRow++)
105 for (
int indexBucket = 0; indexBucket < (int)buckets[indexRow].size(); indexBucket++)
107 int tmpIndex = buckets[indexRow][indexBucket];
109 indexList.push_back(indexJ[tmpIndex]);
114 rowToIndexList[indexRow + 1] = rowToIndexList[indexRow] + numElements;
118 int index2DtoLinear(
int i,
int j)
127 return *std::max_element(rowSum.begin(), rowSum.end());
140 for (
int index = rowToIndexList[k]; index < rowToIndexList[k + 1]; ++index)
142 result[indexList[index]] += (T)1;
157 #pragma omp parallel for 160 T tmpSum =
static_cast<T
>(0);
161 for (
int index = rowToIndexList[k]; index < rowToIndexList[k + 1]; ++index)
184 for (
int index = rowToIndexList[i]; index < rowToIndexList[i + 1]; ++index)
186 printf(
"(%d,%d,1)|", i, indexList[index]);
205 thrust::device_vector<T> result(this->
getNumRows(), (T)1);
212 void doTimesCPU(
bool transposed,
const Tdata &input, Tdata &output,
const mySign s)
217 #pragma omp parallel for 220 int indexNext = rowToIndexList[i + 1];
221 for (
int index = rowToIndexList[i]; index < indexNext; ++index)
227 output[indexList[index]] += input[i];
232 output[indexList[index]] -= input[i];
241 #pragma omp parallel for 246 int indexNext = rowToIndexList[i + 1];
247 for (
int index = rowToIndexList[i]; index < indexNext; ++index)
249 rowsum += input[indexList[index]];
flexMatrixLogical()
initializes an empty matrix
Definition: flexMatrixLogical.h:26
int getNumRows() const
returns number of rows of the linear operator
Definition: flexLinearOperator.h:57
bool isMinus
determines if operator is negated
Definition: flexLinearOperator.h:25
thrust::device_vector< T > getAbsRowSumCUDA(bool transposed)
same function as getAbsRowSum() but implemented in CUDA
Definition: flexMatrixLogical.h:203
flexMatrixLogical(int aNumRows, int aNumCols, bool aMinus)
initializes a matrix
Definition: flexMatrixLogical.h:34
represents a full (non-CUDA) logical matrix
Definition: flexMatrixLogical.h:10
void blockInsert(const std::vector< int > &indexI, const std::vector< int > &indexJ)
inserts position of all non-zero elements into matrix
Definition: flexMatrixLogical.h:82
int getNumCols() const
returns number of columns of the linear operator
Definition: flexLinearOperator.h:48
T getMaxRowSumAbs(bool transposed)
returns the maximum sum of absolute values per row used for preconditioning
Definition: flexMatrixLogical.h:123
std::vector< T > getAbsRowSum(bool transposed)
returns a vector of sum of absolute values per row used for preconditioning
Definition: flexMatrixLogical.h:131
flexMatrixLogical< T > * copy()
copies the linear operator
Definition: flexMatrixLogical.h:36
void printMatrix()
prints the whole matrix
Definition: flexMatrixLogical.h:193
void printRow(int i)
prints requested row
Definition: flexMatrixLogical.h:182
void timesPlus(bool transposed, const Tdata &input, Tdata &output)
applies linear operator on vector and adds its result to y
Definition: flexMatrixLogical.h:52
abstract base class for linear operators
Definition: flexLinearOperator.h:12
void times(bool transposed, const Tdata &input, Tdata &output)
applies linear operator on vector
Definition: flexMatrixLogical.h:47
void timesMinus(bool transposed, const Tdata &input, Tdata &output)
applies linear operator on vector and substracts its result from y
Definition: flexMatrixLogical.h:64