11#include <kernel/util/math.hpp>
12#include <kernel/util/statistics.hpp>
13#include <kernel/util/tiny_algebra.hpp>
14#include <kernel/util/type_traits.hpp>
15#include <kernel/util/time_stamp.hpp>
16#include <kernel/adjacency/permutation.hpp>
17#include <kernel/lafem/forward.hpp>
18#include <kernel/lafem/container.hpp>
19#include <kernel/lafem/arch/min_max_value_dense.hpp>
20#include <kernel/lafem/arch/max_rel_diff_dense.hpp>
48 template <
typename DT_,
typename IT_,
int block_size_>
132 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
135 this->deserialize<DT2_,IT2_>(input);
185 this->
move(std::forward<SparseVectorBlocked>(other));
201 t.
clone(*
this, clone_mode);
213 template<
typename DT2_,
typename IT2_>
229 template <
typename DT2_,
typename IT2_>
244 return this->
size() *
Index(block_size_);
284 return Memory::TypedView<ValueType>();
291 return Memory::TypedView<ValueType>();
298 return Memory::TypedView<ValueType>();
305 return Memory::TypedView<ValueType>();
306 return Memory::TypedView<ValueType>(this->
_elements.at(0).view(loc, acc));
309 Memory::Arbiter& indices_arbiter()
314 const Memory::Arbiter& indices_arbiter()
const
322 return Memory::TypedView<IT_>();
329 return Memory::TypedView<IT_>();
336 return Memory::TypedView<IT_>();
343 return Memory::TypedView<IT_>();
344 return Memory::TypedView<IT_>(this->
_indices.at(0).view(loc, acc));
354 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
363 const IT_* pindices = idx_view.
get_r();
377 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
391 std::ifstream file(filename.c_str(), std::ifstream::in | std::ifstream::binary);
392 if (! file.is_open())
393 XABORTM(
"Unable to open Vector file " + filename);
413 XABORTM(
"Filemode not supported!");
425 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
427 bin = std::ofstream::out;
429 char* buff =
nullptr;
435 file.open(filename.c_str(), bin);
437 XABORTM(
"Unable to open Matrix file " + filename);
463 file <<
"%%MatrixMarket matrix coordinate real general\n";
464 file << this->
size()*block_size <<
" " << 1 <<
" " << this->
num_nzes()*block_size <<
"\n";
470 for (
Index i(0) ; i < u_elem ; ++i)
473 file << (idx_view[i]*
Index(
block_size+k+1)) <<
" " << 1 <<
" " << val_view[i][k] <<
"\n";
479 XABORTM(
"Filemode not supported!");
497 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->
num_nzes_raw(),
false,
true);
500 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
516 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->
num_nzes_raw(),
true,
true);
519 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
535 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->
num_nzes_raw(),
false,
false);
538 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
554 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->
num_nzes_raw(),
true,
false);
557 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
570 XASSERTM(x.
num_nzes() == this->num_nzes(),
"Nonzero count does not match!");
575 DataType result = Arch::MaxRelDiffDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), this->num_nzes_raw());
578 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
588 if (perm.
size() == 0)
591 std::map<IT_, ValueType> xm;
594 const Index *
const inv_pos(ip.get_perm_pos());
600 xm.emplace(IT_(inv_pos[xi[i]]), xv[i]);
604 for(
const auto& x : xm)
619 return "SparseVectorBlocked";
642 if(this->indices_arbiter() == other.indices_arbiter())
650 for(
Index i(0); i < n; ++i)
652 if(idx_a[i] != idx_b[i])
674 for (
Index i(0) ; i < nze ; ++i)
676 for(; k < idx_view[i]; ++k)
678 for(
int d = 0; d < block_size_; ++d)
679 lhs <<
" " << DT_(0);
682 for(
int d = 0; d < block_size_; ++d)
683 lhs <<
" " << val_view[i][d];
687 for(
int d = 0; d < block_size_; ++d)
688 lhs <<
" " << DT_(0);
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Index size() const
returns the size of the permutation
Permutation inverse() const
Computes the inverse permutation.
void move(Container &&source)
Assignment move operation.
void clone(const Container &source, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
std::vector< Memory::Arbiter > _indices
List of pointers to all IT_ dependent arrays.
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
std::vector< Memory::Arbiter > _elements
List of pointers to all datatype dependent arrays.
std::vector< Index > _scalar_index
List of scalars with datatype index.
Blocked Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Config class for serialize parameter.
Sparse vector class template.
bool hollow() const
Checks whether the sparse vector does not contain any non-zero elements.
Index size() const
Returns the native size of the sparse vector.
DT_ DataType
Our datatype.
SparseVectorBlocked(std::vector< char > input)
Constructor.
void read_from(FileMode mode, const String &filename)
Read in vector from file.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
static constexpr int block_size
Our size of a single block.
friend std::ostream & operator<<(std::ostream &lhs, const SparseVectorBlocked &b)
SparseVectorBlocked streaming operator.
DT_ max_abs_element() const
Retrieve the absolute maximum value of this vector.
SparseVectorBlocked()
Constructor.
DT_ max_rel_diff(const SparseVectorBlocked &x) const
Retrieve the maximum relative difference of this vector and another one y.max_rel_diff(x) returns .
SparseVectorBlocked(Index size_in, Index nnze_in)
Constructor.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
SparseVectorBlocked(FileMode mode, const String &filename)
Constructor.
SparseVectorBlocked & operator=(SparseVectorBlocked &&other)
Assignment move operator.
bool empty() const
Checks whether the size of the sparse vector is zero.
Index num_nzes_raw() const
Returns the raw number of non-zero elements in the sparse vector.
static String name()
Returns a descriptive string.
void convert(const SparseVectorBlocked< DT2_, IT2_, block_size_ > &other)
Conversion method.
Index num_nzes() const
Returns the number of non-zero elements in the sparse vector.
Tiny::Vector< DT_, block_size_ > ValueType
Our value type.
bool same_layout(const SparseVectorBlocked &other) const
Checks whether the layout of this vector is identical to another sparse vector.
void read_from(FileMode mode, std::istream &file)
Read in vector from stream.
DT_ max_element() const
Retrieve the maximum value of this vector.
SparseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
void write_out(FileMode mode, std::ostream &file) const
Write out vector to file.
IT_ IndexType
Our indextype.
DT_ min_element() const
Retrieve the minimum value of this vector.
void permute(Adjacency::Permutation &perm)
Permute vector according to the given Permutation.
SparseVectorBlocked(SparseVectorBlocked &&other)
Move Constructor.
void clone(const SparseVectorBlocked< DT2_, IT2_, block_size_ > &other, CloneMode clone_mode=CloneMode::Deep)
Clone operation.
SparseVectorBlocked(FileMode mode, std::istream &file)
Constructor.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this vector.
SparseVectorBlocked(Index size_in, DenseVectorBlocked< DT_, IT_, block_size_ > &elements_in, DenseVector< IT_, IT_ > &indices_in)
Constructor.
std::vector< char > serialize(const LAFEM::SerialConfig &config=SerialConfig()) const
Serialization of complete container entity.
Index size_raw() const
Returns the raw size of the sparse vector.
Arbiter attach(std::size_t offset=0u, std::size_t size=full_size) const
Creates a new arbiter that is attached to the same memory block as this arbiter.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
String class implementation.
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
Tiny Vector class template.
constexpr std::size_t file_out_stream_buffer_size
OutStreamBufferSize.
Access
Memory access enumeration.
@ read_write
read-write access
@ write
write-only access (see attention note above)
Location
Memory location enumeration.
std::uint64_t Index
Index data type.