28 #ifndef SPLA_TVECTOR_HPP
29 #define SPLA_TVECTOR_HPP
67 void set_label(std::string label)
override;
68 const std::string&
get_label()
const override;
84 template<
typename Decorator>
85 Decorator*
get() {
return m_storage.template get<Decorator>(); }
103 m_storage.set_dims(n_rows, 1);
108 return m_storage.get_n_rows();
112 return get_ttype<T>().template as<Type>();
117 m_label = std::move(label);
133 m_storage.invalidate();
135 if constexpr (std::is_same<T, T_INT>::value) m_storage.set_fill_value(value->as_int());
136 if constexpr (std::is_same<T, T_UINT>::value) m_storage.set_fill_value(value->as_uint());
137 if constexpr (std::is_same<T, T_FLOAT>::value) m_storage.set_fill_value(value->as_float());
146 auto reduce = resolve_duplicates.template cast_safe<TOpBinary<T, T, T>>();
150 auto* vec = get<CpuDokVec<T>>();
151 vec->reduce = reduce->function;
162 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
174 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
186 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
199 const auto& Ax = get<CpuDokVec<T>>()->Ax;
200 const auto entry = Ax.find(row_id);
201 value = m_storage.get_fill_value();
203 if (entry != Ax.end()) {
204 value =
static_cast<T_INT>(entry->second);
213 const auto& Ax = get<CpuDokVec<T>>()->Ax;
214 const auto entry = Ax.find(row_id);
215 value = m_storage.get_fill_value();
217 if (entry != Ax.end()) {
218 value =
static_cast<T_UINT>(entry->second);
227 const auto& Ax = get<CpuDokVec<T>>()->Ax;
228 const auto entry = Ax.find(row_id);
229 value = m_storage.get_fill_value();
231 if (entry != Ax.end()) {
232 value =
static_cast<T_FLOAT>(entry->second);
241 auto& Ax = get<CpuDenseVec<T>>()->Ax;
242 auto engine = std::default_random_engine(seed);
244 if constexpr (std::is_integral_v<T>) {
245 std::uniform_int_distribution<T> dist;
246 for (
auto& x : Ax) x = dist(engine);
248 if constexpr (std::is_floating_point_v<T>) {
249 std::uniform_real_distribution<T> dist;
250 for (
auto& x : Ax) x = dist(engine);
261 if constexpr (std::is_same<T, T_INT>::value) t = value->as_int();
262 if constexpr (std::is_same<T, T_UINT>::value) t = value->as_uint();
263 if constexpr (std::is_same<T, T_FLOAT>::value) t = value->as_float();
266 auto& Ax = get<CpuDenseVec<T>>()->Ax;
267 std::fill(Ax.begin(), Ax.end(), t);
277 const auto key_size =
sizeof(
uint);
278 const auto value_size =
sizeof(T);
279 const auto elements_count = keys->get_size() / key_size;
281 if (elements_count != values->get_size() / value_size) {
284 if (elements_count * key_size != keys->get_size()) {
291 coo.
Ai.resize(elements_count);
292 coo.
Ax.resize(elements_count);
295 keys->read(0, key_size * elements_count, coo.
Ai.data());
296 values->read(0, value_size * elements_count, coo.
Ax.data());
302 const auto key_size =
sizeof(
uint);
303 const auto value_size =
sizeof(T);
308 const auto elements_count = coo.
Ai.size();
311 values =
MemView::make(coo.
Ax.data(), value_size * elements_count,
false);
318 m_storage.invalidate();
348 return m_storage.is_valid(format);
353 static std::unique_ptr<StorageManagerVector<T>> storage_manager;
355 if (!storage_manager) {
356 storage_manager = std::make_unique<StorageManagerVector<T>>();
360 return storage_manager.get();
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
Definition: cpu_formats.hpp:55
static ref_ptr< MemView > make()
Definition: memview.cpp:67
General format converter for vector or matrix decoration storage.
Definition: storage_manager.hpp:57
Storage for decorators with data of a particular vector or matrix object.
Definition: tdecoration.hpp:70
uint values
Definition: tdecoration.hpp:58
Vector interface implementation with type information bound.
Definition: tvector.hpp:60
T get_fill_value() const
Definition: tvector.hpp:92
Decorator * get()
Definition: tvector.hpp:85
~TVector() override=default
Generalized N dimensional vector object.
Definition: vector.hpp:48
Automates reference counting and behaves as shared smart pointer.
Definition: ref.hpp:117
Status fill_noize(uint seed) override
Definition: tvector.hpp:239
Status build(const ref_ptr< MemView > &keys, const ref_ptr< MemView > &values) override
Definition: tvector.hpp:273
void validate_rwd(FormatVector format)
Definition: tvector.hpp:329
uint get_n_rows() override
Definition: tvector.hpp:107
Status set_int(uint row_id, std::int32_t value) override
Definition: tvector.hpp:159
void set_label(std::string label) override
Definition: tvector.hpp:116
void validate_wd(F format, Storage &storage)
Definition: storage_manager.hpp:212
Status set_float(uint row_id, float value) override
Definition: tvector.hpp:183
Status get_float(uint row_id, float &value) override
Definition: tvector.hpp:224
void validate_rw(F format, Storage &storage)
Definition: storage_manager.hpp:128
Status get_int(uint row_id, int32_t &value) override
Definition: tvector.hpp:196
ref_ptr< Type > get_type() override
Definition: tvector.hpp:111
bool is_valid(FormatVector format) const
Definition: tvector.hpp:347
void validate_wd(FormatVector format)
Definition: tvector.hpp:335
Status read(ref_ptr< MemView > &keys, ref_ptr< MemView > &values) override
Definition: tvector.hpp:301
TVector(uint n_rows)
Definition: tvector.hpp:102
Status set_format(FormatVector format) override
Definition: tvector.hpp:126
const std::string & get_label() const override
Definition: tvector.hpp:121
void validate_ctor(F format, Storage &storage)
Definition: storage_manager.hpp:121
void validate_rwd(F format, Storage &storage)
Definition: storage_manager.hpp:206
void validate_rw(FormatVector format)
Definition: tvector.hpp:323
Status get_uint(uint row_id, uint32_t &value) override
Definition: tvector.hpp:210
void cpu_dok_vec_add_element(uint row_id, T element, CpuDokVec< T > &vec)
Definition: cpu_format_dok_vec.hpp:85
Status clear() override
Definition: tvector.hpp:317
void validate_ctor(FormatVector format)
Definition: tvector.hpp:341
Status fill_with(const ref_ptr< Scalar > &value) override
Definition: tvector.hpp:256
static StorageManagerVector< T > * get_storage_manager()
Definition: tvector.hpp:352
Status set_uint(uint row_id, std::uint32_t value) override
Definition: tvector.hpp:171
Status set_fill_value(const ref_ptr< Scalar > &value) override
Definition: tvector.hpp:131
Status set_reduce(ref_ptr< OpBinary > resolve_duplicates) override
Definition: tvector.hpp:145
std::int32_t T_INT
Definition: type.hpp:58
std::uint32_t uint
Library index and size type.
Definition: config.hpp:56
std::uint32_t T_UINT
Definition: type.hpp:59
float T_FLOAT
Definition: type.hpp:60
#define LOG_MSG(status, msg)
Definition: logger.hpp:66
Definition: algorithm.hpp:37
void register_formats_vector(StorageManagerVector< T > &manager)
Definition: storage_manager_vector.hpp:51