some helper functions are in

This commit is contained in:
Samuel Li 2016-08-09 17:02:10 -06:00
parent f3d7aeced1
commit 062aec45f7
3 changed files with 64 additions and 2 deletions

@ -104,7 +104,6 @@ public:
sigInPtr = cptr;
}
return 0;
}

@ -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;

@ -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