comparison liboctave/dSparse.cc @ 8964:f4f4d65faaa0

Implement sparse * diagonal and diagonal * sparse operations, double-prec only. Date: Sun, 8 Mar 2009 16:28:18 -0400 These preserve sparsity, so eye(5) * sprand (5, 5, .2) is *sparse* and not dense. This may affect people who use multiplication by eye() rather than full(). The liboctave routines do *not* check if arguments are scalars in disguise. There is a type problem with checking at that level. I suspect we want diag * "sparse scalar" to stay diagonal, but we have to return a sparse matrix at the liboctave. Rather than worrying about that in liboctave, we cope with it when binding to Octave and return the correct higher-level type. The implementation is in Sparse-diag-op-defs.h rather than Sparse-op-defs.h to limit recompilation. And the implementations are templates rather than macros to produce better compiler errors and debugging information.
author Jason Riedy <jason@acm.org>
date Mon, 09 Mar 2009 17:49:13 -0400
parents 5bce1357edd6
children 1bba53c0a38d
comparison
equal deleted inserted replaced
8963:d1eab3ddb02d 8964:f4f4d65faaa0
27 27
28 #include <cfloat> 28 #include <cfloat>
29 29
30 #include <iostream> 30 #include <iostream>
31 #include <vector> 31 #include <vector>
32 #include <functional>
32 33
33 #include "quit.h" 34 #include "quit.h"
34 #include "lo-ieee.h" 35 #include "lo-ieee.h"
35 #include "lo-mappers.h" 36 #include "lo-mappers.h"
36 #include "f77-fcn.h" 37 #include "f77-fcn.h"
37 #include "dRowVector.h" 38 #include "dRowVector.h"
38 #include "oct-locbuf.h" 39 #include "oct-locbuf.h"
39 40
41 #include "dDiagMatrix.h"
40 #include "CSparse.h" 42 #include "CSparse.h"
41 #include "boolSparse.h" 43 #include "boolSparse.h"
42 #include "dSparse.h" 44 #include "dSparse.h"
43 #include "functor.h" 45 #include "functor.h"
44 #include "oct-spparms.h" 46 #include "oct-spparms.h"
46 #include "MatrixType.h" 48 #include "MatrixType.h"
47 #include "oct-sparse.h" 49 #include "oct-sparse.h"
48 #include "sparse-util.h" 50 #include "sparse-util.h"
49 #include "SparsedbleCHOL.h" 51 #include "SparsedbleCHOL.h"
50 #include "SparseQR.h" 52 #include "SparseQR.h"
53
54 #include "Sparse-diag-op-defs.h"
51 55
52 // Define whether to use a basic QR solver or one that uses a Dulmange 56 // Define whether to use a basic QR solver or one that uses a Dulmange
53 // Mendelsohn factorization to seperate the problem into under-determined, 57 // Mendelsohn factorization to seperate the problem into under-determined,
54 // well-determined and over-determined parts and solves them seperately 58 // well-determined and over-determined parts and solves them seperately
55 #ifndef USE_QRSOLVE 59 #ifndef USE_QRSOLVE
7696 trans_mul (const SparseMatrix& m, const Matrix& a) 7700 trans_mul (const SparseMatrix& m, const Matrix& a)
7697 { 7701 {
7698 SPARSE_FULL_TRANS_MUL (Matrix, double, 0., ); 7702 SPARSE_FULL_TRANS_MUL (Matrix, double, 0., );
7699 } 7703 }
7700 7704
7705 // diag * sparse and sparse * diag
7706
7707 SparseMatrix
7708 operator * (const DiagMatrix& d, const SparseMatrix& a)
7709 {
7710 return octave_impl::do_mul_dm_sm<SparseMatrix> (d, a);
7711 }
7712
7713 SparseMatrix
7714 operator * (const SparseMatrix& a, const DiagMatrix& d)
7715 {
7716 return octave_impl::do_mul_sm_dm<SparseMatrix> (a, d);
7717 }
7718
7701 // FIXME -- it would be nice to share code among the min/max 7719 // FIXME -- it would be nice to share code among the min/max
7702 // functions below. 7720 // functions below.
7703 7721
7704 #define EMPTY_RETURN_CHECK(T) \ 7722 #define EMPTY_RETURN_CHECK(T) \
7705 if (nr == 0 || nc == 0) \ 7723 if (nr == 0 || nc == 0) \