21 #ifndef TENSOR_SPARSE_H
22 #define TENSOR_SPARSE_H
24 #include <tensor/tensor.h>
36 template<
typename elt>
45 Sparse(index
rows, index cols, index nonzero = 0);
48 index rows = 0, index
columns = 0);
51 const Indices &column,
const Vector<elt_t> &data);
86 const Indices &priv_row_start()
const {
return row_start_; }
87 const Indices &priv_column()
const {
return column_; }
88 const Vector<elt> &priv_data()
const {
return data_; }
112 const Sparse<t> operator-(
const Sparse<t> &);
119 const Sparse<t> operator*(t b,
const Sparse<t> &s);
121 const Sparse<t> operator*(
const Sparse<t> &s, t b);
123 const Sparse<t> operator/(
const Sparse<t> &s, t b);
126 const Sparse<t> operator+(
const Sparse<t> &m1,
const Sparse<t> &m2);
128 const Sparse<t> operator-(
const Sparse<t> &m1,
const Sparse<t> &m2);
130 const Sparse<t> operator*(
const Sparse<t> &m1,
const Sparse<t> &m2);
134 const Sparse<t> kron(
const Sparse<t> &s1,
const Sparse<t> &s2);
137 const Sparse<t> kron2(
const Sparse<t> &s1,
const Sparse<t> &s2);
142 template<
typename t1,
typename t2>
143 inline bool all_equal(
const Sparse<t1> &s1,
const Sparse<t2> &s2) {
144 return all_equal(s1.dimensions(), s2.dimensions()) &&
145 all_equal(s1.priv_row_start(), s2.priv_row_start()) &&
146 all_equal(s1.priv_column(), s2.priv_column()) &&
147 all_equal(s1.priv_data(), s2.priv_data());
150 template<
typename t1,
typename t2>
151 inline bool all_equal(
const Sparse<t1> &s1,
const Tensor<t2> &s2) {
152 return all_equal(full(s1), s2);
155 template<
typename t1,
typename t2>
156 inline bool all_equal(
const Tensor<t1> &s1,
const Sparse<t2> &s2) {
157 return all_equal(full(s2), s1);
160 const RTensor mmult(
const RTensor &m1,
const RSparse &m2);
161 const CTensor mmult(
const CTensor &m1,
const CSparse &m2);
162 const RTensor mmult(
const RSparse &m1,
const RTensor &m2);
163 const CTensor mmult(
const CSparse &m1,
const CTensor &m2);
165 inline const RSparse &real(
const RSparse &A) {
return A; }
166 inline const RSparse &
conj(
const RSparse &A) {
return A; }
167 inline const RSparse imag(
const RSparse &A) {
168 return RSparse(A.rows(), A.columns());
171 const RSparse real(
const CSparse &A);
172 const CSparse
conj(
const CSparse &A);
173 const RSparse imag(
const CSparse &A);
177 #ifdef TENSOR_LOAD_IMPL
178 #include <tensor/detail/sparse_base.hpp>
179 #include <tensor/detail/sparse_kron.hpp>
180 #include <tensor/detail/sparse_ops.hpp>
183 #endif // !TENSOR_SPARSE_H
index rows() const
Number of rows.
Vector< elt_t > data_
The single data entries.
Indices column_
Gives for each data_ entry the column in the matrix.
const Indices & dimensions() const
Return Sparse matrix dimensions.
static Sparse< elt_t > random(index rows, index columns, double density=0.2)
Return a random sparse matrix.
An N-dimensional array of numbers.
static Sparse< elt_t > eye(index rows)
Identity matrix in sparse form.
static Sparse< elt_t > eye(index rows, index cols)
Identity matrix in sparse form.
index dimension(int which) const
Length of a given Sparse matrix index.
index columns() const
Number of columns.
Sparse()
Build an empty matrix.
Sparse & operator=(const Sparse< elt_t > &s)
Assignment operator.
Vector of 'index' type, where 'index' fits the indices of a tensor.
Indices dims_
The dimensions (rows and columns) of the sparse matrix.
Indices row_start_
Gives for each row of the matrix at which index the column_/data_ entries start.
const RTensor conj(const RTensor &r)
Complex conjugate of a real tensor.
index length() const
Number of nonzero elements.
elt_t operator()(index row, index col) const
Return an element of the sparse matrix.
bool is_empty() const
Empty matrix?