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;
121 std::array< std::size_t, XArgType::rank::value > out_dim;
122 std::array< std::size_t, XArgType::rank::value > out_loc;
123 std::array< std::size_t, XArgType::rank::value > in_loc;
125 out->GetDimensions(&(out_dim[0]));
126 std::size_t total_size = out->GetSize();
128 if(fAxisSelectionMap.size() == 0)
133 else if(fAxisSelectionMap.size() == XArgType::rank::value)
136 for(std::size_t i = 0; i < total_size; i++)
139 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(i, &(out_dim[0]), &(out_loc[0]));
143 for(std::size_t a = 0; a < XArgType::rank::value; a++)
145 in_loc[a] = (fAxisSelectionMap[a])[out_loc[a]];
147 out->ValueAt(out_loc) = in->ValueAt(in_loc);
149 IfTableSelectOnAxes(in, out);
155 for(std::size_t i = 0; i < total_size; i++)
158 MHO_NDArrayMath::RowMajorIndexFromOffset< XArgType::rank::value >(i, &(out_dim[0]), &(out_loc[0]));
162 for(std::size_t a = 0; a < XArgType::rank::value; a++)
164 if(fAxisSelectionMap.count(a) == 0)
166 in_loc[a] = out_loc[a];
170 in_loc[a] = (fAxisSelectionMap[a])[out_loc[a]];
173 out->ValueAt(out_loc) = in->ValueAt(in_loc);
177 IfTableSelectOnAxes(in, out);
194 std::array< std::size_t, XArgType::rank::value > DetermineOutputDimensions(
const XArgType* in)
196 std::array< std::size_t, XArgType::rank::value > out_dim;
197 in->GetDimensions(&(out_dim[0]));
198 for(std::size_t a = 0; a < XArgType::rank::value; a++)
201 if(fAxisSelectionMap.count(a) != 0)
203 out_dim[a] = fAxisSelectionMap[a].size();
215 void ConditionallyResizeOutput(
const std::array< std::size_t, XArgType::rank::value >& dims, XArgType* out)
217 auto out_dim = out->GetDimensionArray();
218 bool have_to_resize =
false;
219 for(std::size_t i = 0; i < XArgType::rank::value; i++)
221 if(out_dim[i] != dims[i])
223 have_to_resize =
true;
228 out->Resize(&(dims[0]));
240 template<
typename XCheckType = XArgType >
241 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
242 IfTableSelectOnAxes(
const XArgType* , XArgType* ){};
252 template<
typename XCheckType = XArgType >
253 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
254 IfTableSelectOnAxes(
const XArgType* in, XArgType* out)
256 for(std::size_t a = 0; a < XArgType::rank::value; a++)
260 std::vector< std::size_t > selection;
261 auto sel_iter = fAxisSelectionMap.find(a);
262 if(sel_iter != fAxisSelectionMap.end())
264 selection = sel_iter->second;
266 SelectOnAxis axis_sub_sampler(selection);
267 apply_at2< typename XArgType::axis_pack_tuple_type, SelectOnAxis >(*in, *out, a, axis_sub_sampler);
278 SelectOnAxis(std::vector< std::size_t > selection): fSelection(selection){};
281 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
283 if(fSelection.size() != 0)
286 axis2.CopyTags(axis1);
288 axis2.ClearIndexLabels();
290 for(std::size_t i = 0; i < fSelection.size(); i++)
292 axis2(i) = axis1(fSelection[i]);
293 mho_json obj = axis1.GetLabelObject(fSelection[i]);
294 axis2.SetLabelObject(obj, i);
297 TODO_FIXME_MSG(
"TODO FIXME -- ensure that only the proper interval tags are selected/copied here.")
310 std::vector< std::size_t > fSelection;
319 std::map< std::size_t, std::vector< std::size_t > > fAxisSelectionMap;
#define TODO_FIXME_MSG(x)
Definition: MHO_Message.hh:35
#define profiler_scope()
Definition: MHO_Profiler.hh:237
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_AdhocFlagging.hh:18