103#ifndef __ADS_DenseMatrix
104 #define __ADS_DenseMatrix
119#include <type_traits>
128#if defined( ADS_WITH_BLAS ) && ! defined( ADS_GEMM_BLAS )
129 #define ADS_GEMM_BLAS 1
132 #define ADS_GEMM_BLAS 0
136 #if defined( ADS_BLAS_ACCELERATE )
137 #include <vecLib/cblas.h>
156struct DefaultInitAllocator : std::allocator< U >
158 using value_type = U;
162 using other = DefaultInitAllocator< V >;
164 DefaultInitAllocator(
void ) =
default;
166 DefaultInitAllocator(
const DefaultInitAllocator< V > & )
noexcept { }
168 void construct( V * p )
noexcept(
169 std::is_nothrow_default_constructible_v< V > ) {
170 ::new(
static_cast< void *
>( p ) ) V;
172 template<
class V ,
class... Args >
173 void construct( V * p , Args &&... args ) {
174 ::new(
static_cast< void *
>( p ) ) V( std::forward< Args >( args )... );
195 DenseMatrix( std::size_t m , std::size_t n ,
const T & v = T( 0 ) )
196 : f_m( m ) , f_n( n ) , f_A( m * n ) {
197 std::fill( f_A.begin() , f_A.end() , v );
206 M.f_A.resize( m * n );
215 [[nodiscard]] std::size_t
rows(
void )
const {
return( f_m ); }
217 [[nodiscard]] std::size_t
cols(
void )
const {
return( f_n ); }
221 [[nodiscard]] T &
operator()( std::size_t i , std::size_t j ) {
222 ADS_PRE( ( i < f_m ) && ( j < f_n ) );
223 return( f_A[ i * f_n + j ] );
227 [[nodiscard]]
const T &
operator()( std::size_t i , std::size_t j )
const {
228 ADS_PRE( ( i < f_m ) && ( j < f_n ) );
229 return( f_A[ i * f_n + j ] );
233 [[nodiscard]] T *
data(
void ) {
return( f_A.data() ); }
235 [[nodiscard]]
const T *
data(
void )
const {
return( f_A.data() ); }
244 std::size_t f_m = 0 ,
246 std::vector< T , detail::DefaultInitAllocator< T > > f_A;
287void gemm( std::size_t m , std::size_t n , std::size_t k , T alpha ,
289 std::size_t lda ,
const T * B , std::size_t ldb , T beta , T * C ,
344 std::size_t cutoff = 3072 );
354#include "ADS/numeric/impl/DenseMatrix.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The product of two square matrices (section 12.4):
an matrix by rows in one contiguous vector
Definition DenseMatrix.h:187
const T * data(void) const
the entries of a constant matrix, by rows
Definition DenseMatrix.h:235
Matrix< T > toMatrix(void) const
the Matrix of the book with the same entries
bool operator==(const DenseMatrix &) const =default
true if the two matrices have the same sizes and entries
DenseMatrix(void)=default
the empty matrix
T value_type
the type of the entries
Definition DenseMatrix.h:189
static DenseMatrix uninitialized(std::size_t m, std::size_t n)
the matrix whose entries are not set, which a function then writes, if T is a number (they are T() o...
Definition DenseMatrix.h:202
DenseMatrix(const Matrix< T > &A)
the matrix of the rows of the Matrix of the book
const T & operator()(std::size_t i, std::size_t j) const
the entry of a constant matrix
Definition DenseMatrix.h:227
DenseMatrix(std::size_t m, std::size_t n, const T &v=T(0))
the matrix of entries
Definition DenseMatrix.h:195
std::size_t rows(void) const
the number of rows
Definition DenseMatrix.h:215
T * data(void)
the entries, by rows
Definition DenseMatrix.h:233
T & operator()(std::size_t i, std::size_t j)
the entry , at the place
Definition DenseMatrix.h:221
std::size_t cols(void) const
the number of columns
Definition DenseMatrix.h:217
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
ListGraph transpose(const G &g)
the transposed graph, with the edges reversed
DenseMatrix< T > multiplyStrassen(const DenseMatrix< T > &A, const DenseMatrix< T > &B, std::size_t cutoff=3072)
the product by the variant of Winograd of the algorithm of Strassen, 7 products of halves and 15 sum...
DenseMatrix< T > multiply(const DenseMatrix< T > &A, const DenseMatrix< T > &B)
the product , a new matrix, by gemm() with and
constexpr std::size_t kGemmBlock
the columns and the rows of of a block of the product of the definition, without the CBLAS: a round ...
Definition DenseMatrix.h:255
void gemm(std::size_t m, std::size_t n, std::size_t k, T alpha, const T *A, std::size_t lda, const T *B, std::size_t ldb, T beta, T *C, std::size_t ldc)
the product , , and by rows, with the leading dimensions lda, ldb, ldc (the distance of two rows...
std::vector< std::vector< T > > Matrix
by rows
Definition Matrix.h:74