Changeset 2938 in Sophya
- Timestamp:
- Apr 24, 2006, 4:25:14 PM (19 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r2927 r2938 598 598 /*! 599 599 Add a constant to the source array \b this and store the result in \b res (res = *this+x). 600 If not initially allocated, the output array \b res is automatically 600 601 If not initially allocated, and if the source array (this) is not flagged as 602 temporary, the output array \b res is automatically 601 603 resized as a packed array with the same sizes as the source (this) array. 604 If \b res is not allocated and (this) is temporary, data is shared between \b res and this. 605 602 606 Returns a reference to the output array \b res. 607 603 608 \param x : constant to add to the array elements 604 609 \param res : Output array containing the result (res=this+x). … … 609 614 if (NbDimensions() < 1) 610 615 throw RangeCheckError("TArray<T>::AddCst(T,res) - Not allocated source array "); 611 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 616 if (res.NbDimensions() < 1) { 617 if ( IsTemp() ) res.Share(*this); 618 else res.SetSize(*this, true, false); 619 } 612 620 bool smo; 613 621 if (!CompareSizes(res, smo)) … … 640 648 /*! 641 649 Subtract a constant from the source array \b this and store the result in \b res (res = *this-x). 642 If not initially allocated, the output array \b res is automatically 650 651 If not initially allocated, and if the source array (this) is not flagged as 652 temporary, the output array \b res is automatically 643 653 resized as a packed array with the same sizes as the source (this) array. 654 If \b res is not allocated and (this) is temporary, data is shared between \b res and this. 655 644 656 Returns a reference to the output array \b res. 657 645 658 \param x : constant to subtract from the array elements 646 659 \param res : Output array containing the result (res=this+x or res=x-this). … … 652 665 if (NbDimensions() < 1) 653 666 throw RangeCheckError("TArray<T>::SubCst(T,res) - Not allocated source array "); 654 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 667 if (res.NbDimensions() < 1) { 668 if ( IsTemp() ) res.Share(*this); 669 else res.SetSize(*this, true, false); 670 } 655 671 bool smo; 656 672 if (!CompareSizes(res, smo)) … … 689 705 /*! 690 706 Multiply the source array \b this by a constant \b x and store the result in \b res (res = *this*x). 691 If not initially allocated, the output array \b res is automatically 707 708 If not initially allocated, and if the source array (this) is not flagged as 709 temporary, the output array \b res is automatically 692 710 resized as a packed array with the same sizes as the source (this) array. 711 If \b res is not allocated and (this) is temporary, data is shared between \b res and this. 712 693 713 Returns a reference to the output array \b res. 714 694 715 \param x : Array elements are multiplied by x 695 716 \param res : Output array containing the result (res=this*x). … … 700 721 if (NbDimensions() < 1) 701 722 throw RangeCheckError("TArray<T>::MulCst(T,res) - Not allocated source array "); 702 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 723 if (res.NbDimensions() < 1) { 724 if ( IsTemp() ) res.Share(*this); 725 else res.SetSize(*this, true, false); 726 } 703 727 bool smo; 704 728 if (!CompareSizes(res, smo)) … … 731 755 /*! 732 756 Divide the source array \b this by a constant \b x and store the result in \b res (res = *this/x). 733 If not initially allocated, the output array \b res is automatically 757 758 If not initially allocated, and if the source array (this) is not flagged as 759 temporary, the output array \b res is automatically 734 760 resized as a packed array with the same sizes as the source (this) array. 761 If \b res is not allocated and (this) is temporary, data is shared between \b res and this. 762 735 763 Returns a reference to the output array \b res. 764 736 765 \param x : Array elements are divied by x 737 766 \param res : Output array containing the result (res=(*this)/x or res=x/(*this)). … … 745 774 if (!fginv && (x == (T) 0) ) 746 775 throw MathExc("TArray<T>::DivCst(T,res) - Divide by zero ! "); 747 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 776 if (res.NbDimensions() < 1) { 777 if ( IsTemp() ) res.Share(*this); 778 else res.SetSize(*this, true, false); 779 } 748 780 bool smo; 749 781 if (!CompareSizes(res, smo)) … … 782 814 //! Stores the opposite of the source array in \b res (res=-(*this)). 783 815 /*! 784 If not initially allocated, the output array \b res is automatically 816 If not initially allocated, and if the source array (this) is not flagged as 817 temporary, the output array \b res is automatically 785 818 resized as a packed array with the same sizes as the source (this) array. 819 If \b res is not allocated and (this) is temporary, data is shared between \b res and this. 820 786 821 Returns a reference to the output array \b res. 787 822 */ … … 791 826 if (NbDimensions() < 1) 792 827 throw RangeCheckError("TArray<T>::NegateElt(res) - Not allocated source array "); 793 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 828 if (res.NbDimensions() < 1) { 829 if ( IsTemp() ) res.Share(*this); 830 else res.SetSize(*this, true, false); 831 } 794 832 bool smo; 795 833 if (!CompareSizes(res, smo)) … … 826 864 and store the result in \b res (res = *this+a). The source and argument arrays (this, a) 827 865 should have the same sizes. 828 If not initially allocated, the output array \b res is automatically 866 867 If not initially allocated, and if none of the source arrays is flagged as 868 temporary, the output array \b res is automatically 829 869 resized as a packed array with the same sizes as the source (this) array. 870 If \b res is not allocated and one of the source array is temporary, 871 data is shared between \b res and the temporary source array. 872 830 873 Returns a reference to the output array \b res. 874 831 875 \param a : Array to be added to the source array. 832 876 \param res : Output array containing the result (res=this+a). … … 840 884 if (!CompareSizes(a, smoa)) 841 885 throw(SzMismatchError("TArray<T>::AddElt(...) SizeMismatch(this,a)")) ; 842 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 886 if (res.NbDimensions() < 1) { 887 if ( IsTemp() ) res.Share(*this); 888 else if ( a.IsTemp() ) res.Share(a); 889 else res.SetSize(*this, true, false); 890 } 843 891 bool smor; 844 892 if (!CompareSizes(res, smor)) … … 892 940 and the store result in \b res (res = *this-a or res=a-(*this)). 893 941 The source and argument arrays (this, a) should have the same sizes. 894 If not initially allocated, the output array \b res is automatically 942 943 If not initially allocated, and if none of the source arrays is flagged as 944 temporary, the output array \b res is automatically 895 945 resized as a packed array with the same sizes as the source (this) array. 946 If \b res is not allocated and one of the source array is temporary, 947 data is shared between \b res and the temporary source array. 948 896 949 Returns a reference to the output array \b res. 950 897 951 \param a : Array to be added to the source array. 898 952 \param res : Output array containing the result (res=*this+x). … … 908 962 if (!CompareSizes(a, smoa)) 909 963 throw(SzMismatchError("TArray<T>::SubElt(...) SizeMismatch(this,a)")) ; 910 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 964 if (res.NbDimensions() < 1) { 965 if ( IsTemp() ) res.Share(*this); 966 else if ( a.IsTemp() ) res.Share(a); 967 else res.SetSize(*this, true, false); 968 } 911 969 bool smor; 912 970 if (!CompareSizes(res, smor)) … … 966 1024 and store the result in \b res (res = *this*a). The source and argument arrays (this, a) 967 1025 should have the same sizes. 968 If not initially allocated, the output array \b res is automatically 1026 1027 If not initially allocated, and if none of the source arrays is flagged as 1028 temporary, the output array \b res is automatically 969 1029 resized as a packed array with the same sizes as the source (this) array. 1030 If \b res is not allocated and one of the source array is temporary, 1031 data is shared between \b res and the temporary source array. 1032 970 1033 Returns a reference to the output array \b res. 1034 971 1035 \param a : Array to be added to the source array. 972 1036 \param res : Output array containing the result (res=(*this)*a). … … 980 1044 if (!CompareSizes(a, smoa)) 981 1045 throw(SzMismatchError("TArray<T>::MulElt(...) SizeMismatch(this,a)")) ; 982 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 1046 if (res.NbDimensions() < 1) { 1047 if ( IsTemp() ) res.Share(*this); 1048 else if ( a.IsTemp() ) res.Share(a); 1049 else res.SetSize(*this, true, false); 1050 } 983 1051 bool smor; 984 1052 if (!CompareSizes(res, smor)) … … 1032 1100 and store the result in \b res (res = *this/a). The source and argument arrays (this, a) 1033 1101 should have the same sizes. 1034 If not initially allocated, the output array \b res is automatically 1102 1103 If not initially allocated, and if none of the source arrays is flagged as 1104 temporary, the output array \b res is automatically 1035 1105 resized as a packed array with the same sizes as the source (this) array. 1106 If \b res is not allocated and one of the source array is temporary, 1107 data is shared between \b res and the temporary source array. 1108 1036 1109 Returns a reference to the output array \b res. 1110 1037 1111 \param a : Array to be added to the source array. 1038 1112 \param res : Output array containing the result (res=*this/a). … … 1049 1123 if (!CompareSizes(a, smoa)) 1050 1124 throw(SzMismatchError("TArray<T>::DivElt(...) SizeMismatch(this,a)")) ; 1051 if (res.NbDimensions() < 1) res.SetSize(*this, true, false); 1125 if (res.NbDimensions() < 1) { 1126 if ( IsTemp() ) res.Share(*this); 1127 else if ( a.IsTemp() ) res.Share(a); 1128 else res.SetSize(*this, true, false); 1129 } 1052 1130 bool smor; 1053 1131 if (!CompareSizes(res, smor)) -
trunk/SophyaLib/TArray/tarray.h
r2917 r2938 298 298 299 299 //////////////////////////////////////////////////////////////// 300 // Surcharge d'operateurs C = A (+,- ) B300 // Surcharge d'operateurs C = A (+,-,&&,/) B 301 301 302 302 /*! \ingroup TArray \fn operator+(const TArray<T>&,const TArray<T>&) … … 314 314 a.SubElt(b, result); return result; } 315 315 316 /*! \ingroup TArray \fn MultiplyElt((const TArray<T>&,const TArray<T>&)316 /*! \ingroup TArray \fn operator && (const TArray<T>&,const TArray<T>&) 317 317 \brief Element by element multiplication of two arrays TArray = TArray * TArray */ 318 318 319 319 template <class T> 320 inline TArray<T> MultiplyElt(const TArray<T>& a,const TArray<T>& b)320 inline TArray<T> operator && (const TArray<T>& a,const TArray<T>& b) 321 321 { TArray<T> result; result.SetTemp(true); 322 322 a.MulElt(b, result); return result; } 323 323 324 /*! \ingroup TArray \fn DivideElt((const TArray<T>&,const TArray<T>&)325 \brief Element by element division of two arrays TArray = TArray *TArray */326 template <class T> 327 inline TArray<T> DivideElt(const TArray<T>& a,const TArray<T>& b, bool divzero=false)324 /*! \ingroup TArray \fn operator / (const TArray<T>&,const TArray<T>&) 325 \brief Element by element division of two arrays TArray = TArray / TArray */ 326 template <class T> 327 inline TArray<T> operator / (const TArray<T>& a,const TArray<T>& b) 328 328 { TArray<T> result; result.SetTemp(true); 329 a.DivElt(b, result, false, divzero); return result; }329 a.DivElt(b, result, false, false); return result; } 330 330 331 331 // --------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.