Blaze 3.9
ZeroVector.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SPARSE_ZEROVECTOR_H_
36#define _BLAZE_MATH_SPARSE_ZEROVECTOR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
48#include <blaze/math/Forward.h>
80#include <blaze/util/Assert.h>
85#include <blaze/util/EnableIf.h>
89#include <blaze/util/Types.h>
91
92
93namespace blaze {
94
95//=================================================================================================
96//
97// CLASS DEFINITION
98//
99//=================================================================================================
100
101//*************************************************************************************************
178template< typename Type // Data type of the vector
179 , bool TF // Transpose flag
180 , typename Tag > // Type tag
182 : public Expression< SparseVector< ZeroVector<Type,TF,Tag>, TF > >
183{
184 private:
185 //**Type definitions****************************************************************************
187 //**********************************************************************************************
188
189 public:
190 //**Type definitions****************************************************************************
193
196
199
200 using ElementType = Type;
201 using TagType = Tag;
202 using ReturnType = const Type&;
203
204 using CompositeType = const This&;
205 using Reference = const Type&;
206 using ConstReference = const Type&;
207 using Iterator = Element*;
208 using ConstIterator = const Element*;
209 //**********************************************************************************************
210
211 //**Rebind struct definition********************************************************************
214 template< typename NewType > // Data type of the other vector
215 struct Rebind {
217 };
218 //**********************************************************************************************
219
220 //**Resize struct definition********************************************************************
223 template< size_t NewN > // Number of elements of the other vector
224 struct Resize {
226 };
227 //**********************************************************************************************
228
229 //**Compilation flags***************************************************************************
231
234 static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>;
235 //**********************************************************************************************
236
237 //**Constructors********************************************************************************
240 constexpr ZeroVector() noexcept;
241 explicit constexpr ZeroVector( size_t size ) noexcept;
242
243 template< typename VT > inline ZeroVector( const Vector<VT,TF>& v );
244
245 ZeroVector( const ZeroVector& ) = default;
246 ZeroVector( ZeroVector&& ) = default;
248 //**********************************************************************************************
249
250 //**Destructor**********************************************************************************
253 ~ZeroVector() = default;
255 //**********************************************************************************************
256
257 //**Data access functions***********************************************************************
260 constexpr ConstReference operator[]( size_t index ) const noexcept;
261 inline ConstReference at( size_t index ) const;
262 constexpr ConstIterator begin () const noexcept;
263 constexpr ConstIterator cbegin() const noexcept;
264 constexpr ConstIterator end () const noexcept;
265 constexpr ConstIterator cend () const noexcept;
267 //**********************************************************************************************
268
269 //**Assignment operators************************************************************************
272 template< typename VT >
273 inline ZeroVector& operator=( const Vector<VT,TF>& rhs ) &;
274
275 ZeroVector& operator=( const ZeroVector& ) & = default;
276 ZeroVector& operator=( ZeroVector&& ) & = default;
278 //**********************************************************************************************
279
280 //**Utility functions***************************************************************************
283 constexpr size_t size() const noexcept;
284 constexpr size_t capacity() const noexcept;
285 constexpr size_t nonZeros() const noexcept;
286 constexpr void clear() noexcept;
287 constexpr void resize( size_t n ) noexcept;
288 constexpr void swap( ZeroVector& v ) noexcept;
290 //**********************************************************************************************
291
292 //**Lookup functions****************************************************************************
295 inline ConstIterator find ( size_t index ) const;
296 inline ConstIterator lowerBound( size_t index ) const;
297 inline ConstIterator upperBound( size_t index ) const;
299 //**********************************************************************************************
300
301 //**Expression template evaluation functions****************************************************
304 template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
305 template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
306
307 inline bool canSMPAssign() const noexcept;
309 //**********************************************************************************************
310
311 private:
312 //**Member variables****************************************************************************
315 size_t size_;
316
317 static const Type zero_;
319 //**********************************************************************************************
320
321 //**Compile time checks*************************************************************************
328 //**********************************************************************************************
329};
330//*************************************************************************************************
331
332
333
334
335//=================================================================================================
336//
337// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
338//
339//=================================================================================================
340
341template< typename Type // Data type of the vector
342 , bool TF // Transpose flag
343 , typename Tag > // Type tag
344const Type ZeroVector<Type,TF,Tag>::zero_{};
345
346
347
348
349//=================================================================================================
350//
351// CONSTRUCTORS
352//
353//=================================================================================================
354
355//*************************************************************************************************
358template< typename Type // Data type of the vector
359 , bool TF // Transpose flag
360 , typename Tag > // Type tag
362 : size_( 0UL ) // The current size/dimension of the zero vector
363{}
364//*************************************************************************************************
365
366
367//*************************************************************************************************
372template< typename Type // Data type of the vector
373 , bool TF // Transpose flag
374 , typename Tag > // Type tag
375constexpr ZeroVector<Type,TF,Tag>::ZeroVector( size_t n ) noexcept
376 : size_( n ) // The current size/dimension of the zero vector
377{}
378//*************************************************************************************************
379
380
381//*************************************************************************************************
390template< typename Type // Data type of the vector
391 , bool TF // Transpose flag
392 , typename Tag > // Type tag
393template< typename VT > // Type of the foreign zero vector
395 : size_( (*v).size() ) // The current size/dimension of the zero vector
396{
398
399 if( !IsZero_v<VT> && !isZero( *v ) ) {
400 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setup of zero vector" );
401 }
402}
403//*************************************************************************************************
404
405
406
407
408//=================================================================================================
409//
410// DATA ACCESS FUNCTIONS
411//
412//=================================================================================================
413
414//*************************************************************************************************
420template< typename Type // Data type of the vector
421 , bool TF // Transpose flag
422 , typename Tag > // Type tag
424 ZeroVector<Type,TF,Tag>::operator[]( size_t index ) const noexcept
425{
426 MAYBE_UNUSED( index );
427
428 BLAZE_USER_ASSERT( index < size(), "Invalid zero vector access index" );
429
430 return zero_;
431}
432//*************************************************************************************************
433
434
435//*************************************************************************************************
445template< typename Type // Data type of the vector
446 , bool TF // Transpose flag
447 , typename Tag > // Type tag
449 ZeroVector<Type,TF,Tag>::at( size_t index ) const
450{
451 if( index >= size_ ) {
452 BLAZE_THROW_OUT_OF_RANGE( "Invalid zero vector access index" );
453 }
454
455 return zero_;
456}
457//*************************************************************************************************
458
459
460//*************************************************************************************************
465template< typename Type // Data type of the vector
466 , bool TF // Transpose flag
467 , typename Tag > // Type tag
470{
471 return nullptr;
472}
473//*************************************************************************************************
474
475
476//*************************************************************************************************
481template< typename Type // Data type of the vector
482 , bool TF // Transpose flag
483 , typename Tag > // Type tag
486{
487 return nullptr;
488}
489//*************************************************************************************************
490
491
492//*************************************************************************************************
497template< typename Type // Data type of the vector
498 , bool TF // Transpose flag
499 , typename Tag > // Type tag
502{
503 return nullptr;
504}
505//*************************************************************************************************
506
507
508//*************************************************************************************************
513template< typename Type // Data type of the vector
514 , bool TF // Transpose flag
515 , typename Tag > // Type tag
518{
519 return nullptr;
520}
521//*************************************************************************************************
522
523
524
525
526//=================================================================================================
527//
528// ASSIGNMENT OPERATORS
529//
530//=================================================================================================
531
532//*************************************************************************************************
542template< typename Type // Data type of the vector
543 , bool TF // Transpose flag
544 , typename Tag > // Type tag
545template< typename VT > // Type of the right-hand side dense vector
548{
550
551 if( !IsZero_v<VT> && !isZero( *rhs ) ) {
552 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment of zero vector" );
553 }
554
555 size_ = (*rhs).size();
556
557 return *this;
558}
559//*************************************************************************************************
560
561
562
563
564//=================================================================================================
565//
566// UTILITY FUNCTIONS
567//
568//=================================================================================================
569
570//*************************************************************************************************
575template< typename Type // Data type of the vector
576 , bool TF // Transpose flag
577 , typename Tag > // Type tag
578constexpr size_t ZeroVector<Type,TF,Tag>::size() const noexcept
579{
580 return size_;
581}
582//*************************************************************************************************
583
584
585//*************************************************************************************************
590template< typename Type // Data type of the vector
591 , bool TF // Transpose flag
592 , typename Tag > // Type tag
593constexpr size_t ZeroVector<Type,TF,Tag>::capacity() const noexcept
594{
595 return 0UL;
596}
597//*************************************************************************************************
598
599
600//*************************************************************************************************
608template< typename Type // Data type of the vector
609 , bool TF // Transpose flag
610 , typename Tag > // Type tag
611constexpr size_t ZeroVector<Type,TF,Tag>::nonZeros() const noexcept
612{
613 return 0UL;
614}
615//*************************************************************************************************
616
617
618//*************************************************************************************************
625template< typename Type // Data type of the vector
626 , bool TF // Transpose flag
627 , typename Tag > // Type tag
628constexpr void ZeroVector<Type,TF,Tag>::clear() noexcept
629{
630 size_ = 0UL;
631}
632//*************************************************************************************************
633
634
635//*************************************************************************************************
645template< typename Type // Data type of the vector
646 , bool TF // Transpose flag
647 , typename Tag > // Type tag
648constexpr void ZeroVector<Type,TF,Tag>::resize( size_t n ) noexcept
649{
650 size_ = n;
651}
652//*************************************************************************************************
653
654
655//*************************************************************************************************
661template< typename Type // Data type of the vector
662 , bool TF // Transpose flag
663 , typename Tag > // Type tag
664constexpr void ZeroVector<Type,TF,Tag>::swap( ZeroVector& v ) noexcept
665{
666 const size_t tmp( size_ );
667 size_ = v.size_;
668 v.size_ = tmp;
669}
670//*************************************************************************************************
671
672
673
674
675//=================================================================================================
676//
677// LOOKUP FUNCTIONS
678//
679//=================================================================================================
680
681//*************************************************************************************************
692template< typename Type // Data type of the vector
693 , bool TF // Transpose flag
694 , typename Tag > // Type tag
696 ZeroVector<Type,TF,Tag>::find( size_t index ) const
697{
698 MAYBE_UNUSED( index );
699
700 BLAZE_USER_ASSERT( index < size(), "Invalid zero vector access index" );
701
702 return nullptr;
703}
704//*************************************************************************************************
705
706
707//*************************************************************************************************
717template< typename Type // Data type of the vector
718 , bool TF // Transpose flag
719 , typename Tag > // Type tag
722{
723 MAYBE_UNUSED( index );
724
725 BLAZE_USER_ASSERT( index < size(), "Invalid zero vector access index" );
726
727 return nullptr;
728}
729//*************************************************************************************************
730
731
732//*************************************************************************************************
742template< typename Type // Data type of the vector
743 , bool TF // Transpose flag
744 , typename Tag > // Type tag
747{
748 MAYBE_UNUSED( index );
749
750 BLAZE_USER_ASSERT( index < size(), "Invalid zero vector access index" );
751
752 return nullptr;
753}
754//*************************************************************************************************
755
756
757
758
759//=================================================================================================
760//
761// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
762//
763//=================================================================================================
764
765//*************************************************************************************************
775template< typename Type // Data type of the vector
776 , bool TF // Transpose flag
777 , typename Tag > // Type tag
778template< typename Other > // Data type of the foreign expression
779inline bool ZeroVector<Type,TF,Tag>::canAlias( const Other* alias ) const noexcept
780{
781 MAYBE_UNUSED( alias );
782
783 return false;
784}
785//*************************************************************************************************
786
787
788//*************************************************************************************************
798template< typename Type // Data type of the vector
799 , bool TF // Transpose flag
800 , typename Tag > // Type tag
801template< typename Other > // Data type of the foreign expression
802inline bool ZeroVector<Type,TF,Tag>::isAliased( const Other* alias ) const noexcept
803{
804 MAYBE_UNUSED( alias );
805
806 return false;
807}
808//*************************************************************************************************
809
810
811//*************************************************************************************************
821template< typename Type // Data type of the vector
822 , bool TF // Transpose flag
823 , typename Tag > // Type tag
824inline bool ZeroVector<Type,TF,Tag>::canSMPAssign() const noexcept
825{
826 return false;
827}
828//*************************************************************************************************
829
830
831
832
833
834
835
836
837//=================================================================================================
838//
839// ZEROVECTOR OPERATORS
840//
841//=================================================================================================
842
843//*************************************************************************************************
846template< RelaxationFlag RF, typename Type, bool TF, typename Tag >
847constexpr bool isDefault( const ZeroVector<Type,TF,Tag>& v ) noexcept;
848
849template< typename Type, bool TF, typename Tag >
850constexpr bool isIntact( const ZeroVector<Type,TF,Tag>& v ) noexcept;
851
852template< typename Type, bool TF, typename Tag >
853constexpr void swap( ZeroVector<Type,TF,Tag>& a, ZeroVector<Type,TF,Tag>& b ) noexcept;
855//*************************************************************************************************
856
857
858//*************************************************************************************************
882template< RelaxationFlag RF // Relaxation flag
883 , typename Type // Data type of the vector
884 , bool TF // Transpose flag
885 , typename Tag > // Type tag
886constexpr bool isDefault( const ZeroVector<Type,TF,Tag>& v ) noexcept
887{
888 return ( v.size() == 0UL );
889}
890//*************************************************************************************************
891
892
893//*************************************************************************************************
910template< typename Type // Data type of the vector
911 , bool TF // Transpose flag
912 , typename Tag > // Type tag
913constexpr bool isIntact( const ZeroVector<Type,TF,Tag>& v ) noexcept
914{
915 MAYBE_UNUSED( v );
916
917 return true;
918}
919//*************************************************************************************************
920
921
922//*************************************************************************************************
930template< typename Type // Data type of the vector
931 , bool TF // Transpose flag
932 , typename Tag > // Type tag
933constexpr void swap( ZeroVector<Type,TF,Tag>& a, ZeroVector<Type,TF,Tag>& b ) noexcept
934{
935 a.swap( b );
936}
937//*************************************************************************************************
938
939
940//*************************************************************************************************
949template< typename Type // Data type of the vector
950 , bool TF // Transpose flag
951 , typename Tag > // Type tag
952inline void erase( ZeroVector<Type,TF,Tag>& v, size_t index )
953{
954 MAYBE_UNUSED( v, index );
955}
957//*************************************************************************************************
958
959
960//*************************************************************************************************
971template< typename Type // Data type of the vector
972 , bool TF // Transpose flag
973 , typename Tag // Type tag
974 , typename Iterator > // Type of the vector iterator
975inline Iterator erase( ZeroVector<Type,TF,Tag>& v, Iterator pos )
976{
977 MAYBE_UNUSED( v, pos );
978
979 return nullptr;
980}
982//*************************************************************************************************
983
984
985//*************************************************************************************************
997template< typename Type // Data type of the vector
998 , bool TF // Transpose flag
999 , typename Tag // Type tag
1000 , typename Iterator > // Type of the vector iterator
1001inline Iterator erase( ZeroVector<Type,TF,Tag>& m, Iterator first, Iterator last )
1002{
1003 MAYBE_UNUSED( m, first, last );
1004
1005 return nullptr;
1006}
1008//*************************************************************************************************
1009
1010
1011//*************************************************************************************************
1035template< typename Type // Data type of the vector
1036 , bool TF // Transpose flag
1037 , typename Tag // Type tag
1038 , typename Pred > // Type of the unary predicate
1039inline void erase( ZeroVector<Type,TF,Tag>& v, Pred predicate )
1040{
1041 MAYBE_UNUSED( v, predicate );
1042}
1044//*************************************************************************************************
1045
1046
1047//*************************************************************************************************
1073template< typename Type // Data type of the vector
1074 , bool TF // Transpose flag
1075 , typename Tag // Type tag
1076 , typename Iterator // Type of the vector iterator
1077 , typename Pred > // Type of the unary predicate
1078inline void erase( ZeroVector<Type,TF,Tag>& m, Iterator first, Iterator last, Pred predicate )
1079{
1080 MAYBE_UNUSED( m, first, last, predicate );
1081}
1083//*************************************************************************************************
1084
1085
1086
1087
1088//=================================================================================================
1089//
1090// GLOBAL FUNCTIONS
1091//
1092//=================================================================================================
1093
1094//*************************************************************************************************
1120template< typename T, bool TF = defaultTransposeFlag >
1121constexpr decltype(auto) zero( size_t n ) noexcept
1122{
1123 return ZeroVector<T,TF>( n );
1124}
1125//*************************************************************************************************
1126
1127
1128//*************************************************************************************************
1144template< typename VT // Type of the vector
1145 , bool TF > // Transpose flag
1146inline ZeroVector<ElementType_t<VT>,TF>
1148{
1150
1151 return ZeroVector<ElementType_t<VT>,TF>( (*v).size() );
1152}
1153//*************************************************************************************************
1154
1155
1156
1157
1158//=================================================================================================
1159//
1160// ISUNIFORM SPECIALIZATIONS
1161//
1162//=================================================================================================
1163
1164//*************************************************************************************************
1166template< typename Type, bool TF, typename Tag >
1167struct IsUniform< ZeroVector<Type,TF,Tag> >
1168 : public TrueType
1169{};
1171//*************************************************************************************************
1172
1173
1174
1175
1176//=================================================================================================
1177//
1178// ISZERO SPECIALIZATIONS
1179//
1180//=================================================================================================
1181
1182//*************************************************************************************************
1184template< typename Type, bool TF, typename Tag >
1185struct IsZero< ZeroVector<Type,TF,Tag> >
1186 : public TrueType
1187{};
1189//*************************************************************************************************
1190
1191
1192
1193
1194//=================================================================================================
1195//
1196// ADDTRAIT SPECIALIZATIONS
1197//
1198//=================================================================================================
1199
1200//*************************************************************************************************
1202template< typename T1, typename T2 >
1203struct AddTraitEval1< T1, T2
1204 , EnableIf_t< IsVector_v<T1> &&
1205 IsVector_v<T2> &&
1206 !IsZero_v<T1> && IsZero_v<T2> > >
1207{
1208 using Type = Rebind_t< ResultType_t<T1>, AddTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1209};
1210
1211template< typename T1, typename T2 >
1212struct AddTraitEval1< T1, T2
1213 , EnableIf_t< IsVector_v<T1> &&
1214 IsVector_v<T2> &&
1215 IsZero_v<T1> && !IsZero_v<T2> > >
1216{
1217 using Type = Rebind_t< ResultType_t<T2>, AddTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1218};
1219
1220template< typename T1, typename T2 >
1221struct AddTraitEval1< T1, T2
1222 , EnableIf_t< IsVector_v<T1> &&
1223 IsVector_v<T2> &&
1224 IsZero_v<T1> && IsZero_v<T2> > >
1225{
1226 using Type = ZeroVector< AddTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1227 , TransposeFlag_v<T1>
1228 , AddTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1229};
1231//*************************************************************************************************
1232
1233
1234
1235
1236//=================================================================================================
1237//
1238// SUBTRAIT SPECIALIZATIONS
1239//
1240//=================================================================================================
1241
1242//*************************************************************************************************
1244template< typename T1, typename T2 >
1245struct SubTraitEval1< T1, T2
1246 , EnableIf_t< IsVector_v<T1> &&
1247 IsVector_v<T2> &&
1248 !IsZero_v<T1> && IsZero_v<T2> > >
1249{
1250 using Type = Rebind_t< ResultType_t<T1>, SubTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1251};
1252
1253template< typename T1, typename T2 >
1254struct SubTraitEval1< T1, T2
1255 , EnableIf_t< IsVector_v<T1> &&
1256 IsVector_v<T2> &&
1257 IsZero_v<T1> && !IsZero_v<T2> > >
1258{
1259 using Type = Rebind_t< ResultType_t<T2>, SubTrait_t< ElementType_t<T1>, ElementType_t<T2> > >;
1260};
1261
1262template< typename T1, typename T2 >
1263struct SubTraitEval1< T1, T2
1264 , EnableIf_t< IsVector_v<T1> &&
1265 IsVector_v<T2> &&
1266 IsZero_v<T1> && IsZero_v<T2> > >
1267{
1268 using Type = ZeroVector< SubTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1269 , TransposeFlag_v<T1>
1270 , SubTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1271};
1273//*************************************************************************************************
1274
1275
1276
1277
1278//=================================================================================================
1279//
1280// MULTTRAIT SPECIALIZATIONS
1281//
1282//=================================================================================================
1283
1284//*************************************************************************************************
1286template< typename T1, typename T2 >
1287struct MultTraitEval1< T1, T2
1288 , EnableIf_t< IsVector_v<T1> &&
1289 IsScalar_v<T2> &&
1290 IsZero_v<T1> > >
1291{
1292 using Type = ZeroVector< MultTrait_t< ElementType_t<T1>, T2 >
1293 , TransposeFlag_v<T1>
1294 , MultTrait_t< TagType_t<T1>, T2 > >;
1295};
1296
1297template< typename T1, typename T2 >
1298struct MultTraitEval1< T1, T2
1299 , EnableIf_t< IsScalar_v<T1> &&
1300 IsVector_v<T2> &&
1301 IsZero_v<T2> > >
1302{
1303 using Type = ZeroVector< MultTrait_t< T1, ElementType_t<T2> >
1304 , TransposeFlag_v<T2>
1305 , MultTrait_t< T1, TagType_t<T2> > >;
1306};
1307
1308template< typename T1, typename T2 >
1309struct MultTraitEval1< T1, T2
1310 , EnableIf_t< ( ( IsRowVector_v<T1> && IsRowVector_v<T2> ) ||
1311 ( IsColumnVector_v<T1> && IsColumnVector_v<T2> ) ) &&
1312 ( IsZero_v<T1> || IsZero_v<T2> ) > >
1313{
1314 using Type = ZeroVector< MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1315 , TransposeFlag_v<T1>
1316 , MultTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1317};
1318
1319template< typename T1, typename T2 >
1320struct MultTraitEval1< T1, T2
1321 , EnableIf_t< IsMatrix_v<T1> &&
1322 IsColumnVector_v<T2> &&
1323 ( IsZero_v<T1> || IsZero_v<T2> ) > >
1324{
1325 using MultType = MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >;
1326 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
1327
1328 using Type = ZeroVector< AddTrait_t<MultType,MultType>
1329 , false
1330 , AddTrait_t<MultTag,MultTag> >;
1331};
1332
1333template< typename T1, typename T2 >
1334struct MultTraitEval1< T1, T2
1335 , EnableIf_t< IsRowVector_v<T1> &&
1336 IsMatrix_v<T2> &&
1337 ( IsZero_v<T1> || IsZero_v<T2> ) > >
1338{
1339 using MultType = MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >;
1340 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
1341
1342 using Type = ZeroVector< AddTrait_t<MultType,MultType>
1343 , true
1344 , AddTrait_t<MultTag,MultTag> >;
1345};
1347//*************************************************************************************************
1348
1349
1350
1351
1352//=================================================================================================
1353//
1354// KRONTRAIT SPECIALIZATIONS
1355//
1356//=================================================================================================
1357
1358//*************************************************************************************************
1360template< typename T1, typename T2 >
1361struct KronTraitEval1< T1, T2
1362 , EnableIf_t< IsVector_v<T1> &&
1363 IsVector_v<T2> &&
1364 ( IsZero_v<T1> ||
1365 IsZero_v<T2> ) > >
1366{
1367 using Type = ZeroVector< MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1368 , ( IsZero_v<T2> ? TransposeFlag_v<T2> : TransposeFlag_v<T1> )
1369 , MultTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1370};
1372//*************************************************************************************************
1373
1374
1375
1376
1377//=================================================================================================
1378//
1379// DIVTRAIT SPECIALIZATIONS
1380//
1381//=================================================================================================
1382
1383//*************************************************************************************************
1385template< typename T1, typename T2 >
1386struct DivTraitEval1< T1, T2
1387 , EnableIf_t< IsVector_v<T1> &&
1388 IsScalar_v<T2> &&
1389 IsZero_v<T1> > >
1390{
1391 using Type = ZeroVector< DivTrait_t< ElementType_t<T1>, T2 >
1392 , TransposeFlag_v<T1>
1393 , DivTrait_t< TagType_t<T1>, T2 > >;
1394};
1395
1396template< typename T1, typename T2 >
1397struct DivTraitEval1< T1, T2
1398 , EnableIf_t< ( ( IsRowVector_v<T1> && IsRowVector_v<T2> ) ||
1399 ( IsColumnVector_v<T1> && IsColumnVector_v<T2> ) ) &&
1400 ( IsZero_v<T1> || IsZero_v<T2> ) > >
1401{
1402 using Type = ZeroVector< DivTrait_t< ElementType_t<T1>, ElementType_t<T2> >
1403 , TransposeFlag_v<T1>
1404 , DivTrait_t< TagType_t<T1>, TagType_t<T2> > >;
1405};
1407//*************************************************************************************************
1408
1409
1410
1411
1412//=================================================================================================
1413//
1414// CROSSTRAIT SPECIALIZATIONS
1415//
1416//=================================================================================================
1417
1418//*************************************************************************************************
1420template< typename T1, typename T2 >
1421struct CrossTraitEval1< T1, T2
1422 , EnableIf_t< IsVector_v<T1> &&
1423 IsVector_v<T2> &&
1424 ( IsZero_v<T1> || IsZero_v<T2> ) > >
1425{
1426 using MultType = MultTrait_t< ElementType_t<T1>, ElementType_t<T2> >;
1427 using MultTag = MultTrait_t< TagType_t<T1>, TagType_t<T2> >;
1428
1429 using Type = ZeroVector< SubTrait_t<MultType,MultType>
1430 , TransposeFlag_v<T1>
1431 , SubTrait_t<MultTag,MultTag> >;
1432};
1434//*************************************************************************************************
1435
1436
1437
1438
1439//=================================================================================================
1440//
1441// MAPTRAIT SPECIALIZATIONS
1442//
1443//=================================================================================================
1444
1445//*************************************************************************************************
1447template< typename T, typename OP >
1448struct UnaryMapTraitEval1< T, OP
1449 , EnableIf_t< IsVector_v<T> &&
1450 YieldsZero_v<OP,T> > >
1451{
1452 using ElementType = decltype( std::declval<OP>()( std::declval< ElementType_t<T> >() ) );
1453
1454 using Type = ZeroVector< EvaluateTrait_t<ElementType>
1455 , TransposeFlag_v<T>
1456 , MapTrait_t< TagType_t<T>, OP > >;
1457};
1459//*************************************************************************************************
1460
1461
1462//*************************************************************************************************
1464template< typename T1, typename T2, typename OP >
1465struct BinaryMapTraitEval1< T1, T2, OP
1466 , EnableIf_t< IsVector_v<T1> &&
1467 IsVector_v<T2> &&
1468 YieldsZero_v<OP,T1,T2> > >
1469{
1470 using ElementType = decltype( std::declval<OP>()( std::declval< ElementType_t<T1> >()
1471 , std::declval< ElementType_t<T2> >() ) );
1472
1473 using Type = ZeroVector< EvaluateTrait_t<ElementType>
1474 , TransposeFlag_v<T1>
1475 , MapTrait_t< TagType_t<T1>, TagType_t<T2>, OP > >;
1476};
1478//*************************************************************************************************
1479
1480
1481
1482
1483//=================================================================================================
1484//
1485// REPEATTRAIT SPECIALIZATIONS
1486//
1487//=================================================================================================
1488
1489//*************************************************************************************************
1491template< typename T, size_t R0 >
1492struct RepeatTraitEval1< T, R0, inf, inf
1493 , EnableIf_t< IsVector_v<T> &&
1494 IsZero_v<T> > >
1495{
1496 using Type = ZeroVector< ElementType_t<T>
1497 , TransposeFlag_v<T>
1498 , TagType_t<T> >;
1499};
1501//*************************************************************************************************
1502
1503
1504
1505
1506//=================================================================================================
1507//
1508// HIGHTYPE SPECIALIZATIONS
1509//
1510//=================================================================================================
1511
1512//*************************************************************************************************
1514template< typename T1, bool TF, typename Tag, typename T2 >
1515struct HighType< ZeroVector<T1,TF,Tag>, ZeroVector<T2,TF,Tag> >
1516{
1517 using Type = ZeroVector< typename HighType<T1,T2>::Type, TF, Tag >;
1518};
1520//*************************************************************************************************
1521
1522
1523
1524
1525//=================================================================================================
1526//
1527// LOWTYPE SPECIALIZATIONS
1528//
1529//=================================================================================================
1530
1531//*************************************************************************************************
1533template< typename T1, bool TF, typename Tag, typename T2 >
1534struct LowType< ZeroVector<T1,TF,Tag>, ZeroVector<T2,TF,Tag> >
1535{
1536 using Type = ZeroVector< typename LowType<T1,T2>::Type, TF, Tag >;
1537};
1539//*************************************************************************************************
1540
1541
1542
1543
1544//=================================================================================================
1545//
1546// SUBVECTORTRAIT SPECIALIZATIONS
1547//
1548//=================================================================================================
1549
1550//*************************************************************************************************
1552template< typename VT, size_t I, size_t N >
1553struct SubvectorTraitEval1< VT, I, N
1554 , EnableIf_t< IsZero_v<VT> > >
1555{
1556 using Type = ZeroVector< RemoveConst_t< ElementType_t<VT> >
1557 , TransposeFlag_v<VT>
1558 , TagType_t<VT> >;
1559};
1561//*************************************************************************************************
1562
1563
1564
1565
1566//=================================================================================================
1567//
1568// ELEMENTSTRAIT SPECIALIZATIONS
1569//
1570//=================================================================================================
1571
1572//*************************************************************************************************
1574template< typename VT, size_t N >
1575struct ElementsTraitEval1< VT, N
1576 , EnableIf_t< IsZero_v<VT> > >
1577{
1578 using Type = ZeroVector< RemoveConst_t< ElementType_t<VT> >
1579 , TransposeFlag_v<VT>
1580 , TagType_t<VT> >;
1581};
1583//*************************************************************************************************
1584
1585
1586
1587
1588//=================================================================================================
1589//
1590// ROWTRAIT SPECIALIZATIONS
1591//
1592//=================================================================================================
1593
1594//*************************************************************************************************
1596template< typename MT, size_t I >
1597struct RowTraitEval1< MT, I
1598 , EnableIf_t< IsZero_v<MT> > >
1599{
1600 using Type = ZeroVector< RemoveConst_t< ElementType_t<MT> >
1601 , true
1602 , TagType_t<MT> >;
1603};
1605//*************************************************************************************************
1606
1607
1608
1609
1610//=================================================================================================
1611//
1612// COLUMNTRAIT SPECIALIZATIONS
1613//
1614//=================================================================================================
1615
1616//*************************************************************************************************
1618template< typename MT, size_t I >
1619struct ColumnTraitEval1< MT, I
1620 , EnableIf_t< IsZero_v<MT> > >
1621{
1622 using Type = ZeroVector< RemoveConst_t< ElementType_t<MT> >
1623 , false
1624 , TagType_t<MT> >;
1625};
1627//*************************************************************************************************
1628
1629
1630
1631
1632//=================================================================================================
1633//
1634// BANDTRAIT SPECIALIZATIONS
1635//
1636//=================================================================================================
1637
1638//*************************************************************************************************
1640template< typename MT, ptrdiff_t I >
1641struct BandTraitEval1< MT, I
1642 , EnableIf_t< IsZero_v<MT> > >
1643{
1644 using Type = ZeroVector< RemoveConst_t< ElementType_t<MT> >
1646 , TagType_t<MT> >;
1647};
1649//*************************************************************************************************
1650
1651} // namespace blaze
1652
1653#endif
Header file for the addition trait.
Header file for auxiliary alias declarations.
typename ResultType_t< T >::TagType TagType_t
Alias declaration for nested TagType type definitions.
Definition: Aliases.h:530
Header file for run time assertion macros.
Header file for the band trait.
Header file for the column trait.
Constraint on the data type.
Header file for the cross product trait.
Header file for the division trait.
Header file for the elements trait.
Header file for the EnableIf class template.
Header file for the EvaluateTrait class template.
Header file for the function trace functionality.
Header file for the HighType type trait.
Header file for the IntegralConstant class template.
Header file for the IsColumnVector type trait.
Header file for the IsMatrix type trait.
Header file for the IsRowVector type trait.
Header file for the IsSMPAssignable type trait.
Header file for the IsScalar type trait.
Header file for the IsUniform type trait.
Header file for the IsVector type trait.
Header file for the Kron product trait.
Header file for the LowType type trait.
Header file for the map trait.
Header file for the MAYBE_UNUSED function template.
Header file for the multiplication trait.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Header file for the RemoveConst type trait.
Header file for the repeat trait.
Header file for the row trait.
Data type constraint.
Header file for the subtraction trait.
Header file for the subvector trait.
Header file for the ValueIndexPair class.
Constraint on the data type.
Header file for the YieldsZero type trait.
Index-value-pair for sparse vectors and matrices.
Definition: ValueIndexPair.h:75
Base class for N-dimensional vectors.
Definition: Vector.h:82
Efficient implementation of an arbitrary sized zero vector.
Definition: ZeroVector.h:183
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: ZeroVector.h:746
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: ZeroVector.h:696
constexpr ConstIterator begin() const noexcept
Returns an iterator to the first non-zero element of the zero vector.
Definition: ZeroVector.h:469
const Type & ReturnType
Return type for expression template evaluations.
Definition: ZeroVector.h:202
constexpr void resize(size_t n) noexcept
Changing the size of the zero vector.
Definition: ZeroVector.h:648
constexpr size_t capacity() const noexcept
Returns the maximum capacity of the zero vector.
Definition: ZeroVector.h:593
constexpr ConstReference operator[](size_t index) const noexcept
Subscript operator for the direct access to the zero vector elements.
Definition: ZeroVector.h:424
Type ElementType
Type of the zero vector elements.
Definition: ZeroVector.h:200
constexpr ZeroVector() noexcept
The default constructor for ZeroVector.
Definition: ZeroVector.h:361
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the zero vector.
Definition: ZeroVector.h:611
constexpr size_t size() const noexcept
Returns the current size/dimension of the zero vector.
Definition: ZeroVector.h:578
constexpr ConstIterator cbegin() const noexcept
Returns an iterator to the first non-zero element of the zero vector.
Definition: ZeroVector.h:485
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: ZeroVector.h:721
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: ZeroVector.h:824
constexpr void swap(ZeroVector &v) noexcept
Swapping the contents of two zero vectors.
Definition: ZeroVector.h:664
Tag TagType
Tag type of this ZeroVector instance.
Definition: ZeroVector.h:201
ZeroVector< Type, TF, Tag > This
Type of this ZeroVector instance.
Definition: ZeroVector.h:191
constexpr ConstIterator cend() const noexcept
Returns an iterator just past the last non-zero element of the zero vector.
Definition: ZeroVector.h:517
constexpr ConstIterator end() const noexcept
Returns an iterator just past the last non-zero element of the zero vector.
Definition: ZeroVector.h:501
static const Type zero_
The zero element.
Definition: ZeroVector.h:317
const Type & Reference
Reference to a zero vector element.
Definition: ZeroVector.h:205
constexpr void clear() noexcept
Clearing the zero vector.
Definition: ZeroVector.h:628
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: ZeroVector.h:802
const Type & ConstReference
Reference to a constant zero vector element.
Definition: ZeroVector.h:206
ConstReference at(size_t index) const
Checked access to the zero vector elements.
Definition: ZeroVector.h:449
size_t size_
The current size/dimension of the zero vector.
Definition: ZeroVector.h:315
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: ZeroVector.h:234
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: ZeroVector.h:779
Header file for the Expression base class.
Header file for the SparseVector 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_BE_SAME_TAG(A, B)
Data type constraint.
Definition: SameTag.h:68
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
bool isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition: MultTrait.h:165
constexpr bool IsScalar_v
Auxiliary variable template for the IsScalar type trait.
Definition: IsScalar.h:104
constexpr bool IsVector_v
Auxiliary variable template for the IsVector type trait.
Definition: IsVector.h:125
constexpr bool IsZero_v
Auxiliary variable template for the IsZero type trait.
Definition: IsZero.h:166
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.
Definition: IsMatrix.h:124
constexpr bool IsRowVector_v
Auxiliary variable template for the IsRowVector type trait.
Definition: IsRowVector.h:126
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition: RelaxationFlag.h:66
constexpr Infinity inf
Global Infinity instance.
Definition: Infinity.h:1080
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
constexpr bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.
Definition: TransposeFlag.h:75
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
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
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
constexpr bool isIntact(const ZeroVector< Type, TF, Tag > &v) noexcept
Returns whether the invariants of the given zero vector are intact.
Definition: ZeroVector.h:913
constexpr decltype(auto) zero(size_t n) noexcept
Creating a zero vector.
Definition: ZeroVector.h:1121
constexpr void swap(ZeroVector< Type, TF, Tag > &a, ZeroVector< Type, TF, Tag > &b) noexcept
Swapping the contents of two zero vectors.
Definition: ZeroVector.h:933
ZeroVector< ElementType_t< VT >, TF > declzero(const Vector< VT, TF > &v)
Declares the given vector expression v as zero vector.
Definition: ZeroVector.h:1147
constexpr bool isDefault(const ZeroVector< Type, TF, Tag > &v) noexcept
Returns whether the given zero vector is in default state.
Definition: ZeroVector.h:886
Header file for the exception macros of the math module.
Header file for all forward declarations of the math module.
Header file for all forward declarations for sparse vectors and matrices.
Header file for the TransposeFlag type trait.
Header file for the isZero shim.
Base class for all expression templates.
Definition: Expression.h:60
Rebind mechanism to obtain a ZeroVector with different data/element type.
Definition: ZeroVector.h:215
Resize mechanism to obtain a ZeroVector with a different fixed number of elements.
Definition: ZeroVector.h:224
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the IsZero type trait.
Header file for basic type definitions.