LCOV - code coverage report
Current view: top level - elsa/operators - Scaling.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 47 51 92.2 %
Date: 2024-05-16 04:22:26 Functions: 31 36 86.1 %

          Line data    Source code
       1             : #include "Scaling.h"
       2             : #include "Timer.h"
       3             : #include "TypeCasts.hpp"
       4             : 
       5             : namespace elsa
       6             : {
       7             :     template <typename data_t>
       8             :     Scaling<data_t>::Scaling(const DataDescriptor& descriptor, data_t scaleFactor)
       9             :         : LinearOperator<data_t>(descriptor, descriptor),
      10             :           _isIsotropic{true},
      11             :           _scaleFactor{scaleFactor}
      12         398 :     {
      13         398 :     }
      14             : 
      15             :     template <typename data_t>
      16             :     Scaling<data_t>::Scaling(const DataContainer<data_t>& scaleFactors)
      17             :         : LinearOperator<data_t>(scaleFactors.getDataDescriptor(),
      18             :                                  scaleFactors.getDataDescriptor()),
      19             :           _isIsotropic{false},
      20             :           _scaleFactors{std::make_unique<DataContainer<data_t>>(scaleFactors)}
      21        1959 :     {
      22        1959 :     }
      23             : 
      24             :     template <typename data_t>
      25             :     bool Scaling<data_t>::isIsotropic() const
      26           4 :     {
      27           4 :         return _isIsotropic;
      28           4 :     }
      29             : 
      30             :     template <typename data_t>
      31             :     data_t Scaling<data_t>::getScaleFactor() const
      32          12 :     {
      33          12 :         if (!_isIsotropic)
      34           2 :             throw LogicError("Scaling: scaling is not isotropic");
      35             : 
      36          10 :         return _scaleFactor;
      37          10 :     }
      38             : 
      39             :     template <typename data_t>
      40             :     const DataContainer<data_t>& Scaling<data_t>::getScaleFactors() const
      41          46 :     {
      42          46 :         if (_isIsotropic)
      43           2 :             throw LogicError("Scaling: scaling is isotropic");
      44             : 
      45          44 :         return *_scaleFactors;
      46          44 :     }
      47             : 
      48             :     template <typename data_t>
      49             :     void Scaling<data_t>::applyImpl(const DataContainer<data_t>& x, DataContainer<data_t>& Ax) const
      50        7982 :     {
      51        7982 :         Timer timeguard("Scaling", "apply");
      52             : 
      53        7982 :         if (_isIsotropic)
      54          70 :             Ax = _scaleFactor * x;
      55        7912 :         else
      56        7912 :             Ax = *_scaleFactors * x;
      57        7982 :     }
      58             : 
      59             :     template <typename data_t>
      60             :     void Scaling<data_t>::applyAdjointImpl(const DataContainer<data_t>& y,
      61             :                                            DataContainer<data_t>& Aty) const
      62        1710 :     {
      63        1710 :         Timer timeguard("Scaling", "applyAdjoint");
      64             : 
      65        1710 :         if (_isIsotropic)
      66          50 :             Aty = _scaleFactor * y;
      67        1660 :         else
      68        1660 :             Aty = *_scaleFactors * y;
      69        1710 :     }
      70             : 
      71             :     template <typename data_t>
      72             :     Scaling<data_t>* Scaling<data_t>::cloneImpl() const
      73        1764 :     {
      74        1764 :         if (_isIsotropic)
      75         256 :             return new Scaling(this->getDomainDescriptor(), _scaleFactor);
      76        1508 :         else
      77        1508 :             return new Scaling(*_scaleFactors);
      78        1764 :     }
      79             : 
      80             :     template <typename data_t>
      81             :     bool Scaling<data_t>::isEqual(const LinearOperator<data_t>& other) const
      82          94 :     {
      83          94 :         if (!LinearOperator<data_t>::isEqual(other))
      84           0 :             return false;
      85             : 
      86          94 :         auto otherScaling = downcast_safe<Scaling>(&other);
      87          94 :         if (!otherScaling)
      88           0 :             return false;
      89             : 
      90          94 :         if (_isIsotropic != otherScaling->_isIsotropic)
      91           0 :             return false;
      92             : 
      93          94 :         if (_isIsotropic && _scaleFactor != otherScaling->_scaleFactor)
      94           4 :             return false;
      95             : 
      96          90 :         if (!_isIsotropic && *_scaleFactors != *otherScaling->_scaleFactors)
      97           0 :             return false;
      98             : 
      99          90 :         return true;
     100          90 :     }
     101             : 
     102             :     // ------------------------------------------
     103             :     // explicit template instantiation
     104             :     template class Scaling<float>;
     105             :     template class Scaling<complex<float>>;
     106             :     template class Scaling<double>;
     107             :     template class Scaling<complex<double>>;
     108             : 
     109             : } // namespace elsa

Generated by: LCOV version 1.14