comparison liboctave/CSparse.cc @ 9469:c6edba80dfae

sanity checks for loading sparse matrices
author John W. Eaton <jwe@octave.org>
date Wed, 29 Jul 2009 12:15:27 -0400
parents 5d46c4a894e8
children a5035bc7fbfb
comparison
equal deleted inserted replaced
9468:5af462716bff 9469:c6edba80dfae
7464 } 7464 }
7465 7465
7466 std::istream& 7466 std::istream&
7467 operator >> (std::istream& is, SparseComplexMatrix& a) 7467 operator >> (std::istream& is, SparseComplexMatrix& a)
7468 { 7468 {
7469 octave_idx_type nr = a.rows (); 7469 typedef SparseComplexMatrix::element_type elt_type;
7470 octave_idx_type nc = a.cols (); 7470
7471 octave_idx_type nz = a.nzmax (); 7471 return read_sparse_matrix<elt_type> (is, a, octave_read_value<Complex>);
7472
7473 if (nr > 0 && nc > 0)
7474 {
7475 octave_idx_type itmp, jtmp, jold = 0;
7476 Complex tmp;
7477 octave_idx_type ii = 0;
7478
7479 a.cidx (0) = 0;
7480 for (octave_idx_type i = 0; i < nz; i++)
7481 {
7482 is >> itmp;
7483 itmp--;
7484 is >> jtmp;
7485 jtmp--;
7486 tmp = octave_read_complex (is);
7487
7488 if (is)
7489 {
7490 if (jold != jtmp)
7491 {
7492 for (octave_idx_type j = jold; j < jtmp; j++)
7493 a.cidx(j+1) = ii;
7494
7495 jold = jtmp;
7496 }
7497 a.data (ii) = tmp;
7498 a.ridx (ii++) = itmp;
7499 }
7500 else
7501 goto done;
7502 }
7503
7504 for (octave_idx_type j = jold; j < nc; j++)
7505 a.cidx(j+1) = ii;
7506 }
7507
7508 done:
7509
7510 return is;
7511 } 7472 }
7512 7473
7513 SparseComplexMatrix 7474 SparseComplexMatrix
7514 operator * (const SparseComplexMatrix& m, const SparseMatrix& a) 7475 operator * (const SparseComplexMatrix& m, const SparseMatrix& a)
7515 { 7476 {