[Scipy-svn] r4784 - trunk/scipy/sparse/sparsetools
scipy-svn at scipy.org
scipy-svn at scipy.org
Mon Oct 6 00:29:48 EDT 2008
Author: wnbell
Date: 2008-10-05 23:29:46 -0500 (Sun, 05 Oct 2008)
New Revision: 4784
Modified:
trunk/scipy/sparse/sparsetools/csr.h
Log:
added csr_toell()
Modified: trunk/scipy/sparse/sparsetools/csr.h
===================================================================
--- trunk/scipy/sparse/sparsetools/csr.h 2008-10-05 16:55:22 UTC (rev 4783)
+++ trunk/scipy/sparse/sparsetools/csr.h 2008-10-06 04:29:46 UTC (rev 4784)
@@ -381,7 +381,55 @@
+/*
+ * Compute B = A for CSR matrix A, ELL matrix B
+ *
+ * Input Arguments:
+ * I n_row - number of rows in A
+ * I n_col - number of columns in A
+ * I Ap[n_row+1] - row pointer
+ * I Aj[nnz(A)] - column indices
+ * T Ax[nnz(A)] - nonzeros
+ * I row_length - maximum nnz in a row of A
+ *
+ * Output Arguments:
+ * I Bj[n_row * row_length] - column indices
+ * T Bx[n_row * row_length] - nonzeros
+ *
+ * Note:
+ * Output arrays Bj, Bx must be preallocated
+ * Duplicate entries in A are not merged.
+ * Explicit zeros in A are carried over to B.
+ * Rows with fewer than row_length columns are padded with zeros.
+ *
+ */
+template <class I, class T>
+void csr_toell(const I n_row,
+ const I n_col,
+ const I Ap[],
+ const I Aj[],
+ const T Ax[],
+ const I row_length,
+ I Bj[],
+ T Bx[])
+{
+ const I ell_nnz = row_length * n_row;
+ std::fill(Bj, Bj + ell_nnz, 0);
+ std::fill(Bx, Bx + ell_nnz, 0);
+ for(I i = 0; i < n_row; i++){
+ I * Bj_row = Bj + row_length * i;
+ T * Bx_row = Bx + row_length * i;
+ for(I jj = Ap[i]; jj < Ap[i+1]; jj++){
+ *Bj_row = Aj[jj];
+ *Bx_row = Ax[jj];
+ Bj_row++;
+ Bx_row++;
+ }
+ }
+}
+
+
/*
* Compute C = A*B for CSR matrices A,B
*
More information about the Scipy-svn
mailing list