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>
108 return m_storage.get_n_rows();
112 return get_ttype<T>().template as<Type>();
117 m_label = std::move(label);
141#if defined(SPLA_BUILD_OPENCL)
145 if constexpr (std::is_same<T, T_INT>::value) m_storage.set_fill_value(value->as_int());
146 if constexpr (std::is_same<T, T_UINT>::value) m_storage.set_fill_value(value->as_uint());
147 if constexpr (std::is_same<T, T_FLOAT>::value) m_storage.set_fill_value(value->as_float());
156 auto reduce = resolve_duplicates.template cast_safe<TOpBinary<T, T, T>>();
160 auto* vec = get<CpuDokVec<T>>();
161 vec->reduce = reduce->function;
172 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
184 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
196 get<CpuDenseVec<T>>()->Ax[row_id] =
static_cast<T
>(value);
209 const auto& Ax = get<CpuDokVec<T>>()->Ax;
210 const auto entry = Ax.find(row_id);
211 value = m_storage.get_fill_value();
213 if (entry != Ax.end()) {
214 value =
static_cast<T_INT>(entry->second);
223 const auto& Ax = get<CpuDokVec<T>>()->Ax;
224 const auto entry = Ax.find(row_id);
225 value = m_storage.get_fill_value();
227 if (entry != Ax.end()) {
228 value =
static_cast<T_UINT>(entry->second);
237 const auto& Ax = get<CpuDokVec<T>>()->Ax;
238 const auto entry = Ax.find(row_id);
239 value = m_storage.get_fill_value();
241 if (entry != Ax.end()) {
242 value =
static_cast<T_FLOAT>(entry->second);
251 auto& Ax = get<CpuDenseVec<T>>()->Ax;
252 auto engine = std::default_random_engine(seed);
254 if constexpr (std::is_integral_v<T>) {
255 std::uniform_int_distribution<T> dist;
256 for (
auto& x : Ax) x = dist(engine);
258 if constexpr (std::is_floating_point_v<T>) {
259 std::uniform_real_distribution<T> dist;
260 for (
auto& x : Ax) x = dist(engine);
271 if constexpr (std::is_same<T, T_INT>::value) t = value->as_int();
272 if constexpr (std::is_same<T, T_UINT>::value) t = value->as_uint();
273 if constexpr (std::is_same<T, T_FLOAT>::value) t = value->as_float();
276 auto& Ax = get<CpuDenseVec<T>>()->Ax;
277 std::fill(Ax.begin(), Ax.end(), t);
287 const auto key_size =
sizeof(
uint);
288 const auto value_size =
sizeof(T);
289 const auto elements_count = keys->get_size() / key_size;
291 if (elements_count != values->get_size() / value_size) {
294 if (elements_count * key_size != keys->get_size()) {
301 coo.
Ai.resize(elements_count);
302 coo.
Ax.resize(elements_count);
305 keys->read(0, key_size * elements_count, coo.
Ai.data());
306 values->read(0, value_size * elements_count, coo.
Ax.data());
312 const auto key_size =
sizeof(
uint);
313 const auto value_size =
sizeof(T);
318 const auto elements_count = coo.
Ai.size();
321 values =
MemView::make(coo.
Ax.data(), value_size * elements_count,
false);
328 m_storage.invalidate();
358 return m_storage.is_valid(format);
363 static std::unique_ptr<StorageManagerVector<T>> storage_manager;
365 if (!storage_manager) {
366 storage_manager = std::make_unique<StorageManagerVector<T>>();
370 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
void set_dims(uint n_rows, uint n_cols)
Definition tdecoration.hpp:93
uint values
Definition tdecoration.hpp:58
Vector interface implementation with type information bound.
Definition tvector.hpp:60
Decorator * get()
Definition tvector.hpp:85
T get_fill_value() const
Definition tvector.hpp:92
~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:249
Status build(const ref_ptr< MemView > &keys, const ref_ptr< MemView > &values) override
Definition tvector.hpp:283
void validate_rwd(FormatVector format)
Definition tvector.hpp:339
uint get_n_rows() override
Definition tvector.hpp:107
Status set_int(uint row_id, std::int32_t value) override
Definition tvector.hpp:169
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:193
Status get_float(uint row_id, float &value) override
Definition tvector.hpp:234
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:206
ref_ptr< Type > get_type() override
Definition tvector.hpp:111
bool is_valid(FormatVector format) const
Definition tvector.hpp:357
void validate_wd(FormatVector format)
Definition tvector.hpp:345
Status read(ref_ptr< MemView > &keys, ref_ptr< MemView > &values) override
Definition tvector.hpp:311
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:333
Status get_uint(uint row_id, uint32_t &value) override
Definition tvector.hpp:220
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:327
void validate_ctor(FormatVector format)
Definition tvector.hpp:351
Status fill_with(const ref_ptr< Scalar > &value) override
Definition tvector.hpp:266
static StorageManagerVector< T > * get_storage_manager()
Definition tvector.hpp:362
Status set_uint(uint row_id, std::uint32_t value) override
Definition tvector.hpp:181
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:155
float T_FLOAT
Definition type.hpp:60
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
#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