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;
134 for(std::size_t i = 0; i < XArgType::rank::value; i++)
136 fAxesToXForm[i] =
true;
145 for(std::size_t i = 0; i < XArgType::rank::value; i++)
147 fAxesToXForm[i] =
false;
158 if(axis_index < XArgType::rank::value)
160 fAxesToXForm[axis_index] =
true;
164 msg_error(
"operators",
"Cannot transform axis with index: " << axis_index <<
"for array with rank: "
165 << XArgType::rank::value << eom);
179 if(fTmpWorkspace ==
nullptr)
181 fTmpWorkspace =
new XArgType();
197 in->Copy(*fTmpWorkspace);
198 if(!fPreserveWorkspace)
201 delete fTmpWorkspace;
202 fTmpWorkspace =
nullptr;
217 if(in !=
nullptr && out !=
nullptr && in != out)
225 in->GetDimensions(fInputDimensionSize);
226 out->GetDimensions(fOutputDimensionSize);
227 ConditionallyResizeOutput(in->GetDimensionArray(), out);
230 return (fInitialized && fIsValid);
243 if(fIsValid && fInitialized)
250 auto in_iter = in->cbegin();
251 auto in_iter_end = in->cend();
252 std::array< std::size_t, XArgType::rank::value > in_indices;
253 while(in_iter != in_iter_end)
258 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(
259 in_iter.GetOffset(), fInputDimensionSize, &(in_indices[0]));
260 std::size_t out_loc = MHO_NDArrayMath::OffsetFromRowMajorIndex< XArgType::rank::value >(
261 fOutputDimensionSize, &(in_indices[0]));
262 (*(out))[out_loc] = *in_iter;
269 auto in_iter = in->cbegin();
270 auto in_iter_end = in->cend();
271 std::array< std::size_t, XArgType::rank::value > in_index;
272 std::size_t out_index[XArgType::rank::value];
273 while(in_iter != in_iter_end)
276 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(in_iter.GetOffset(),
277 in->GetDimensions(), &(in_index[0]));
278 for(std::size_t i = 0; i < XArgType::rank::value; i++)
282 out_index[i] = (fOutputDimensionSize[i] - 1) - in_index[i];
288 out_index[i] = fOutputDimensionSize[i] - in_index[i];
291 out_index[i] = fOutputDimensionSize[i] / 2;
297 out_index[i] = in_index[i];
300 std::size_t out_loc =
301 MHO_NDArrayMath::OffsetFromRowMajorIndex< XArgType::rank::value >(fOutputDimensionSize, out_index);
302 (*(out))[out_loc] = *in_iter;
307 IfTableTransformAxis(in, out);
314 msg_error(
"operators",
"Array dimensions are not valid or intialization failed. Aborting zero padding." << eom);
328 template<
typename XCheckType = XArgType >
329 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
330 IfTableTransformAxis(
const XArgType* , XArgType* ){};
333 template<
typename XCheckType = XArgType >
334 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
335 IfTableTransformAxis(
const XArgType* in, XArgType* out)
337 for(
size_t i = 0; i < XArgType::rank::value; i++)
339 TransformAxis axis_transformer(fAxesToXForm[i], fFlipped, fCopyTags);
340 apply_at2< typename XArgType::axis_pack_tuple_type, TransformAxis >(*in, *out, i, axis_transformer);
348 TransformAxis(
bool modify,
bool flipped,
bool copy_tags)
349 : fModify(modify), fFlipped(flipped), fCopyTags(copy_tags){};
354 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
358 CopyLabelsWithoutTags(axis1, axis2);
372 std::size_t ax1_size = axis1.
GetSize();
373 std::size_t ax2_size = axis2.
GetSize();
376 CopyLabelsWithoutTags(axis1, axis2);
388 double delta = axis1(1) - axis1(0);
391 for(std::size_t i = 0; i < ax1_size; i++)
395 for(std::size_t i = ax1_size; i < ax2_size; i++)
397 axis2(i) = axis1(ax1_size - 1) + (i - (ax1_size - 1)) * delta;
402 for(std::size_t i = 0; i < ax1_size; i++)
404 axis2(i) = axis1(ax1_size - 1 - i);
406 for(std::size_t i = ax1_size; i < ax2_size; i++)
408 axis2(i) = axis1(0) - (i - (ax1_size - 1)) * delta;
413 void operator()(
const MHO_Axis< float >& axis1, MHO_Axis< float >& axis2)
415 std::size_t ax1_size = axis1.
GetSize();
416 std::size_t ax2_size = axis2.GetSize();
419 CopyLabelsWithoutTags(axis1, axis2);
429 axis2.Resize(ax2_size);
431 double delta = axis1(1) - axis1(0);
434 for(std::size_t i = 0; i < ax1_size; i++)
438 for(std::size_t i = ax1_size; i < ax2_size; i++)
440 axis2(i) = axis1(ax1_size - 1) + (i - (ax1_size - 1)) * delta;
445 for(std::size_t i = 0; i < ax1_size; i++)
447 axis2(i) = axis1(ax1_size - 1 - i);
449 for(std::size_t i = ax1_size; i < ax2_size; i++)
451 axis2(i) = axis1(0) - (i - (ax1_size - 1)) * delta;
457 template<
typename XAxisType >
void CopyLabelsWithoutTags(
const XAxisType& axis1, XAxisType& axis2)
460 std::size_t ax1_size = axis1.GetSize();
461 std::size_t ax2_size = axis2.GetSize();
462 std::size_t s =
std::min(ax1_size, ax2_size);
463 for(std::size_t i = 0; i < s; i++)
474 void ConditionallyResizeOutput(
const std::array< std::size_t, XArgType::rank::value >& dims, XArgType* out)
476 auto out_dim = out->GetDimensionArray();
477 bool have_to_resize =
false;
478 for(std::size_t i = 0; i < XArgType::rank::value; i++)
482 if(dims[i] * fPaddingFactor != out_dim[i])
484 have_to_resize =
true;
485 out_dim[i] = dims[i] * fPaddingFactor;
487 if(fPaddingFactor == 1)
489 if(dims[i] != fPaddedSize)
491 have_to_resize =
true;
492 out_dim[i] = fPaddedSize;
498 if(dims[i] != out_dim[i])
500 have_to_resize =
true;
501 out_dim[i] = dims[i];
507 out->Resize(&(out_dim[0]));
509 out->GetDimensions(fOutputDimensionSize);
516 bool fPreserveWorkspace;
519 std::size_t fPaddingFactor;
520 std::size_t fPaddedSize;
521 std::size_t fInputDimensionSize[XArgType::rank::value];
522 std::size_t fOutputDimensionSize[XArgType::rank::value];
523 bool fAxesToXForm[XArgType::rank::value];
525 XArgType* fTmpWorkspace;
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
virtual void Copy(const MHO_Axis &rhs)
Expensive copy for MHO_Axis that handles special treatment of index/interval labels.
Definition: MHO_Axis.hh:202
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:143
virtual void DoNotPreserveWorkspace()
Sets preserve workspace flag to false, delete memory after execution.
Definition: MHO_EndZeroPadder.hh:112
virtual bool ExecuteInPlace(XArgType *in)
Executes operation in-place by copying temporary workspace back to input object.
Definition: MHO_EndZeroPadder.hh:193
virtual ~MHO_EndZeroPadder()
Definition: MHO_EndZeroPadder.hh:51
virtual bool ExecuteOutOfPlace(const XArgType *in, XArgType *out)
Function ExecuteOutOfPlace.
Definition: MHO_EndZeroPadder.hh:241
virtual void EnableTagCopy()
Enables copying of tags.
Definition: MHO_EndZeroPadder.hh:124
void SelectAllAxes()
Selects all axes for transformation. sometimes we may want to select/deselect particular dimensions o...
Definition: MHO_EndZeroPadder.hh:132
virtual bool InitializeInPlace(XArgType *in)
Initializes in-place by creating a temporary workspace and calling InitializeOutOfPlace.
Definition: MHO_EndZeroPadder.hh:177
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 bool InitializeOutOfPlace(const XArgType *in, XArgType *out)
Initializes out-of-place processing for input and output arrays.
Definition: MHO_EndZeroPadder.hh:215
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
void SelectAxis(std::size_t axis_index)
Selects an axis for transformation if its index is within the array rank.
Definition: MHO_EndZeroPadder.hh:156
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
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:107
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_ChannelLabeler.hh:17