Mercurial > hg > octave-lyh
comparison liboctave/dim-vector.h @ 4915:c638c144d4da
[project @ 2004-07-23 19:01:22 by jwe]
author | jwe |
---|---|
date | Fri, 23 Jul 2004 19:01:23 +0000 |
parents | bbddd4339cf2 |
children | 954cc2ba6a49 |
comparison
equal
deleted
inserted
replaced
4914:1c0442da75fd | 4915:c638c144d4da |
---|---|
354 else | 354 else |
355 new_dims.resize(k); | 355 new_dims.resize(k); |
356 } | 356 } |
357 | 357 |
358 return new_dims; | 358 return new_dims; |
359 } | |
360 | |
361 bool concat (const dim_vector& dvb, int dim = 0) | |
362 { | |
363 if (all_zero ()) | |
364 { | |
365 *this = dvb; | |
366 return true; | |
367 } | |
368 | |
369 if (dvb.all_zero ()) | |
370 return true; | |
371 | |
372 int na = length (); | |
373 int nb = dvb.length (); | |
374 | |
375 // Find the max and min value of na and nb | |
376 int n_max = na > nb ? na : nb; | |
377 int n_min = na < nb ? na : nb; | |
378 | |
379 // The elements of the dimension vectors can only differ | |
380 // if the dim variable differs from the actual dimension | |
381 // they differ. | |
382 | |
383 for (int i = 0; i < n_min; i++) | |
384 { | |
385 if (elem(i) != dvb(i) && dim != i) | |
386 return false; | |
387 } | |
388 | |
389 // Ditto. | |
390 for (int i = n_min; i < n_max; i++) | |
391 { | |
392 if (na > n_min) | |
393 { | |
394 if (elem(i) != 1 && dim != i) | |
395 return false; | |
396 } | |
397 else | |
398 { | |
399 if (dvb(i) != 1 && dim != i) | |
400 return false; | |
401 } | |
402 } | |
403 | |
404 // If we want to add the dimension vectors at a dimension | |
405 // larger than both, then we need to set n_max to this number | |
406 // so that we resize *this to the right dimension. | |
407 | |
408 n_max = n_max > (dim + 1) ? n_max : (dim + 1); | |
409 | |
410 // Resize *this to the appropriate dimensions. | |
411 | |
412 if (n_max > na) | |
413 { | |
414 dim_vector_rep *old_rep = rep; | |
415 | |
416 rep = new dim_vector_rep (n_max, old_rep, 1); | |
417 | |
418 if (--old_rep->count <= 0) | |
419 delete old_rep; | |
420 } | |
421 | |
422 // Larger or equal since dim has been decremented by one. | |
423 | |
424 if (dim >= nb) | |
425 elem (dim) = elem (dim)++; | |
426 else | |
427 elem (dim) += dvb(dim); | |
428 | |
429 return true; | |
359 } | 430 } |
360 }; | 431 }; |
361 | 432 |
362 static inline bool | 433 static inline bool |
363 operator == (const dim_vector& a, const dim_vector& b) | 434 operator == (const dim_vector& a, const dim_vector& b) |