gko::matrix::Dense#

Column-major dense matrix. Doubles as Ginkgo’s vector type (a Dense matrix with one column) and as the storage for right-hand sides and solution vectors in iterative solvers. Backed by a contiguous value array with an explicit leading-dimension stride.

template<typename ValueType = default_precision>
class Dense #

Inherits from

  • public gko::EnableLinOp<Dense<default_precision>>

  • public ConvertibleTo<Dense<next_precision<default_precision>>>

  • public ConvertibleTo<Dense<next_precision<default_precision, 2>>>

  • public ConvertibleTo<Dense<next_precision<default_precision, 3>>>

  • public ConvertibleTo<Coo<default_precision, int32>>

  • public ConvertibleTo<Coo<default_precision, int64>>

  • public ConvertibleTo<Csr<default_precision, int32>>

  • public ConvertibleTo<Csr<default_precision, int64>>

  • public ConvertibleTo<Ell<default_precision, int32>>

  • public ConvertibleTo<Ell<default_precision, int64>>

  • public ConvertibleTo<Fbcsr<default_precision, int32>>

  • public ConvertibleTo<Fbcsr<default_precision, int64>>

  • public ConvertibleTo<Hybrid<default_precision, int32>>

  • public ConvertibleTo<Hybrid<default_precision, int64>>

  • public ConvertibleTo<Sellp<default_precision, int32>>

  • public ConvertibleTo<Sellp<default_precision, int64>>

  • public ConvertibleTo<SparsityCsr<default_precision, int32>>

  • public ConvertibleTo<SparsityCsr<default_precision, int64>>

  • public gko::DiagonalExtractable<default_precision>

  • public gko::ReadableFromMatrixData<default_precision, int32>

  • public gko::ReadableFromMatrixData<default_precision, int64>

  • public gko::WritableToMatrixData<default_precision, int32>

  • public gko::WritableToMatrixData<default_precision, int64>

  • public gko::Transposable

  • public gko::Permutable<int32>

  • public gko::Permutable<int64>

  • public gko::EnableAbsoluteComputation<remove_complex<Dense<default_precision>>>

  • public gko::ScaledIdentityAddable

Dense is a matrix format which explicitly stores all values of the matrix.

The values are stored in row-major format (values belonging to the same row appear consecutive in the memory). Optionally, rows can be padded for better memory access.

Note

While this format is not very useful for storing sparse matrices, it is often suitable to store vectors, and sets of vectors.

Template Parameters:

ValueType – precision of matrix elements

Public Functions

virtual std::unique_ptr<LinOp> transpose() const override#

Returns a LinOp representing the transpose of the Transposable object.

Returns:

a pointer to the new transposed object

virtual std::unique_ptr<LinOp> conj_transpose() const override#

Returns a LinOp representing the conjugate transpose of the Transposable object.

Returns:

a pointer to the new conjugate transposed object

void transpose(ptr_param<Dense> output) const#

Writes the transposed matrix into the given output matrix.

Parameters:

output – The output matrix. It must have the dimensions gko::transpose(this->get_size())

void conj_transpose(ptr_param<Dense> output) const#

Writes the conjugate-transposed matrix into the given output matrix.

Parameters:

output – The output matrix. It must have the dimensions gko::transpose(this->get_size())

void fill(const ValueType value)#

Fill the dense matrix with a given value.

Parameters:

value – the value to be filled

std::unique_ptr<Dense> permute(
ptr_param<const Permutation<int32>> permutation,
permute_mode mode = permute_mode::symmetric,
) const#

