26#if ! defined (octave_MSparse_h)
27#define octave_MSparse_h 1
29#include "octave-config.h"
63 MSparse (
const Array<T>& a,
const octave::idx_vector& r,
const octave::idx_vector& c,
66 :
Sparse<T> (a, r, c, nr, nc, sum_terms, nzm) { }
69 :
Sparse<T> (r, c, val) { }
74 :
Sparse<T> (r, c, num_nz) { }
115 template <
typename U>
120 template <
typename U>
122 map (U (&fcn) (
const T&))
const
130#define SPARSE_OP_ASSIGN_DECL(T, OP, API) \
131 template API MSparse<T>& \
132 operator OP (MSparse<T>&, const MSparse<T>&)
135#define SPARSE_UNOP_DECL(T, OP, API) \
136 template API MSparse<T> \
137 operator OP (const MSparse<T>&)
140#define SPARSE_BINOP_DECL(A_T, T, F, API, X_T, Y_T) \
141 template API A_T<T> \
142 F (const X_T&, const Y_T&)
146#define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
148 F (X_T& x, const Y_T& y) \
150 return R (F (C_X (x), C_Y (y))); \
155#define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \
159 return R (F (C_X (x))); \
164#define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
166 F (const X_T& x, const Y_T& y) \
168 return R (F (C_X (x), C_Y (y))); \
172#define INSTANTIATE_SPARSE_FRIENDS(T, API) \
173 SPARSE_OP_ASSIGN_DECL (T, +=, API); \
174 SPARSE_OP_ASSIGN_DECL (T, -=, API); \
175 SPARSE_UNOP_DECL (T, +, API); \
176 SPARSE_UNOP_DECL (T, -, API); \
177 SPARSE_BINOP_DECL (MArray, T, operator +, API, MSparse<T>, T); \
178 SPARSE_BINOP_DECL (MArray, T, operator -, API, MSparse<T>, T); \
179 SPARSE_BINOP_DECL (MSparse, T, operator *, API, MSparse<T>, T); \
180 SPARSE_BINOP_DECL (MSparse, T, operator /, API, MSparse<T>, T); \
181 SPARSE_BINOP_DECL (MArray, T, operator +, API, T, MSparse<T>); \
182 SPARSE_BINOP_DECL (MArray, T, operator -, API, T, MSparse<T>); \
183 SPARSE_BINOP_DECL (MSparse, T, operator *, API, T, MSparse<T>); \
184 SPARSE_BINOP_DECL (MSparse, T, operator /, API, T, MSparse<T>); \
185 SPARSE_BINOP_DECL (MSparse, T, operator +, API, MSparse<T>, MSparse<T>); \
186 SPARSE_BINOP_DECL (MSparse, T, operator -, API, MSparse<T>, MSparse<T>); \
187 SPARSE_BINOP_DECL (MSparse, T, quotient, API, MSparse<T>, MSparse<T>); \
188 SPARSE_BINOP_DECL (MSparse, T, product, API, MSparse<T>, MSparse<T>);
192#define SPARSE_FORWARD_DEFS(B, R, F, T) \
193 SPARSE_OP_ASSIGN_FWD_FCN (R, operator +=, T, dynamic_cast<B<T>&>, \
194 R, dynamic_cast<const B<T>&>, R) \
195 SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, dynamic_cast<B<T>&>, \
196 R, dynamic_cast<const B<T>&>, R) \
197 SPARSE_UNOP_FWD_FCN (R, operator +, T, dynamic_cast<const B<T>&>, R) \
198 SPARSE_UNOP_FWD_FCN (R, operator -, T, dynamic_cast<const B<T>&>, R) \
199 SPARSE_BINOP_FWD_FCN (F, operator +, T, dynamic_cast<const B<T>&>, R, , T) \
200 SPARSE_BINOP_FWD_FCN (F, operator -, T, dynamic_cast<const B<T>&>, R, , T) \
201 SPARSE_BINOP_FWD_FCN (R, operator *, T, dynamic_cast<const B<T>&>, R, , T) \
202 SPARSE_BINOP_FWD_FCN (R, operator /, T, dynamic_cast<const B<T>&>, R, , T) \
203 SPARSE_BINOP_FWD_FCN (F, operator +, T, , T, dynamic_cast<const B<T>&>, R) \
204 SPARSE_BINOP_FWD_FCN (F, operator -, T, , T, dynamic_cast<const B<T>&>, R) \
205 SPARSE_BINOP_FWD_FCN (R, operator *, T, , T, dynamic_cast<const B<T>&>, R) \
206 SPARSE_BINOP_FWD_FCN (R, operator /, T, , T, dynamic_cast<const B<T>&>, R) \
207 SPARSE_BINOP_FWD_FCN (R, operator +, T, dynamic_cast<const B<T>&>, \
208 R, dynamic_cast<const B<T>&>, R) \
209 SPARSE_BINOP_FWD_FCN (R, operator -, T, dynamic_cast<const B<T>&>, \
210 R, dynamic_cast<const B<T>&>, R) \
211 SPARSE_BINOP_FWD_FCN (R, product, T, dynamic_cast<const B<T>&>, \
212 R, dynamic_cast<const B<T>&>, R) \
213 SPARSE_BINOP_FWD_FCN (R, quotient, T, dynamic_cast<const B<T>&>, \
214 R, dynamic_cast<const B<T>&>, R)
N Dimensional Array with copy-on-write semantics.
MSparse(const MSparse< T > &a)
MSparse(octave_idx_type n, octave_idx_type m)
Sparse< U > map(U(&fcn)(const T &)) const
MSparse(octave_idx_type r, octave_idx_type c, T val)
MSparse< T > & insert(const Sparse< T > &a, const Array< octave_idx_type > &indx)
MSparse< T > transpose() const
Sparse< U > map(U(&fcn)(T)) const
MSparse(const Sparse< U > &a)
MSparse(const Sparse< T > &a)
MSparse(octave_idx_type r, octave_idx_type c, octave_idx_type num_nz)
MSparse< T > diag(octave_idx_type k=0) const
MSparse< T > & insert(const Sparse< T > &a, octave_idx_type r, octave_idx_type c)
MSparse< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
MSparse(const Array< T > &a, const octave::idx_vector &r, const octave::idx_vector &c, octave_idx_type nr=-1, octave_idx_type nc=-1, bool sum_terms=true, octave_idx_type nzm=-1)
MSparse< T > reshape(const dim_vector &new_dims) const
MSparse< T > squeeze() const
MSparse(const MSparse< T > &a, const dim_vector &dv)
MSparse(const dim_vector &dv, octave_idx_type nz=0)
MSparse(const PermMatrix &a)
MSparse< T > ipermute(const Array< octave_idx_type > &vec) const
Sparse< T, Alloc > diag(octave_idx_type k=0) const
Sparse< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Sparse< T, Alloc > squeeze() const
Sparse< T, Alloc > & insert(const Sparse< T, Alloc > &a, octave_idx_type r, octave_idx_type c)
Sparse< T, Alloc > ipermute(const Array< octave_idx_type > &vec) const
Sparse< T, Alloc > & operator=(const Sparse< T, Alloc > &a)
Sparse< T, Alloc > transpose() const
Sparse< T, Alloc > reshape(const dim_vector &new_dims) const
Vector representing the dimensions (size) of an Array.