1 #ifndef MHO_Reducer_HH__
2 #define MHO_Reducer_HH__
29 template<
typename XArrayType,
template<
typename >
class XFunctorType >
38 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
60 if(axis_index < XArrayType::rank::value)
62 fAxesToReduce[axis_index] = 1;
66 msg_error(
"operators",
"Cannot reduce axis with index: " << axis_index <<
"for array with rank: "
67 << XArrayType::rank::value << eom);
78 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
106 in->Copy(fWorkspace);
120 if(in !=
nullptr && out !=
nullptr)
122 std::size_t in_dim[XArrayType::rank::value];
123 std::size_t out_dim[XArrayType::rank::value];
124 std::size_t current_out_dim[XArrayType::rank::value];
125 in->GetDimensions(in_dim);
126 out->GetDimensions(current_out_dim);
130 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
138 out_dim[i] = in_dim[i];
142 bool have_to_resize =
false;
143 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
145 if(out_dim[i] != current_out_dim[i])
147 have_to_resize =
true;
154 out->Resize(out_dim);
159 out->SetArray(this->fReductionFunctor.identity);
177 std::size_t in_dim[XArrayType::rank::value];
178 std::size_t out_dim[XArrayType::rank::value];
179 in->GetDimensions(in_dim);
180 out->GetDimensions(out_dim);
183 std::size_t in_loc[XArrayType::rank::value];
184 std::size_t out_loc[XArrayType::rank::value];
185 auto iter_begin = in->cbegin();
186 auto iter_end = in->cend();
187 for(
auto iter = iter_begin; iter != iter_end; ++iter)
190 offset = iter.GetOffset();
191 MHO_NDArrayMath::RowMajorIndexFromOffset< XArrayType::rank::value >(offset, in->GetDimensions(),
195 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
197 out_loc[i] =
std::min(in_loc[i], out_dim[i] - 1);
200 std::size_t m = MHO_NDArrayMath::OffsetFromRowMajorIndex< XArrayType::rank::value >(out_dim, out_loc);
202 fReductionFunctor((*(out))[m], *iter);
205 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
208 IfTableReduceAxis(in, out, i);
223 AxisReducer(std::size_t reduce_ax): fReduce(false)
233 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
240 auto it1 = axis1.cbegin();
241 auto it2 = axis2.begin();
243 axis2.CopyTags(axis1);
265 template<
typename XCheckType = XArrayType >
266 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
267 IfTableReduceAxis(
const XArrayType* , XArrayType* , std::size_t ){};
278 template<
typename XCheckType = XArrayType >
279 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
280 IfTableReduceAxis(
const XArrayType* in, XArrayType* out, std::size_t ax_index)
282 AxisReducer axis_reducer(fAxesToReduce[ax_index]);
283 apply_at2< typename XArrayType::axis_pack_tuple_type, AxisReducer >(*in, *out, ax_index, axis_reducer);
291 std::size_t fAxesToReduce[XArrayType::rank::value];
292 XFunctorType< XItemType > fReductionFunctor;
293 XArrayType fWorkspace;
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
Class MHO_Reducer.
Definition: MHO_Reducer.hh:31
void ClearAxisSelection()
De-selects all axes by setting internal flags and arrays to default values (no reduction)
Definition: MHO_Reducer.hh:75
typename XArrayType::value_type XItemType
Definition: MHO_Reducer.hh:33
MHO_Reducer()
Definition: MHO_Reducer.hh:35
void ReduceAxis(std::size_t axis_index)
Sets axis index for reduction operation.
Definition: MHO_Reducer.hh:57
virtual ~MHO_Reducer()
Definition: MHO_Reducer.hh:44
virtual bool ExecuteInPlace(XArrayType *in) override
Executes operation in-place by calling ExecuteOutOfPlace and copying result back to input.
Definition: MHO_Reducer.hh:102
virtual bool InitializeOutOfPlace(const XArrayType *in, XArrayType *out) override
Initializes out-of-place operation using input array and workspace.
Definition: MHO_Reducer.hh:118
virtual bool InitializeInPlace(XArrayType *in) override
Initializes XArrayType in-place by calling InitializeOutOfPlace with given workspace.
Definition: MHO_Reducer.hh:93
virtual bool ExecuteOutOfPlace(const XArrayType *in, XArrayType *out) override
Function ExecuteOutOfPlace - carries out the array reduction.
Definition: MHO_Reducer.hh:173
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