Changeset 970 in Sophya for trunk/SophyaLib/TArray/tarray.cc
- Timestamp:
- Apr 26, 2000, 7:55:11 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r967 r970 140 140 TArray<T>& TArray<T>::Set(const TArray<T>& a) 141 141 { 142 if (this != &a) {143 CloneOrShare(a);144 if (mInfo) {delete mInfo; mInfo = NULL;}145 if (a.mInfo) mInfo = new DVList(*(a.mInfo));146 }142 if (this == &a) return(*this); 143 if (a.NbDimensions() < 1) 144 throw RangeCheckError("TArray<T>::Set(a ) - Array a not allocated ! "); 145 if (NbDimensions() < 1) CloneOrShare(a); 146 else CopyElt(a); 147 147 return(*this); 148 148 } … … 158 158 if (a.mInfo) mInfo = new DVList(*(a.mInfo)); 159 159 } 160 161 //! Clone if \b a is not temporary, share if temporary 162 template <class T> 163 void TArray<T>::CloneOrShare(const TArray<T>& a) 164 { 165 string exmsg = "TArray<T>::CloneOrShare()"; 166 if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) ); 167 mNDBlock.CloneOrShare(a.mNDBlock); 168 } 169 170 //! Share data with a 171 template <class T> 172 void TArray<T>::Share(const TArray<T>& a) 173 { 174 string exmsg = "TArray<T>::Share()"; 175 if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) ); 176 mNDBlock.Share(a.mNDBlock); 177 } 178 160 179 161 180 //! Resize array … … 261 280 throw RangeCheckError("TArray<T>::PackElements() - Not Allocated Array ! "); 262 281 if ( !force && (AvgStep() == 1) ) { 263 TArray<T> ra(*this, true); 282 TArray<T> ra; 283 ra.Share(*this); 264 284 ra.SetTemp(true); 265 285 return(ra); … … 408 428 409 429 //! Substract a constant value \b x to an array 410 template <class T> 411 TArray<T>& TArray<T>::Sub(T x) 430 /*! 431 Substract a constant from the *this = *this-x 432 \param fginv == true : Perfoms the inverse subtraction (*this = x-(*this)) 433 */ 434 template <class T> 435 TArray<T>& TArray<T>::Sub(T x, bool fginv) 412 436 { 413 437 if (NbDimensions() < 1) … … 419 443 uint_8 maxx = totsize_*step; 420 444 pe = Data(); 421 for(k=0; k<maxx; k+=step ) pe[k] -= x; 445 if (fginv) 446 for(k=0; k<maxx; k+=step ) pe[k] = x-pe[k]; 447 else 448 for(k=0; k<maxx; k+=step ) pe[k] -= x; 422 449 } 423 450 else { // Non regular data spacing ... … … 428 455 for(j=0; j<naxa; j++) { 429 456 pe = mNDBlock.Begin()+Offset(ka,j); 430 for(k=0; k<gpas; k+=step) pe[k] -= x; 457 if (fginv) 458 for(k=0; k<gpas; k+=step) pe[k] = x-pe[k]; 459 else 460 for(k=0; k<gpas; k+=step) pe[k] -= x; 431 461 } 432 462 } … … 462 492 463 493 //! Divide an array by a constant value \b x 464 template <class T> 465 TArray<T>& TArray<T>::Div(T x) 494 /*! 495 Divide the array by a constant *this = *this/x 496 \param fginv == true : Perfoms the inverse division (*this = x/(*this)) 497 */ 498 template <class T> 499 TArray<T>& TArray<T>::Div(T x, bool fginv) 466 500 { 467 501 if (NbDimensions() < 1) 468 502 throw RangeCheckError("TArray<T>::Div(T ) - Not Allocated Array ! "); 469 if ( x == (T) 0)503 if (!fginv && (x == (T) 0) ) 470 504 throw MathExc("TArray<T>::Div(T ) - Divide by zero ! "); 471 505 T * pe; … … 475 509 uint_8 maxx = totsize_*step; 476 510 pe = Data(); 477 for(k=0; k<maxx; k+=step ) pe[k] /= x; 511 if (fginv) 512 for(k=0; k<maxx; k+=step ) pe[k] = x/pe[k]; 513 else 514 for(k=0; k<maxx; k+=step ) pe[k] /= x; 478 515 } 479 516 else { // Non regular data spacing ... … … 484 521 for(j=0; j<naxa; j++) { 485 522 pe = mNDBlock.Begin()+Offset(ka,j); 486 for(k=0; k<gpas; k+=step) pe[k] /= x; 487 } 488 } 489 return(*this); 490 } 491 492 493 //! Inverse substract : A = \b x - A 494 template <class T> 495 TArray<T>& TArray<T>::SubInv(T x) 496 { 497 if (NbDimensions() < 1) 498 throw RangeCheckError("TArray<T>::SubInv(T ) - Not Allocated Array ! "); 499 T * pe; 500 uint_8 j,k; 501 if (AvgStep() > 0) { // regularly spaced elements 502 uint_8 step = AvgStep(); 503 uint_8 maxx = totsize_*step; 504 pe = Data(); 505 for(k=0; k<maxx; k+=step ) pe[k] = x-pe[k]; 506 } 507 else { // Non regular data spacing ... 508 uint_4 ka = MaxSizeKA(); 509 uint_8 step = Step(ka); 510 uint_8 gpas = Size(ka)*step; 511 uint_8 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-pe[k]; 515 } 516 } 517 return(*this); 518 } 519 520 //! Inverse Divide : A(i,j,...) = x / A(i,j,...) 521 template <class T> 522 TArray<T>& TArray<T>::DivInv(T x) 523 { 524 if (NbDimensions() < 1) 525 throw RangeCheckError("TArray<T>::DivInv(T ) - Not Allocated Array ! "); 526 T * pe; 527 uint_8 j,k; 528 if (AvgStep() > 0) { // regularly spaced elements 529 uint_8 step = AvgStep(); 530 uint_8 maxx = totsize_*step; 531 pe = Data(); 532 for(k=0; k<maxx; k+=step ) pe[k] = x/pe[k]; 533 } 534 else { // Non regular data spacing ... 535 uint_4 ka = MaxSizeKA(); 536 uint_8 step = Step(ka); 537 uint_8 gpas = Size(ka)*step; 538 uint_8 naxa = Size()/Size(ka); 539 for(j=0; j<naxa; j++) { 540 pe = mNDBlock.Begin()+Offset(ka,j); 541 for(k=0; k<gpas; k+=step) pe[k] = x/pe[k]; 542 } 543 } 544 return(*this); 545 } 523 if (fginv) 524 for(k=0; k<gpas; k+=step) pe[k] = x/pe[k]; 525 else 526 for(k=0; k<gpas; k+=step) pe[k] /= x; 527 } 528 } 529 return(*this); 530 } 531 532 546 533 547 534 … … 583 570 584 571 //! Substract two TArrays 585 template <class T> 586 TArray<T>& TArray<T>::SubElt(const TArray<T>& a) 572 /*! 573 Substract two TArrays *this = *this-a 574 \param fginv == true : Perfoms the inverse subtraction (*this = a-(*this)) 575 */ 576 template <class T> 577 TArray<T>& TArray<T>::SubElt(const TArray<T>& a, bool fginv) 587 578 { 588 579 if (NbDimensions() < 1) … … 600 591 pe = Data(); 601 592 pea = a.Data(); 602 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] -= pea[ka] ; 593 if (fginv) 594 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]-pe[k] ; 595 else 596 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] -= pea[ka] ; 603 597 } 604 598 else { // Non regular data spacing ... … … 611 605 pe = mNDBlock.Begin()+Offset(ax,j); 612 606 pea = a.DataBlock().Begin()+a.Offset(ax,j); 613 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] -= pea[ka]; 614 } 615 } 616 return(*this); 617 } 607 if (fginv) 608 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]-pe[k] ; 609 else 610 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] -= pea[ka]; 611 } 612 } 613 return(*this); 614 } 615 618 616 619 617 //! Multiply two TArrays (elements by elements) … … 654 652 655 653 //! Divide two TArrays (elements by elements) 656 template <class T> 657 TArray<T>& TArray<T>::DivElt(const TArray<T>& a) 654 /*! 655 Divide two TArrays *this = (*this)/a 656 \param fginv == true : Perfoms the inverse division (*this = a/(*this)) 657 */ 658 template <class T> 659 TArray<T>& TArray<T>::DivElt(const TArray<T>& a, bool fginv) 658 660 { 659 661 if (NbDimensions() < 1) … … 671 673 pe = Data(); 672 674 pea = a.Data(); 673 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] /= pea[ka] ; 675 if (fginv) 676 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]/pe[k]; 677 else 678 for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] /= pea[ka] ; 674 679 } 675 680 else { // Non regular data spacing ... … … 682 687 pe = mNDBlock.Begin()+Offset(ax,j); 683 688 pea = a.DataBlock().Begin()+a.Offset(ax,j); 684 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] /= pea[ka]; 689 if (fginv) 690 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]/pe[k]; 691 else 692 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] /= pea[ka]; 685 693 } 686 694 } … … 835 843 } 836 844 837 //! Clone if \b a is not temporary, share if temporary838 template <class T>839 void TArray<T>::CloneOrShare(const TArray<T>& a)840 {841 string exmsg = "TArray<T>::CloneOrShare()";842 if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) );843 mNDBlock.CloneOrShare(a.mNDBlock);844 }845 846 //! Share data with a847 template <class T>848 void TArray<T>::Share(const TArray<T>& a)849 {850 string exmsg = "TArray<T>::Share()";851 if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) );852 mNDBlock.Share(a.mNDBlock);853 }854 855 845 856 846
Note:
See TracChangeset
for help on using the changeset viewer.