35#ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SPARSENONSCALAR_H_
36#define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SPARSENONSCALAR_H_
107class SymmetricMatrix<MT,SO,false,false>
108 :
public SparseMatrix< SymmetricMatrix<MT,SO,false,false>, SO >
112 using OT = OppositeType_t<MT>;
113 using TT = TransposeType_t<MT>;
114 using ET = ElementType_t<MT>;
117 using MatrixType =
typename MT::template Rebind< SharedValue<ET> >::Other;
122 using This = SymmetricMatrix<MT,SO,false,false>;
123 using BaseType = SparseMatrix<This,SO>;
124 using ResultType = This;
125 using OppositeType = SymmetricMatrix<OT,!SO,false,false>;
126 using TransposeType = SymmetricMatrix<TT,!SO,false,false>;
127 using ElementType = ET;
128 using TagType = TagType_t<MT>;
129 using ReturnType = ReturnType_t<MT>;
130 using CompositeType =
const This&;
131 using Reference = NonScalarProxy<MatrixType>;
132 using ConstReference = ConstReference_t<MT>;
138 template<
typename NewType >
141 using Other = SymmetricMatrix< typename MT::template Rebind<NewType>::Other >;
148 template<
size_t NewM
152 using Other = SymmetricMatrix< typename MT::template Resize<NewM,NewN>::Other >;
159 template<
typename IteratorType >
161 :
private SparseElement
165 using ValueType = ET;
167 using Reference = ValueType&;
168 using ConstReference =
const ValueType&;
169 using Pointer = SharedElement*;
170 using ConstPointer =
const SharedElement*;
178 inline SharedElement( IteratorType pos )
189 template<
typename T >
inline SharedElement& operator=(
const T& v ) {
201 template<
typename T >
inline SharedElement&
operator+=(
const T& v ) {
213 template<
typename T >
inline SharedElement&
operator-=(
const T& v ) {
225 template<
typename T >
inline SharedElement&
operator*=(
const T& v ) {
237 template<
typename T >
inline SharedElement&
operator/=(
const T& v ) {
248 inline Pointer operator->() {
258 inline ConstPointer operator->()
const {
268 inline Reference value() {
269 return *pos_->value();
278 inline ConstReference value()
const {
279 return *pos_->value();
288 inline IndexType index()
const {
289 return pos_->index();
303 template<
typename SparseElementType
304 ,
typename IteratorType >
309 using IteratorCategory = std::forward_iterator_tag;
310 using ValueType = SparseElementType;
311 using PointerType = SparseElementType;
312 using ReferenceType = SparseElementType;
316 using iterator_category = IteratorCategory;
317 using value_type = ValueType;
318 using pointer = PointerType;
319 using reference = ReferenceType;
320 using difference_type = DifferenceType;
326 inline SharedIterator()
336 inline SharedIterator( IteratorType pos )
346 template<
typename SparseElementType2,
typename IteratorType2 >
347 inline SharedIterator(
const SharedIterator<SparseElementType2,IteratorType2>& it )
357 inline SharedIterator& operator++() {
368 inline const SharedIterator operator++(
int ) {
369 const SharedIterator tmp( *
this );
381 return ReferenceType( pos_ );
390 inline PointerType operator->()
const {
391 return PointerType( pos_ );
401 inline bool operator==(
const SharedIterator& rhs )
const {
402 return pos_ == rhs.pos_;
412 inline bool operator!=(
const SharedIterator& rhs )
const {
413 return !( *
this == rhs );
423 inline DifferenceType
operator-(
const SharedIterator& rhs )
const {
424 return pos_ - rhs.pos_;
433 inline IteratorType base()
const {
444 template<
typename SparseElementType2,
typename IteratorType2 >
friend class SharedIterator;
451 using Iterator = SharedIterator< SharedElement< Iterator_t<MatrixType> >
452 , Iterator_t<MatrixType> >;
455 using ConstIterator = SharedIterator< const SharedElement< ConstIterator_t<MatrixType> >
456 , ConstIterator_t<MatrixType> >;
461 static constexpr bool smpAssignable =
false;
467 inline SymmetricMatrix();
468 explicit inline SymmetricMatrix(
size_t n );
469 inline SymmetricMatrix(
size_t n,
size_t nonzeros );
470 inline SymmetricMatrix(
size_t n,
const std::vector<size_t>& nonzeros );
472 inline SymmetricMatrix(
const SymmetricMatrix& m );
473 inline SymmetricMatrix( SymmetricMatrix&& m )
noexcept;
475 template<
typename MT2 >
inline SymmetricMatrix(
const Matrix<MT2,SO>& m );
476 template<
typename MT2 >
inline SymmetricMatrix(
const Matrix<MT2,!SO>& m );
483 ~SymmetricMatrix() =
default;
490 inline Reference operator()(
size_t i,
size_t j );
491 inline ConstReference operator()(
size_t i,
size_t j )
const;
492 inline Reference at(
size_t i,
size_t j );
493 inline ConstReference at(
size_t i,
size_t j )
const;
494 inline Iterator
begin (
size_t i );
495 inline ConstIterator
begin (
size_t i )
const;
496 inline ConstIterator
cbegin(
size_t i )
const;
497 inline Iterator
end (
size_t i );
498 inline ConstIterator
end (
size_t i )
const;
499 inline ConstIterator
cend (
size_t i )
const;
506 inline SymmetricMatrix& operator=(
const SymmetricMatrix& rhs );
507 inline SymmetricMatrix& operator=( SymmetricMatrix&& rhs )
noexcept;
509 template<
typename MT2 >
510 inline auto operator=(
const Matrix<MT2,SO>& rhs )
511 -> DisableIf_t< IsComputation_v<MT2>, SymmetricMatrix& >;
513 template<
typename MT2 >
514 inline auto operator=(
const Matrix<MT2,SO>& rhs )
515 -> EnableIf_t< IsComputation_v<MT2>, SymmetricMatrix& >;
517 template<
typename MT2 >
518 inline auto operator=(
const Matrix<MT2,!SO>& rhs ) -> SymmetricMatrix&;
520 template<
typename MT2 >
521 inline auto operator+=(
const Matrix<MT2,SO>& rhs ) -> SymmetricMatrix&;
523 template<
typename MT2 >
524 inline auto operator+=(
const Matrix<MT2,!SO>& rhs ) -> SymmetricMatrix&;
526 template<
typename MT2 >
527 inline auto operator-=(
const Matrix<MT2,SO>& rhs ) -> SymmetricMatrix&;
529 template<
typename MT2 >
530 inline auto operator-=(
const Matrix<MT2,!SO>& rhs ) -> SymmetricMatrix&;
532 template<
typename MT2 >
533 inline auto operator%=(
const Matrix<MT2,SO>& rhs ) -> SymmetricMatrix&;
535 template<
typename MT2 >
536 inline auto operator%=(
const Matrix<MT2,!SO>& rhs ) -> SymmetricMatrix&;
538 template<
typename ST >
539 inline auto operator*=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, SymmetricMatrix& >;
541 template<
typename ST >
542 inline auto operator/=( ST rhs ) -> EnableIf_t< IsScalar_v<ST>, SymmetricMatrix& >;
549 inline size_t rows() const noexcept;
550 inline
size_t columns() const noexcept;
551 inline
size_t capacity() const noexcept;
552 inline
size_t capacity(
size_t i ) const noexcept;
554 inline
size_t nonZeros(
size_t i ) const;
556 inline
void reset(
size_t i );
558 inline
void resize (
size_t n,
bool preserve=true );
559 inline
void reserve(
size_t nonzeros );
560 inline
void reserve(
size_t i,
size_t nonzeros );
562 inline
void trim(
size_t i );
564 inline
void swap( SymmetricMatrix& m ) noexcept;
571 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
572 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
573 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
574 inline
void finalize(
size_t i );
581 inline
void erase(
size_t i,
size_t j );
582 inline Iterator erase(
size_t i, Iterator pos );
583 inline Iterator erase(
size_t i, Iterator first, Iterator last );
585 template< typename Pred >
586 inline
void erase( Pred predicate );
588 template< typename Pred >
589 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
596 inline Iterator
find (
size_t i,
size_t j );
597 inline ConstIterator
find (
size_t i,
size_t j ) const;
598 inline Iterator
lowerBound(
size_t i,
size_t j );
599 inline ConstIterator
lowerBound(
size_t i,
size_t j ) const;
600 inline Iterator
upperBound(
size_t i,
size_t j );
601 inline ConstIterator
upperBound(
size_t i,
size_t j ) const;
611 template< typename Other > inline SymmetricMatrix& scale( const Other& scalar );
618 inline
bool isIntact() const noexcept;
625 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
626 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
628 inline
bool canSMPAssign() const noexcept;
636 template< typename MT2 >
void assign( DenseMatrix<MT2,SO>& rhs );
637 template< typename MT2 >
void assign( const DenseMatrix<MT2,SO>& rhs );
638 template< typename MT2 >
void assign( SparseMatrix<MT2,SO>& rhs );
639 template< typename MT2 >
void assign( const SparseMatrix<MT2,SO>& rhs );
687inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix()
706inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
size_t n )
728inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
size_t n,
size_t nonzeros )
729 : matrix_( n, n, nonzeros )
752inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
size_t n,
const std::vector<size_t>& nonzeros )
753 : matrix_( n, n, nonzeros )
771inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
const SymmetricMatrix& m )
776 resize( matrix_, m.rows(), m.columns() );
794inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix( SymmetricMatrix&& m ) noexcept
795 : matrix_( std::move( m.matrix_ ) )
816template<
typename MT2 >
817inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
const Matrix<MT2,SO>& m )
822 using RT = RemoveAdaptor_t< ResultType_t<MT2> >;
823 using Tmp = If_t< IsComputation_v<MT2>, RT,
const MT2& >;
831 resize( matrix_, tmp.rows(), tmp.columns() );
853template<
typename MT2 >
854inline SymmetricMatrix<MT,SO,false,false>::SymmetricMatrix(
const Matrix<MT2,!SO>& m )
859 using RT = RemoveAdaptor_t< ResultType_t<MT2> >;
860 using Tmp = If_t< IsComputation_v<MT2>, RT,
const MT2& >;
868 resize( matrix_, tmp.rows(), tmp.columns() );
869 assign(
trans( tmp ) );
903inline typename SymmetricMatrix<MT,SO,false,false>::Reference
904 SymmetricMatrix<MT,SO,false,false>::operator()(
size_t i,
size_t j )
909 return Reference( matrix_, i, j );
932inline typename SymmetricMatrix<MT,SO,false,false>::ConstReference
933 SymmetricMatrix<MT,SO,false,false>::operator()(
size_t i,
size_t j )
const
938 return *matrix_(i,j);
962inline typename SymmetricMatrix<MT,SO,false,false>::Reference
963 SymmetricMatrix<MT,SO,false,false>::at(
size_t i,
size_t j )
995inline typename SymmetricMatrix<MT,SO,false,false>::ConstReference
996 SymmetricMatrix<MT,SO,false,false>::at(
size_t i,
size_t j )
const
1004 return (*
this)(i,j);
1022template<
typename MT
1024inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
1027 return Iterator( matrix_.begin(i) );
1045template<
typename MT
1047inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
1050 return ConstIterator( matrix_.begin(i) );
1068template<
typename MT
1070inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
1073 return ConstIterator( matrix_.cbegin(i) );
1091template<
typename MT
1093inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
1096 return Iterator( matrix_.end(i) );
1114template<
typename MT
1116inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
1119 return ConstIterator( matrix_.end(i) );
1137template<
typename MT
1139inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
1142 return ConstIterator( matrix_.cend(i) );
1166template<
typename MT
1168inline SymmetricMatrix<MT,SO,false,false>&
1169 SymmetricMatrix<MT,SO,false,false>::operator=(
const SymmetricMatrix& rhs )
1173 if( &rhs ==
this )
return *
this;
1175 resize( matrix_, rhs.rows(), rhs.columns() );
1195template<
typename MT
1197inline SymmetricMatrix<MT,SO,false,false>&
1198 SymmetricMatrix<MT,SO,false,false>::operator=( SymmetricMatrix&& rhs )
noexcept
1200 matrix_ = std::move( rhs.matrix_ );
1225template<
typename MT
1227template<
typename MT2 >
1228inline auto SymmetricMatrix<MT,SO,false,false>::operator=(
const Matrix<MT2,SO>& rhs )
1229 -> DisableIf_t< IsComputation_v<MT2>, SymmetricMatrix& >
1233 if( !IsSymmetric_v<MT2> && !
isSymmetric( *rhs ) ) {
1237 if( (*rhs).canAlias(
this ) ) {
1238 SymmetricMatrix tmp( *rhs );
1242 resize( matrix_, (*rhs).rows(), (*rhs).columns() );
1270template<
typename MT
1272template<
typename MT2 >
1273inline auto SymmetricMatrix<MT,SO,false,false>::operator=(
const Matrix<MT2,SO>& rhs )
1274 -> EnableIf_t< IsComputation_v<MT2>, SymmetricMatrix& >
1278 if( !IsSquare_v<MT2> && !
isSquare( *rhs ) ) {
1282 const ResultType_t<MT2> tmp( *rhs );
1284 if( !IsSymmetric_v<MT2> && !
isSymmetric( tmp ) ) {
1288 resize( matrix_, tmp.rows(), tmp.columns() );
1315template<
typename MT
1317template<
typename MT2 >
1318inline auto SymmetricMatrix<MT,SO,false,false>::operator=(
const Matrix<MT2,!SO>& rhs )
1321 return this->operator=(
trans( *rhs ) );
1340template<
typename MT
1342template<
typename MT2 >
1348 using Tmp = AddTrait_t< MT, ResultType_t<MT2> >;
1350 if( !IsSquare_v<MT2> && !
isSquare( *rhs ) ) {
1354 Tmp tmp( (*
this) + *rhs );
1356 if( !IsSymmetric_v<Tmp> && !
isSymmetric( tmp ) ) {
1360 resize( matrix_, tmp.rows(), tmp.columns() );
1387template<
typename MT
1389template<
typename MT2 >
1412template<
typename MT
1414template<
typename MT2 >
1420 using Tmp = SubTrait_t< MT, ResultType_t<MT2> >;
1422 if( !IsSquare_v<MT2> && !
isSquare( *rhs ) ) {
1426 Tmp tmp( (*
this) - *rhs );
1428 if( !IsSymmetric_v<Tmp> && !
isSymmetric( tmp ) ) {
1432 resize( matrix_, tmp.rows(), tmp.columns() );
1459template<
typename MT
1461template<
typename MT2 >
1484template<
typename MT
1486template<
typename MT2 >
1487inline auto SymmetricMatrix<MT,SO,false,false>::operator%=(
const Matrix<MT2,SO>& rhs )
1492 using Tmp = SchurTrait_t< MT, ResultType_t<MT2> >;
1494 if( !IsSquare_v<MT2> && !
isSquare( *rhs ) ) {
1498 Tmp tmp( (*
this) % *rhs );
1500 if( !IsSymmetric_v<Tmp> && !
isSymmetric( tmp ) ) {
1504 resize( matrix_, tmp.rows(), tmp.columns() );
1531template<
typename MT
1533template<
typename MT2 >
1534inline auto SymmetricMatrix<MT,SO,false,false>::operator%=(
const Matrix<MT2,!SO>& rhs )
1537 return this->operator%=(
trans( *rhs ) );
1551template<
typename MT
1553template<
typename ST >
1555 -> EnableIf_t< IsScalar_v<ST>, SymmetricMatrix& >
1557 for(
size_t i=0UL; i<
rows(); ++i ) {
1558 const auto last( matrix_.upperBound(i,i) );
1559 for(
auto element=matrix_.begin(i); element!=last; ++element )
1560 *element->value() *= rhs;
1577template<
typename MT
1579template<
typename ST >
1581 -> EnableIf_t< IsScalar_v<ST>, SymmetricMatrix& >
1585 for(
size_t i=0UL; i<
rows(); ++i ) {
1586 const auto last( matrix_.upperBound(i,i) );
1587 for(
auto element=matrix_.begin(i); element!=last; ++element )
1588 *element->value() /= rhs;
1611template<
typename MT
1615 return matrix_.rows();
1627template<
typename MT
1631 return matrix_.columns();
1643template<
typename MT
1647 return matrix_.capacity();
1664template<
typename MT
1668 return matrix_.capacity(i);
1680template<
typename MT
1684 return matrix_.nonZeros();
1702template<
typename MT
1706 return matrix_.nonZeros(i);
1718template<
typename MT
1768template<
typename MT
1774 for(
auto it=matrix_.begin(i); it!=matrix_.end(i); ++it )
1776 const size_t j( it->index() );
1782 const Iterator_t<MatrixType> pos( matrix_.find( i, j ) );
1784 erase( matrix_, j, pos );
1787 const Iterator_t<MatrixType> pos( matrix_.find( j, i ) );
1789 erase( matrix_, j, pos );
1807template<
typename MT
1835template<
typename MT
1845 matrix_.resize( n, n,
true );
1862template<
typename MT
1864inline void SymmetricMatrix<MT,SO,false,false>::reserve(
size_t nonzeros )
1866 matrix_.reserve( nonzeros );
1886template<
typename MT
1888inline void SymmetricMatrix<MT,SO,false,false>::reserve(
size_t i,
size_t nonzeros )
1890 matrix_.reserve( i, nonzeros );
1907template<
typename MT
1909inline void SymmetricMatrix<MT,SO,false,false>::trim()
1929template<
typename MT
1931inline void SymmetricMatrix<MT,SO,false,false>::trim(
size_t i )
1949template<
typename MT
1953 matrix_.shrinkToFit();
1966template<
typename MT
1972 swap( matrix_, m.matrix_ );
2000template<
typename MT
2002inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2005 SharedValue<ET> shared( value );
2008 matrix_.set( j, i, shared );
2010 return Iterator( matrix_.set( i, j, shared ) );
2031template<
typename MT
2033inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2034 SymmetricMatrix<MT,SO,false,false>::insert(
size_t i,
size_t j,
const ElementType& value )
2036 SharedValue<ET> shared( value );
2039 matrix_.insert( j, i, shared );
2041 return Iterator( matrix_.insert( i, j, shared ) );
2102template<
typename MT
2104inline void SymmetricMatrix<MT,SO,false,false>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
2106 SharedValue<ET> shared( value );
2108 matrix_.append( i, j, shared, check );
2109 if( i != j && ( !check || !isDefault<strict>( value ) ) )
2110 matrix_.insert( j, i, shared );
2130template<
typename MT
2132inline void SymmetricMatrix<MT,SO,false,false>::finalize(
size_t i )
2158template<
typename MT
2160inline void SymmetricMatrix<MT,SO,false,false>::erase(
size_t i,
size_t j )
2164 erase( matrix_, i, j );
2166 erase( matrix_, j, i );
2184template<
typename MT
2186inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2187 SymmetricMatrix<MT,SO,false,false>::erase(
size_t i, Iterator pos )
2191 if( pos ==
end( i ) )
2194 const size_t j( pos->index() );
2197 return Iterator( erase( matrix_, i, pos.base() ) );
2201 erase( matrix_, j, matrix_.find( i, j ) );
2202 return Iterator( erase( matrix_, i, pos.base() ) );
2206 erase( matrix_, j, matrix_.find( j, i ) );
2207 return Iterator( erase( matrix_, i, pos.base() ) );
2228template<
typename MT
2230inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2231 SymmetricMatrix<MT,SO,false,false>::erase(
size_t i, Iterator first, Iterator last )
2235 for(
auto it=first; it!=last; ++it )
2237 const size_t j( it->index() );
2244 erase( matrix_, i, j );
2248 erase( matrix_, j, i );
2252 return Iterator( erase( matrix_, i, first.base(), last.base() ) );
2272template<
typename MT
2274template<
typename Pred >
2275inline void SymmetricMatrix<MT,SO,false,false>::erase( Pred predicate )
2279 erase( matrix_, [predicate=predicate](
const SharedValue<ET>& value ) {
2280 return predicate( *value );
2308template<
typename MT
2310template<
typename Pred >
2312 SymmetricMatrix<MT,SO,false,false>::erase(
size_t i, Iterator first, Iterator last, Pred predicate )
2316 for(
auto it=first; it!=last; ++it ) {
2317 const size_t j( it->index() );
2318 if( i != j && predicate( it->value() ) ) {
2320 erase( matrix_, i, j );
2322 erase( matrix_, j, i );
2326 erase( matrix_, i, first.base(), last.base(),
2327 [predicate=predicate](
const SharedValue<ET>& value ) {
2328 return predicate( *value );
2361template<
typename MT
2363inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2366 return Iterator( matrix_.find( i, j ) );
2388template<
typename MT
2390inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
2393 return ConstIterator( matrix_.find( i, j ) );
2415template<
typename MT
2417inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2420 return Iterator( matrix_.lowerBound( i, j ) );
2442template<
typename MT
2444inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
2447 return ConstIterator( matrix_.lowerBound( i, j ) );
2469template<
typename MT
2471inline typename SymmetricMatrix<MT,SO,false,false>::Iterator
2474 return Iterator( matrix_.upperBound( i, j ) );
2496template<
typename MT
2498inline typename SymmetricMatrix<MT,SO,false,false>::ConstIterator
2501 return ConstIterator( matrix_.upperBound( i, j ) );
2521template<
typename MT
2537template<
typename MT
2541 for(
size_t i=0UL; i<
rows(); ++i ) {
2542 const auto last( matrix_.upperBound(i,i) );
2543 for(
auto element=matrix_.begin(i); element!=last; ++element )
2571template<
typename MT
2573template<
typename Other >
2574inline SymmetricMatrix<MT,SO,false,false>&
2575 SymmetricMatrix<MT,SO,false,false>::scale(
const Other& scalar )
2577 for(
size_t i=0UL; i<
rows(); ++i ) {
2578 const auto last( matrix_.upperBound(i,i) );
2579 for(
auto element=matrix_.begin(i); element!=last; ++element )
2580 ( *element->value() ).scale( scalar );
2607template<
typename MT
2638template<
typename MT
2640template<
typename Other >
2641inline bool SymmetricMatrix<MT,SO,false,false>::canAlias(
const Other* alias )
const noexcept
2643 return matrix_.canAlias( alias );
2660template<
typename MT
2662template<
typename Other >
2663inline bool SymmetricMatrix<MT,SO,false,false>::isAliased(
const Other* alias )
const noexcept
2665 return matrix_.isAliased( alias );
2682template<
typename MT
2684inline bool SymmetricMatrix<MT,SO,false,false>::canSMPAssign() const noexcept
2686 return matrix_.canSMPAssign();
2704template<
typename MT
2706template<
typename MT2 >
2707void SymmetricMatrix<MT,SO,false,false>::assign( DenseMatrix<MT2,SO>& rhs )
2714 std::vector<size_t> nonzeros(
rows(), 0UL );
2717 for(
size_t i=0UL; i<
rows(); ++i ) {
2718 nonzeros[i] = (*rhs).nonZeros(i);
2722 matrix_.reserve(
sum );
2723 for(
size_t i=0UL; i<
rows(); ++i ) {
2724 matrix_.reserve( i, nonzeros[i] );
2727 for(
size_t i=0UL; i<
rows(); ++i ) {
2728 for(
size_t j=i; j<
columns(); ++j ) {
2730 SharedValue<ET> shared;
2731 *shared = std::move( (*rhs)(i,j) );
2732 matrix_.append( i, j, shared,
false );
2734 matrix_.append( j, i, shared,
false );
2755template<
typename MT
2757template<
typename MT2 >
2758void SymmetricMatrix<MT,SO,false,false>::assign(
const DenseMatrix<MT2,SO>& rhs )
2765 std::vector<size_t> nonzeros(
rows(), 0UL );
2768 for(
size_t i=0UL; i<
rows(); ++i ) {
2769 nonzeros[i] = (*rhs).nonZeros(i);
2773 matrix_.reserve(
sum );
2774 for(
size_t i=0UL; i<
rows(); ++i ) {
2775 matrix_.reserve( i, nonzeros[i] );
2778 for(
size_t i=0UL; i<
rows(); ++i ) {
2779 for(
size_t j=i; j<
columns(); ++j ) {
2781 const SharedValue<ET> shared( (*rhs)(i,j) );
2782 matrix_.append( i, j, shared,
false );
2784 matrix_.append( j, i, shared,
false );
2805template<
typename MT
2807template<
typename MT2 >
2808void SymmetricMatrix<MT,SO,false,false>::assign( SparseMatrix<MT2,SO>& rhs )
2815 std::vector<size_t> nonzeros(
rows(), 0UL );
2818 for(
size_t i=0UL; i<
rows(); ++i ) {
2819 nonzeros[i] = (*rhs).nonZeros(i);
2823 matrix_.reserve(
sum );
2824 for(
size_t i=0UL; i<
rows(); ++i ) {
2825 matrix_.reserve( i, nonzeros[i] );
2828 for(
size_t i=0UL; i<
rows(); ++i ) {
2829 for(
auto it=(*rhs).lowerBound(i,i); it!=(*rhs).end(i); ++it ) {
2831 SharedValue<ET> shared;
2832 *shared = std::move( it->value() );
2833 matrix_.append( i, it->index(), shared,
false );
2834 if( i != it->index() )
2835 matrix_.append( it->index(), i, shared,
false );
2856template<
typename MT
2858template<
typename MT2 >
2859void SymmetricMatrix<MT,SO,false,false>::assign(
const SparseMatrix<MT2,SO>& rhs )
2866 std::vector<size_t> nonzeros(
rows(), 0UL );
2869 for(
size_t i=0UL; i<
rows(); ++i ) {
2870 nonzeros[i] = (*rhs).nonZeros(i);
2874 matrix_.reserve(
sum );
2875 for(
size_t i=0UL; i<
rows(); ++i ) {
2876 matrix_.reserve( i, nonzeros[i] );
2879 for(
size_t i=0UL; i<
rows(); ++i ) {
2880 for(
auto it=(*rhs).lowerBound(i,i); it!=(*rhs).end(i); ++it ) {
2882 const SharedValue<ET> shared( it->value() );
2883 matrix_.append( i, it->index(), shared,
false );
2884 if( i != it->index() )
2885 matrix_.append( it->index(), i, shared,
false );
Header file for the addition trait.
Header file for auxiliary alias declarations.
Header file for run time assertion macros.
Header file for the conjugate shim.
Constraint on the data type.
constexpr const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:751
Header file for the EnableIf class template.
Constraint on the data type.
Header file for the If class template.
Header file for the IsComputation type trait class.
Header file for the isDefault shim.
Header file for the IsScalar type trait.
Header file for the IsSquare type trait.
Header file for the IsSymmetric type trait.
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Header file for the NonScalarProxy class.
Constraint on the data type.
Constraint on the data type.
Header file for the RemoveAdaptor type trait.
Constraint on the data type.
Constraint on the data type.
Header file for the Schur product trait.
Header file for the SharedValue class.
Header file for the subtraction trait.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of the base template of the SymmetricMatrix.
Pointer difference type of the Blaze library.
Size type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the SparseMatrix base class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:574
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:386
auto operator*=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:510
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:1456
decltype(auto) operator*(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9640
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:448
bool isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:225
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.
Definition: View.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Upper.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE(T)
Constraint on the data type.
Definition: Resizable.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
BLAZE_ALWAYS_INLINE void conjugate(T &a) noexcept(IsNumeric_v< T >)
In-place conjugation of the given value/object.
Definition: Conjugate.h:118
constexpr ptrdiff_t Size_v
Auxiliary variable template for the Size type trait.
Definition: Size.h:176
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960
MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:628
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730
MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:562
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:1108
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:584
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:1221
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:1195
void shrinkToFit(Matrix< MT, SO > &matrix)
Requesting the removal of unused capacity.
Definition: Matrix.h:1169
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:1383
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
MT::Iterator upperBound(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:244
MT::Iterator lowerBound(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:194
MT::Iterator find(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:144
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.
Definition: StaticAssert.h:112
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for the Size type trait.
Header file for the isZero shim.
Header file for the SparseElement base class.
Header file for utility functions for sparse matrices.
Header file for basic type definitions.