1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#ifndef __CSC_H__
#define __CSC_H__
#include "csr.h"
/*
* Compute Y += A*X for CSC matrix A and dense vectors X,Y
*
*
* Input Arguments:
* I n_row - number of rows in A
* I n_col - number of columns in A
* I Ap[n_row+1] - column pointer
* I Ai[nnz(A)] - row indices
* T Ax[n_col] - nonzeros
* T Xx[n_col] - input vector
*
* Output Arguments:
* T Yx[n_row] - output vector
*
* Note:
* Output array Yx must be preallocated
*
* Complexity: Linear. Specifically O(nnz(A) + n_col)
*
*/
template <class I, class T>
void csc_matvec(const I n_row,
const I n_col,
const I Ap[],
const I Ai[],
const T Ax[],
const T Xx[],
T Yx[])
{
for(I j = 0; j < n_col; j++){
I col_start = Ap[j];
I col_end = Ap[j+1];
for(I ii = col_start; ii < col_end; ii++){
I i = Ai[ii];
Yx[i] += Ax[ii] * Xx[j];
}
}
}
/*
* Compute Y += A*X for CSC matrix A and dense block vectors X,Y
*
*
* Input Arguments:
* I n_row - number of rows in A
* I n_col - number of columns in A
* I n_vecs - number of column vectors in X and Y
* I Ap[n_row+1] - row pointer
* I Aj[nnz(A)] - column indices
* T Ax[nnz(A)] - nonzeros
* T Xx[n_col,n_vecs] - input vector
*
* Output Arguments:
* T Yx[n_row,n_vecs] - output vector
*
* Note:
* Output array Yx must be preallocated
*
*/
template <class I, class T>
void csc_matvecs(const I n_row,
const I n_col,
const I n_vecs,
const I Ap[],
const I Ai[],
const T Ax[],
const T Xx[],
T Yx[])
{
for(I j = 0; j < n_col; j++){
for(I ii = Ap[j]; ii < Ap[j+1]; ii++){
const I i = Ai[ii];
axpy(n_vecs, Ax[ii], Xx + n_vecs * j, Yx + n_vecs * i);
}
}
}
/*
* Derived methods
*/
template <class I, class T>
void csc_diagonal(const I n_row,
const I n_col,
const I Ap[],
const I Aj[],
const T Ax[],
T Yx[])
{ csr_diagonal(n_col, n_row, Ap, Aj, Ax, Yx); }
template <class I, class T>
void csc_tocsr(const I n_row,
const I n_col,
const I Ap[],
const I Ai[],
const T Ax[],
I Bp[],
I Bj[],
T Bx[])
{ csr_tocsc<I,T>(n_col, n_row, Ap, Ai, Ax, Bp, Bj, Bx); }
template <class I>
void csc_matmat_pass1(const I n_row,
const I n_col,
const I Ap[],
const I Ai[],
const I Bp[],
const I Bi[],
I Cp[])
{ csr_matmat_pass1(n_col, n_row, Bp, Bi, Ap, Ai, Cp); }
template <class I, class T>
void csc_matmat_pass2(const I n_row,
const I n_col,
const I Ap[],
const I Ai[],
const T Ax[],
const I Bp[],
const I Bi[],
const T Bx[],
I Cp[],
I Ci[],
T Cx[])
{ csr_matmat_pass2(n_col, n_row, Bp, Bi, Bx, Ap, Ai, Ax, Cp, Ci, Cx); }
template <class I, class T>
void csc_elmul_csc(const I n_row, const I n_col,
const I Ap[], const I Ai[], const T Ax[],
const I Bp[], const I Bi[], const T Bx[],
I Cp[], I Ci[], T Cx[])
{
csr_elmul_csr(n_col, n_row, Ap, Ai, Ax, Bp, Bi, Bx, Cp, Ci, Cx);
}
template <class I, class T>
void csc_eldiv_csc(const I n_row, const I n_col,
const I Ap[], const I Ai[], const T Ax[],
const I Bp[], const I Bi[], const T Bx[],
I Cp[], I Ci[], T Cx[])
{
csr_eldiv_csr(n_col, n_row, Ap, Ai, Ax, Bp, Bi, Bx, Cp, Ci, Cx);
}
template <class I, class T>
void csc_plus_csc(const I n_row, const I n_col,
const I Ap[], const I Ai[], const T Ax[],
const I Bp[], const I Bi[], const T Bx[],
I Cp[], I Ci[], T Cx[])
{
csr_plus_csr(n_col, n_row, Ap, Ai, Ax, Bp, Bi, Bx, Cp, Ci, Cx);
}
template <class I, class T>
void csc_minus_csc(const I n_row, const I n_col,
const I Ap[], const I Ai[], const T Ax[],
const I Bp[], const I Bi[], const T Bx[],
I Cp[], I Ci[], T Cx[])
{
csr_minus_csr(n_col, n_row, Ap, Ai, Ax, Bp, Bi, Bx, Cp, Ci, Cx);
}
#endif
|