.. _program_listing_file_src_sparsebase_format_array.cc: Program Listing for File array.cc ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``src/sparsebase/format/array.cc``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "sparsebase/format/array.h" #include "sparsebase/utils/logger.h" namespace sparsebase::format { template Array::Array(Array &&rhs) : vals_(std::move(rhs.vals_)) { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); this->nnz_ = rhs.get_num_nnz(); this->order_ = 1; this->dimension_ = rhs.dimension_; rhs.vals_ = std::unique_ptr>( nullptr, BlankDeleter()); this->context_ = std::unique_ptr( new sparsebase::context::CPUContext); } template Array &Array::operator=(const Array &rhs) { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); this->nnz_ = rhs.nnz_; this->order_ = 1; this->dimension_ = rhs.dimension_; ValueType *vals = nullptr; if constexpr (!std::is_same_v) { if (rhs.get_vals() != nullptr) { vals = new ValueType[rhs.get_num_nnz()]; std::copy(rhs.get_vals(), rhs.get_vals() + rhs.get_num_nnz(), vals); } this->vals_ = std::unique_ptr>( vals, Deleter()); return *this; } else { throw utils::TypeException("Cannot create an array with ValueType == void"); } } template Array::Array(const Array &rhs) : vals_(nullptr, BlankDeleter()) { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); this->nnz_ = rhs.nnz_; this->order_ = 1; this->dimension_ = rhs.dimension_; ValueType *vals = nullptr; if constexpr (!std::is_same_v) { if (rhs.get_vals() != nullptr) { vals = new ValueType[rhs.get_num_nnz()]; std::copy(rhs.get_vals(), rhs.get_vals() + rhs.get_num_nnz(), vals); } this->vals_ = std::unique_ptr>( vals, Deleter()); this->context_ = std::unique_ptr( new sparsebase::context::CPUContext); } else { throw utils::TypeException("Cannot create an array with ValueType == void"); } } template Array::Array(DimensionType nnz, ValueType *vals, Ownership own) : vals_(vals, BlankDeleter()) { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); this->order_ = 1; this->dimension_ = {(DimensionType)nnz}; this->nnz_ = nnz; if (own == kOwned) { this->vals_ = std::unique_ptr>( vals, Deleter()); } this->context_ = std::unique_ptr( new sparsebase::context::CPUContext); } template Format *Array::Clone() const { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); return new Array(*this); } template ValueType *Array::get_vals() const { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); return vals_.get(); } template ValueType *Array::release_vals() { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); auto vals = vals_.release(); this->vals_ = std::unique_ptr>( vals, BlankDeleter()); return vals; } template void Array::set_vals(ValueType *vals, Ownership own) { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); if (own == kOwned) { this->vals_ = std::unique_ptr>( vals, Deleter()); } else { this->vals_ = std::unique_ptr>( vals, BlankDeleter()); } } template bool Array::ValsIsOwned() { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); return (this->vals_.get_deleter().target_type() != typeid(BlankDeleter)); } template Array::~Array() { static_assert(!std::is_same_v, "A format::Array cannot contain have ValueType as void"); } #ifndef _HEADER_ONLY #include "init/array.inc" #endif } // namespace sparsebase::format