comparison liboctave/Sparse.cc @ 10527:b4d2080b6df7

Replace nzmax by nnz as needed
author David Bateman <dbateman@free.fr>
date Fri, 16 Apr 2010 16:14:45 +0200
parents 4d1fc073fbb7
children 2dd8ea8bfd71
comparison
equal deleted inserted replaced
10526:660c244d3206 10527:b4d2080b6df7
255 } 255 }
256 256
257 template <class T> 257 template <class T>
258 Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r, 258 Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r,
259 const idx_vector& c, octave_idx_type nr, 259 const idx_vector& c, octave_idx_type nr,
260 octave_idx_type nc, bool sum_terms) 260 octave_idx_type nc, bool sum_terms,
261 octave_idx_type nzm)
261 : rep (nil_rep ()), dimensions () 262 : rep (nil_rep ()), dimensions ()
262 { 263 {
263 if (nr < 0) 264 if (nr < 0)
264 nr = r.extent (0); 265 nr = r.extent (0);
265 else if (r.extent (nr) > nr) 266 else if (r.extent (nr) > nr)
294 295
295 if (rl <= 1 && cl <= 1) 296 if (rl <= 1 && cl <= 1)
296 { 297 {
297 if (n == 1 && a(0) != T ()) 298 if (n == 1 && a(0) != T ())
298 { 299 {
299 change_capacity (1); 300 change_capacity (nzm > 1 ? nzm : 1);
300 xridx(0) = r(0); 301 xridx(0) = r(0);
301 xdata(0) = a(0); 302 xdata(0) = a(0);
302 for (octave_idx_type j = 0; j < nc; j++) 303 for (octave_idx_type j = 0; j < nc; j++)
303 xcidx(j+1) = j >= c(0); 304 xcidx(j+1) = j >= c(0);
304 } 305 }
322 // Count unique indices. 323 // Count unique indices.
323 octave_idx_type new_nz = 1; 324 octave_idx_type new_nz = 1;
324 for (octave_idx_type i = 1; i < n; i++) 325 for (octave_idx_type i = 1; i < n; i++)
325 new_nz += rd[i-1] != rd[i]; 326 new_nz += rd[i-1] != rd[i];
326 // Allocate result. 327 // Allocate result.
327 change_capacity (new_nz); 328 change_capacity (nzm > new_nz ? nzm : new_nz);
328 xcidx (1) = new_nz; 329 xcidx (1) = new_nz;
329 octave_idx_type *rri = ridx (); 330 octave_idx_type *rri = ridx ();
330 T *rrd = data (); 331 T *rrd = data ();
331 332
332 octave_quit (); 333 octave_quit ();
405 } 406 }
406 // Set column pointer. 407 // Set column pointer.
407 xcidx(j+1) = xcidx(j) + nzj; 408 xcidx(j+1) = xcidx(j) + nzj;
408 } 409 }
409 410
410 change_capacity (xcidx (nc)); 411 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc));
411 octave_idx_type *rri = ridx (); 412 octave_idx_type *rri = ridx ();
412 T *rrd = data (); 413 T *rrd = data ();
413 414
414 // Fill-in data. 415 // Fill-in data.
415 for (octave_idx_type j = 0, jj = -1; j < nc; j++) 416 for (octave_idx_type j = 0, jj = -1; j < nc; j++)
461 // Count unique indices. 462 // Count unique indices.
462 octave_idx_type new_nz = 1; 463 octave_idx_type new_nz = 1;
463 for (octave_idx_type i = 1; i < n; i++) 464 for (octave_idx_type i = 1; i < n; i++)
464 new_nz += rd[i-1] != rd[i]; 465 new_nz += rd[i-1] != rd[i];
465 // Allocate result. 466 // Allocate result.
466 change_capacity (new_nz); 467 change_capacity (nzm > new_nz ? nzm : new_nz);
467 xcidx(1) = new_nz; 468 xcidx(1) = new_nz;
468 octave_idx_type *rri = ridx (); 469 octave_idx_type *rri = ridx ();
469 T *rrd = data (); 470 T *rrd = data ();
470 471
471 octave_quit (); 472 octave_quit ();
548 } 549 }
549 // Set column pointer. 550 // Set column pointer.
550 xcidx(j+1) = xcidx(j) + nzj; 551 xcidx(j+1) = xcidx(j) + nzj;
551 } 552 }
552 553
553 change_capacity (xcidx (nc)); 554 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc));
554 octave_idx_type *rri = ridx (); 555 octave_idx_type *rri = ridx ();
555 T *rrd = data (); 556 T *rrd = data ();
556 557
557 // Fill-in data. 558 // Fill-in data.
558 for (octave_idx_type j = 0, jj = -1; j < nc; j++) 559 for (octave_idx_type j = 0, jj = -1; j < nc; j++)