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++)
59 if(axis_index < XArrayType::rank::value)
61 fAxesToReduce[axis_index] = 1;
65 msg_error(
"operators",
"Cannot reduce axis with index: " << axis_index <<
"for array with rank: "
66 << XArrayType::rank::value << eom);
77 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
104 in->Copy(fWorkspace);
118 if(in !=
nullptr && out !=
nullptr)
120 std::size_t in_dim[XArrayType::rank::value];
121 std::size_t out_dim[XArrayType::rank::value];
122 std::size_t current_out_dim[XArrayType::rank::value];
123 in->GetDimensions(in_dim);
124 out->GetDimensions(current_out_dim);
128 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
136 out_dim[i] = in_dim[i];
140 bool have_to_resize =
false;
141 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
143 if(out_dim[i] != current_out_dim[i])
145 have_to_resize =
true;
152 out->Resize(out_dim);
157 out->SetArray(this->fReductionFunctor.identity);
175 std::size_t in_dim[XArrayType::rank::value];
176 std::size_t out_dim[XArrayType::rank::value];
177 in->GetDimensions(in_dim);
178 out->GetDimensions(out_dim);
181 std::size_t in_loc[XArrayType::rank::value];
182 std::size_t out_loc[XArrayType::rank::value];
183 auto iter_begin = in->cbegin();
184 auto iter_end = in->cend();
185 for(
auto iter = iter_begin; iter != iter_end; ++iter)
188 offset = iter.GetOffset();
189 MHO_NDArrayMath::RowMajorIndexFromOffset< XArrayType::rank::value >(offset, in->GetDimensions(),
193 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
195 out_loc[i] =
std::min(in_loc[i], out_dim[i] - 1);
198 std::size_t m = MHO_NDArrayMath::OffsetFromRowMajorIndex< XArrayType::rank::value >(out_dim, out_loc);
200 fReductionFunctor((*(out))[m], *iter);
203 for(std::size_t i = 0; i < XArrayType::rank::value; i++)
206 IfTableReduceAxis(in, out, i);
221 AxisReducer(std::size_t reduce_ax): fReduce(false)
231 template<
typename XAxisType >
void operator()(
const XAxisType& axis1, XAxisType& axis2)
238 auto it1 = axis1.cbegin();
239 auto it2 = axis2.begin();
241 axis2.CopyTags(axis1);
263 template<
typename XCheckType = XArrayType >
264 typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
265 IfTableReduceAxis(
const XArrayType* , XArrayType* , std::size_t ){};
276 template<
typename XCheckType = XArrayType >
277 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
278 IfTableReduceAxis(
const XArrayType* in, XArrayType* out, std::size_t ax_index)
280 AxisReducer axis_reducer(fAxesToReduce[ax_index]);
281 apply_at2< typename XArrayType::axis_pack_tuple_type, AxisReducer >(*in, *out, ax_index, axis_reducer);
289 std::size_t fAxesToReduce[XArrayType::rank::value];
290 XFunctorType< XItemType > fReductionFunctor;
291 XArrayType fWorkspace;
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
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:74
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:56
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:100
virtual bool InitializeOutOfPlace(const XArrayType *in, XArrayType *out) override
Initializes out-of-place operation using input array and workspace.
Definition: MHO_Reducer.hh:116
virtual bool InitializeInPlace(XArrayType *in) override
Initializes XArrayType in-place by calling InitializeOutOfPlace with given workspace.
Definition: MHO_Reducer.hh:91
virtual bool ExecuteOutOfPlace(const XArrayType *in, XArrayType *out) override
Function ExecuteOutOfPlace - carries out the array reduction.
Definition: MHO_Reducer.hh:171
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_AdhocFlagging.hh:18