diff --git a/vtkm/worklet/WaveletCompressor.h b/vtkm/worklet/WaveletCompressor.h index 85070a75c..7337a5cce 100644 --- a/vtkm/worklet/WaveletCompressor.h +++ b/vtkm/worklet/WaveletCompressor.h @@ -104,7 +104,6 @@ public: sigInPtr = cptr; } - return 0; } diff --git a/vtkm/worklet/wavelets/WaveletBase.h b/vtkm/worklet/wavelets/WaveletBase.h index a260da39a..37ef4f6d1 100644 --- a/vtkm/worklet/wavelets/WaveletBase.h +++ b/vtkm/worklet/wavelets/WaveletBase.h @@ -265,7 +265,6 @@ public: return vtkm::cont::DeviceAdapterAlgorithm< VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Reduce ( array, initVal, maxAbsFunctor() ); } - // Calculate variance of an array template< typename ArrayType > @@ -289,6 +288,20 @@ public: return sdMean; } + // Transpose a matrix in an array + template< typename InputArrayType, typename OutputArrayType > + void DeviceTranspose( const InputArrayType &inputArray, + OutputArrayType &outputArray, + vtkm::Id inputX, + vtkm::Id inputY ) + { + // use a worklet + typedef vtkm::worklet::wavelets::TransposeWorklet TransposeType; + TransposeType tw ( inputX, inputY ); + vtkm::worklet::DispatcherMapField< TransposeType > dispatcher( tw ); + dispatcher.Invoke( inputArray, outputArray ); + } + protected: vtkm::worklet::wavelets::DWTMode wmode; diff --git a/vtkm/worklet/wavelets/WaveletTransforms.h b/vtkm/worklet/wavelets/WaveletTransforms.h index 564a1a15c..a411d4f4d 100644 --- a/vtkm/worklet/wavelets/WaveletTransforms.h +++ b/vtkm/worklet/wavelets/WaveletTransforms.h @@ -503,6 +503,56 @@ private: vtkm::Id zeroIdx; }; +class TransposeWorklet : public vtkm::worklet::WorkletMapField +{ +public: + typedef void ControlSignature( FieldIn < ScalarAll >, + WholeArrayOut< ScalarAll > ); + typedef void ExecutionSignature( _1, _2, WorkIndex ); + + // Constructor + VTKM_EXEC_CONT_EXPORT + TransposeWorklet( vtkm::Id x, vtkm::Id y ) + { + this->inXLen = x; + this->inYLen = y; + this->outXLen = y; + this->outYLen = x; + } + + VTKM_EXEC_CONT_EXPORT + void GetLogicalDimOfInputMatrix( const vtkm::Id &idx, + vtkm::Id &x, + vtkm::Id &y ) const + { + y = idx / inYLen; + x = idx % inYLen; + } + + VTKM_EXEC_CONT_EXPORT + vtkm::Id Get1DIdxOfOutputMatrix( vtkm::Id &x, + vtkm::Id &y ) const + { + return y * outXLen + x; + } + + template< typename ValueInType, typename PortalOutType > + VTKM_EXEC_CONT_EXPORT + void operator()( const ValueInType &valueIn, + PortalOutType &arrayOut, + const vtkm::Id &workIdx ) const + { + vtkm::Id x, y; + GetLogicalDimOfInputMatrix( workIdx, x, y ); + vtkm::Id outputIdx = Get1DIdxOfOutputMatrix( y, x ); + arrayOut.Set( outputIdx, valueIn ); + } + +private: + vtkm::Id inXLen, inYLen; + vtkm::Id outXLen, outYLen; +}; + } // namespace wavelets } // namespace worlet