Blaze 3.9
SparseMatrix.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SPARSEMATRIX_H_
36#define _BLAZE_MATH_EXPRESSIONS_SPARSEMATRIX_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
47#include <blaze/util/EnableIf.h>
49
50
51namespace blaze {
52
53//=================================================================================================
54//
55// CLASS DEFINITION
56//
57//=================================================================================================
58
59//*************************************************************************************************
73template< typename MT // Type of the sparse matrix
74 , bool SO > // Storage order
76 : public Matrix<MT,SO>
77{
78 protected:
79 //**Special member functions********************************************************************
82 SparseMatrix() = default;
83 SparseMatrix( const SparseMatrix& ) = default;
84 SparseMatrix( SparseMatrix&& ) = default;
85 ~SparseMatrix() = default;
86 SparseMatrix& operator=( const SparseMatrix& ) = default;
87 SparseMatrix& operator=( SparseMatrix&& ) = default;
89 //**********************************************************************************************
90};
91//*************************************************************************************************
92
93
94
95
96//=================================================================================================
97//
98// GLOBAL FUNCTIONS
99//
100//=================================================================================================
101
102//*************************************************************************************************
105template< typename MT, bool SO >
106typename MT::Iterator find( SparseMatrix<MT,SO>& sm, size_t i, size_t j );
107
108template< typename MT, bool SO >
109typename MT::ConstIterator find( const SparseMatrix<MT,SO>& sm, size_t i, size_t j );
110
111template< typename MT, bool SO >
112typename MT::Iterator lowerBound( SparseMatrix<MT,SO>& sm, size_t i, size_t j );
113
114template< typename MT, bool SO >
115typename MT::ConstIterator lowerBound( const SparseMatrix<MT,SO>& sm, size_t i, size_t j );
116
117template< typename MT, bool SO >
118typename MT::Iterator upperBound( SparseMatrix<MT,SO>& sm, size_t i, size_t j );
119
120template< typename MT, bool SO >
121typename MT::ConstIterator upperBound( const SparseMatrix<MT,SO>& sm, size_t i, size_t j );
123//*************************************************************************************************
124
125
126//*************************************************************************************************
143template< typename MT, bool SO >
144typename MT::Iterator find( SparseMatrix<MT,SO>& sm, size_t i, size_t j )
145{
146 return (*sm).find( i, j );
147}
148//*************************************************************************************************
149
150
151//*************************************************************************************************
168template< typename MT, bool SO >
169typename MT::ConstIterator find( const SparseMatrix<MT,SO>& sm, size_t i, size_t j )
170{
171 return (*sm).find( i, j );
172}
173//*************************************************************************************************
174
175
176//*************************************************************************************************
193template< typename MT, bool SO >
194typename MT::Iterator lowerBound( SparseMatrix<MT,SO>& sm, size_t i, size_t j )
195{
196 return (*sm).lowerBound( i, j );
197}
198//*************************************************************************************************
199
200
201//*************************************************************************************************
218template< typename MT, bool SO >
219typename MT::ConstIterator lowerBound( const SparseMatrix<MT,SO>& sm, size_t i, size_t j )
220{
221 return (*sm).lowerBound( i, j );
222}
223//*************************************************************************************************
224
225
226//*************************************************************************************************
243template< typename MT, bool SO >
244typename MT::Iterator upperBound( SparseMatrix<MT,SO>& sm, size_t i, size_t j )
245{
246 return (*sm).upperBound( i, j );
247}
248//*************************************************************************************************
249
250
251//*************************************************************************************************
268template< typename MT, bool SO >
269typename MT::ConstIterator upperBound( const SparseMatrix<MT,SO>& sm, size_t i, size_t j )
270{
271 return (*sm).upperBound( i, j );
272}
273//*************************************************************************************************
274
275
276//*************************************************************************************************
287template< typename MT > // Type of the matrix
288inline auto resetLower_backend( SparseMatrix<MT,false>& dm ) -> DisableIf_t< IsUpper_v<MT> >
289{
290 const size_t m( (*dm).rows() );
291
292 for( size_t i=1UL; i<m; ++i ) {
293 (*dm).erase( i, (*dm).begin( i ), (*dm).lowerBound( i, i ) );
294 }
295}
297//*************************************************************************************************
298
299
300//*************************************************************************************************
311template< typename MT > // Type of the matrix
312inline auto resetLower_backend( SparseMatrix<MT,true>& dm ) -> DisableIf_t< IsUpper_v<MT> >
313{
314 const size_t m ( (*dm).rows() );
315 const size_t n ( (*dm).columns() );
316 const size_t jend( min( m, n ) );
317
318 for( size_t j=0UL; j<jend; ++j ) {
319 (*dm).erase( j, (*dm).lowerBound( j+1UL, j ), (*dm).end( j ) );
320 }
321}
323//*************************************************************************************************
324
325
326//*************************************************************************************************
336template< typename MT // Type of the matrix
337 , bool SO > // Storage order of the matrix
338inline auto resetLower_backend( SparseMatrix<MT,SO>& dm ) -> EnableIf_t< IsUpper_v<MT> >
339{
340 MAYBE_UNUSED( dm );
341}
343//*************************************************************************************************
344
345
346//*************************************************************************************************
356template< typename MT // Type of the matrix
357 , bool SO > // Storage order of the matrix
358inline void resetLower( SparseMatrix<MT,SO>& dm )
359{
360 resetLower_backend( *dm );
361}
363//*************************************************************************************************
364
365
366//*************************************************************************************************
377template< typename MT > // Type of the matrix
378inline auto resetUpper_backend( SparseMatrix<MT,false>& dm ) -> DisableIf_t< IsLower_v<MT> >
379{
380 const size_t m ( (*dm).rows() );
381 const size_t n ( (*dm).columns() );
382 const size_t iend( min( m, n ) );
383
384 for( size_t i=0UL; i<iend; ++i ) {
385 (*dm).erase( i, (*dm).lowerBound( i, i+1UL ), (*dm).end( i ) );
386 }
387}
389//*************************************************************************************************
390
391
392//*************************************************************************************************
403template< typename MT > // Type of the matrix
404inline auto resetUpper_backend( SparseMatrix<MT,true>& dm ) -> DisableIf_t< IsLower_v<MT> >
405{
406 const size_t n( (*dm).columns() );
407
408 for( size_t j=1UL; j<n; ++j ) {
409 (*dm).erase( j, (*dm).begin( j ), (*dm).lowerBound( j, j ) );
410 }
411}
413//*************************************************************************************************
414
415
416//*************************************************************************************************
426template< typename MT // Type of the matrix
427 , bool SO > // Storage order of the matrix
428inline auto resetUpper_backend( SparseMatrix<MT,SO>& dm ) -> EnableIf_t< IsLower_v<MT> >
429{
430 MAYBE_UNUSED( dm );
431}
433//*************************************************************************************************
434
435
436//*************************************************************************************************
446template< typename MT // Type of the matrix
447 , bool SO > // Storage order of the matrix
448inline void resetUpper( SparseMatrix<MT,SO>& dm )
449{
450 resetUpper_backend( *dm );
451}
453//*************************************************************************************************
454
455} // namespace blaze
456
457#endif
Header file for the EnableIf class template.
Header file for the IsLower type trait.
Header file for the IsUpper type trait.
Header file for the MAYBE_UNUSED function template.
Base class for matrices.
Definition: Matrix.h:85
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Header file for the Matrix base class.
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
MT::ConstIterator find(const SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:169
MT::ConstIterator upperBound(const SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: SparseMatrix.h:269
MT::ConstIterator lowerBound(const SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: SparseMatrix.h:219
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for the generic min algorithm.