1 #ifndef MHO_SubSample_HH__
2 #define MHO_SubSample_HH__
49 if(dimension_index < XArrayType::rank::value)
51 fDimIndex = dimension_index;
56 msg_error(
"operators",
"error, cannot select dimension: " << dimension_index <<
", exceeds array rank." << eom);
102 if(in !=
nullptr && out !=
nullptr)
105 if(in->GetDimension(fDimIndex) % fStride != 0)
107 msg_error(
"operators",
"dimension to sub-sample must be divisable by stride." << eom);
110 auto dims = DetermineOutputDimensions(in);
111 ConditionallyResizeOutput(dims, out);
127 size_t index[XArrayType::rank::value];
128 size_t non_active_dimension_size[XArrayType::rank::value - 1];
129 size_t non_active_dimension_value[XArrayType::rank::value - 1];
130 size_t non_active_dimension_index[XArrayType::rank::value - 1];
132 std::size_t d = fDimIndex;
137 size_t in_stride = in->GetStride(d);
138 for(
size_t i = 0; i < XArrayType::rank::value; i++)
142 n_srow *= in->GetDimension(i);
143 non_active_dimension_index[count] = i;
144 non_active_dimension_size[count] = in->GetDimension(i);
150 for(
size_t n = 0; n < n_srow; n++)
154 non_active_dimension_value);
157 for(
size_t i = 0; i < XArrayType::rank::value - 1; i++)
159 index[non_active_dimension_index[i]] = non_active_dimension_value[i];
164 size_t in_data_location;
166 MHO_NDArrayMath::OffsetFromRowMajorIndex< XArrayType::rank::value >(in->GetDimensions(), index);
169 size_t out_data_location;
171 MHO_NDArrayMath::OffsetFromRowMajorIndex< XArrayType::rank::value >(out->GetDimensions(), index);
174 auto in_iter = in->cstride_iterator_at(in_data_location, fStride * in_stride);
175 auto out_iter = out->stride_iterator_at(out_data_location, out->GetStride(d));
176 auto in_end = in_iter + in->GetDimension(d);
177 auto out_end = out_iter + out->GetDimension(d);
181 *out_iter = *in_iter;
185 while(in_iter != in_end && out_iter != out_end);
188 IfTableSubSampleAxis(in, out);
201 std::array< std::size_t, XArrayType::rank::value > DetermineOutputDimensions(
const XArrayType* in)
203 auto in_dim = in->GetDimensionArray();
204 in_dim[fDimIndex] /= fStride;
214 void ConditionallyResizeOutput(
const std::array< std::size_t, XArrayType::rank::value >& dims, XArrayType* out)
216 auto out_dim = out->GetDimensionArray();
217 bool have_to_resize =
false;
218 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
220 if(out_dim[i] != dims[i])
222 have_to_resize =
true;
227 out->Resize(&(dims[0]));
239 template<
typename XCheckType = XArrayType >
240 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
241 IfTableSubSampleAxis(
const XArrayType* , XArrayType* ){};
251 template<
typename XCheckType = XArrayType >
252 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
253 IfTableSubSampleAxis(
const XArrayType* in, XArrayType* out)
255 for(
size_t i = 0; i < XArrayType::rank::value; i++)
257 std::size_t stride = 1;
262 SubSampleAxis axis_sub_sampler(stride);
263 apply_at2< typename XArrayType::axis_pack_tuple_type, SubSampleAxis >(*in, *out, i, axis_sub_sampler);
274 SubSampleAxis(std::size_t stride): fStride(stride){};
277 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
285 TODO_FIXME_MSG(
"ensure that only the proper index tags are selected/copied here.")
286 axis2.CopyTags(axis1);
288 auto it1 = axis1.cstride_begin(fStride);
289 auto end1 = axis1.cstride_end(fStride);
290 auto it2 = axis2.begin();
291 auto end2 = axis2.end();
292 while(it1 != end1 && it2 != end2)
304 std::size_t fDimIndex;
306 XArrayType fWorkspace;
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
#define TODO_FIXME_MSG(x)
Definition: MHO_Message.hh:35
static void RowMajorIndexFromOffset(std::size_t offset, const std::size_t *DimSize, std::size_t *Index)
Function RowMajorIndexFromOffset.
Definition: MHO_NDArrayMath.hh:121
Class MHO_SubSample.
Definition: MHO_SubSample.hh:30
virtual bool InitializeOutOfPlace(const XArrayType *in, XArrayType *out) override
Initializes output array out-of-place using input array in.
Definition: MHO_SubSample.hh:100
virtual bool ExecuteInPlace(XArrayType *in) override
Executes operation in-place and updates input array from workspace.
Definition: MHO_SubSample.hh:79
MHO_SubSample()
Definition: MHO_SubSample.hh:32
virtual bool InitializeInPlace(XArrayType *in) override
Initializes in-place execution by calling InitializeOutOfPlace with workspace and returning its resul...
Definition: MHO_SubSample.hh:70
virtual bool ExecuteOutOfPlace(const XArrayType *in, XArrayType *out) override
Function ExecuteOutOfPlace.
Definition: MHO_SubSample.hh:125
void SetDimensionAndStride(std::size_t dimension_index, std::size_t stride)
set the axis to sub sample, and the stride at which samples are selected
Definition: MHO_SubSample.hh:47
virtual ~MHO_SubSample()
Definition: MHO_SubSample.hh:39
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
struct type_status status
Definition: fourfit3.c:53
Definition: MHO_ChannelLabeler.hh:17