35 #ifndef _BLAZE_MATH_SPARSE_SPARSEVECTOR_H_ 36 #define _BLAZE_MATH_SPARSE_SPARSEVECTOR_H_ 83 template<
typename VT,
bool TF,
typename ST >
84 auto operator*=( SparseVector<VT,TF>& vec, ST scalar )
85 -> EnableIf_t< IsNumeric_v<ST>, VT& >;
87 template<
typename VT,
bool TF,
typename ST >
88 auto operator*=( SparseVector<VT,TF>&& vec, ST scalar )
89 -> EnableIf_t< IsNumeric_v<ST>, VT& >;
91 template<
typename VT,
bool TF,
typename ST >
92 auto operator/=( SparseVector<VT,TF>& vec, ST scalar )
93 -> EnableIf_t< IsNumeric_v<ST>, VT& >;
95 template<
typename VT,
bool TF,
typename ST >
96 auto operator/=( SparseVector<VT,TF>&& vec, ST scalar )
97 -> EnableIf_t< IsNumeric_v<ST>, VT& >;
115 template<
typename VT
121 if( IsRestricted_v<VT> ) {
122 if( !tryMult( ~vec, 0UL, (~vec).
size(), scalar ) ) {
133 BLAZE_DECLTYPE_AUTO( left, derestrict( ~vec ) );
135 const auto last( left.end() );
136 for(
auto element=left.begin(); element!=last; ++element ) {
137 element->value() *= scalar;
161 template<
typename VT
187 template<
typename VT
195 if( IsRestricted_v<VT> ) {
196 if( !tryDiv( ~vec, 0UL, (~vec).
size(), scalar ) ) {
202 IsFloatingPoint_v< UnderlyingBuiltin_t<ST> >
208 BLAZE_DECLTYPE_AUTO( left, derestrict( ~vec ) );
210 if( IsInvertible_v<ScalarType> ) {
211 const ScalarType tmp( ScalarType(1)/static_cast<ScalarType>( scalar ) );
212 for(
auto element=left.begin(); element!=left.end(); ++element ) {
213 element->value() *= tmp;
217 for(
auto element=left.begin(); element!=left.end(); ++element ) {
218 element->value() /= scalar;
244 template<
typename VT
266 template<
typename VT,
bool TF >
267 bool isnan(
const SparseVector<VT,TF>& sv );
269 template<
bool RF,
typename VT,
bool TF >
270 bool isUniform(
const SparseVector<VT,TF>& sv );
272 template<
bool RF,
typename VT,
bool TF >
273 bool isZero(
const SparseVector<VT,TF>& sv );
275 template<
typename VT,
bool TF >
276 const ElementType_t<VT>
sqrLength(
const SparseVector<VT,TF>& sv );
278 template<
typename VT,
bool TF >
304 template<
typename VT
312 const auto end( a.end() );
313 for(
auto element=a.begin(); element!=
end; ++element ) {
314 if(
isnan( element->value() ) )
return true;
361 if( IsUniform_v<VT> || (~sv).
size() < 2UL )
366 if( a.nonZeros() != a.size() )
368 const auto end( a.end() );
369 for(
auto element=a.begin(); element!=
end; ++element ) {
370 if( !isDefault<RF>( element->value() ) )
376 const auto& cmp( a[0] );
377 auto element( a.begin() );
378 const auto end( a.end() );
382 for( ; element!=
end; ++element ) {
383 if( !equal<RF>( element->value(), cmp ) )
431 if( IsZero_v<VT> || (~sv).
nonZeros() == 0UL )
436 const auto end( a.end() );
437 for(
auto element=a.begin(); element!=
end; ++element ) {
438 if( !isZero<RF>( element->value() ) )
460 template<
typename VT
469 for(
auto element=(~sv).
begin(); element!=(~sv).
end(); ++element )
470 sum +=
pow2( element->value() );
513 template<
typename VT
536 template<
typename VT
539 auto erase( SparseVector<VT,TF>& sv, Args&&... args )
540 -> decltype( (~sv).erase( std::forward<Args>( args )... ) )
542 return (~sv).erase( std::forward<Args>( args )... );
Header file for the isnan shim.
Header file for the UnderlyingNumeric type trait.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Constraint on the data type.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:354
Header file for basic type definitions.
Header file for the SparseVector base class.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
Header file for the isZero shim.
typename DivTrait< T1, T2 >::Type DivTrait_t
Auxiliary alias declaration for the DivTrait class template.The DivTrait_t alias declaration provides...
Definition: DivTrait.h:239
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the decltype(auto) workaround.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
auto length(const DenseVector< VT, TF > &dv) -> decltype(sqrt(sqrLength(~dv)))
Calculation of the length (magnitude) of the dense vector .
Definition: DenseVector.h:606
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:673
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Header file for the sqrt shim.
constexpr bool IsResizable_v
Auxiliary variable template for the IsResizable type trait.The IsResizable_v variable template provid...
Definition: IsResizable.h:134
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
const ElementType_t< VT > sqrLength(const DenseVector< VT, TF > &dv)
Calculation of the square length (magnitude) of the dense vector .
Definition: DenseVector.h:553
Header file for the IsFloatingPoint type trait.
Header file for the UnderlyingBuiltin type trait.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2146
Header file for the pow2 shim.
Header file for the equal shim.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:713
Header file for the exception macros of the math module.
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:849
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:438
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
Header file for the division trait.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
Header file for the IsZero type trait.
decltype(auto) pow2(const Proxy< PT, RT > &proxy)
Computing the square value of the represented element.
Definition: Proxy.h:1384
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Header file for the RemoveReference type trait.
Header file for the IsInvertible type trait.
decltype(auto) sqrt(const DenseMatrix< MT, SO > &dm)
Computes the square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1453
Header file for the IsBuiltin type trait.
auto operator*=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:290
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:263
Header file for the IsComplex type trait.
Header file for the IsResizable type trait.
Header file for the IsRestricted type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101