1 #ifndef MHO_SelectRepack_HH__
2 #define MHO_SelectRepack_HH__
35 fAxisSelectionMap.clear();
43 void Reset() { fAxisSelectionMap.clear(); }
51 void SelectAxisItems(std::size_t axis_index,
const std::vector< std::size_t >& valid_indexes)
53 fAxisSelectionMap[axis_index] = valid_indexes;
55 std::sort(fAxisSelectionMap[axis_index].begin(), fAxisSelectionMap[axis_index].end());
94 if(in !=
nullptr && out !=
nullptr)
96 std::array< std::size_t, XArgType::rank::value > out_dim = DetermineOutputDimensions(in);
97 ConditionallyResizeOutput(out_dim, out);
103 fInitialized =
false;
120 std::array< std::size_t, XArgType::rank::value > out_dim;
121 std::array< std::size_t, XArgType::rank::value > out_loc;
122 std::array< std::size_t, XArgType::rank::value > in_loc;
124 out->GetDimensions(&(out_dim[0]));
125 std::size_t total_size = out->GetSize();
127 if(fAxisSelectionMap.size() == 0)
132 else if(fAxisSelectionMap.size() == XArgType::rank::value)
135 for(std::size_t i = 0; i < total_size; i++)
138 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(i, &(out_dim[0]), &(out_loc[0]));
142 for(std::size_t a = 0; a < XArgType::rank::value; a++)
144 in_loc[a] = (fAxisSelectionMap[a])[out_loc[a]];
145 out->ValueAt(out_loc) = in->ValueAt(in_loc);
148 IfTableSelectOnAxes(in, out);
154 for(std::size_t i = 0; i < total_size; i++)
157 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(i, &(out_dim[0]), &(out_loc[0]));
161 for(std::size_t a = 0; a < XArgType::rank::value; a++)
163 if(fAxisSelectionMap.count(a) == 0)
165 in_loc[a] = out_loc[a];
169 in_loc[a] = (fAxisSelectionMap[a])[out_loc[a]];
172 out->ValueAt(out_loc) = in->ValueAt(in_loc);
176 IfTableSelectOnAxes(in, out);
193 std::array< std::size_t, XArgType::rank::value > DetermineOutputDimensions(
const XArgType* in)
195 std::array< std::size_t, XArgType::rank::value > out_dim;
196 in->GetDimensions(&(out_dim[0]));
197 for(std::size_t a = 0; a < XArgType::rank::value; a++)
200 if(fAxisSelectionMap.count(a) != 0)
202 out_dim[a] = fAxisSelectionMap[a].size();
214 void ConditionallyResizeOutput(
const std::array< std::size_t, XArgType::rank::value >& dims, XArgType* out)
216 auto out_dim = out->GetDimensionArray();
217 bool have_to_resize =
false;
218 for(std::size_t i = 0; i < XArgType::rank::value; i++)
220 if(out_dim[i] != dims[i])
222 have_to_resize =
true;
227 out->Resize(&(dims[0]));
239 template<
typename XCheckType = XArgType >
240 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
241 IfTableSelectOnAxes(
const XArgType* , XArgType* ){};
251 template<
typename XCheckType = XArgType >
252 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
253 IfTableSelectOnAxes(
const XArgType* in, XArgType* out)
255 for(std::size_t a = 0; a < XArgType::rank::value; a++)
257 SelectOnAxis axis_sub_sampler(fAxisSelectionMap[a]);
258 apply_at2< typename XArgType::axis_pack_tuple_type, SelectOnAxis >(*in, *out, a, axis_sub_sampler);
269 SelectOnAxis(std::vector< std::size_t > selection): fSelection(selection){};
272 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
274 if(fSelection.size() != 0)
277 axis2.CopyTags(axis1);
279 axis2.ClearIndexLabels();
281 for(std::size_t i = 0; i < fSelection.size(); i++)
283 axis2(i) = axis1(fSelection[i]);
284 mho_json obj = axis1.GetLabelObject(fSelection[i]);
285 axis2.SetLabelObject(obj, i);
288 TODO_FIXME_MSG(
"TODO FIXME -- ensure that only the proper interval tags are selected/copied here.")
301 std::vector< std::size_t > fSelection;
310 std::map< std::size_t, std::vector< std::size_t > > fAxisSelectionMap;
#define TODO_FIXME_MSG(x)
Definition: MHO_Message.hh:35
Class MHO_SelectRepack.
Definition: MHO_SelectRepack.hh:30
virtual bool ExecuteOutOfPlace(const XArgType *in, XArgType *out) override
Function ExecuteOutOfPlace.
Definition: MHO_SelectRepack.hh:116
virtual ~MHO_SelectRepack()
Definition: MHO_SelectRepack.hh:38
virtual bool ExecuteInPlace(XArgType *in) override
Executes operation in-place by calling ExecuteOutOfPlace and copying result back to input.
Definition: MHO_SelectRepack.hh:76
virtual bool InitializeInPlace(XArgType *in) override
Initializes in-place by calling InitializeOutOfPlace with workspace.
Definition: MHO_SelectRepack.hh:67
virtual bool InitializeOutOfPlace(const XArgType *in, XArgType *out) override
Initializes out-of-place processing for given input and output arguments.
Definition: MHO_SelectRepack.hh:92
void SelectAxisItems(std::size_t axis_index, const std::vector< std::size_t > &valid_indexes)
Stores valid indexes for a given axis and marks selection as uninitialized.
Definition: MHO_SelectRepack.hh:51
MHO_SelectRepack()
Definition: MHO_SelectRepack.hh:32
void Reset()
Clears all entries from fAxisSelectionMap.
Definition: MHO_SelectRepack.hh:43
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
struct type_status status
Definition: fourfit3.c:53
Definition: MHO_ChannelLabeler.hh:17