1 #ifndef MHO_EndZeroPadder_HH__
2 #define MHO_EndZeroPadder_HH__
35 for(std::size_t i = 0; i < XArgType::rank::value; i++)
37 fInputDimensionSize[i] = 0;
38 fOutputDimensionSize[i] = 0;
39 fAxesToXForm[i] =
true;
46 fPreserveWorkspace =
false;
48 fTmpWorkspace =
nullptr;
71 fPaddedSize = new_size;
105 fPreserveWorkspace =
true;
133 for(std::size_t i = 0; i < XArgType::rank::value; i++)
135 fAxesToXForm[i] =
true;
144 for(std::size_t i = 0; i < XArgType::rank::value; i++)
146 fAxesToXForm[i] =
false;
157 if(axis_index < XArgType::rank::value)
159 fAxesToXForm[axis_index] =
true;
163 msg_error(
"operators",
"Cannot transform axis with index: " << axis_index <<
"for array with rank: "
164 << XArgType::rank::value << eom);
178 if(fTmpWorkspace ==
nullptr)
180 fTmpWorkspace =
new XArgType();
196 in->Copy(*fTmpWorkspace);
197 if(!fPreserveWorkspace)
200 delete fTmpWorkspace;
201 fTmpWorkspace =
nullptr;
215 if(in !=
nullptr && out !=
nullptr && in != out)
223 in->GetDimensions(fInputDimensionSize);
224 out->GetDimensions(fOutputDimensionSize);
225 ConditionallyResizeOutput(in->GetDimensionArray(), out);
228 return (fInitialized && fIsValid);
241 if(fIsValid && fInitialized)
249 auto in_iter = in->cbegin();
250 auto in_iter_end = in->cend();
251 std::array< std::size_t, XArgType::rank::value > in_indices;
252 while(in_iter != in_iter_end)
257 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(
258 in_iter.GetOffset(), fInputDimensionSize, &(in_indices[0]));
259 std::size_t out_loc = MHO_NDArrayMath::OffsetFromRowMajorIndex< XArgType::rank::value >(
260 fOutputDimensionSize, &(in_indices[0]));
261 (*(out))[out_loc] = *in_iter;
268 auto in_iter = in->cbegin();
269 auto in_iter_end = in->cend();
270 std::array< std::size_t, XArgType::rank::value > in_index;
271 std::size_t out_index[XArgType::rank::value];
272 while(in_iter != in_iter_end)
275 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(in_iter.GetOffset(),
276 in->GetDimensions(), &(in_index[0]));
277 for(std::size_t i = 0; i < XArgType::rank::value; i++)
281 out_index[i] = (fOutputDimensionSize[i] - 1) - in_index[i];
287 out_index[i] = fOutputDimensionSize[i] - in_index[i];
290 out_index[i] = fOutputDimensionSize[i] / 2;
296 out_index[i] = in_index[i];
299 std::size_t out_loc =
300 MHO_NDArrayMath::OffsetFromRowMajorIndex< XArgType::rank::value >(fOutputDimensionSize, out_index);
301 (*(out))[out_loc] = *in_iter;
306 IfTableTransformAxis(in, out);
313 msg_error(
"operators",
"Array dimensions are not valid or intialization failed. Aborting zero padding." << eom);
327 template<
typename XCheckType = XArgType >
328 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
329 IfTableTransformAxis(
const XArgType* , XArgType* ){};
332 template<
typename XCheckType = XArgType >
333 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
334 IfTableTransformAxis(
const XArgType* in, XArgType* out)
336 for(
size_t i = 0; i < XArgType::rank::value; i++)
338 TransformAxis axis_transformer(fAxesToXForm[i], fFlipped, fCopyTags);
339 apply_at2< typename XArgType::axis_pack_tuple_type, TransformAxis >(*in, *out, i, axis_transformer);
347 TransformAxis(
bool modify,
bool flipped,
bool copy_tags)
348 : fModify(modify), fFlipped(flipped), fCopyTags(copy_tags){};
353 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
357 CopyLabelsWithoutTags(axis1, axis2);
371 std::size_t ax1_size = axis1.
GetSize();
372 std::size_t ax2_size = axis2.
GetSize();
375 CopyLabelsWithoutTags(axis1, axis2);
387 double delta = axis1(1) - axis1(0);
390 for(std::size_t i = 0; i < ax1_size; i++)
394 for(std::size_t i = ax1_size; i < ax2_size; i++)
396 axis2(i) = axis1(ax1_size - 1) + (i - (ax1_size - 1)) * delta;
401 for(std::size_t i = 0; i < ax1_size; i++)
403 axis2(i) = axis1(ax1_size - 1 - i);
405 for(std::size_t i = ax1_size; i < ax2_size; i++)
407 axis2(i) = axis1(0) - (i - (ax1_size - 1)) * delta;
412 void operator()(
const MHO_Axis< float >& axis1, MHO_Axis< float >& axis2)
414 std::size_t ax1_size = axis1.
GetSize();
415 std::size_t ax2_size = axis2.GetSize();
418 CopyLabelsWithoutTags(axis1, axis2);
428 axis2.Resize(ax2_size);
430 double delta = axis1(1) - axis1(0);
433 for(std::size_t i = 0; i < ax1_size; i++)
437 for(std::size_t i = ax1_size; i < ax2_size; i++)
439 axis2(i) = axis1(ax1_size - 1) + (i - (ax1_size - 1)) * delta;
444 for(std::size_t i = 0; i < ax1_size; i++)
446 axis2(i) = axis1(ax1_size - 1 - i);
448 for(std::size_t i = ax1_size; i < ax2_size; i++)
450 axis2(i) = axis1(0) - (i - (ax1_size - 1)) * delta;
456 template<
typename XAxisType >
void CopyLabelsWithoutTags(
const XAxisType& axis1, XAxisType& axis2)
459 std::size_t ax1_size = axis1.GetSize();
460 std::size_t ax2_size = axis2.GetSize();
461 std::size_t s =
std::min(ax1_size, ax2_size);
462 for(std::size_t i = 0; i < s; i++)
473 void ConditionallyResizeOutput(
const std::array< std::size_t, XArgType::rank::value >& dims, XArgType* out)
475 auto out_dim = out->GetDimensionArray();
476 bool have_to_resize =
false;
477 for(std::size_t i = 0; i < XArgType::rank::value; i++)
481 if(dims[i] * fPaddingFactor != out_dim[i])
483 have_to_resize =
true;
484 out_dim[i] = dims[i] * fPaddingFactor;
486 if(fPaddingFactor == 1)
488 if(dims[i] != fPaddedSize)
490 have_to_resize =
true;
491 out_dim[i] = fPaddedSize;
497 if(dims[i] != out_dim[i])
499 have_to_resize =
true;
500 out_dim[i] = dims[i];
506 out->Resize(&(out_dim[0]));
508 out->GetDimensions(fOutputDimensionSize);
515 bool fPreserveWorkspace;
518 std::size_t fPaddingFactor;
519 std::size_t fPaddedSize;
520 std::size_t fInputDimensionSize[XArgType::rank::value];
521 std::size_t fOutputDimensionSize[XArgType::rank::value];
522 bool fAxesToXForm[XArgType::rank::value];
524 XArgType* fTmpWorkspace;
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
#define profiler_scope()
Definition: MHO_Profiler.hh:237
virtual void Copy(const MHO_Axis &rhs)
Expensive copy for MHO_Axis that handles special treatment of index/interval labels.
Definition: MHO_Axis.hh:200
Class MHO_EndZeroPadder.
Definition: MHO_EndZeroPadder.hh:29
virtual void SetReverseEndPadded()
Setter for reverse end padded, place data at end of array and zero pad out to start.
Definition: MHO_EndZeroPadder.hh:85
void DeselectAllAxes()
Deselects all axes by setting each axis to false.
Definition: MHO_EndZeroPadder.hh:142
virtual void DoNotPreserveWorkspace()
Sets preserve workspace flag to false, delete memory after execution.
Definition: MHO_EndZeroPadder.hh:112
virtual ~MHO_EndZeroPadder()
Definition: MHO_EndZeroPadder.hh:51
virtual void EnableTagCopy()
Enables copying of tags.
Definition: MHO_EndZeroPadder.hh:124
virtual bool ExecuteOutOfPlace(const XArgType *in, XArgType *out) override
Function ExecuteOutOfPlace.
Definition: MHO_EndZeroPadder.hh:239
void SelectAllAxes()
Selects all axes for transformation. sometimes we may want to select/deselect particular dimensions o...
Definition: MHO_EndZeroPadder.hh:131
virtual void PreserveWorkspace()
Sets a flag to preserve workspace memory after execution.
Definition: MHO_EndZeroPadder.hh:103
virtual void EnableNormFXMode()
Enables Normalized FX Mode by setting fNormFXMode to true. UNUSED - TODO REMOVE ME!
Definition: MHO_EndZeroPadder.hh:97
virtual void SetPaddingFactor(std::size_t factor)
Setter for padding factor, the factor M by which the new array will be extended (original array,...
Definition: MHO_EndZeroPadder.hh:60
virtual bool InitializeInPlace(XArgType *in) override
Initializes in-place by creating a temporary workspace and calling InitializeOutOfPlace.
Definition: MHO_EndZeroPadder.hh:176
virtual bool ExecuteInPlace(XArgType *in) override
Executes operation in-place by copying temporary workspace back to input object.
Definition: MHO_EndZeroPadder.hh:192
void SelectAxis(std::size_t axis_index)
Selects an axis for transformation if its index is within the array rank.
Definition: MHO_EndZeroPadder.hh:155
virtual void SetEndPadded()
Setter for end padded, zero padding from end of data out to end of the array.
Definition: MHO_EndZeroPadder.hh:79
virtual void DisableTagCopy()
Disables copying tags by setting fCopyTags to false.
Definition: MHO_EndZeroPadder.hh:118
virtual bool InitializeOutOfPlace(const XArgType *in, XArgType *out) override
Initializes out-of-place processing for input and output arrays.
Definition: MHO_EndZeroPadder.hh:213
MHO_EndZeroPadder()
Definition: MHO_EndZeroPadder.hh:31
virtual void SetPaddedSize(std::size_t new_size)
Setter for padded size, instead of a multiplicative factor, the original array, length N is padded ou...
Definition: MHO_EndZeroPadder.hh:69
virtual void DisableNormFXMode()
Disables Normal Mapping FX Mode by setting fNormFXMode to false. UNUSED - TODO REMOVE ME!
Definition: MHO_EndZeroPadder.hh:91
virtual void Resize(const std::size_t *dim)
Resize an externally managed array using provided dimensions.
Definition: MHO_NDArrayWrapper_1.hh:52
std::size_t GetSize() const
Getter for size.
Definition: MHO_NDArrayWrapper_1.hh:99
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
struct type_status status
Definition: fourfit3.c:53
#define min(a, b)
Definition: max555.c:9
Definition: MHO_AdhocFlagging.hh:18