# HG changeset patch # User jwe # Date 1138731780 0 # Node ID 2857357f9d3cd31223f10ba9559de72839fd7fa9 # Parent 2c66c36d2698676ee17d0d09fa75f748f095c36c [project @ 2006-01-31 18:22:59 by jwe] diff --git a/liboctave/CSparse.cc b/liboctave/CSparse.cc --- a/liboctave/CSparse.cc +++ b/liboctave/CSparse.cc @@ -105,10 +105,10 @@ } SparseComplexMatrix::SparseComplexMatrix (const SparseMatrix& a) - : MSparse (a.rows (), a.cols (), a.nnz ()) + : MSparse (a.rows (), a.cols (), a.nzmax ()) { octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); for (octave_idx_type i = 0; i < nc + 1; i++) cidx (i) = a.cidx (i); @@ -121,10 +121,10 @@ } SparseComplexMatrix::SparseComplexMatrix (const SparseBoolMatrix& a) - : MSparse (a.rows (), a.cols (), a.nnz ()) + : MSparse (a.rows (), a.cols (), a.nzmax ()) { octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); for (octave_idx_type i = 0; i < nc + 1; i++) cidx (i) = a.cidx (i); @@ -141,10 +141,10 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type nr_a = a.rows (); octave_idx_type nc_a = a.cols (); - octave_idx_type nz_a = a.nnz (); + octave_idx_type nz_a = a.nzmax (); if (nr != nr_a || nc != nc_a || nz != nz_a) return false; @@ -545,7 +545,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); SparseComplexMatrix retval (nc, nr, nz); retval.cidx(0) = 0; @@ -569,7 +569,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseComplexMatrix retval (nc, nr, nz); for (octave_idx_type i = 0; i < nc + 1; i++) @@ -702,7 +702,7 @@ if (typ == SparseType::Upper || typ == SparseType::Lower) { - octave_idx_type nz = nnz(); + octave_idx_type nz = nzmax (); octave_idx_type cx = 0; octave_idx_type nz2 = nz; retval = SparseComplexMatrix (nr, nc, nz2); @@ -787,7 +787,7 @@ } else { - octave_idx_type nz = nnz(); + octave_idx_type nz = nzmax (); octave_idx_type cx = 0; octave_idx_type nz2 = nz; retval = SparseComplexMatrix (nr, nc, nz2); @@ -1179,7 +1179,7 @@ { octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; @@ -1309,7 +1309,7 @@ { octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; @@ -1611,7 +1611,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -2085,7 +2085,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -2581,7 +2581,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -3098,7 +3098,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -3580,7 +3580,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseComplexMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -3891,7 +3891,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -4279,7 +4279,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -4385,7 +4385,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseComplexMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -4691,7 +4691,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -4804,7 +4804,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseComplexMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -5057,7 +5057,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5326,7 +5326,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5350,7 +5350,7 @@ B->ncol = b.cols(); B->p = b.cidx(); B->i = b.ridx(); - B->nzmax = b.nonzero(); + B->nzmax = b.nnz(); B->packed = true; B->sorted = true; B->nz = NULL; @@ -5464,7 +5464,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - octave_idx_type x_nz = b.nnz (); + octave_idx_type x_nz = b.nzmax (); octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -5640,7 +5640,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5887,7 +5887,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5911,7 +5911,7 @@ B->ncol = b.cols(); B->p = b.cidx(); B->i = b.ridx(); - B->nzmax = b.nonzero(); + B->nzmax = b.nnz(); B->packed = true; B->sorted = true; B->nz = NULL; @@ -6018,7 +6018,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - octave_idx_type x_nz = b.nnz (); + octave_idx_type x_nz = b.nzmax (); octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -6718,7 +6718,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz1 = nnz (); + octave_idx_type nz1 = nzmax (); octave_idx_type nz2 = nr*nc - nz1; SparseBoolMatrix r (nr, nc, nz2); @@ -6792,7 +6792,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); bool f_zero = (f(0.0) == 0.0); // Count number of non-zero elements @@ -6842,7 +6842,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); bool f_zero = (f(0.0) == 0.0); // Count number of non-zero elements @@ -6892,7 +6892,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); bool f_zero = f(0.0); // Count number of non-zero elements @@ -6947,7 +6947,7 @@ bool SparseComplexMatrix::any_element_is_inf_or_nan (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -6964,7 +6964,7 @@ bool SparseComplexMatrix::all_elements_are_real (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -6984,7 +6984,7 @@ bool SparseComplexMatrix::all_integers (double& max_val, double& min_val) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); if (nel == 0) return false; @@ -7021,7 +7021,7 @@ bool SparseComplexMatrix::too_large_for_float (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -7099,7 +7099,7 @@ SparseMatrix SparseComplexMatrix::abs (void) const { - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type nc = cols (); SparseMatrix retval (rows(), nc, nz); @@ -7227,7 +7227,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); if (nr < 1 || nc < 1) is.clear (std::ios::badbit); @@ -7394,14 +7394,14 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - if (a_nr == 0 || b_nc == 0 || a.nnz () == 0 || b.nnz () == 0) + if (a_nr == 0 || b_nc == 0 || a.nzmax () == 0 || b.nzmax () == 0) return SparseComplexMatrix (a_nr, a_nc); if (a_nr != b_nr || a_nc != b_nc) gripe_nonconformant ("min", a_nr, a_nc, b_nr, b_nc); else { - r = SparseComplexMatrix (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = SparseComplexMatrix (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; r.cidx (0) = 0; @@ -7516,16 +7516,16 @@ if (a_nr == 0 || b_nc == 0) return SparseComplexMatrix (a_nr, a_nc); - if (a.nnz () == 0) + if (a.nzmax () == 0) return SparseComplexMatrix (b); - if (b.nnz () == 0) + if (b.nzmax () == 0) return SparseComplexMatrix (a); if (a_nr != b_nr || a_nc != b_nc) gripe_nonconformant ("min", a_nr, a_nc, b_nr, b_nc); else { - r = SparseComplexMatrix (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = SparseComplexMatrix (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; r.cidx (0) = 0; diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2006-01-31 John W. Eaton + + * Sparse.h (Sparse::nzmax): New function. + (Sparse::nnz): Rename from nonzero. + Change all uses of old nnz function to be nzmax. Change all uses + of nonzero to be nnz. + (Sparse::nzmx): Rename from nnz (data member). Change all uses. + 2006-01-21 David Bateman * sparse-sort.cc (bool octave_sparse_sidxl_comp): 64-bit fix. diff --git a/liboctave/MSparse.cc b/liboctave/MSparse.cc --- a/liboctave/MSparse.cc +++ b/liboctave/MSparse.cc @@ -52,7 +52,7 @@ gripe_nonconformant ("operator +=" , a_nr, a_nc, b_nr, b_nc); else { - r = MSparse (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = MSparse (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; for (octave_idx_type i = 0 ; i < a_nc ; i++) @@ -125,7 +125,7 @@ gripe_nonconformant ("operator -=" , a_nr, a_nc, b_nr, b_nc); else { - r = MSparse (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = MSparse (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; for (octave_idx_type i = 0 ; i < a_nc ; i++) @@ -207,7 +207,7 @@ { \ octave_idx_type nr = a.rows (); \ octave_idx_type nc = a.cols (); \ - octave_idx_type nz = a.nnz (); \ + octave_idx_type nz = a.nzmax (); \ \ MSparse r (nr, nc, nz); \ \ @@ -253,7 +253,7 @@ { \ octave_idx_type nr = a.rows (); \ octave_idx_type nc = a.cols (); \ - octave_idx_type nz = a.nnz (); \ + octave_idx_type nz = a.nzmax (); \ \ MSparse r (nr, nc, nz); \ \ @@ -292,7 +292,7 @@ gripe_nonconformant ("operator " # OP, a_nr, a_nc, b_nr, b_nc); \ else \ { \ - r = MSparse (a_nr, a_nc, (a.nnz () + b.nnz ())); \ + r = MSparse (a_nr, a_nc, (a.nzmax () + b.nzmax ())); \ \ octave_idx_type jx = 0; \ r.cidx (0) = 0; \ @@ -367,7 +367,7 @@ gripe_nonconformant (#FCN, a_nr, a_nc, b_nr, b_nc); \ else \ { \ - r = MSparse (a_nr, a_nc, (a.nnz() > b.nnz() ? a.nnz() : b.nnz())); \ + r = MSparse (a_nr, a_nc, (a.nzmax () > b.nzmax () ? a.nzmax () : b.nzmax ())); \ \ octave_idx_type jx = 0; \ r.cidx (0) = 0; \ @@ -494,7 +494,7 @@ operator - (const MSparse& a) { MSparse retval (a); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); for (octave_idx_type i = 0; i < nz; i++) retval.data(i) = - retval.data(i); return retval; diff --git a/liboctave/Sparse-op-defs.h b/liboctave/Sparse-op-defs.h --- a/liboctave/Sparse-op-defs.h +++ b/liboctave/Sparse-op-defs.h @@ -63,7 +63,7 @@ { \ octave_idx_type nr = m.rows (); \ octave_idx_type nc = m.cols (); \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ \ R r (nr, nc, nz); \ \ @@ -103,7 +103,7 @@ { \ /* Count num of non-zero elements */ \ octave_idx_type nel = 0; \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ if (MC (MZ) OP SC (s)) \ nel += m.numel() - nz; \ for (octave_idx_type i = 0; i < nz; i++) \ @@ -178,7 +178,7 @@ { \ /* Count num of non-zero elements */ \ octave_idx_type nel = 0; \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ if (LHS_ZERO OP (s != RHS_ZERO)) \ nel += m.numel() - nz; \ for (octave_idx_type i = 0; i < nz; i++) \ @@ -273,7 +273,7 @@ { \ octave_idx_type nr = m.rows (); \ octave_idx_type nc = m.cols (); \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ \ R r (nr, nc, nz); \ \ @@ -313,7 +313,7 @@ { \ /* Count num of non-zero elements */ \ octave_idx_type nel = 0; \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ if (SC (s) OP MC (MZ)) \ nel += m.numel() - nz; \ for (octave_idx_type i = 0; i < nz; i++) \ @@ -388,7 +388,7 @@ { \ /* Count num of non-zero elements */ \ octave_idx_type nel = 0; \ - octave_idx_type nz = m.nnz (); \ + octave_idx_type nz = m.nzmax (); \ if ((s != LHS_ZERO) OP RHS_ZERO) \ nel += m.numel() - nz; \ for (octave_idx_type i = 0; i < nz; i++) \ @@ -477,7 +477,7 @@ gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ else \ { \ - r = R (m1_nr, m1_nc, (m1.nnz () + m2.nnz ())); \ + r = R (m1_nr, m1_nc, (m1.nzmax () + m2.nzmax ())); \ \ octave_idx_type jx = 0; \ r.cidx (0) = 0; \ @@ -551,7 +551,7 @@ gripe_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ else \ { \ - r = R (m1_nr, m1_nc, (m1.nnz () > m2.nnz () ? m1.nnz () : m2.nnz ())); \ + r = R (m1_nr, m1_nc, (m1.nzmax () > m2.nzmax () ? m1.nzmax () : m2.nzmax ())); \ \ octave_idx_type jx = 0; \ r.cidx (0) = 0; \ diff --git a/liboctave/Sparse.cc b/liboctave/Sparse.cc --- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -50,7 +50,7 @@ { octave_idx_type i; - if (nnz > 0) + if (nzmx > 0) { for (i = c[_c]; i < c[_c + 1]; i++) if (r[i] == _r) @@ -60,7 +60,7 @@ // Ok, If we've gotten here, we're in trouble.. Have to create a // new element in the sparse array. This' gonna be slow!!! - if (c[ncols+1] == nnz) + if (c[ncols+1] == nzmx) { (*current_liboctave_error_handler) ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); @@ -97,7 +97,7 @@ T Sparse::SparseRep::celem (octave_idx_type _r, octave_idx_type _c) const { - if (nnz > 0) + if (nzmx > 0) for (octave_idx_type i = c[_c]; i < c[_c + 1]; i++) if (r[i] == _r) return d[i]; @@ -108,11 +108,11 @@ void Sparse::SparseRep::maybe_compress (bool remove_zeros) { - octave_idx_type ndel = nnz - c[ncols]; + octave_idx_type ndel = nzmx - c[ncols]; octave_idx_type nzero = 0; if (remove_zeros) - for (octave_idx_type i = 0; i < nnz - ndel; i++) + for (octave_idx_type i = 0; i < nzmx - ndel; i++) if (d[i] == T ()) nzero++; @@ -121,26 +121,26 @@ if (!nzero) { - octave_idx_type new_nnz = nnz - ndel; - - T *new_data = new T [new_nnz]; - for (octave_idx_type i = 0; i < new_nnz; i++) + octave_idx_type new_nzmx = nzmx - ndel; + + T *new_data = new T [new_nzmx]; + for (octave_idx_type i = 0; i < new_nzmx; i++) new_data[i] = d[i]; delete [] d; d = new_data; - octave_idx_type *new_ridx = new octave_idx_type [new_nnz]; - for (octave_idx_type i = 0; i < new_nnz; i++) + octave_idx_type *new_ridx = new octave_idx_type [new_nzmx]; + for (octave_idx_type i = 0; i < new_nzmx; i++) new_ridx[i] = r[i]; delete [] r; r = new_ridx; } else { - octave_idx_type new_nnz = nnz - ndel - nzero; - - T *new_data = new T [new_nnz]; - octave_idx_type *new_ridx = new octave_idx_type [new_nnz]; + octave_idx_type new_nzmx = nzmx - ndel - nzero; + + T *new_data = new T [new_nzmx]; + octave_idx_type *new_ridx = new octave_idx_type [new_nzmx]; octave_idx_type ii = 0; octave_idx_type ic = 0; @@ -163,37 +163,37 @@ r = new_ridx; } - nnz -= ndel + nzero; + nzmx -= ndel + nzero; } template void Sparse::SparseRep::change_length (octave_idx_type nz) { - if (nz != nnz) + if (nz != nzmx) { - octave_idx_type min_nnz = (nz < nnz ? nz : nnz); + octave_idx_type min_nzmx = (nz < nzmx ? nz : nzmx); octave_idx_type * new_ridx = new octave_idx_type [nz]; - for (octave_idx_type i = 0; i < min_nnz; i++) + for (octave_idx_type i = 0; i < min_nzmx; i++) new_ridx[i] = r[i]; delete [] r; r = new_ridx; T * new_data = new T [nz]; - for (octave_idx_type i = 0; i < min_nnz; i++) + for (octave_idx_type i = 0; i < min_nzmx; i++) new_data[i] = d[i]; delete [] d; d = new_data; - if (nz < nnz) + if (nz < nzmx) for (octave_idx_type i = 0; i <= ncols; i++) if (c[i] > nz) c[i] = nz; - nnz = nz; + nzmx = nz; } } @@ -202,13 +202,13 @@ Sparse::Sparse (const Sparse& a) : dimensions (a.dimensions), idx (0), idx_count (0) { - if (a.nnz () == 0) + if (a.nzmax () == 0) rep = new typename Sparse::SparseRep (rows (), cols()); else { - rep = new typename Sparse::SparseRep (rows (), cols (), a.nnz ()); + rep = new typename Sparse::SparseRep (rows (), cols (), a.nzmax ()); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type nc = cols (); for (octave_idx_type i = 0; i < nz; i++) { @@ -267,13 +267,13 @@ else { dim_vector old_dims = a.dims(); - octave_idx_type new_nnz = a.nnz (); + octave_idx_type new_nzmx = a.nzmax (); octave_idx_type new_nr = dv (0); octave_idx_type new_nc = dv (1); octave_idx_type old_nr = old_dims (0); octave_idx_type old_nc = old_dims (1); - rep = new typename Sparse::SparseRep (new_nr, new_nc, new_nnz); + rep = new typename Sparse::SparseRep (new_nr, new_nc, new_nzmx); octave_idx_type kk = 0; xcidx(0) = 0; @@ -290,7 +290,7 @@ xridx(j) = ii; } for (octave_idx_type k = kk; k < new_nc; k++) - xcidx(k+1) = new_nnz; + xcidx(k+1) = new_nzmx; } } @@ -318,17 +318,17 @@ } else { - octave_idx_type max_nnz = (r_len > c_len ? r_len : c_len); - - OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nnz); - OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nnz); - - for (octave_idx_type i = 0; i < max_nnz; i++) + octave_idx_type max_nzmx = (r_len > c_len ? r_len : c_len); + + OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nzmx); + OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nzmx); + + for (octave_idx_type i = 0; i < max_nzmx; i++) sidx[i] = &sidxX[i]; - octave_idx_type actual_nnz = 0; + octave_idx_type actual_nzmx = 0; OCTAVE_QUIT; - for (octave_idx_type i = 0; i < max_nnz; i++) + for (octave_idx_type i = 0; i < max_nzmx; i++) { octave_idx_type rowidx = (ri_scalar ? r(0) : r(i)); octave_idx_type colidx = (ci_scalar ? c(0) : c(i)); @@ -337,10 +337,10 @@ { if ( a (cf_scalar ? 0 : i ) != T ()) { - sidx[actual_nnz]->r = rowidx; - sidx[actual_nnz]->c = colidx; - sidx[actual_nnz]->idx = i; - actual_nnz++; + sidx[actual_nzmx]->r = rowidx; + sidx[actual_nzmx]->c = colidx; + sidx[actual_nzmx]->idx = i; + actual_nzmx++; } } else @@ -354,7 +354,7 @@ } } - if (actual_nnz == 0) + if (actual_nzmx == 0) rep = new typename Sparse::SparseRep (nr, nc); else { @@ -362,23 +362,23 @@ octave_sort sort (octave_sparse_sidxl_comp); - sort.sort (sidx, actual_nnz); + sort.sort (sidx, actual_nzmx); OCTAVE_QUIT; // Now count the unique non-zero values - octave_idx_type real_nnz = 1; - for (octave_idx_type i = 1; i < actual_nnz; i++) + octave_idx_type real_nzmx = 1; + for (octave_idx_type i = 1; i < actual_nzmx; i++) if (sidx[i-1]->r != sidx[i]->r || sidx[i-1]->c != sidx[i]->c) - real_nnz++; - - rep = new typename Sparse::SparseRep (nr, nc, real_nnz); + real_nzmx++; + + rep = new typename Sparse::SparseRep (nr, nc, real_nzmx); octave_idx_type cx = 0; octave_idx_type prev_rval = -1; octave_idx_type prev_cval = -1; octave_idx_type ii = -1; xcidx (0) = 0; - for (octave_idx_type i = 0; i < actual_nnz; i++) + for (octave_idx_type i = 0; i < actual_nzmx; i++) { OCTAVE_QUIT; octave_idx_type iidx = sidx[i]->idx; @@ -435,18 +435,18 @@ } else { - octave_idx_type max_nnz = (r_len > c_len ? r_len : c_len); + octave_idx_type max_nzmx = (r_len > c_len ? r_len : c_len); - OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nnz); - OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nnz); - - for (octave_idx_type i = 0; i < max_nnz; i++) + OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nzmx); + OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nzmx); + + for (octave_idx_type i = 0; i < max_nzmx; i++) sidx[i] = &sidxX[i]; - octave_idx_type actual_nnz = 0; + octave_idx_type actual_nzmx = 0; OCTAVE_QUIT; - for (octave_idx_type i = 0; i < max_nnz; i++) + for (octave_idx_type i = 0; i < max_nzmx; i++) { octave_idx_type rowidx = static_cast (ri_scalar ? r(0) : r(i)); octave_idx_type colidx = static_cast (ci_scalar ? c(0) : c(i)); @@ -455,10 +455,10 @@ { if ( a (cf_scalar ? 0 : i ) != T ()) { - sidx[actual_nnz]->r = rowidx; - sidx[actual_nnz]->c = colidx; - sidx[actual_nnz]->idx = i; - actual_nnz++; + sidx[actual_nzmx]->r = rowidx; + sidx[actual_nzmx]->c = colidx; + sidx[actual_nzmx]->idx = i; + actual_nzmx++; } } else @@ -472,7 +472,7 @@ } } - if (actual_nnz == 0) + if (actual_nzmx == 0) rep = new typename Sparse::SparseRep (nr, nc); else { @@ -480,23 +480,23 @@ octave_sort sort (octave_sparse_sidxl_comp); - sort.sort (sidx, actual_nnz); + sort.sort (sidx, actual_nzmx); OCTAVE_QUIT; // Now count the unique non-zero values - octave_idx_type real_nnz = 1; - for (octave_idx_type i = 1; i < actual_nnz; i++) + octave_idx_type real_nzmx = 1; + for (octave_idx_type i = 1; i < actual_nzmx; i++) if (sidx[i-1]->r != sidx[i]->r || sidx[i-1]->c != sidx[i]->c) - real_nnz++; - - rep = new typename Sparse::SparseRep (nr, nc, real_nnz); + real_nzmx++; + + rep = new typename Sparse::SparseRep (nr, nc, real_nzmx); octave_idx_type cx = 0; octave_idx_type prev_rval = -1; octave_idx_type prev_cval = -1; octave_idx_type ii = -1; xcidx (0) = 0; - for (octave_idx_type i = 0; i < actual_nnz; i++) + for (octave_idx_type i = 0; i < actual_nzmx; i++) { OCTAVE_QUIT; octave_idx_type iidx = sidx[i]->idx; @@ -537,14 +537,14 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); octave_idx_type len = a.length (); - octave_idx_type new_nnz = 0; + octave_idx_type new_nzmx = 0; // First count the number of non-zero terms for (octave_idx_type i = 0; i < len; i++) if (a(i) != T ()) - new_nnz++; - - rep = new typename Sparse::SparseRep (nr, nc, new_nnz); + new_nzmx++; + + rep = new typename Sparse::SparseRep (nr, nc, new_nzmx); octave_idx_type ii = 0; xcidx(0) = 0; @@ -572,14 +572,14 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); octave_idx_type len = a.length (); - octave_idx_type new_nnz = 0; + octave_idx_type new_nzmx = 0; // First count the number of non-zero terms for (octave_idx_type i = 0; i < len; i++) if (a(i) != T ()) - new_nnz++; - - rep = new typename Sparse::SparseRep (nr, nc, new_nnz); + new_nzmx++; + + rep = new typename Sparse::SparseRep (nr, nc, new_nzmx); octave_idx_type ii = 0; xcidx(0) = 0; @@ -731,12 +731,12 @@ { if (dimensions.numel () == new_dims.numel ()) { - octave_idx_type new_nnz = nnz (); + octave_idx_type new_nzmx = nzmax (); octave_idx_type new_nr = new_dims (0); octave_idx_type new_nc = new_dims (1); octave_idx_type old_nr = rows (); octave_idx_type old_nc = cols (); - retval = Sparse (new_nr, new_nc, new_nnz); + retval = Sparse (new_nr, new_nc, new_nzmx); octave_idx_type kk = 0; retval.xcidx(0) = 0; @@ -753,7 +753,7 @@ retval.xridx(j) = ii; } for (octave_idx_type k = kk; k < new_nc; k++) - retval.xcidx(k+1) = new_nnz; + retval.xcidx(k+1) = new_nzmx; } else (*current_liboctave_error_handler) ("reshape: size mismatch"); @@ -846,7 +846,7 @@ octave_idx_type nc = cols (); octave_idx_type nr = rows (); - if (nnz () == 0 || r == 0 || c == 0) + if (nzmax () == 0 || r == 0 || c == 0) // Special case of redimensioning to/from a sparse matrix with // no elements rep = new typename Sparse::SparseRep (r, c); @@ -935,7 +935,7 @@ } // First count the number of elements in the final array - octave_idx_type nel = cidx(c) + a.nnz (); + octave_idx_type nel = cidx(c) + a.nzmax (); if (c + a_cols < nc) nel += cidx(nc) - cidx(c + a_cols); @@ -1025,7 +1025,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); Sparse retval (nc, nr, nz); retval.cidx(0) = 0; @@ -1123,7 +1123,7 @@ if (num_to_delete != 0) { octave_idx_type new_n = n; - octave_idx_type new_nnz = nnz (); + octave_idx_type new_nzmx = nzmax (); octave_idx_type iidx = 0; @@ -1139,7 +1139,7 @@ new_n--; if (tmp.elem (i) != T ()) - new_nnz--; + new_nzmx--; if (iidx == num_to_delete) break; @@ -1151,9 +1151,9 @@ rep->count--; if (nr == 1) - rep = new typename Sparse::SparseRep (1, new_n, new_nnz); + rep = new typename Sparse::SparseRep (1, new_n, new_nzmx); else - rep = new typename Sparse::SparseRep (new_n, 1, new_nnz); + rep = new typename Sparse::SparseRep (new_n, 1, new_nzmx); octave_idx_type ii = 0; octave_idx_type jj = 0; @@ -1196,7 +1196,7 @@ else { cidx(0) = 0; - cidx(1) = new_nnz; + cidx(1) = new_nzmx; dimensions(0) = new_n; dimensions(1) = 1; } @@ -1268,7 +1268,7 @@ else { octave_idx_type new_nc = nc; - octave_idx_type new_nnz = nnz (); + octave_idx_type new_nzmx = nzmax (); octave_idx_type iidx = 0; @@ -1281,7 +1281,7 @@ iidx++; new_nc--; - new_nnz -= cidx(j+1) - cidx(j); + new_nzmx -= cidx(j+1) - cidx(j); if (iidx == num_to_delete) break; @@ -1293,7 +1293,7 @@ const Sparse tmp (*this); --rep->count; rep = new typename Sparse::SparseRep (nr, new_nc, - new_nnz); + new_nzmx); octave_idx_type ii = 0; octave_idx_type jj = 0; iidx = 0; @@ -1343,7 +1343,7 @@ else { octave_idx_type new_nr = nr; - octave_idx_type new_nnz = nnz (); + octave_idx_type new_nzmx = nzmax (); octave_idx_type iidx = 0; @@ -1356,9 +1356,9 @@ iidx++; new_nr--; - for (octave_idx_type j = 0; j < nnz (); j++) + for (octave_idx_type j = 0; j < nzmax (); j++) if (ridx(j) == i) - new_nnz--; + new_nzmx--; if (iidx == num_to_delete) break; @@ -1370,7 +1370,7 @@ const Sparse tmp (*this); --rep->count; rep = new typename Sparse::SparseRep (new_nr, nc, - new_nnz); + new_nzmx); octave_idx_type jj = 0; cidx(0) = 0; @@ -1464,7 +1464,7 @@ octave_idx_type nr = dim1 (); octave_idx_type nc = dim2 (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type orig_len = nr * nc; @@ -1572,7 +1572,7 @@ else { - octave_idx_type new_nnz = 0; + octave_idx_type new_nzmx = 0; if (nr == 1) for (octave_idx_type i = 0; i < n; i++) { @@ -1581,7 +1581,7 @@ octave_idx_type ii = idx_arg.elem (i); if (ii < len) if (cidx(ii) != cidx(ii+1)) - new_nnz++; + new_nzmx++; } else for (octave_idx_type i = 0; i < n; i++) @@ -1593,7 +1593,7 @@ OCTAVE_QUIT; if (ridx(j) == ii) - new_nnz++; + new_nzmx++; if (ridx(j) >= ii) break; } @@ -1604,7 +1604,7 @@ { if (nr == 1) { - retval = Sparse (1, n, new_nnz); + retval = Sparse (1, n, new_nzmx); octave_idx_type jj = 0; retval.xcidx(0) = 0; for (octave_idx_type i = 0; i < n; i++) @@ -1623,9 +1623,9 @@ } else { - retval = Sparse (n, 1, new_nnz); + retval = Sparse (n, 1, new_nzmx); retval.xcidx(0) = 0; - retval.xcidx(1) = new_nnz; + retval.xcidx(1) = new_nzmx; octave_idx_type jj = 0; for (octave_idx_type i = 0; i < n; i++) { @@ -1661,7 +1661,7 @@ new_nc = 1; } - retval = Sparse (new_nr, new_nc, new_nnz); + retval = Sparse (new_nr, new_nc, new_nzmx); if (nr == 1) { @@ -1737,7 +1737,7 @@ else { // Count number of non-zero elements - octave_idx_type new_nnz = 0; + octave_idx_type new_nzmx = 0; octave_idx_type kk = 0; for (octave_idx_type j = 0; j < result_nc; j++) { @@ -1753,7 +1753,7 @@ for (octave_idx_type k = cidx(fc); k < cidx(fc+1); k++) { if (ridx(k) == fr) - new_nnz++; + new_nzmx++; if (ridx(k) >= fr) break; } @@ -1761,7 +1761,7 @@ } } - retval = Sparse (result_nr, result_nc, new_nnz); + retval = Sparse (result_nr, result_nc, new_nzmx); kk = 0; octave_idx_type jj = 0; @@ -1826,7 +1826,7 @@ else { // First count the number of non-zero elements - octave_idx_type new_nnz = 0; + octave_idx_type new_nzmx = 0; for (octave_idx_type j = 0; j < m; j++) { octave_idx_type jj = idx_j.elem (j); @@ -1840,7 +1840,7 @@ for (octave_idx_type k = cidx(jj); k < cidx(jj+1); k++) { if (ridx(k) == ii) - new_nnz++; + new_nzmx++; if (ridx(k) >= ii) break; } @@ -1848,7 +1848,7 @@ } } - retval = Sparse (n, m, new_nnz); + retval = Sparse (n, m, new_nzmx); octave_idx_type kk = 0; retval.xcidx(0) = 0; @@ -1936,7 +1936,7 @@ octave_idx_type nr = lhs.rows (); octave_idx_type nc = lhs.cols (); - octave_idx_type nz = lhs.nnz (); + octave_idx_type nz = lhs.nzmax (); octave_idx_type n = lhs_idx.freeze (lhs_len, "vector", true, liboctave_wrore_flag); @@ -1952,7 +1952,7 @@ if (rhs_len == n) { - octave_idx_type new_nnz = lhs.nnz (); + octave_idx_type new_nzmx = lhs.nzmax (); OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx, n); if (! lhs_idx.is_colon ()) @@ -1998,16 +1998,16 @@ octave_idx_type ii = lhs_idx.elem (i); if (ii < lhs_len && c_lhs.elem(ii) != LT ()) - new_nnz--; + new_nzmx--; if (rhs.elem(rhs_idx[i]) != RT ()) - new_nnz++; + new_nzmx++; } if (nr > 1) { - Sparse tmp (max_idx, 1, new_nnz); + Sparse tmp (max_idx, 1, new_nzmx); tmp.cidx(0) = 0; - tmp.cidx(1) = tmp.nnz (); + tmp.cidx(1) = tmp.nzmax (); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2049,7 +2049,7 @@ } else { - Sparse tmp (1, max_idx, new_nnz); + Sparse tmp (1, max_idx, new_nzmx); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2105,28 +2105,28 @@ } else if (rhs_len == 1) { - octave_idx_type new_nnz = lhs.nnz (); + octave_idx_type new_nzmx = lhs.nzmax (); RT scalar = rhs.elem (0); bool scalar_non_zero = (scalar != RT ()); lhs_idx.sort (true); // First count the number of non-zero elements if (scalar != RT ()) - new_nnz += n; + new_nzmx += n; for (octave_idx_type i = 0; i < n; i++) { OCTAVE_QUIT; octave_idx_type ii = lhs_idx.elem (i); if (ii < lhs_len && c_lhs.elem(ii) != LT ()) - new_nnz--; + new_nzmx--; } if (nr > 1) { - Sparse tmp (max_idx, 1, new_nnz); + Sparse tmp (max_idx, 1, new_nzmx); tmp.cidx(0) = 0; - tmp.cidx(1) = tmp.nnz (); + tmp.cidx(1) = tmp.nzmax (); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2167,7 +2167,7 @@ } else { - Sparse tmp (1, max_idx, new_nnz); + Sparse tmp (1, max_idx, new_nzmx); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2229,8 +2229,8 @@ if (lhs_len == 0) { - octave_idx_type new_nnz = rhs.nnz (); - Sparse tmp (1, rhs_len, new_nnz); + octave_idx_type new_nzmx = rhs.nzmax (); + Sparse tmp (1, rhs_len, new_nzmx); octave_idx_type ii = 0; octave_idx_type jj = 0; @@ -2277,7 +2277,7 @@ octave_idx_type lhs_nr = lhs.rows (); octave_idx_type lhs_nc = lhs.cols (); - octave_idx_type lhs_nz = lhs.nnz (); + octave_idx_type lhs_nz = lhs.nzmax (); octave_idx_type rhs_nr = rhs.rows (); octave_idx_type rhs_nc = rhs.cols (); @@ -2345,7 +2345,7 @@ RT scalar = rhs.elem (0, 0); // Count the number of non-zero terms - octave_idx_type new_nnz = lhs.nnz (); + octave_idx_type new_nzmx = lhs.nzmax (); for (octave_idx_type j = 0; j < m; j++) { octave_idx_type jj = idx_j.elem (j); @@ -2363,7 +2363,7 @@ k < lhs.cidx(jj+1); k++) { if (lhs.ridx(k) == ii) - new_nnz--; + new_nzmx--; if (lhs.ridx(k) >= ii) break; } @@ -2373,9 +2373,9 @@ } if (scalar != RT()) - new_nnz += m * n; - - Sparse stmp (new_nr, new_nc, new_nnz); + new_nzmx += m * n; + + Sparse stmp (new_nr, new_nc, new_nzmx); octave_idx_type jji = 0; octave_idx_type jj = idx_j.elem (jji); @@ -2526,7 +2526,7 @@ rhs_idx_j[i] = i; // Count the number of non-zero terms - octave_idx_type new_nnz = lhs.nnz (); + octave_idx_type new_nzmx = lhs.nzmax (); for (octave_idx_type j = 0; j < m; j++) { octave_idx_type jj = idx_j.elem (j); @@ -2544,7 +2544,7 @@ k < lhs.cidx(jj+1); k++) { if (lhs.ridx(k) == ii) - new_nnz--; + new_nzmx--; if (lhs.ridx(k) >= ii) break; } @@ -2552,11 +2552,11 @@ } if (rhs.elem(rhs_idx_i[i],rhs_idx_j[j]) != RT ()) - new_nnz++; + new_nzmx++; } } - Sparse stmp (new_nr, new_nc, new_nnz); + Sparse stmp (new_nr, new_nc, new_nzmx); octave_idx_type jji = 0; octave_idx_type jj = idx_j.elem (jji); @@ -2746,7 +2746,7 @@ } else if (len == rhs_nr * rhs_nc) { - octave_idx_type new_nnz = lhs_nz; + octave_idx_type new_nzmx = lhs_nz; OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx, len); if (! idx_i.is_colon ()) @@ -2794,12 +2794,12 @@ octave_idx_type ii = idx_i.elem (i); if (ii < lhs_len && c_lhs.elem(ii) != LT ()) - new_nnz--; + new_nzmx--; if (rhs.elem(rhs_idx[i]) != RT ()) - new_nnz++; + new_nzmx++; } - Sparse stmp (lhs_nr, lhs_nc, new_nnz); + Sparse stmp (lhs_nr, lhs_nc, new_nzmx); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2869,21 +2869,21 @@ else if (rhs_nr == 1 && rhs_nc == 1) { RT scalar = rhs.elem (0, 0); - octave_idx_type new_nnz = lhs_nz; + octave_idx_type new_nzmx = lhs_nz; idx_i.sort (true); // First count the number of non-zero elements if (scalar != RT ()) - new_nnz += len; + new_nzmx += len; for (octave_idx_type i = 0; i < len; i++) { OCTAVE_QUIT; octave_idx_type ii = idx_i.elem (i); if (ii < lhs_len && c_lhs.elem(ii) != LT ()) - new_nnz--; + new_nzmx--; } - Sparse stmp (lhs_nr, lhs_nc, new_nnz); + Sparse stmp (lhs_nr, lhs_nc, new_nzmx); octave_idx_type i = 0; octave_idx_type ii = 0; @@ -2978,7 +2978,7 @@ Sparse::print_info (std::ostream& os, const std::string& prefix) const { os << prefix << "rep address: " << rep << "\n" - << prefix << "rep->nnz: " << rep->nnz << "\n" + << prefix << "rep->nzmx: " << rep->nzmx << "\n" << prefix << "rep->nrows: " << rep->nrows << "\n" << prefix << "rep->ncols: " << rep->ncols << "\n" << prefix << "rep->data: " << static_cast (rep->d) << "\n" diff --git a/liboctave/Sparse.h b/liboctave/Sparse.h --- a/liboctave/Sparse.h +++ b/liboctave/Sparse.h @@ -55,22 +55,22 @@ T *d; octave_idx_type *r; octave_idx_type *c; - octave_idx_type nnz; + octave_idx_type nzmx; octave_idx_type nrows; octave_idx_type ncols; int count; - SparseRep (void) : d (0), r (0), c (new octave_idx_type [1]), nnz (0), nrows (0), + SparseRep (void) : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0), ncols (0), count (1) { c[0] = 0; } - SparseRep (octave_idx_type n) : d (0), r (0), c (new octave_idx_type [n+1]), nnz (0), nrows (n), + SparseRep (octave_idx_type n) : d (0), r (0), c (new octave_idx_type [n+1]), nzmx (0), nrows (n), ncols (n), count (1) { for (octave_idx_type i = 0; i < n + 1; i++) c[i] = 0; } - SparseRep (octave_idx_type nr, octave_idx_type nc) : d (0), r (0), c (new octave_idx_type [nc+1]), nnz (0), + SparseRep (octave_idx_type nr, octave_idx_type nc) : d (0), r (0), c (new octave_idx_type [nc+1]), nzmx (0), nrows (nr), ncols (nc), count (1) { for (octave_idx_type i = 0; i < nc + 1; i++) @@ -78,7 +78,7 @@ } SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz) : d (new T [nz]), - r (new octave_idx_type [nz]), c (new octave_idx_type [nc+1]), nnz (nz), nrows (nr), + r (new octave_idx_type [nz]), c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr), ncols (nc), count (1) { for (octave_idx_type i = 0; i < nc + 1; i++) @@ -86,10 +86,10 @@ } SparseRep (const SparseRep& a) - : d (new T [a.nnz]), r (new octave_idx_type [a.nnz]), c (new octave_idx_type [a.ncols + 1]), - nnz (a.nnz), nrows (a.nrows), ncols (a.ncols), count (1) + : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]), c (new octave_idx_type [a.ncols + 1]), + nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1) { - for (octave_idx_type i = 0; i < nnz; i++) + for (octave_idx_type i = 0; i < nzmx; i++) { d[i] = a.d[i]; r[i] = a.r[i]; @@ -100,9 +100,9 @@ ~SparseRep (void) { delete [] d; delete [] r; delete [] c; } - octave_idx_type length (void) const { return nnz; } + octave_idx_type length (void) const { return nzmx; } - octave_idx_type nonzero (void) const { return c [ncols]; } + octave_idx_type nnz (void) const { return c [ncols]; } T& elem (octave_idx_type _r, octave_idx_type _c); @@ -238,11 +238,12 @@ return *this; } - // Note that capacity and nnz are the amount of storage for non-zero - // elements, while nonzero is the actual number of non-zero terms - octave_idx_type capacity (void) const { return rep->length (); } - octave_idx_type nnz (void) const { return capacity (); } - octave_idx_type nonzero (void) const { return rep->nonzero (); } + // Note that nzmax and capacity are the amount of storage for + // non-zero elements, while nnz is the actual number of non-zero + // terms. + octave_idx_type nzmax (void) const { return rep->length (); } + octave_idx_type capacity (void) const { return nzmax (); } + octave_idx_type nnz (void) const { return rep->nnz (); } // Paranoid number of elements test for case of dims = (-1,-1) octave_idx_type numel (void) const diff --git a/liboctave/SparseType.cc b/liboctave/SparseType.cc --- a/liboctave/SparseType.cc +++ b/liboctave/SparseType.cc @@ -55,7 +55,7 @@ { octave_idx_type nrows = a.rows (); octave_idx_type ncols = a.cols (); - octave_idx_type nnz = a.nnz (); + octave_idx_type nnz = a.nzmax (); if (Voctave_sparse_controls.get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) @@ -326,7 +326,7 @@ { octave_idx_type nrows = a.rows (); octave_idx_type ncols = a.cols (); - octave_idx_type nnz = a.nnz (); + octave_idx_type nnz = a.nzmax (); if (Voctave_sparse_controls.get_key ("spumoni") != 0.) (*current_liboctave_warning_handler) diff --git a/liboctave/boolSparse.cc b/liboctave/boolSparse.cc --- a/liboctave/boolSparse.cc +++ b/liboctave/boolSparse.cc @@ -41,10 +41,10 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type nr_a = a.rows (); octave_idx_type nc_a = a.cols (); - octave_idx_type nz_a = a.nnz (); + octave_idx_type nz_a = a.nzmax (); if (nr != nr_a || nc != nc_a || nz != nz_a) return false; @@ -89,7 +89,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz1 = nnz (); + octave_idx_type nz1 = nzmax (); octave_idx_type nz2 = nr*nc - nz1; SparseBoolMatrix r (nr, nc, nz2); @@ -167,7 +167,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); if (nr < 1 || nc < 1) is.clear (std::ios::badbit); diff --git a/liboctave/dSparse.cc b/liboctave/dSparse.cc --- a/liboctave/dSparse.cc +++ b/liboctave/dSparse.cc @@ -114,10 +114,10 @@ } SparseMatrix::SparseMatrix (const SparseBoolMatrix &a) - : MSparse (a.rows (), a.cols (), a.nnz ()) + : MSparse (a.rows (), a.cols (), a.nzmax ()) { octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); for (octave_idx_type i = 0; i < nc + 1; i++) cidx (i) = a.cidx (i); @@ -134,10 +134,10 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); octave_idx_type nr_a = a.rows (); octave_idx_type nc_a = a.cols (); - octave_idx_type nz_a = a.nnz (); + octave_idx_type nz_a = a.nzmax (); if (nr != nr_a || nc != nc_a || nz != nz_a) return false; @@ -497,7 +497,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseMatrix r (nr, nc, nz); for (octave_idx_type i = 0; i < nc +1; i++) @@ -517,7 +517,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseMatrix r (nr, nc, nz); for (octave_idx_type i = 0; i < nc +1; i++) @@ -559,7 +559,7 @@ { octave_idx_type nr = x.rows (); octave_idx_type nc = x.cols (); - octave_idx_type nz = x.nnz (); + octave_idx_type nz = x.nzmax (); SparseMatrix retval (nr, nc, nz); @@ -612,7 +612,7 @@ gripe_nonconformant ("atan2", x_nr, x_nc, y_nr, y_nc); else { - r = SparseMatrix (x_nr, x_nc, (x.nnz () + y.nnz ())); + r = SparseMatrix (x_nr, x_nc, (x.nzmax () + y.nzmax ())); octave_idx_type jx = 0; r.cidx (0) = 0; @@ -789,7 +789,7 @@ if (typ == SparseType::Upper || typ == SparseType::Lower) { - octave_idx_type nz = nnz(); + octave_idx_type nz = nzmax (); octave_idx_type cx = 0; octave_idx_type nz2 = nz; retval = SparseMatrix (nr, nc, nz2); @@ -874,7 +874,7 @@ } else { - octave_idx_type nz = nnz(); + octave_idx_type nz = nzmax (); octave_idx_type cx = 0; octave_idx_type nz2 = nz; retval = SparseMatrix (nr, nc, nz2); @@ -1259,7 +1259,7 @@ { octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; @@ -1389,7 +1389,7 @@ { octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; @@ -1689,7 +1689,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -2161,7 +2161,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -2659,7 +2659,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -3176,7 +3176,7 @@ octave_idx_type b_nr = b.rows (); octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); + octave_idx_type b_nz = b.nzmax (); retval = SparseComplexMatrix (b_nr, b_nc, b_nz); retval.xcidx(0) = 0; octave_idx_type ii = 0; @@ -3659,7 +3659,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -3970,7 +3970,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -4384,7 +4384,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseMatrix (b_nr, b_nc, x_nz); @@ -4490,7 +4490,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -4865,7 +4865,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); volatile octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -5005,7 +5005,7 @@ else { char job = 'N'; - volatile octave_idx_type x_nz = b.nnz (); + volatile octave_idx_type x_nz = b.nzmax (); octave_idx_type b_nc = b.cols (); retval = SparseComplexMatrix (nr, b_nc, x_nz); retval.xcidx(0) = 0; @@ -5277,7 +5277,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5519,7 +5519,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -5543,7 +5543,7 @@ B->ncol = b.cols(); B->p = b.cidx(); B->i = b.ridx(); - B->nzmax = b.nonzero(); + B->nzmax = b.nnz(); B->packed = true; B->sorted = true; B->nz = NULL; @@ -5651,7 +5651,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - octave_idx_type x_nz = b.nnz (); + octave_idx_type x_nz = b.nzmax (); octave_idx_type ii = 0; retval = SparseMatrix (b_nr, b_nc, x_nz); @@ -5808,7 +5808,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -6070,7 +6070,7 @@ A->p = cidx(); A->i = ridx(); - A->nzmax = nonzero(); + A->nzmax = nnz(); A->packed = true; A->sorted = true; A->nz = NULL; @@ -6094,7 +6094,7 @@ B->ncol = b.cols(); B->p = b.cidx(); B->i = b.ridx(); - B->nzmax = b.nonzero(); + B->nzmax = b.nnz(); B->packed = true; B->sorted = true; B->nz = NULL; @@ -6203,7 +6203,7 @@ // Take a first guess that the number of non-zero terms // will be as many as in b - octave_idx_type x_nz = b.nnz (); + octave_idx_type x_nz = b.nzmax (); octave_idx_type ii = 0; retval = SparseComplexMatrix (b_nr, b_nc, x_nz); @@ -6894,7 +6894,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); bool f_zero = (f(0.0) == 0.0); // Count number of non-zero elements @@ -6944,7 +6944,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); bool f_zero = f(0.0); // Count number of non-zero elements @@ -6999,7 +6999,7 @@ bool SparseMatrix::any_element_is_negative (bool neg_zero) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); if (neg_zero) { @@ -7020,7 +7020,7 @@ bool SparseMatrix::any_element_is_inf_or_nan (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -7035,7 +7035,7 @@ bool SparseMatrix::all_elements_are_int_or_inf_or_nan (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -7055,7 +7055,7 @@ bool SparseMatrix::all_integers (double& max_val, double& min_val) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); if (nel == 0) return false; @@ -7083,7 +7083,7 @@ bool SparseMatrix::too_large_for_float (void) const { - octave_idx_type nel = nnz (); + octave_idx_type nel = nzmax (); for (octave_idx_type i = 0; i < nel; i++) { @@ -7101,7 +7101,7 @@ { octave_idx_type nr = rows (); octave_idx_type nc = cols (); - octave_idx_type nz1 = nnz (); + octave_idx_type nz1 = nzmax (); octave_idx_type nz2 = nr*nc - nz1; SparseBoolMatrix r (nr, nc, nz2); @@ -7187,7 +7187,7 @@ SparseMatrix SparseMatrix::abs (void) const { - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); SparseMatrix retval (*this); @@ -7322,7 +7322,7 @@ { octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); if (nr < 1 || nc < 1) is.clear (std::ios::badbit); @@ -7528,7 +7528,7 @@ gripe_nonconformant ("min", a_nr, a_nc, b_nr, b_nc); else { - r = SparseMatrix (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = SparseMatrix (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; r.cidx (0) = 0; @@ -7678,7 +7678,7 @@ gripe_nonconformant ("min", a_nr, a_nc, b_nr, b_nc); else { - r = SparseMatrix (a_nr, a_nc, (a.nnz () + b.nnz ())); + r = SparseMatrix (a_nr, a_nc, (a.nzmax () + b.nzmax ())); octave_idx_type jx = 0; r.cidx (0) = 0; diff --git a/liboctave/sparse-base-chol.cc b/liboctave/sparse-base-chol.cc --- a/liboctave/sparse-base-chol.cc +++ b/liboctave/sparse-base-chol.cc @@ -150,7 +150,7 @@ ac->p = a.cidx(); ac->i = a.ridx(); - ac->nzmax = a.nonzero(); + ac->nzmax = a.nnz(); ac->packed = true; ac->sorted = true; ac->nz = 0; diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2006-01-31 John W. Eaton + + * ov-base-sparse.h (octave_base_sparse::nzmax): New function. + * ov.h (octave_value::nzmax): New function. + * ov-base.cc (octave_base_value::nzmax): New function. + * ov-base.h: Provide decl. + * data.cc (Fnzmax): New function. + * DLD-FUNCTIONS/sparse.cc (Fnzmax): Delete. + 2006-01-31 Kim Hansen * __glpk__.cc (F_glpk__): Fix for sparse matrices. diff --git a/src/DLD-FUNCTIONS/__glpk__.cc b/src/DLD-FUNCTIONS/__glpk__.cc --- a/src/DLD-FUNCTIONS/__glpk__.cc +++ b/src/DLD-FUNCTIONS/__glpk__.cc @@ -492,7 +492,7 @@ mrowsA = A.rows (); octave_idx_type Anc = A.cols (); - octave_idx_type Anz = A.nnz (); + octave_idx_type Anz = A.nzmax (); rn.resize (Anz+1); cn.resize (Anz+1); a.resize (Anz+1, 0.0); diff --git a/src/DLD-FUNCTIONS/ccolamd.cc b/src/DLD-FUNCTIONS/ccolamd.cc --- a/src/DLD-FUNCTIONS/ccolamd.cc +++ b/src/DLD-FUNCTIONS/ccolamd.cc @@ -218,7 +218,7 @@ scm = args(0). sparse_complex_matrix_value (); n_row = scm.rows (); n_col = scm.cols (); - nnz = scm.nnz (); + nnz = scm.nzmax (); ridx = scm.xridx (); cidx = scm.xcidx (); } @@ -228,7 +228,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -242,7 +242,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -454,7 +454,7 @@ scm = args(0).sparse_complex_matrix_value (); n_row = scm.rows (); n_col = scm.cols (); - nnz = scm.nnz (); + nnz = scm.nzmax (); ridx = scm.xridx (); cidx = scm.xcidx (); } @@ -463,7 +463,7 @@ sm = args(0).sparse_matrix_value (); n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -477,7 +477,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } diff --git a/src/DLD-FUNCTIONS/colamd.cc b/src/DLD-FUNCTIONS/colamd.cc --- a/src/DLD-FUNCTIONS/colamd.cc +++ b/src/DLD-FUNCTIONS/colamd.cc @@ -337,7 +337,7 @@ scm = args(0). sparse_complex_matrix_value (); n_row = scm.rows (); n_col = scm.cols (); - nnz = scm.nnz (); + nnz = scm.nzmax (); ridx = scm.xridx (); cidx = scm.xcidx (); } @@ -347,7 +347,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -361,7 +361,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -546,7 +546,7 @@ scm = args(0).sparse_complex_matrix_value (); n_row = scm.rows (); n_col = scm.cols (); - nnz = scm.nnz (); + nnz = scm.nzmax (); ridx = scm.xridx (); cidx = scm.xcidx (); } @@ -555,7 +555,7 @@ sm = args(0).sparse_matrix_value (); n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -569,7 +569,7 @@ n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } @@ -671,7 +671,7 @@ scm = args(0).sparse_complex_matrix_value (); n_row = scm.rows (); n_col = scm.cols (); - nnz = scm.nnz (); + nnz = scm.nzmax (); ridx = scm.xridx (); cidx = scm.xcidx (); } @@ -680,7 +680,7 @@ sm = args(0).sparse_matrix_value (); n_row = sm.rows (); n_col = sm.cols (); - nnz = sm.nnz (); + nnz = sm.nzmax (); ridx = sm.xridx (); cidx = sm.xcidx (); } diff --git a/src/DLD-FUNCTIONS/sparse.cc b/src/DLD-FUNCTIONS/sparse.cc --- a/src/DLD-FUNCTIONS/sparse.cc +++ b/src/DLD-FUNCTIONS/sparse.cc @@ -404,49 +404,11 @@ return retval; } -DEFUN_DLD (nzmax, args, , - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{scalar} =} nzmax (@var{SM})\n\ -Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ -Note that Octave tends to crop unused memory at the first oppurtunity\n\ -for sparse objects. There are some cases of user created sparse objects\n\ -where the value returned by @dfn{nzmaz} will not be the same as @dfn{nnz},\n\ -but in general they will give the same result.\n\ -@seealso{sparse, spalloc}\n\ -@end deftypefn") -{ - octave_value retval; - - if (args.length() < 1) - { - print_usage ("nzmax"); - return retval; - } - - if (args(0).class_name () == "sparse") - { - // XXX FIXME XXX should nnz be a method of octave_base_value so that the - // below can be replaced with "retval = (double) (args(0).nz ());" - const octave_value& rep = args(0).get_rep (); - - if (args(0).type_name () == "sparse matrix") - retval = (double) ((const octave_sparse_matrix&) rep) .nnz (); - else if (args(0).type_name () == "sparse complex matrix") - retval = (double) ((const octave_sparse_complex_matrix&) rep) .nnz (); - else if (args(0).type_name () == "sparse bool matrix") - retval = (double) ((const octave_sparse_bool_matrix&) rep) .nnz (); - } - else - error ("nzmax: argument must be a sparse matrix"); - - return retval; -} - static octave_value_list sparse_find (const SparseMatrix& v) { octave_value_list retval; - octave_idx_type nnz = v.nonzero (); + octave_idx_type nnz = v.nnz (); dim_vector dv = v.dims (); octave_idx_type nr = dv(0); octave_idx_type nc = dv (1); @@ -487,7 +449,7 @@ sparse_find (const SparseComplexMatrix& v) { octave_value_list retval; - octave_idx_type nnz = v.nonzero (); + octave_idx_type nnz = v.nnz (); dim_vector dv = v.dims (); octave_idx_type nr = dv(0); octave_idx_type nc = dv (1); @@ -528,7 +490,7 @@ sparse_find (const SparseBoolMatrix& v) { octave_value_list retval; - octave_idx_type nnz = v.nonzero (); + octave_idx_type nnz = v.nnz (); dim_vector dv = v.dims (); octave_idx_type nr = dv(0); octave_idx_type nc = dv (1); @@ -1118,7 +1080,7 @@ if (nr == 1) { octave_idx_type n = nc + k; - octave_idx_type nz = m.nnz (); + octave_idx_type nz = m.nzmax (); SparseComplexMatrix r (n, n, nz); for (octave_idx_type i = 0; i < coff+1; i++) r.xcidx (i) = 0; @@ -1138,7 +1100,7 @@ else { octave_idx_type n = nr + k; - octave_idx_type nz = m.nnz (); + octave_idx_type nz = m.nzmax (); octave_idx_type ii = 0; octave_idx_type ir = m.ridx(0); SparseComplexMatrix r (n, n, nz); @@ -1201,7 +1163,7 @@ if (nr == 1) { octave_idx_type n = nc + k; - octave_idx_type nz = m.nnz (); + octave_idx_type nz = m.nzmax (); SparseMatrix r (n, n, nz); for (octave_idx_type i = 0; i < coff+1; i++) @@ -1222,7 +1184,7 @@ else { octave_idx_type n = nr + k; - octave_idx_type nz = m.nnz (); + octave_idx_type nz = m.nzmax (); octave_idx_type ii = 0; octave_idx_type ir = m.ridx(0); SparseMatrix r (n, n, nz); diff --git a/src/DLD-FUNCTIONS/spchol.cc b/src/DLD-FUNCTIONS/spchol.cc --- a/src/DLD-FUNCTIONS/spchol.cc +++ b/src/DLD-FUNCTIONS/spchol.cc @@ -456,7 +456,7 @@ A->ncol = a.cols(); A->p = a.cidx(); A->i = a.ridx(); - A->nzmax = a.nonzero(); + A->nzmax = a.nnz(); A->xtype = CHOLMOD_REAL; if (a.rows() > 0 && a.cols() > 0) @@ -469,7 +469,7 @@ A->ncol = a.cols(); A->p = a.cidx(); A->i = a.ridx(); - A->nzmax = a.nonzero(); + A->nzmax = a.nnz(); A->xtype = CHOLMOD_COMPLEX; if (a.rows() > 0 && a.cols() > 0) diff --git a/src/DLD-FUNCTIONS/spkron.cc b/src/DLD-FUNCTIONS/spkron.cc --- a/src/DLD-FUNCTIONS/spkron.cc +++ b/src/DLD-FUNCTIONS/spkron.cc @@ -50,7 +50,7 @@ { octave_idx_type idx = 0; C = Sparse (A.rows () * B.rows (), A.columns () * B.columns (), - A.nnz () * B.nnz ()); + A.nzmax () * B.nzmax ()); C.cidx (0) = 0; diff --git a/src/DLD-FUNCTIONS/splu.cc b/src/DLD-FUNCTIONS/splu.cc --- a/src/DLD-FUNCTIONS/splu.cc +++ b/src/DLD-FUNCTIONS/splu.cc @@ -125,7 +125,7 @@ { octave_idx_type t_nc = tmp.cols (); - if (tmp.nnz () != t_nc) + if (tmp.nzmax () != t_nc) error ("splu: Not a valid permutation matrix"); else { @@ -181,7 +181,7 @@ octave_idx_type t_nc = tmp2.cols (); - if (tmp2.nnz () != t_nc) + if (tmp2.nzmax () != t_nc) error ("splu: Not a valid permutation matrix"); else { diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -1094,6 +1094,27 @@ return retval; } +DEFUN (nzmax, args, , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {@var{scalar} =} nzmax (@var{SM})\n\ +Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ +Note that Octave tends to crop unused memory at the first oppurtunity\n\ +for sparse objects. There are some cases of user created sparse objects\n\ +where the value returned by @dfn{nzmaz} will not be the same as @dfn{nnz},\n\ +but in general they will give the same result.\n\ +@seealso{sparse, spalloc}\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length() == 1) + retval = args(0).nzmax (); + else + print_usage ("nzmax"); + + return retval; +} + DEFUN (sum, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} sum (@var{x}, @var{dim})\n\ diff --git a/src/ls-mat5.cc b/src/ls-mat5.cc --- a/src/ls-mat5.cc +++ b/src/ls-mat5.cc @@ -1355,7 +1355,7 @@ { SparseComplexMatrix m = tc.sparse_complex_matrix_value (); int nc = m.cols (); - int nnz = m.nnz (); + int nnz = m.nzmax (); ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + save_mat5_array_length (m.data (), m.nelem (), save_as_floats); @@ -1364,7 +1364,7 @@ { SparseMatrix m = tc.sparse_matrix_value (); int nc = m.cols (); - int nnz = m.nnz (); + int nnz = m.nzmax (); ret += 16 + PAD (nnz * sizeof (int)) + PAD ((nc + 1) * sizeof (int)) + save_mat5_array_length (m.data (), m.nelem (), save_as_floats); @@ -1543,12 +1543,12 @@ if (tc.is_complex_type ()) { SparseComplexMatrix scm = tc.sparse_complex_matrix_value (); - nnz = scm.nnz (); + nnz = scm.nzmax (); } else { SparseMatrix sm = tc.sparse_matrix_value (); - nnz = sm.nnz (); + nnz = sm.nzmax (); } } else if (tc.is_real_scalar ()) diff --git a/src/ov-base-sparse.cc b/src/ov-base-sparse.cc --- a/src/ov-base-sparse.cc +++ b/src/ov-base-sparse.cc @@ -201,7 +201,7 @@ bool retval = false; dim_vector dv = matrix.dims (); octave_idx_type nel = dv.numel (); - octave_idx_type nz = nnz (); + octave_idx_type nz = nzmax (); if (nz == nel && nel > 0) { @@ -247,7 +247,7 @@ { octave_idx_type nr = matrix.rows (); octave_idx_type nc = matrix.cols (); - octave_idx_type nz = nonzero (); + octave_idx_type nz = nnz (); // XXX FIXME XXX -- this should probably all be handled by a // separate octave_print_internal function that can handle format @@ -293,7 +293,7 @@ // Ensure that additional memory is deallocated matrix.maybe_compress (); - os << "# nnz: " << nnz () << "\n"; + os << "# nnz: " << nzmax () << "\n"; os << "# rows: " << dv (0) << "\n"; os << "# columns: " << dv (1) << "\n"; diff --git a/src/ov-base-sparse.h b/src/ov-base-sparse.h --- a/src/ov-base-sparse.h +++ b/src/ov-base-sparse.h @@ -76,7 +76,8 @@ { return new octave_base_sparse (); } octave_idx_type nnz (void) const { return matrix.nnz (); } - octave_idx_type nonzero (void) const { return matrix.nonzero (); } + + octave_idx_type nzmax (void) const { return matrix.nzmax (); } size_t byte_size (void) const { return matrix.byte_size (); } diff --git a/src/ov-base.cc b/src/ov-base.cc --- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -180,6 +180,13 @@ return -1; } +octave_idx_type +octave_base_value::nzmax (void) const +{ + gripe_wrong_type_arg ("octave_base_value::nzmax ()", type_name ()); + return -1; +} + octave_value octave_base_value::reshape (const dim_vector&) const { diff --git a/src/ov-base.h b/src/ov-base.h --- a/src/ov-base.h +++ b/src/ov-base.h @@ -101,6 +101,8 @@ octave_idx_type nnz (void) const; + octave_idx_type nzmax (void) const; + octave_value reshape (const dim_vector&) const; octave_value permute (const Array& vec, bool = false) const; diff --git a/src/ov-bool-sparse.cc b/src/ov-bool-sparse.cc --- a/src/ov-bool-sparse.cc +++ b/src/ov-bool-sparse.cc @@ -205,7 +205,7 @@ int nr = d(0); int nc = d(1); - int nz = nnz (); + int nz = nzmax (); FOUR_BYTE_INT itmp; // Use negative value for ndims to be consistent with other formats @@ -395,7 +395,7 @@ return false; } - tmp = m.nnz (); + tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void*) &tmp) >= 0; H5Dclose (data_hid); @@ -441,7 +441,7 @@ H5Sclose (space_hid); - hdims[0] = m.nnz(); + hdims[0] = m.nzmax (); hdims[1] = 1; space_hid = H5Screate_simple (2, hdims, 0); @@ -481,8 +481,8 @@ return false; } - hbool_t htmp[m.nnz ()]; - for (int i = 0; i < m.nnz (); i++) + hbool_t htmp[m.nzmax ()]; + for (int i = 0; i < m.nzmax (); i++) htmp[i] = m.xdata(i); retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, diff --git a/src/ov-cx-sparse.cc b/src/ov-cx-sparse.cc --- a/src/ov-cx-sparse.cc +++ b/src/ov-cx-sparse.cc @@ -211,7 +211,7 @@ int nr = d(0); int nc = d(1); - int nz = nnz (); + int nz = nzmax (); FOUR_BYTE_INT itmp; // Use negative value for ndims to be consistent with other formats @@ -238,7 +238,7 @@ else st = LS_FLOAT; } - else if (matrix.nnz () > 8192) // XXX FIXME XXX -- make this configurable. + else if (matrix.nzmax () > 8192) // XXX FIXME XXX -- make this configurable. { double max_val, min_val; if (matrix.all_integers (max_val, min_val)) @@ -414,7 +414,7 @@ return false; } - tmp = m.nnz (); + tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void*) &tmp) >= 0; H5Dclose (data_hid); @@ -460,7 +460,7 @@ H5Sclose (space_hid); - hdims[0] = m.nnz(); + hdims[0] = m.nzmax (); hdims[1] = 1; space_hid = H5Screate_simple (2, hdims, 0); diff --git a/src/ov-mapper.cc b/src/ov-mapper.cc --- a/src/ov-mapper.cc +++ b/src/ov-mapper.cc @@ -60,7 +60,7 @@ static bool any_element_less_than (const SparseMatrix& a, double val) { - octave_idx_type len = a.nonzero (); + octave_idx_type len = a.nnz (); if (val > 0. && len != a.numel ()) return true; @@ -95,7 +95,7 @@ static bool any_element_greater_than (const SparseMatrix& a, double val) { - octave_idx_type len = a.nonzero (); + octave_idx_type len = a.nnz (); if (val < 0. && len != a.numel ()) return true; @@ -170,7 +170,7 @@ } \ else \ { \ - octave_idx_type nnz = M.nonzero (); \ + octave_idx_type nnz = M.nnz (); \ octave_idx_type nr = M.rows (); \ octave_idx_type nc = M.cols (); \ \ diff --git a/src/ov-re-sparse.cc b/src/ov-re-sparse.cc --- a/src/ov-re-sparse.cc +++ b/src/ov-re-sparse.cc @@ -51,7 +51,7 @@ idx_vector octave_sparse_matrix::index_vector (void) const { - if (matrix.numel () == matrix.nonzero ()) + if (matrix.numel () == matrix.nnz ()) return idx_vector (array_value ()); else { @@ -256,7 +256,7 @@ int nr = d(0); int nc = d(1); - int nz = nnz (); + int nz = nzmax (); FOUR_BYTE_INT itmp; // Use negative value for ndims to be consistent with other formats @@ -283,7 +283,7 @@ else st = LS_FLOAT; } - else if (matrix.nnz () > 8192) // XXX FIXME XXX -- make this configurable. + else if (matrix.nzmax () > 8192) // XXX FIXME XXX -- make this configurable. { double max_val, min_val; if (matrix.all_integers (max_val, min_val)) @@ -458,7 +458,7 @@ return false; } - tmp = m.nnz (); + tmp = m.nzmax (); retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void*) &tmp) >= 0; H5Dclose (data_hid); @@ -504,7 +504,7 @@ H5Sclose (space_hid); - hdims[0] = m.nnz(); + hdims[0] = m.nzmax (); hdims[1] = 1; space_hid = H5Screate_simple (2, hdims, 0); diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -378,6 +378,8 @@ virtual octave_idx_type nnz (void) const { return rep->nnz (); } + virtual octave_idx_type nzmax (void) const { return rep->nzmax (); } + virtual octave_value reshape (const dim_vector& dv) const { return rep->reshape (dv); } diff --git a/src/sparse-xpow.cc b/src/sparse-xpow.cc --- a/src/sparse-xpow.cc +++ b/src/sparse-xpow.cc @@ -306,7 +306,7 @@ octave_value retval; - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); if (b <= 0.0) { @@ -492,7 +492,7 @@ retval = octave_value (NDArray (a.dims (), 1)); else { - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseComplexMatrix result (a); for (octave_idx_type i = 0; i < nz; i++) @@ -635,7 +635,7 @@ } else { - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseComplexMatrix result (a); @@ -728,7 +728,7 @@ else { - octave_idx_type nz = a.nnz (); + octave_idx_type nz = a.nzmax (); SparseComplexMatrix result (a);