Changeset 2564 in Sophya
- Timestamp:
- Jul 26, 2004, 7:30:40 PM (21 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r2338 r2564 70 70 \param siz[ndim] : size along each dimension 71 71 \param step : step (same for all dimensions) 72 */ 73 template <class T> 74 TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step) 75 : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1)) 72 \param fzero : if \b true , set array elements to zero 73 */ 74 template <class T> 75 TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step, bool fzero) 76 : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), fzero) 76 77 { 77 78 string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, sa_size_t)"; … … 82 83 /*! 83 84 \param nx,ny,nz,nt,nu : sizes along first, second, third, fourth and fifth dimension 84 */ 85 template <class T> 86 TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu) 85 \param fzero : if \b true , set array elements to zero 86 */ 87 template <class T> 88 TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu, bool fzero) 87 89 : BaseArray() , mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)*((nt>0)?nt:1)*((nu>0)?nu:1)) 88 90 { … … 268 270 \param siz[ndim] : size along each dimension 269 271 \param step : step (same for all dimensions) 270 */ 271 template <class T> 272 void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step) 272 \param fzero : if \b true , set array elements to zero 273 */ 274 template <class T> 275 void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step, bool fzero) 273 276 { 274 277 if (arrtype_ != 0) { … … 280 283 string exmsg = "TArray<T>::ReSize(int_4 ...)"; 281 284 if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) ); 282 mNDBlock.ReSize(totsize_ );285 mNDBlock.ReSize(totsize_, fzero); 283 286 } 284 287 … … 287 290 The array size and memory layout are copied from the array \b a. 288 291 \param a : Array used as template for setting the size and memory layout. 289 */ 290 template <class T> 291 void TArray<T>::ReSize(const BaseArray& a) 292 \param pack : if \b true , create a packed array, else same memory layout as \b a. 293 \param fzero : if \b true , set array elements to zero 294 */ 295 template <class T> 296 void TArray<T>::ReSize(const BaseArray& a, bool pack, bool fzero) 292 297 { 293 298 if (arrtype_ != 0) { … … 298 303 } 299 304 string exmsg = "TArray<T>::ReSize(const TArray<T>&)"; 300 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 301 mNDBlock.ReSize(totsize_); 305 if (pack) { 306 sa_size_t siz[BASEARRAY_MAXNDIMS]; 307 for(int ksz=0; ksz<BASEARRAY_MAXNDIMS; ksz++) siz[ksz] = a.Size(ksz); 308 if (!UpdateSizes(a.NbDimensions(), siz, 1, 0, exmsg)) throw( ParmError(exmsg) ); 309 mNDBlock.ReSize(totsize_, fzero); 310 } 311 else { 312 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 313 mNDBlock.ReSize(totsize_); 314 } 302 315 } 303 316 … … 491 504 } 492 505 493 //! Add a constant value \b x to an array 494 template <class T> 495 TArray<T>& TArray<T>::Add(T x) 496 { 497 if (NbDimensions() < 1) 498 throw RangeCheckError("TArray<T>::Add(T ) - Not Allocated Array ! "); 499 T * pe; 500 sa_size_t j,k; 501 if (AvgStep() > 0) { // regularly spaced elements 502 sa_size_t step = AvgStep(); 503 sa_size_t maxx = totsize_*step; 504 pe = Data(); 505 for(k=0; k<maxx; k+=step ) pe[k] += x; 506 } 507 else { // Non regular data spacing ... 508 int_4 ka = MaxSizeKA(); 509 sa_size_t step = Step(ka); 510 sa_size_t gpas = Size(ka)*step; 511 sa_size_t naxa = Size()/Size(ka); 512 for(j=0; j<naxa; j++) { 513 pe = mNDBlock.Begin()+Offset(ka,j); 514 for(k=0; k<gpas; k+=step) pe[k] += x; 515 } 516 } 517 return(*this); 518 } 519 520 //! Substract a constant value \b x to an array 506 //! Add a constant value \b x to the source array and store the result in \b res. 521 507 /*! 522 Substract a constant from the *this = *this-x 523 \param fginv == true : Perfoms the inverse subtraction (*this = x-(*this)) 524 */ 525 template <class T> 526 TArray<T>& TArray<T>::Sub(T x, bool fginv) 527 { 528 if (NbDimensions() < 1) 529 throw RangeCheckError("TArray<T>::Sub(T ) - Not Allocated Array ! "); 530 T * pe; 531 sa_size_t j,k; 532 if (AvgStep() > 0) { // regularly spaced elements 533 sa_size_t step = AvgStep(); 534 sa_size_t maxx = totsize_*step; 535 pe = Data(); 536 if (fginv) 537 for(k=0; k<maxx; k+=step ) pe[k] = x-pe[k]; 538 else 539 for(k=0; k<maxx; k+=step ) pe[k] -= x; 540 } 541 else { // Non regular data spacing ... 542 int_4 ka = MaxSizeKA(); 543 sa_size_t step = Step(ka); 544 sa_size_t gpas = Size(ka)*step; 545 sa_size_t naxa = Size()/Size(ka); 546 for(j=0; j<naxa; j++) { 547 pe = mNDBlock.Begin()+Offset(ka,j); 548 if (fginv) 549 for(k=0; k<gpas; k+=step) pe[k] = x-pe[k]; 508 Add a constant to the source array \b this and store the result in \b res (res = *this+x). 509 If not initially allocated, the output array \b res is automatically 510 resized as a packed array with the same sizes as the source (this) array. 511 Returns a reference to the output array \b res. 512 \param x : constant to add to the array elements 513 \param res : Output array containing the result (res=this+x). 514 */ 515 template <class T> 516 TArray<T>& TArray<T>::AddCst(T x, TArray<T>& res) const 517 { 518 if (NbDimensions() < 1) 519 throw RangeCheckError("TArray<T>::AddCst(T,res) - Not allocated source array "); 520 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 521 bool smo; 522 if (!CompareSizes(res, smo)) 523 throw(SzMismatchError("TArray<T>::AddCst(T, res) SizeMismatch(this,res) ")) ; 524 525 const T * pe; 526 T * per; 527 sa_size_t j,k,kr; 528 if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements 529 sa_size_t maxx = totsize_; 530 pe = Data(); 531 per = res.Data(); 532 for(k=0; k<maxx; k++) { *per = (*pe)+x; per++; pe++; } 533 } 534 else { // Non regular data spacing ... 535 int_4 ax,axr; 536 sa_size_t step, stepr; 537 sa_size_t gpas, naxr; 538 GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr); 539 for(j=0; j<naxr; j++) { 540 pe = mNDBlock.Begin()+Offset(ax,j); 541 per = res.DataBlock().Begin()+res.Offset(axr,j); 542 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]+x; 543 } 544 } 545 return(res); 546 } 547 548 //! Subtract a constant value \b x from the source array and store the result in \b res. 549 /*! 550 Subtract a constant from the source array \b this and store the result in \b res (res = *this-x). 551 If not initially allocated, the output array \b res is automatically 552 resized as a packed array with the same sizes as the source (this) array. 553 Returns a reference to the output array \b res. 554 \param x : constant to subtract from the array elements 555 \param res : Output array containing the result (res=this+x or res=x-this). 556 \param fginv == true : Invert subtraction argument order (*this = x-(*this)) 557 */ 558 template <class T> 559 TArray<T>& TArray<T>::SubCst(T x, TArray<T>& res, bool fginv) const 560 { 561 if (NbDimensions() < 1) 562 throw RangeCheckError("TArray<T>::SubCst(T,res) - Not allocated source array "); 563 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 564 bool smo; 565 if (!CompareSizes(res, smo)) 566 throw(SzMismatchError("TArray<T>::SubCst(T, res) SizeMismatch(this,res) ")) ; 567 568 const T * pe; 569 T * per; 570 sa_size_t j,k,kr; 571 if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements 572 sa_size_t maxx = totsize_; 573 pe = Data(); 574 per = res.Data(); 575 if (!fginv) 576 for(k=0; k<maxx; k++) { *per = (*pe)-x; per++; pe++; } 577 else 578 for(k=0; k<maxx; k++) { *per = x-(*pe); per++; pe++; } 579 } 580 else { // Non regular data spacing ... 581 int_4 ax,axr; 582 sa_size_t step, stepr; 583 sa_size_t gpas, naxr; 584 GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr); 585 for(j=0; j<naxr; j++) { 586 pe = mNDBlock.Begin()+Offset(ax,j); 587 per = res.DataBlock().Begin()+res.Offset(axr,j); 588 if (!fginv) 589 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]-x; 550 590 else 551 for(k=0; k<gpas; k+=step) pe[k] -= x; 552 } 553 } 554 return(*this); 555 } 556 557 //! Multiply an array by a constant value \b x 558 template <class T> 559 TArray<T>& TArray<T>::Mul(T x) 560 { 561 if (NbDimensions() < 1) 562 throw RangeCheckError("TArray<T>::Mul(T ) - Not Allocated Array ! "); 563 T * pe; 564 sa_size_t j,k; 565 if (AvgStep() > 0) { // regularly spaced elements 566 sa_size_t step = AvgStep(); 567 sa_size_t maxx = totsize_*step; 568 pe = Data(); 569 for(k=0; k<maxx; k+=step ) pe[k] *= x; 570 } 571 else { // Non regular data spacing ... 572 int_4 ka = MaxSizeKA(); 573 sa_size_t step = Step(ka); 574 sa_size_t gpas = Size(ka)*step; 575 sa_size_t naxa = Size()/Size(ka); 576 for(j=0; j<naxa; j++) { 577 pe = mNDBlock.Begin()+Offset(ka,j); 578 for(k=0; k<gpas; k+=step) pe[k] *= x; 579 } 580 } 581 return(*this); 582 } 583 584 //! Divide an array by a constant value \b x 591 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = x-pe[k]; 592 } 593 } 594 return(res); 595 } 596 597 //! Multiply the source array by a constant value \b x and store the result in \b res. 585 598 /*! 586 Divide the array by a constant *this = *this/x 587 \param fginv == true : Perfoms the inverse division (*this = x/(*this)) 588 */ 589 template <class T> 590 TArray<T>& TArray<T>::Div(T x, bool fginv) 591 { 592 if (NbDimensions() < 1) 593 throw RangeCheckError("TArray<T>::Div(T ) - Not Allocated Array ! "); 599 Multiply the source array \b this by a constant \b x and store the result in \b res (res = *this*x). 600 If not initially allocated, the output array \b res is automatically 601 resized as a packed array with the same sizes as the source (this) array. 602 Returns a reference to the output array \b res. 603 \param x : Array elements are multiplied by x 604 \param res : Output array containing the result (res=this*x). 605 */ 606 template <class T> 607 TArray<T>& TArray<T>::MulCst(T x, TArray<T>& res) const 608 { 609 if (NbDimensions() < 1) 610 throw RangeCheckError("TArray<T>::MulCst(T,res) - Not allocated source array "); 611 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 612 bool smo; 613 if (!CompareSizes(res, smo)) 614 throw(SzMismatchError("TArray<T>::MulCst(T, res) SizeMismatch(this,res) ")) ; 615 616 const T * pe; 617 T * per; 618 sa_size_t j,k,kr; 619 if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements 620 sa_size_t maxx = totsize_; 621 pe = Data(); 622 per = res.Data(); 623 for(k=0; k<maxx; k++) { *per = (*pe)*x; per++; pe++; } 624 } 625 else { // Non regular data spacing ... 626 int_4 ax,axr; 627 sa_size_t step, stepr; 628 sa_size_t gpas, naxr; 629 GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr); 630 for(j=0; j<naxr; j++) { 631 pe = mNDBlock.Begin()+Offset(ax,j); 632 per = res.DataBlock().Begin()+res.Offset(axr,j); 633 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]*x; 634 } 635 } 636 return(res); 637 } 638 639 //! Divide the source array by a constant value \b x and store the result in \b res. 640 /*! 641 Divide the source array \b this by a constant \b x and store the result in \b res (res = *this/x). 642 If not initially allocated, the output array \b res is automatically 643 resized as a packed array with the same sizes as the source (this) array. 644 Returns a reference to the output array \b res. 645 \param x : Array elements are divied by x 646 \param res : Output array containing the result (res=(*this)/x or res=x/(*this)). 647 \param fginv == true : Invert the operation order (res = x/(*this)) 648 */ 649 template <class T> 650 TArray<T>& TArray<T>::DivCst(T x, TArray<T>& res, bool fginv) const 651 { 652 if (NbDimensions() < 1) 653 throw RangeCheckError("TArray<T>::DivCst(T,res) - Not allocated source array ! "); 594 654 if (!fginv && (x == (T) 0) ) 595 throw MathExc("TArray<T>::Div(T ) - Divide by zero ! "); 596 T * pe; 597 sa_size_t j,k; 598 if (AvgStep() > 0) { // regularly spaced elements 599 sa_size_t step = AvgStep(); 600 sa_size_t maxx = totsize_*step; 601 pe = Data(); 602 if (fginv) 603 for(k=0; k<maxx; k+=step ) pe[k] = x/pe[k]; 655 throw MathExc("TArray<T>::DivCst(T,res) - Divide by zero ! "); 656 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 657 bool smo; 658 if (!CompareSizes(res, smo)) 659 throw(SzMismatchError("TArray<T>::DivCst(T, res) SizeMismatch(this,res) ")) ; 660 661 const T * pe; 662 T * per; 663 sa_size_t j,k,kr; 664 if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements 665 sa_size_t maxx = totsize_; 666 pe = Data(); 667 per = res.Data(); 668 if (!fginv) 669 for(k=0; k<maxx; k++) { *per = (*pe)/x; per++; pe++; } 604 670 else 605 for(k=0; k<maxx; k+=step ) pe[k] /= x; 606 } 607 else { // Non regular data spacing ... 608 int_4 ka = MaxSizeKA(); 609 sa_size_t step = Step(ka); 610 sa_size_t gpas = Size(ka)*step; 611 sa_size_t naxa = Size()/Size(ka); 612 for(j=0; j<naxa; j++) { 613 pe = mNDBlock.Begin()+Offset(ka,j); 614 if (fginv) 615 for(k=0; k<gpas; k+=step) pe[k] = x/pe[k]; 616 else 617 for(k=0; k<gpas; k+=step) pe[k] /= x; 618 } 619 } 620 return(*this); 621 } 622 623 624 //! Replace array elements values by their opposite ( a(i) -> -a(i) ) 625 template <class T> 626 TArray<T>& TArray<T>::NegateElt() 627 { 628 if (NbDimensions() < 1) 629 throw RangeCheckError("TArray<T>::NegateElt() - Not Allocated Array ! "); 630 T * pe; 631 sa_size_t j,k; 632 if (AvgStep() > 0) { // regularly spaced elements 633 sa_size_t step = AvgStep(); 634 sa_size_t maxx = totsize_*step; 635 pe = Data(); 636 for(k=0; k<maxx; k+=step ) pe[k] = -pe[k]; 637 } 638 else { // Non regular data spacing ... 639 int_4 ka = MaxSizeKA(); 640 sa_size_t step = Step(ka); 641 sa_size_t gpas = Size(ka)*step; 642 sa_size_t naxa = Size()/Size(ka); 643 for(j=0; j<naxa; j++) { 644 pe = mNDBlock.Begin()+Offset(ka,j); 645 for(k=0; k<gpas; k+=step) pe[k] = -pe[k]; 646 } 647 } 648 return(*this); 671 for(k=0; k<maxx; k++) { *per = x/(*pe); per++; pe++; } 672 } 673 else { // Non regular data spacing ... 674 int_4 ax,axr; 675 sa_size_t step, stepr; 676 sa_size_t gpas, naxr; 677 GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr); 678 for(j=0; j<naxr; j++) { 679 pe = mNDBlock.Begin()+Offset(ax,j); 680 per = res.DataBlock().Begin()+res.Offset(axr,j); 681 if (!fginv) 682 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]/x; 683 else 684 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = x/pe[k]; 685 } 686 } 687 return(res); 688 } 689 690 691 //! Stores the opposite of the source array in \b res (res=-(*this)). 692 /*! 693 If not initially allocated, the output array \b res is automatically 694 resized as a packed array with the same sizes as the source (this) array. 695 Returns a reference to the output array \b res. 696 */ 697 template <class T> 698 TArray<T>& TArray<T>::NegateElt(TArray<T>& res) const 699 { 700 if (NbDimensions() < 1) 701 throw RangeCheckError("TArray<T>::NegateElt(res) - Not allocated source array "); 702 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 703 bool smo; 704 if (!CompareSizes(res, smo)) 705 throw(SzMismatchError("TArray<T>::NegateElt(res) SizeMismatch(this,res) ")) ; 706 707 const T * pe; 708 T * per; 709 sa_size_t j,k,kr; 710 if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements 711 sa_size_t maxx = totsize_; 712 pe = Data(); 713 per = res.Data(); 714 for(k=0; k<maxx; k++) { *per = -(*pe); per++; pe++; } 715 } 716 else { // Non regular data spacing ... 717 int_4 ax,axr; 718 sa_size_t step, stepr; 719 sa_size_t gpas, naxr; 720 GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr); 721 for(j=0; j<naxr; j++) { 722 pe = mNDBlock.Begin()+Offset(ax,j); 723 per = res.DataBlock().Begin()+res.Offset(axr,j); 724 for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = -pe[k]; 725 } 726 } 727 return(res); 649 728 } 650 729 -
trunk/SophyaLib/TArray/tarray.h
r2322 r2564 29 29 // Creation / destruction 30 30 TArray(); 31 TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1 );32 TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0 );31 TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1, bool fzero=true); 32 TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0, bool fzero=true); 33 33 TArray(int_4 ndim, const sa_size_t * siz, NDataBlock<T> & db, bool share=false, sa_size_t step=1, sa_size_t offset=0); 34 34 TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step=1, sa_size_t offset=0, Bridge* br=NULL); … … 57 57 void Share(const TArray<T>& a); 58 58 59 void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1 );60 void ReSize(const BaseArray& a );59 void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true); 60 void ReSize(const BaseArray& a, bool pack=true, bool fzero=true); 61 61 //! a synonym (alias) for method ReSize(int_4, ...) 62 inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1 )63 { ReSize(ndim, siz, step ); }62 inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true) 63 { ReSize(ndim, siz, step, fzero); } 64 64 //! a synonym (alias) for method ReSize(const BaseArray&) 65 inline void SetSize(const BaseArray& a )66 { ReSize(a ); }65 inline void SetSize(const BaseArray& a, bool pack=true, bool fzero=true) 66 { ReSize(a, pack, fzero); } 67 67 void Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool force=false); 68 68 … … 129 129 //! Fill TArray with all elements equal to \b x 130 130 inline TArray<T>& operator = (T x) { return SetT(x); } 131 132 // addition et soustraction de constante 133 virtual TArray<T>& AddCst(T x, TArray<T>& res) const ; 134 virtual TArray<T>& SubCst(T x, TArray<T>& res, bool fginv=false) const ; 135 // Multiplication et division par une constante 136 virtual TArray<T>& MulCst(T x, TArray<T>& res) const ; 137 virtual TArray<T>& DivCst(T x, TArray<T>& res, bool fginv=false) const ; 138 131 139 // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) 132 virtual TArray<T>& Add(T x); 140 inline TArray<T>& Add(T x) { return AddCst(x, *this); } 141 inline TArray<T>& Sub(T x, bool fginv=false) { return SubCst(x, *this, fginv); } 142 inline TArray<T>& Mul(T x) { return MulCst(x, *this); } 143 inline TArray<T>& Div(T x, bool fginv=false) { return DivCst(x, *this, fginv); } 144 133 145 //! Add \b x to all elements 134 inline TArray<T>& operator += (T x) { return Add(x); } 135 virtual TArray<T>& Sub(T x, bool fginv=false); 146 inline TArray<T>& operator += (T x) { return AddCst(x, *this); } 136 147 //! Substract \b x to all elements 137 inline TArray<T>& operator -= (T x) { return Sub(x); } 138 virtual TArray<T>& Mul(T x); 148 inline TArray<T>& operator -= (T x) { return SubCst(x, *this); } 139 149 //! Multiply all elements by \b x 140 inline TArray<T>& operator *= (T x) { return Mul(x); } 141 virtual TArray<T>& Div(T x, bool fginv=false); 150 inline TArray<T>& operator *= (T x) { return MulCst(x, *this); } 142 151 //! Divide all elements by \b x 143 inline TArray<T>& operator /= (T x) { return Div (x); }152 inline TArray<T>& operator /= (T x) { return DivCst(x, *this); } 144 153 145 154 // applique le signe moins a tous les elements 146 virtual TArray<T>& NegateElt(); 147 155 virtual TArray<T>& NegateElt(TArray<T>& res) const ; 156 //! Replace array elements values by their opposite ( (*this)(i) -> -(*this)(i) ) 157 inline TArray<T>& NegateElt() { return NegateElt(*this); } 158 148 159 // A += -= (ajoute, soustrait element par element les deux tableaux ) 149 160 virtual TArray<T>& AddElt(const TArray<T>& a); … … 209 220 \brief Operator TArray = TArray + constant */ 210 221 template <class T> inline TArray<T> operator + (const TArray<T>& a, T b) 211 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);212 result.Add(b); return result;}222 {TArray<T> result; result.SetTemp(true); 223 a.Add(b, result); return result;} 213 224 214 225 /*! \ingroup TArray \fn operator+(T,const TArray<T>&) 215 226 \brief Operator TArray = constant + TArray */ 216 227 template <class T> inline TArray<T> operator + (T b,const TArray<T>& a) 217 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);218 result.Add(b); return result;}228 {TArray<T> result; result.SetTemp(true); 229 a.Add(b, result); return result;} 219 230 220 231 /*! \ingroup TArray \fn operator-(const TArray<T>&,T) 221 232 \brief Operator TArray = TArray - constant */ 222 233 template <class T> inline TArray<T> operator - (const TArray<T>& a, T b) 223 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);224 result.Sub(b); return result;}234 {TArray<T> result; result.SetTemp(true); 235 a.Sub(b,result); return result;} 225 236 226 237 /*! \ingroup TArray \fn operator-(T,const TArray<T>&) 227 238 \brief Operator TArray = constant - TArray */ 228 239 template <class T> inline TArray<T> operator - (T b,const TArray<T>& a) 229 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);230 result.Sub(b,true); return result;}240 {TArray<T> result; result.SetTemp(true); 241 a.Sub(b,result,true); return result;} 231 242 232 243 /*! \ingroup TArray \fn operator*(const TArray<T>&,T) 233 244 \brief Operator TArray = TArray * constant */ 234 245 template <class T> inline TArray<T> operator * (const TArray<T>& a, T b) 235 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);236 result.Mul(b); return result;}246 {TArray<T> result; result.SetTemp(true); 247 a.MulCst(b, result); return result;} 237 248 238 249 /*! \ingroup TArray \fn operator*(T,const TArray<T>&) 239 250 \brief Operator TArray = constant * TArray */ 240 251 template <class T> inline TArray<T> operator * (T b,const TArray<T>& a) 241 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);242 result.Mul(b); return result;}252 {TArray<T> result; result.SetTemp(true); 253 a.MulCst(b,result); return result;} 243 254 244 255 /*! \ingroup TArray \fn operator/(const TArray<T>&,T) 245 256 \brief Operator TArray = TArray / constant */ 246 257 template <class T> inline TArray<T> operator / (const TArray<T>& a, T b) 247 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);248 result.Div(b); return result;}258 {TArray<T> result; result.SetTemp(true); 259 a.Div(b,result); return result;} 249 260 250 261 /*! \ingroup TArray \fn operator/(T,const TArray<T>&) 251 262 \brief Operator TArray = constant / TArray */ 252 263 template <class T> inline TArray<T> operator / (T b, const TArray<T>& a) 253 {TArray<T> result; result. CloneOrShare(a); result.SetTemp(true);254 result.Div(b, true); return result;}264 {TArray<T> result; result.SetTemp(true); 265 a.Div(b, result, true); return result;} 255 266 256 267 //////////////////////////////////////////////////////////////// -
trunk/SophyaLib/TArray/tmatrix.h
r2421 r2564 93 93 inline TMatrix<T>& operator = (T x) { SetT(x); return(*this); } 94 94 //! += : add constant value \b x to matrix 95 inline TMatrix<T>& operator += (T x) { Add (x); return(*this); }95 inline TMatrix<T>& operator += (T x) { AddCst(x,*this); return(*this); } 96 96 //! -= : substract constant value \b x to matrix 97 inline TMatrix<T>& operator -= (T x) { Sub (x); return(*this); }97 inline TMatrix<T>& operator -= (T x) { SubCst(x,*this); return(*this); } 98 98 //! *= : multiply matrix by constant value \b x 99 inline TMatrix<T>& operator *= (T x) { Mul (x); return(*this); }99 inline TMatrix<T>& operator *= (T x) { MulCst(x,*this); return(*this); } 100 100 //! /= : divide matrix by constant value \b x 101 inline TMatrix<T>& operator /= (T x) { Div (x); return(*this); }101 inline TMatrix<T>& operator /= (T x) { DivCst(x,*this); return(*this); } 102 102 103 103 // operations avec matrices … … 149 149 \brief Operator TMatrix = TMatrix + constant */ 150 150 template <class T> inline TMatrix<T> operator + (const TMatrix<T>& a, T b) 151 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);152 result.Add(b); return result;}151 {TMatrix<T> result; result.SetTemp(true); 152 a.AddCst(b,result); return result;} 153 153 154 154 /*! \ingroup TMatrix \fn operator+(T,const TMatrix<T>&) 155 155 \brief Operator TMatrix = constant + TMatrix */ 156 156 template <class T> inline TMatrix<T> operator + (T b,const TMatrix<T>& a) 157 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);158 result.Add(b); return result;}157 {TMatrix<T> result; result.SetTemp(true); 158 a.AddCst(b,result); return result;} 159 159 160 160 /*! \ingroup TMatrix \fn operator-(const TMatrix<T>&,T) 161 161 \brief Operator TMatrix = TMatrix - constant */ 162 162 template <class T> inline TMatrix<T> operator - (const TMatrix<T>& a, T b) 163 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);164 result.Sub(b); return result;}163 {TMatrix<T> result; result.SetTemp(true); 164 a.SubCst(b,result); return result;} 165 165 166 166 /*! \ingroup TMatrix \fn operator-(T,const TMatrix<T>&) 167 167 \brief Operator TMatrix = constant - TMatrix */ 168 168 template <class T> inline TMatrix<T> operator - (T b,const TMatrix<T>& a) 169 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);170 result.Sub(b,true); return result;}169 {TMatrix<T> result; result.SetTemp(true); 170 a.SubCst(b,result,true); return result;} 171 171 172 172 /*! \ingroup TMatrix \fn operator*(const TMatrix<T>&,T) 173 173 \brief Operator TMatrix = TMatrix * constant */ 174 174 template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, T b) 175 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);176 result.Mul(b); return result;}175 {TMatrix<T> result; result.SetTemp(true); 176 a.MulCst(b,result); return result;} 177 177 178 178 /*! \ingroup TMatrix \fn operator*(T,const TMatrix<T>&) 179 179 \brief Operator TMatrix = constant * TMatrix */ 180 180 template <class T> inline TMatrix<T> operator * (T b,const TMatrix<T>& a) 181 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);182 result.Mul(b); return result;}181 {TMatrix<T> result; result.SetTemp(true); 182 a.MulCst(b,result); return result;} 183 183 184 184 /*! \ingroup TMatrix \fn operator/(const TMatrix<T>&,T) 185 185 \brief Operator TMatrix = TMatrix / constant */ 186 186 template <class T> inline TMatrix<T> operator / (const TMatrix<T>& a, T b) 187 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);188 result.Div(b); return result;}187 {TMatrix<T> result; result.SetTemp(true); 188 a.DivCst(b,result); return result;} 189 189 190 190 /*! \ingroup TMatrix \fn operator/(T,const TMatrix<T>&) 191 191 \brief Operator TMatrix = constant / TMatrix */ 192 192 template <class T> inline TMatrix<T> operator / (T b, const TMatrix<T>& a) 193 {TMatrix<T> result; result. CloneOrShare(a); result.SetTemp(true);194 result.Div(b,true); return result;}193 {TMatrix<T> result; result.SetTemp(true); 194 a.Div(b,result,true); return result;} 195 195 196 196 //////////////////////////////////////////////////////////////// -
trunk/SophyaLib/TArray/tvector.h
r2299 r2564 67 67 inline TVector<T>& operator = (T x) { SetT(x); return(*this); } 68 68 //! Add constant value \b x to vector elements 69 inline TVector<T>& operator += (T x) { Add (x); return(*this); }69 inline TVector<T>& operator += (T x) { AddCst(x,*this); return(*this); } 70 70 //! Substract constant value \b x to vector elements 71 inline TVector<T>& operator -= (T x) { Sub (x); return(*this); }71 inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); } 72 72 //! Multiply vector elements by constant value \b x 73 inline TVector<T>& operator *= (T x) { Mul (x); return(*this); }73 inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); } 74 74 //! Divide vector elements by constant value \b x 75 inline TVector<T>& operator /= (T x) { Div (x); return(*this); }75 inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); } 76 76 77 77 // operations avec matrices
Note:
See TracChangeset
for help on using the changeset viewer.