28 #ifndef SPLA_CPU_M_REDUCE_BY_ROW_HPP
29 #define SPLA_CPU_M_REDUCE_BY_ROW_HPP
51 return "m_reduce_by_row";
55 return "reduce matrix by row on cpu sequentially";
59 auto t = ctx.
task.template cast_safe<ScheduleTask_m_reduce_by_row>();
60 auto M = t->M.template cast_safe<TMatrix<T>>();
63 return execute_lil(ctx);
66 return execute_dok(ctx);
69 return execute_dok(ctx);
74 auto t = ctx.
task.template cast_safe<ScheduleTask_m_reduce_by_row>();
75 auto r = t->r.template cast_safe<TVector<T>>();
76 auto M = t->M.template cast_safe<TMatrix<T>>();
77 auto op_reduce = t->op_reduce.template cast_safe<TOpBinary<T, T, T>>();
78 auto init = t->init.template cast_safe<TScalar<T>>();
84 const CpuDok<T>* p_dok_M = M->template get<CpuDok<T>>();
86 std::fill(p_dense_r->
Ax.begin(), p_dense_r->
Ax.end(), init->get_value());
88 auto& func_reduce = op_reduce->function;
90 for (
const auto& entry : p_dok_M->Ax) {
91 const uint i = entry.first.first;
92 const T x = entry.second;
94 p_dense_r->
Ax[i] = func_reduce(p_dense_r->
Ax[i], x);
99 Status execute_lil(
const DispatchContext& ctx) {
100 auto t = ctx.task.template cast_safe<ScheduleTask_m_reduce_by_row>();
101 auto r = t->r.template cast_safe<TVector<T>>();
102 auto M = t->M.template cast_safe<TMatrix<T>>();
103 auto op_reduce = t->op_reduce.template cast_safe<TOpBinary<T, T, T>>();
104 auto init = t->init.template cast_safe<TScalar<T>>();
109 CpuDenseVec<T>* p_dense_r = r->template get<CpuDenseVec<T>>();
110 const CpuLil<T>* p_lil_M = M->template get<CpuLil<T>>();
112 std::fill(p_dense_r->Ax.begin(), p_dense_r->Ax.end(), init->get_value());
114 auto& func_reduce = op_reduce->function;
116 for (std::size_t i = 0; i < p_lil_M->Ar.size(); i++) {
117 for (
const auto& entry : p_lil_M->Ar[i]) {
118 const T x = entry.second;
120 p_dense_r->Ax[i] = func_reduce(p_dense_r->Ax[i], x);
Status of library operation execution.
Definition: cpu_m_reduce_by_row.hpp:46
std::string get_description() override
Definition: cpu_m_reduce_by_row.hpp:54
std::string get_name() override
Definition: cpu_m_reduce_by_row.hpp:50
Status execute(const DispatchContext &ctx) override
Definition: cpu_m_reduce_by_row.hpp:58
~Algo_m_reduce_by_row_cpu() override=default
CPU one-dim array for dense vector representation.
Definition: cpu_formats.hpp:74
std::vector< T > Ax
Definition: cpu_formats.hpp:80
Dictionary of keys sparse matrix format.
Definition: cpu_formats.hpp:128
Algorithm suitable to process schedule task based on task string key.
Definition: registry.hpp:66
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
Definition: algorithm.hpp:37
Execution context of a single task.
Definition: dispatcher.hpp:46
ref_ptr< ScheduleTask > task
Definition: dispatcher.hpp:48