28 #ifndef SPLA_CPU_M_EXTRACT_ROW_HPP
29 #define SPLA_CPU_M_EXTRACT_ROW_HPP
52 return "m_extract_row";
56 return "extract matrix row on cpu sequentially";
60 auto t = ctx.
task.template cast_safe<ScheduleTask_m_extract_row>();
61 auto M = t->M.template cast_safe<TMatrix<T>>();
64 return execute_csr(ctx);
67 return execute_lil(ctx);
70 return execute_dok(ctx);
73 return execute_csr(ctx);
80 auto t = ctx.
task.template cast_safe<ScheduleTask_m_extract_row>();
85 uint index = t->index;
91 const CpuDok<T>* p_dok_M = M->template get<CpuDok<T>>();
92 auto& func_apply = op_apply->function;
94 for (
const auto [key, value] : p_dok_M->Ax) {
95 if (key.first == index) {
97 p_coo_r->
Ai.push_back(key.second);
98 p_coo_r->
Ax.push_back(func_apply(value));
107 Status execute_lil(
const DispatchContext& ctx) {
110 auto t = ctx.task.template cast_safe<ScheduleTask_m_extract_row>();
112 ref_ptr<TVector<T>> r = t->r.template cast_safe<TVector<T>>();
113 ref_ptr<TMatrix<T>> M = t->M.template cast_safe<TMatrix<T>>();
114 ref_ptr<TOpUnary<T, T>> op_apply = t->op_apply.template cast_safe<TOpUnary<T, T>>();
115 uint index = t->index;
120 CpuCooVec<T>* p_coo_r = r->template get<CpuCooVec<T>>();
121 const CpuLil<T>* p_lil_M = M->template get<CpuLil<T>>();
122 auto& func_apply = op_apply->function;
124 assert(index < M->get_n_rows());
126 p_coo_r->Ai.reserve(p_lil_M->Ar[index].size());
127 p_coo_r->Ax.reserve(p_lil_M->Ar[index].size());
129 for (
const auto [key, value] : p_lil_M->Ar[index]) {
130 p_coo_r->values += 1;
131 p_coo_r->Ai.push_back(key);
132 p_coo_r->Ax.push_back(func_apply(value));
138 Status execute_csr(
const DispatchContext& ctx) {
141 auto t = ctx.task.template cast_safe<ScheduleTask_m_extract_row>();
143 ref_ptr<TVector<T>> r = t->r.template cast_safe<TVector<T>>();
144 ref_ptr<TMatrix<T>> M = t->M.template cast_safe<TMatrix<T>>();
145 ref_ptr<TOpUnary<T, T>> op_apply = t->op_apply.template cast_safe<TOpUnary<T, T>>();
146 uint index = t->index;
151 CpuCooVec<T>* p_coo_r = r->template get<CpuCooVec<T>>();
152 const CpuCsr<T>* p_csr_M = M->template get<CpuCsr<T>>();
153 auto& func_apply = op_apply->function;
155 assert(index < M->get_n_rows());
157 const uint start = p_csr_M->Ap[index];
158 const uint end = p_csr_M->Ap[index + 1];
159 const uint count = end - start;
161 p_coo_r->Ai.reserve(count);
162 p_coo_r->Ax.reserve(count);
164 for (
uint k = start; k < end; k++) {
165 p_coo_r->values += 1;
166 p_coo_r->Ai.push_back(p_csr_M->Aj[k]);
167 p_coo_r->Ax.push_back(func_apply(p_csr_M->Ax[k]));
Status of library operation execution.
CPU list-of-coordinates sparse vector representation.
Definition: cpu_formats.hpp:90
std::vector< uint > Ai
Definition: cpu_formats.hpp:96
std::vector< T > Ax
Definition: cpu_formats.hpp:97
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
uint values
Definition: tdecoration.hpp:58
Automates reference counting and behaves as shared smart pointer.
Definition: ref.hpp:117
void cpu_coo_vec_sort(CpuCooVec< T > &vec)
Definition: cpu_format_coo_vec.hpp:44
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
#define TIME_PROFILE_SCOPE(name)
Definition: time_profiler.hpp:92