octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Project progress


From: marco Vassallo
Subject: RE: Project progress
Date: Sun, 6 Oct 2013 20:28:27 +0200

> If you don't know whether the matrix is CSC or CSR, yu can just use
> the number of nonzeros to preallocate
> the correct space for the Octave SparseMatrix, but to fill it
> it is safer to still use dolfin high level methods.
>
At the moment I'm doing something very close (I hope) to what you suggest, just 
using nnz 
to preallocate the vector. [1]
But, even if the method data() produces an estimation of nnz for excess, at the 
moment I prefer to keep the if statement at line 114 of [1], because I've not 
yet fully understood how it work.
 
Thanks for your help,

Marco

[1] 
http://sourceforge.net/p/octave/fem-fenics/ci/default/tree/src/assemble.cc#l101
> 
For example you could do (N.B. this an examlpe and is untested):
>
> ----------------------------------------------------------------
> dim_vector dims (nnz, 1);
>
> Array<octave_idx_type> I(dims, 0);
> octave_idx_type *Iptr;
>
> Array<octave_idx_type> J(dims, 0);
> octave_idx_type *Jptr;
>
> Array<double> V(dims, 0);
> double *Vptr;
>
> octave_idx_type ival = 0;
> std::vector<octave_idx_type> tmpcols;
> std::vector<double> tmpvals;
> for (octave_idx_value ir = 0; ir < fenics_matrix.size (0); ++ir)
> {
> fenics_matrix.getrow (ir, tmpcols, tmpvals);
> for (octave_idx_type ii = 0; ii < tmpcols.length (); ++ii)
> {
> Iptr[ival] = ir;
> Jptr[ival] = tmpcols[ii];
> Vptr[ival++] = tmpvals[ii];
> }
> }
>
> retval(0) = octave_value (SparseMatrix (V, I, J, nrows, ncols, true));        
>                                   

reply via email to

[Prev in Thread] Current Thread [Next in Thread]