// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup MapMat //! @{ // this class is for internal use only; subject to change and/or removal without notice template class MapMat { public: typedef eT elem_type; //!< the type of elements stored in the matrix typedef typename get_pod_type::result pod_type; //!< if eT is std::complex, pod_type is T; otherwise pod_type is eT static constexpr bool is_row = false; static constexpr bool is_col = false; static constexpr bool is_xvec = false; const uword n_rows; //!< number of rows (read-only) const uword n_cols; //!< number of columns (read-only) const uword n_elem; //!< number of elements (read-only) private: typedef typename std::map map_type; arma_aligned map_type* map_ptr; public: inline ~MapMat(); inline MapMat(); inline explicit MapMat(const uword in_n_rows, const uword in_n_cols); inline explicit MapMat(const SizeMat& s); inline MapMat(const MapMat& x); inline void operator=(const MapMat& x); inline explicit MapMat(const SpMat& x); inline void operator=(const SpMat& x); inline MapMat(MapMat&& x); inline void operator=(MapMat&& x); inline void reset(); inline void set_size(const uword in_n_rows); inline void set_size(const uword in_n_rows, const uword in_n_cols); inline void set_size(const SizeMat& s); inline void zeros(); inline void zeros(const uword in_n_rows); inline void zeros(const uword in_n_rows, const uword in_n_cols); inline void zeros(const SizeMat& s); inline void eye(); inline void eye(const uword in_n_rows, const uword in_n_cols); inline void eye(const SizeMat& s); inline void speye(); inline void speye(const uword in_n_rows, const uword in_n_cols); inline void speye(const SizeMat& s); arma_warn_unused arma_inline MapMat_val operator[](const uword index); arma_warn_unused inline eT operator[](const uword index) const; arma_warn_unused arma_inline MapMat_val operator()(const uword index); arma_warn_unused inline eT operator()(const uword index) const; arma_warn_unused arma_inline MapMat_val at(const uword in_row, const uword in_col); arma_warn_unused inline eT at(const uword in_row, const uword in_col) const; arma_warn_unused arma_inline MapMat_val operator()(const uword in_row, const uword in_col); arma_warn_unused inline eT operator()(const uword in_row, const uword in_col) const; arma_warn_unused inline bool is_empty() const; arma_warn_unused inline bool is_vec() const; arma_warn_unused inline bool is_rowvec() const; arma_warn_unused inline bool is_colvec() const; arma_warn_unused inline bool is_square() const; inline void sprandu(const uword in_n_rows, const uword in_n_cols, const double density); inline void print(const std::string& extra_text) const; inline uword get_n_nonzero() const; inline void get_locval_format(umat& locs, Col& vals) const; private: inline void init_cold(); inline void init_warm(const uword in_n_rows, const uword in_n_cols); arma_inline void set_val(const uword index, const eT& in_val); inline void erase_val(const uword index); friend class SpMat; friend class MapMat_val; friend class SpMat_MapMat_val; friend class SpSubview_MapMat_val; }; template class MapMat_val { private: arma_aligned MapMat& parent; arma_aligned const uword index; inline MapMat_val(MapMat& in_parent, const uword in_index); friend class MapMat; public: arma_inline operator eT() const; arma_inline typename get_pod_type::result real() const; arma_inline typename get_pod_type::result imag() const; arma_inline void operator= (const MapMat_val& x); arma_inline void operator= (const eT in_val); arma_inline void operator+=(const eT in_val); arma_inline void operator-=(const eT in_val); arma_inline void operator*=(const eT in_val); arma_inline void operator/=(const eT in_val); arma_inline void operator++(); arma_inline void operator++(int); arma_inline void operator--(); arma_inline void operator--(int); }; template class SpMat_MapMat_val { private: arma_aligned SpMat& s_parent; arma_aligned MapMat& m_parent; arma_aligned const uword row; arma_aligned const uword col; inline SpMat_MapMat_val(SpMat& in_s_parent, MapMat& in_m_parent, const uword in_row, const uword in_col); friend class SpMat; friend class MapMat; friend class SpSubview_MapMat_val; public: inline operator eT() const; inline typename get_pod_type::result real() const; inline typename get_pod_type::result imag() const; inline SpMat_MapMat_val& operator= (const SpMat_MapMat_val& x); inline SpMat_MapMat_val& operator= (const eT in_val); inline SpMat_MapMat_val& operator+=(const eT in_val); inline SpMat_MapMat_val& operator-=(const eT in_val); inline SpMat_MapMat_val& operator*=(const eT in_val); inline SpMat_MapMat_val& operator/=(const eT in_val); inline SpMat_MapMat_val& operator++(); arma_warn_unused inline eT operator++(int); inline SpMat_MapMat_val& operator--(); arma_warn_unused inline eT operator--(int); inline void set(const eT in_val); inline void add(const eT in_val); inline void sub(const eT in_val); inline void mul(const eT in_val); inline void div(const eT in_val); }; template class SpSubview_MapMat_val : public SpMat_MapMat_val { private: arma_inline SpSubview_MapMat_val(SpSubview& in_sv_parent, MapMat& in_m_parent, const uword in_row, const uword in_col); arma_aligned SpSubview& sv_parent; friend class SpMat; friend class MapMat; friend class SpSubview; friend class SpMat_MapMat_val; public: inline SpSubview_MapMat_val& operator= (const SpSubview_MapMat_val& x); inline SpSubview_MapMat_val& operator= (const eT in_val); inline SpSubview_MapMat_val& operator+=(const eT in_val); inline SpSubview_MapMat_val& operator-=(const eT in_val); inline SpSubview_MapMat_val& operator*=(const eT in_val); inline SpSubview_MapMat_val& operator/=(const eT in_val); inline SpSubview_MapMat_val& operator++(); arma_warn_unused inline eT operator++(int); inline SpSubview_MapMat_val& operator--(); arma_warn_unused inline eT operator--(int); }; //! @}