.. _program_listing_file_src_sparsebase_format_csr.h: Program Listing for File csr.h ============================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/sparsebase/format/csr.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "sparsebase/config.h" #include "sparsebase/context/cpu_context.h" #include "sparsebase/format/format_order_two.h" #include "sparsebase/utils/exception.h" #include "sparsebase/utils/utils.h" #ifndef SPARSEBASE_PROJECT_CSR_H #define SPARSEBASE_PROJECT_CSR_H namespace sparsebase::format { template class CSR : public utils::IdentifiableImplementation< CSR, FormatOrderTwo> { public: CSR(IDType n, IDType m, NNZType *row_ptr, IDType *col, ValueType *vals, Ownership own = kNotOwned, bool ignore_sort = false); CSR(const CSR &); CSR(CSR &&); CSR &operator=( const CSR &); Format *Clone() const override; virtual ~CSR(); NNZType *get_row_ptr() const; IDType *get_col() const; ValueType *get_vals() const; NNZType *release_row_ptr(); IDType *release_col(); ValueType *release_vals(); void set_row_ptr(NNZType *, Ownership own = kNotOwned); void set_col(IDType *, Ownership own = kNotOwned); void set_vals(ValueType *, Ownership own = kNotOwned); virtual bool ColIsOwned(); virtual bool RowPtrIsOwned(); virtual bool ValsIsOwned(); protected: std::unique_ptr> row_ptr_; std::unique_ptr> col_; std::unique_ptr> vals_; }; template template struct format::FormatOrderTwo::TypeConverter< CSR, ToIDType, ToNNZType, ToValueType> { CSR *operator()( FormatOrderTwo *source, bool is_move_conversion) { CSR *csr = source->template As(); auto dims = csr->get_dimensions(); auto num_nnz = csr->get_num_nnz(); ToNNZType *new_row_ptr; ToIDType *new_col; ToValueType *new_vals; if (!is_move_conversion || !std::is_same_v) { new_row_ptr = utils::ConvertArrayType(csr->get_row_ptr(), dims[0] + 1); } else { if constexpr (std::is_same_v) { new_row_ptr = csr->release_row_ptr(); } } if (!is_move_conversion || !std::is_same_v) { new_col = utils::ConvertArrayType(csr->get_col(), num_nnz); } else { if constexpr (std::is_same_v) { new_col = csr->release_col(); } } if (!is_move_conversion || !std::is_same_v) { new_vals = utils::ConvertArrayType(csr->get_vals(), num_nnz); } else { if constexpr (std::is_same_v) { new_vals = csr->release_vals(); } } return new CSR( dims[0], dims[1], new_row_ptr, new_col, new_vals, kOwned); } }; } // namespace sparsebase::format #ifdef _HEADER_ONLY #include "csr.cc" #endif #endif // SPARSEBASE_PROJECT_CSR_H