comparison liboctave/dSparse.cc @ 9790:a5035bc7fbfb

rewrite dispatch part & slightly improve min,max,cummin,cummax
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 09 Nov 2009 13:09:49 +0100
parents c6edba80dfae
children f80c566bc751
comparison
equal deleted inserted replaced
9789:97f5de91427b 9790:a5035bc7fbfb
272 } 272 }
273 273
274 SparseMatrix 274 SparseMatrix
275 SparseMatrix::max (int dim) const 275 SparseMatrix::max (int dim) const
276 { 276 {
277 Array2<octave_idx_type> dummy_idx; 277 Array<octave_idx_type> dummy_idx;
278 return max (dummy_idx, dim); 278 return max (dummy_idx, dim);
279 } 279 }
280 280
281 SparseMatrix 281 SparseMatrix
282 SparseMatrix::max (Array2<octave_idx_type>& idx_arg, int dim) const 282 SparseMatrix::max (Array<octave_idx_type>& idx_arg, int dim) const
283 { 283 {
284 SparseMatrix result; 284 SparseMatrix result;
285 dim_vector dv = dims (); 285 dim_vector dv = dims ();
286 286
287 if (dv.numel () == 0 || dim > dv.length () || dim < 0) 287 if (dv.numel () == 0 || dim >= dv.length ())
288 return result; 288 return result;
289 289
290 if (dim < 0)
291 dim = dv.first_non_singleton ();
292
290 octave_idx_type nr = dv(0); 293 octave_idx_type nr = dv(0);
291 octave_idx_type nc = dv(1); 294 octave_idx_type nc = dv(1);
292 295
293 if (dim == 0) 296 if (dim == 0)
294 { 297 {
295 idx_arg.resize (1, nc); 298 idx_arg.clear (1, nc);
296 octave_idx_type nel = 0; 299 octave_idx_type nel = 0;
297 for (octave_idx_type j = 0; j < nc; j++) 300 for (octave_idx_type j = 0; j < nc; j++)
298 { 301 {
299 double tmp_max = octave_NaN; 302 double tmp_max = octave_NaN;
300 octave_idx_type idx_j = 0; 303 octave_idx_type idx_j = 0;
344 347
345 } 348 }
346 } 349 }
347 else 350 else
348 { 351 {
349 idx_arg.resize (nr, 1, 0); 352 idx_arg.resize_fill (nr, 1, 0);
350 353
351 for (octave_idx_type i = cidx(0); i < cidx(1); i++) 354 for (octave_idx_type i = cidx(0); i < cidx(1); i++)
352 idx_arg.elem(ridx(i)) = -1; 355 idx_arg.elem(ridx(i)) = -1;
353 356
354 for (octave_idx_type j = 0; j < nc; j++) 357 for (octave_idx_type j = 0; j < nc; j++)
418 } 421 }
419 422
420 SparseMatrix 423 SparseMatrix
421 SparseMatrix::min (int dim) const 424 SparseMatrix::min (int dim) const
422 { 425 {
423 Array2<octave_idx_type> dummy_idx; 426 Array<octave_idx_type> dummy_idx;
424 return min (dummy_idx, dim); 427 return min (dummy_idx, dim);
425 } 428 }
426 429
427 SparseMatrix 430 SparseMatrix
428 SparseMatrix::min (Array2<octave_idx_type>& idx_arg, int dim) const 431 SparseMatrix::min (Array<octave_idx_type>& idx_arg, int dim) const
429 { 432 {
430 SparseMatrix result; 433 SparseMatrix result;
431 dim_vector dv = dims (); 434 dim_vector dv = dims ();
432 435
433 if (dv.numel () == 0 || dim > dv.length () || dim < 0) 436 if (dv.numel () == 0 || dim >= dv.length ())
434 return result; 437 return result;
435 438
439 if (dim < 0)
440 dim = dv.first_non_singleton ();
441
436 octave_idx_type nr = dv(0); 442 octave_idx_type nr = dv(0);
437 octave_idx_type nc = dv(1); 443 octave_idx_type nc = dv(1);
438 444
439 if (dim == 0) 445 if (dim == 0)
440 { 446 {
441 idx_arg.resize (1, nc); 447 idx_arg.clear (1, nc);
442 octave_idx_type nel = 0; 448 octave_idx_type nel = 0;
443 for (octave_idx_type j = 0; j < nc; j++) 449 for (octave_idx_type j = 0; j < nc; j++)
444 { 450 {
445 double tmp_min = octave_NaN; 451 double tmp_min = octave_NaN;
446 octave_idx_type idx_j = 0; 452 octave_idx_type idx_j = 0;
490 496
491 } 497 }
492 } 498 }
493 else 499 else
494 { 500 {
495 idx_arg.resize (nr, 1, 0); 501 idx_arg.resize_fill (nr, 1, 0);
496 502
497 for (octave_idx_type i = cidx(0); i < cidx(1); i++) 503 for (octave_idx_type i = cidx(0); i < cidx(1); i++)
498 idx_arg.elem(ridx(i)) = -1; 504 idx_arg.elem(ridx(i)) = -1;
499 505
500 for (octave_idx_type j = 0; j < nc; j++) 506 for (octave_idx_type j = 0; j < nc; j++)