comparison liboctave/CSparse.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 eb63fbe60fab
children 1bba53c0a38d
comparison
equal deleted inserted replaced
8963:d1eab3ddb02d 8964:f4f4d65faaa0
35 #include "lo-mappers.h" 35 #include "lo-mappers.h"
36 #include "f77-fcn.h" 36 #include "f77-fcn.h"
37 #include "dRowVector.h" 37 #include "dRowVector.h"
38 #include "oct-locbuf.h" 38 #include "oct-locbuf.h"
39 39
40 #include "dDiagMatrix.h"
41 #include "CDiagMatrix.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"
45 #include "SparseCmplxLU.h" 47 #include "SparseCmplxLU.h"
46 #include "oct-sparse.h" 48 #include "oct-sparse.h"
47 #include "sparse-util.h" 49 #include "sparse-util.h"
48 #include "SparseCmplxCHOL.h" 50 #include "SparseCmplxCHOL.h"
49 #include "SparseCmplxQR.h" 51 #include "SparseCmplxQR.h"
52
53 #include "Sparse-diag-op-defs.h"
50 54
51 // Define whether to use a basic QR solver or one that uses a Dulmange 55 // Define whether to use a basic QR solver or one that uses a Dulmange
52 // Mendelsohn factorization to seperate the problem into under-determined, 56 // Mendelsohn factorization to seperate the problem into under-determined,
53 // well-determined and over-determined parts and solves them seperately 57 // well-determined and over-determined parts and solves them seperately
54 #ifndef USE_QRSOLVE 58 #ifndef USE_QRSOLVE
7582 herm_mul (const SparseComplexMatrix& m, const ComplexMatrix& a) 7586 herm_mul (const SparseComplexMatrix& m, const ComplexMatrix& a)
7583 { 7587 {
7584 SPARSE_FULL_TRANS_MUL (ComplexMatrix, Complex, Complex (0.,0.), conj); 7588 SPARSE_FULL_TRANS_MUL (ComplexMatrix, Complex, Complex (0.,0.), conj);
7585 } 7589 }
7586 7590
7591 // diag * sparse and sparse * diag
7592 SparseComplexMatrix
7593 operator * (const DiagMatrix& d, const SparseComplexMatrix& a)
7594 {
7595 return octave_impl::do_mul_dm_sm<SparseComplexMatrix> (d, a);
7596 }
7597 SparseComplexMatrix
7598 operator * (const SparseComplexMatrix& a, const DiagMatrix& d)
7599 {
7600 return octave_impl::do_mul_sm_dm<SparseComplexMatrix> (a, d);
7601 }
7602
7603 SparseComplexMatrix
7604 operator * (const ComplexDiagMatrix& d, const SparseMatrix& a)
7605 {
7606 return octave_impl::do_mul_dm_sm<SparseComplexMatrix> (d, a);
7607 }
7608 SparseComplexMatrix
7609 operator * (const SparseMatrix& a, const ComplexDiagMatrix& d)
7610 {
7611 return octave_impl::do_mul_sm_dm<SparseComplexMatrix> (a, d);
7612 }
7613
7614 SparseComplexMatrix
7615 operator * (const ComplexDiagMatrix& d, const SparseComplexMatrix& a)
7616 {
7617 return octave_impl::do_mul_dm_sm<SparseComplexMatrix> (d, a);
7618 }
7619 SparseComplexMatrix
7620 operator * (const SparseComplexMatrix& a, const ComplexDiagMatrix& d)
7621 {
7622 return octave_impl::do_mul_sm_dm<SparseComplexMatrix> (a, d);
7623 }
7624
7587 // FIXME -- it would be nice to share code among the min/max 7625 // FIXME -- it would be nice to share code among the min/max
7588 // functions below. 7626 // functions below.
7589 7627
7590 #define EMPTY_RETURN_CHECK(T) \ 7628 #define EMPTY_RETURN_CHECK(T) \
7591 if (nr == 0 || nc == 0) \ 7629 if (nr == 0 || nc == 0) \