Creates a permuted copy \(A'\) of this matrix \(A\) with the given permutation \(P\). By default, this computes a symmetric permutation (permute_mode::symmetric). For the effect of the different permutation modes, see permute_mode.

Parameters:
  • permutation – The input permutation.

  • mode – The permutation mode. If permute_mode::inverse is set, we use the inverse permutation \(P^{-1}\) instead of \(P\). If permute_mode::rows is set, the rows will be permuted. If permute_mode::columns is set, the columns will be permuted.

Returns:

The permuted matrix.

void permute(
ptr_param<const Permutation<int32>> permutation,
ptr_param<Dense> output,
permute_mode mode,
) const#

Overload of permute(ptr_param<const Permutation<int32>>, permute_mode) that writes the permuted copy into an existing Dense matrix.

Parameters:

output – the output matrix.

std::unique_ptr<Dense> permute(
ptr_param<const Permutation<int32>> row_permutation,
ptr_param<const Permutation<int32>> column_permutation,
bool invert = false,
) const#

Creates a non-symmetrically permuted copy \(A'\) of this matrix \(A\) with the given row and column permutations \(P\) and \(Q\). The operation will compute \(A'(i, j) = A(p[i], q[j])\), or \(A' = P A Q^T\) if invert is false, and \(A'(p[i], q[j]) = A(i,j)\), or \(A' = P^{-1} A Q^{-T}\) if invert is true.

Parameters:
  • row_permutation – The permutation \(P\) to apply to the rows

  • column_permutation – The permutation \(Q\) to apply to the columns

  • invert – If set to false, uses the input permutations, otherwise uses their inverses \(P^{-1}, Q^{-1}\)

Returns:

The permuted matrix.

void permute(
ptr_param<const Permutation<int32>> row_permutation,
ptr_param<const Permutation<int32>> column_permutation,
ptr_param<Dense> output,
bool invert = false,
) const#

Overload of permute(ptr_param<const Permutation<int32>>, ptr_param<const

Permutation<int32>>, permute_mode) that writes the permuted copy into an existing

Dense matrix.

Parameters:

output – the output matrix.

std::unique_ptr<Dense> scale_permute(
ptr_param<const ScaledPermutation<value_type, int32>> permutation,
permute_mode mode = permute_mode::symmetric,
) const#

Creates a scaled and permuted copy of this matrix. For an explanation of the permutation modes, see permute(ptr_param<const Permutation<index_type>>, permute_mode)

Parameters:
  • permutation – The scaled permutation.

  • mode – The permutation mode.

Returns:

The permuted matrix.

void scale_permute(
ptr_param<const ScaledPermutation<value_type, int32>> permutation,
ptr_param<Dense> output,
permute_mode mode,
) const#

Overload of scale_permute(ptr_param<const ScaledPermutation<value_type,

int32>>, permute_mode) that writes the permuted copy into an existing

Dense matrix.

Parameters:

output – the output matrix.

std::unique_ptr<Dense> scale_permute(
ptr_param<const ScaledPermutation<value_type, int32>> row_permutation,
ptr_param<const ScaledPermutation<value_type, int32>> column_permutation,
bool invert = false,
) const#

Creates a scaled and permuted copy of this matrix. For an explanation of the parameters, see permute(ptr_param<const Permutation<index_type>>, ptr_param<const

Permutation<index_type>>, permute_mode)

Parameters:
  • row_permutation – The scaled row permutation.

  • column_permutation – The scaled column permutation.

  • invert – If set to false, uses the input permutations, otherwise uses their inverses \(P^{-1}, Q^{-1}\)

Returns:

The permuted matrix.

void scale_permute(
ptr_param<const ScaledPermutation<value_type, int32>> row_permutation,
ptr_param<const ScaledPermutation<value_type, int32>> column_permutation,
ptr_param<Dense> output,
bool invert = false,
) const#

Overload of scale_permute(ptr_param<const ScaledPermutation<value_type,

int32>>, ptr_param<const ScaledPermutation<value_type, int32>>, bool) that writes the permuted copy into an existing

Dense matrix.

Parameters:

output – the output matrix.

virtual std::unique_ptr<LinOp> permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the symmetric row and column permutation of the Permutable object. In the resulting LinOp, the entry at location (i,j) contains the input value (perm[i],perm[j]).

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P A P^T\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

virtual std::unique_ptr<LinOp> permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the symmetric row and column permutation of the Permutable object. In the resulting LinOp, the entry at location (i,j) contains the input value (perm[i],perm[j]).

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P A P^T\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

void permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the symmetrically permuted matrix into the given output matrix.

See also

Dense::permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[0] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

virtual std::unique_ptr<LinOp> inverse_permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the symmetric inverse row and column permutation of the Permutable object. In the resulting LinOp, the entry at location (perm[i],perm[j]) contains the input value (i,j).

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P^{-1} A P^{-T}\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

virtual std::unique_ptr<LinOp> inverse_permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the symmetric inverse row and column permutation of the Permutable object. In the resulting LinOp, the entry at location (perm[i],perm[j]) contains the input value (i,j).

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P^{-1} A P^{-T}\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

void inverse_permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the inverse symmetrically permuted matrix into the given output matrix.

See also

Dense::inverse_permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[0] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

virtual std::unique_ptr<LinOp> row_permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the Permutable object. In the resulting LinOp, the row i contains the input row perm[i].

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P A\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

virtual std::unique_ptr<LinOp> row_permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the Permutable object. In the resulting LinOp, the row i contains the input row perm[i].

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P A\).

Parameters:

permutation_indices – the array of indices containing the permutation order.

Returns:

a pointer to the new permuted object

void row_permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the row-permuted matrix into the given output matrix.

See also

Dense::row_permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[0] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

std::unique_ptr<Dense> row_gather(
const array<int32> *gather_indices,
) const#

Create a Dense matrix consisting of the given rows from this matrix.

Parameters:

gather_indices – pointer to an array containing row indices from this matrix. It may contain duplicates.

Returns:

Dense matrix on the same executor with the same number of columns and gather_indices->get_size() rows containing the gathered rows from this matrix: output(i,j) = input(gather_indices(i), j)

std::unique_ptr<Dense> row_gather(
const array<int64> *gather_indices,
) const#

Create a Dense matrix consisting of the given rows from this matrix.

Parameters:

gather_indices – pointer to an array containing row indices from this matrix. It may contain duplicates.

Returns:

Dense matrix on the same executor with the same number of columns and gather_indices->get_size() rows containing the gathered rows from this matrix: output(i,j) = input(gather_indices(i), j)

void row_gather(
const array<int32> *gather_indices,
ptr_param<LinOp> row_collection,
) const#

Copies the given rows from this matrix into row_collection

Parameters:
  • gather_indices – pointer to an array containing row indices from this matrix. It may contain duplicates.

  • row_collection – pointer to a LinOp that will store the gathered rows: row_collection(i,j) = input(gather_indices(i), j) It must have the same number of columns as this matrix and gather_indices->get_size() rows.

void row_gather(
ptr_param<const LinOp> alpha,
const array<int32> *gather_indices,
ptr_param<const LinOp> beta,
ptr_param<LinOp> row_collection,
) const#

Copies the given rows from this matrix into row_collection with scaling

Parameters:
  • alpha – scaling the result of row gathering

  • gather_indices – pointer to an array containing row indices from this matrix. It may contain duplicates.

  • beta – scaling the input row_collection

  • row_collection – pointer to a LinOp that will store the gathered rows: row_collection(i,j) = input(gather_indices(i), j) It must have the same number of columns as this matrix and gather_indices->get_size() rows.

virtual std::unique_ptr<LinOp> column_permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the column permutation of the Permutable object. In the resulting LinOp, the column i contains the input column perm[i].

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(A P^T\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new column permuted object

virtual std::unique_ptr<LinOp> column_permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the column permutation of the Permutable object. In the resulting LinOp, the column i contains the input column perm[i].

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(A P^T\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new column permuted object

void column_permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the column-permuted matrix into the given output matrix.

See also

Dense::column_permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[1] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

virtual std::unique_ptr<LinOp> inverse_row_permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the inverse permuted object. In the resulting LinOp, the row perm[i] contains the input row i.

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P^{-1} A\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new inverse permuted object

virtual std::unique_ptr<LinOp> inverse_row_permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the inverse permuted object. In the resulting LinOp, the row perm[i] contains the input row i.

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(P^{-1} A\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new inverse permuted object

void inverse_row_permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the inverse row-permuted matrix into the given output matrix.

See also

Dense::inverse_row_permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[0] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

virtual std::unique_ptr<LinOp> inverse_column_permute(
const array<int32> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the inverse permuted object. In the resulting LinOp, the column perm[i] contains the input column i.

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(A P^{-T}\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new inverse permuted object

virtual std::unique_ptr<LinOp> inverse_column_permute(
const array<int64> *permutation_indices,
) const override#

Returns a LinOp representing the row permutation of the inverse permuted object. In the resulting LinOp, the column perm[i] contains the input column i.

From the linear algebra perspective, with \(P_{ij} = \delta_{i \pi(i)}\), this represents the operation \(A P^{-T}\).

Parameters:

permutation_indices – the array of indices containing the permutation order perm.

Returns:

a pointer to the new inverse permuted object

void inverse_column_permute(
const array<int32> *permutation_indices,
ptr_param<Dense> output,
) const#

Writes the inverse column-permuted matrix into the given output matrix.

See also

Dense::inverse_column_permute(const array<int32>*)

Parameters:
  • permutation_indices – The array containing permutation indices. It must have this->get_size()[1] elements.

  • output – The output matrix. It must have the dimensions this->get_size()

virtual std::unique_ptr<Diagonal<ValueType>> extract_diagonal(
) const override#

Extracts the diagonal entries of the matrix into a vector.

Parameters:

diag – the vector into which the diagonal will be written

void extract_diagonal(
ptr_param<Diagonal<ValueType>> output,
) const#

Writes the diagonal of this matrix into an existing diagonal matrix.

Parameters:

output – The output matrix. Its size must match the size of this matrix’s diagonal.

virtual std::unique_ptr<absolute_type> compute_absolute(
) const override#

Gets the AbsoluteLinOp

Returns:

a pointer to the new absolute object

void compute_absolute(ptr_param<absolute_type> output) const#

Writes the absolute values of this matrix into an existing matrix.

Parameters:

output – The output matrix. Its size must match the size of this matrix.

virtual void compute_absolute_inplace() override#

Compute absolute inplace on each element.

std::unique_ptr<complex_type> make_complex() const#

Creates a complex copy of the original matrix. If the original matrix was real, the imaginary part of the result will be zero.

void make_complex(ptr_param<complex_type> result) const#

Writes a complex copy of the original matrix to a given complex matrix. If the original matrix was real, the imaginary part of the result will be zero.

std::unique_ptr<real_type> get_real() const#

Creates a new real matrix and extracts the real part of the original matrix into that.

void get_real(ptr_param<real_type> result) const#

Extracts the real part of the original matrix into a given real matrix.

std::unique_ptr<real_type> get_imag() const#

Creates a new real matrix and extracts the imaginary part of the original matrix into that.

void get_imag(ptr_param<real_type> result) const#

Extracts the imaginary part of the original matrix into a given real matrix.

inline value_type *get_values() noexcept#

Returns a pointer to the array of values of the matrix.

Returns:

the pointer to the array of values

inline const value_type *get_const_values() const noexcept#

Returns a pointer to the array of values of the matrix.

Note

This is the constant version of the function, which can be significantly more memory efficient than the non-constant version, so always prefer this version.

Returns:

the pointer to the array of values

inline size_type get_stride() const noexcept#

Returns the stride of the matrix.

Returns:

the stride of the matrix.

inline size_type get_num_stored_elements() const noexcept#

Returns the number of elements explicitly stored in the matrix.

Returns:

the number of elements explicitly stored in the matrix

inline value_type &at(size_type row, size_type col) noexcept#

Returns a single element of the matrix.

Note

the method has to be called on the same Executor the matrix is stored at (e.g. trying to call this method on a GPU matrix from the OMP results in a runtime error)

Parameters:
  • row – the row of the requested element

  • col – the column of the requested element

inline value_type at(size_type row, size_type col) const noexcept#

Returns a single element of the matrix.

Note

the method has to be called on the same Executor the matrix is stored at (e.g. trying to call this method on a GPU matrix from the OMP results in a runtime error)

Parameters:
  • row – the row of the requested element

  • col – the column of the requested element

inline ValueType &at(size_type idx) noexcept#

Returns a single element of the matrix.

Useful for iterating across all elements of the matrix. However, it is less efficient than the two-parameter variant of this method.

Note

the method has to be called on the same Executor the matrix is stored at (e.g. trying to call this method on a GPU matrix from the OMP results in a runtime error)

Parameters:

idx – a linear index of the requested element (ignoring the stride)

inline ValueType at(size_type idx) const noexcept#

Returns a single element of the matrix.

Useful for iterating across all elements of the matrix. However, it is less efficient than the two-parameter variant of this method.

Note

the method has to be called on the same Executor the matrix is stored at (e.g. trying to call this method on a GPU matrix from the OMP results in a runtime error)

Parameters:

idx – a linear index of the requested element (ignoring the stride)

void scale(ptr_param<const LinOp> alpha)#

Scales the matrix with a scalar (aka: BLAS scal).

Parameters:

alpha – If alpha is 1x1 Dense matrix, the entire matrix is scaled by alpha. If it is a Dense row vector of values, then i-th column of the matrix is scaled with the i-th element of alpha (the number of columns of alpha has to match the number of columns of the matrix).

void inv_scale(ptr_param<const LinOp> alpha)#

Scales the matrix with the inverse of a scalar.

Parameters:

alpha – If alpha is 1x1 Dense matrix, the entire matrix is scaled by 1 / alpha. If it is a Dense row vector of values, then i-th column of the matrix is scaled with the inverse of the i-th element of alpha (the number of columns of alpha has to match the number of columns of the matrix).

void add_scaled(
ptr_param<const LinOp> alpha,
ptr_param<const LinOp> b,
)#

Adds b scaled by alpha to the matrix (aka: BLAS axpy).

Parameters:
  • alpha – If alpha is 1x1 Dense matrix, the entire matrix is scaled by alpha. If it is a Dense row vector of values, then i-th column of the matrix is scaled with the i-th element of alpha (the number of columns of alpha has to match the number of columns of the matrix).

  • b – a matrix of the same dimension as this

void sub_scaled(
ptr_param<const LinOp> alpha,
ptr_param<const LinOp> b,
)#

Subtracts b scaled by alpha from the matrix (aka: BLAS axpy).

Parameters:
  • alpha – If alpha is 1x1 Dense matrix, b is scaled by alpha. If it is a Dense row vector of values, then i-th column of b is scaled with the i-th element of alpha (the number of columns of alpha has to match the number of columns of the matrix).

  • b – a matrix of the same dimension as this

void compute_dot(
ptr_param<const LinOp> b,
ptr_param<LinOp> result,
) const#

Computes the column-wise dot product of this matrix and b.

Parameters:
  • b – a Dense matrix of same dimension as this

  • result – a Dense row vector, used to store the dot product (the number of column in the vector must match the number of columns of this)

void compute_dot(
ptr_param<const LinOp> b,
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the column-wise dot product of this matrix and b.

Parameters:
  • b – a Dense matrix of same dimension as this

  • result – a Dense row vector, used to store the dot product (the number of column in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

void compute_conj_dot(
ptr_param<const LinOp> b,
ptr_param<LinOp> result,
) const#

Computes the column-wise dot product of conj(this matrix) and b.

Parameters:
  • b – a Dense matrix of same dimension as this

  • result – a Dense row vector, used to store the dot product (the number of column in the vector must match the number of columns of this)

void compute_conj_dot(
ptr_param<const LinOp> b,
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the column-wise dot product of conj(this matrix) and b.

Parameters:
  • b – a Dense matrix of same dimension as this

  • result – a Dense row vector, used to store the dot product (the number of column in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

void compute_norm2(ptr_param<LinOp> result) const#

Computes the column-wise Euclidean (L^2) norm of this matrix.

Parameters:

result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

void compute_norm2(
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the column-wise Euclidean (L^2) norm of this matrix.

Parameters:
  • result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

void compute_norm1(ptr_param<LinOp> result) const#

Computes the column-wise (L^1) norm of this matrix.

Parameters:

result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

void compute_norm1(
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the column-wise (L^1) norm of this matrix.

Parameters:
  • result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

void compute_squared_norm2(ptr_param<LinOp> result) const#

Computes the square of the column-wise Euclidean (L^2) norm of this matrix.

Parameters:

result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

void compute_squared_norm2(
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the square of the column-wise Euclidean (L^2) norm of this matrix.

Parameters:
  • result – a Dense row vector, used to store the norm (the number of columns in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

void compute_mean(ptr_param<LinOp> result) const#

Computes the column-wise arithmetic mean of this matrix.

Parameters:

result – a Dense row vector, used to store the mean (the number of columns in the vector must match the number of columns of this)

void compute_mean(
ptr_param<LinOp> result,
array<char> &tmp,
) const#

Computes the column-wise arithmetic mean of this matrix.

Parameters:
  • result – a Dense row vector, used to store the mean (the number of columns in the vector must match the number of columns of this)

  • tmp – the temporary storage to use for partial sums during the reduction computation. It may be resized and/or reset to the correct executor.

inline std::unique_ptr<Dense> create_submatrix(
const span &rows,
const span &columns,
const size_type stride,
)#

Create a submatrix from the original matrix. Warning: defining stride for this create_submatrix method might cause wrong memory access. Better use the create_submatrix(rows, columns) method instead.

Parameters:
  • rows – row span

  • columns – column span

  • stride – stride of the new submatrix.

inline std::unique_ptr<Dense> create_submatrix(
const span &rows,
const span &columns,
)#

Create a submatrix from the original matrix.

Parameters:
  • rows – row span

  • columns – column span

inline std::unique_ptr<Dense> create_submatrix(
const local_span &rows,
const local_span &columns,
dim<2> size,
)#

Create a submatrix from the original matrix.

Parameters:
  • rows – row span

  • columns – column span

  • size – size of the submatrix (only used for consistency with distributed::Vector)

std::unique_ptr<real_type> create_real_view()#

Create a real view of the (potentially) complex original matrix. If the original matrix is real, nothing changes. If the original matrix is complex, the result is created by viewing the complex matrix with as real with a reinterpret_cast with twice the number of columns and double the stride.

std::unique_ptr<const real_type> create_real_view() const#

Create a real view of the (potentially) complex original matrix. If the original matrix is real, nothing changes. If the original matrix is complex, the result is created by viewing the complex matrix with as real with a reinterpret_cast with twice the number of columns and double the stride.

Dense &operator=(const Dense&)#

Copy-assigns a Dense matrix. Preserves the executor, reallocates the matrix with minimal stride if the dimensions don’t match, then copies the data over, ignoring padding.

Dense &operator=(Dense&&)#

Move-assigns a Dense matrix. Preserves the executor, moves the data over preserving size and stride. Leaves the moved-from object in an empty state (0x0 with empty Array).

Dense(const Dense&)#

Copy-constructs a Dense matrix. Inherits executor and dimensions, but copies data without padding.

Dense(Dense&&)#

Move-constructs a Dense matrix. Inherits executor, dimensions and data with padding. The moved-from object is empty (0x0 with empty Array).

Public Static Functions

static inline std::unique_ptr<Dense> create_with_config_of(
ptr_param<const Dense> other,
)#

Creates a Dense matrix with the same size and stride as another Dense matrix.

Parameters:

other – The other matrix whose configuration needs to copied.

static inline std::unique_ptr<Dense> create_with_type_of(
ptr_param<const Dense> other,
std::shared_ptr<const Executor> exec,
const dim<2> &size = dim<2>{},
)#

Creates a Dense matrix with the same type as another Dense matrix but on a different executor and with a different size.

Parameters:
  • other – The other matrix whose type we target.

  • exec – The executor of the new matrix.

  • size – The size of the new matrix.

  • stride – The stride of the new matrix.

Returns:

a Dense matrix with the type of other.

static inline std::unique_ptr<Dense> create_with_type_of(
ptr_param<const Dense> other,
std::shared_ptr<const Executor> exec,
const dim<2> &size,
size_type stride,
)#

Note

This is an overload which allows full parameter specification.

Parameters:

stride – The stride of the new matrix.

static inline std::unique_ptr<Dense> create_with_type_of(
ptr_param<const Dense> other,
std::shared_ptr<const Executor> exec,
const dim<2> &size,
const dim<2> &local_size,
size_type stride,
)#

Note

This is an overload to stay consistent with gko::experimental::distributed::Vector

Parameters:
  • local_size – Unused

  • stride – The stride of the new matrix.

static inline std::unique_ptr<Dense> create_view_of(
ptr_param<Dense> other,
)#

Creates a Dense matrix, where the underlying array is a view of another Dense matrix’ array.

Parameters:

other – The other matrix on which to create the view

Returns:

A Dense matrix that is a view of other

static inline std::unique_ptr<const Dense> create_const_view_of(
ptr_param<const Dense> other,
)#

Creates a immutable Dense matrix, where the underlying array is a view of another Dense matrix’ array.

Parameters:

other – The other matrix on which to create the view

Returns:

A immutable Dense matrix that is a view of other

static std::unique_ptr<Dense> create(
std::shared_ptr<const Executor> exec,
const dim<2> &size = {},
size_type stride = 0,
)#

Creates an uninitialized Dense matrix of the specified size.

Parameters:
  • execExecutor associated to the matrix

  • size – size of the matrix

  • stride – stride of the rows (i.e. offset between the first elements of two consecutive rows, expressed as the number of matrix elements). If it is set to 0, size[1] will be used instead.

Returns:

A smart pointer to the newly created matrix.

static std::unique_ptr<Dense> create(
std::shared_ptr<const Executor> exec,
const dim<2> &size,
array<value_type> values,
size_type stride,
)#

Creates a Dense matrix from an already allocated (and initialized) array.

Note

If values is not an rvalue, not an array of ValueType, or is on the wrong executor, an internal copy will be created, and the original array data will not be used in the matrix.

Parameters:
  • execExecutor associated to the matrix

  • size – size of the matrix

  • values – array of matrix values

  • stride – stride of the rows (i.e. offset between the first elements of two consecutive rows, expressed as the number of matrix elements)

Returns:

A smart pointer to the newly created matrix.

template<typename InputValueType>
static inline std::unique_ptr<Dense> create(
std::shared_ptr<const Executor> exec,
const dim<2> &size,
std::initializer_list<InputValueType> values,
size_type stride,
)#

create(std::shared_ptr<const Executor>,const dim<2>&, array<value_type>, size_type)

create(std::shared_ptr<const Executor>,const dim<2>&, array<value_type>, size_type)

static std::unique_ptr<const Dense> create_const(
std::shared_ptr<const Executor> exec,
const dim<2> &size,
gko::detail::const_array_view<ValueType> &&values,
size_type stride,
)#

Creates a constant (immutable) Dense matrix from a constant array.

Parameters:
  • exec – the executor to create the matrix on

  • size – the dimensions of the matrix

  • values – the value array of the matrix

  • stride – the row-stride of the matrix

Returns:

A smart pointer to the constant matrix wrapping the input array (if it resides on the same executor as the matrix) or a copy of the array on the correct executor.