Skip to content

Commit c8dcf55

Browse files
author
Vladimir Dimic
authored
Resolve internal issue 448: internal set getinitialized to be invoked via matrixbase (#22)
* Implement get/setInitialized call through MatrixBase * Add a const qualifier for boolean argument of existing setInitialized signatures. * Add 'initialized' field to MatrixFunctor * Add get/setInitialized to MatrixFunctor * Annotate that initialized field in MatrixFunctor is a temporary solution
1 parent b6220ea commit c8dcf55

3 files changed

Lines changed: 53 additions & 23 deletions

File tree

include/alp/reference/blas3.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ namespace alp {
10951095
imf::Id, imf::Id,
10961096
reference
10971097
>(
1098+
internal::getInitialized( x ) && internal::getInitialized( y ), // Temporary solution, pending proper implemention
10981099
lambda,
10991100
imf::Id( getLength( x ) ),
11001101
imf::Id( getLength( y ) )
@@ -1145,6 +1146,7 @@ namespace alp {
11451146
imf::Id, imf::Id,
11461147
reference
11471148
>(
1149+
internal::getInitialized( x ),
11481150
lambda,
11491151
imf::Id( getLength( x ) )
11501152
);

include/alp/reference/matrix.hpp

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace alp {
100100
}
101101

102102
template< typename D >
103-
void setInitialized( alp::internal::Matrix< D, reference > & A, bool initialized ) noexcept {
103+
void setInitialized( alp::internal::Matrix< D, reference > & A, const bool initialized ) noexcept {
104104
A.initialized = initialized;
105105
}
106106

@@ -145,7 +145,7 @@ namespace alp {
145145
friend const bool & internal::getInitialized( const alp::internal::Matrix< DataType, reference > & ) noexcept;
146146

147147
template< typename DataType >
148-
friend void internal::setInitialized( alp::internal::Matrix< DataType, reference > & , bool ) noexcept;
148+
friend void internal::setInitialized( alp::internal::Matrix< DataType, reference > & , const bool ) noexcept;
149149

150150
typedef Matrix< D, reference > self_type;
151151

@@ -392,21 +392,11 @@ namespace alp {
392392
template< typename DerivedMatrix >
393393
std::pair< size_t, size_t > dims( const MatrixBase< DerivedMatrix > & A ) noexcept;
394394

395-
// template< typename DerivedMatrix >
396-
// bool getInitialized( MatrixBase< DerivedMatrix > & ) noexcept;
397-
398-
// template< typename DerivedMatrix >
399-
// void getInitialized( MatrixBase< DerivedMatrix > &, bool ) noexcept;
400-
401-
template< typename T, typename Structure, enum Density density, typename View, typename ImfR, typename ImfC >
402-
bool getInitialized( const alp::Matrix< T, Structure, density, View, ImfR, ImfC, reference > & A ) noexcept {
403-
return internal::getInitialized( internal::getContainer( A ) );
404-
}
395+
template< typename MatrixType >
396+
bool getInitialized( const MatrixType &A ) noexcept;
405397

406-
template< typename T, typename Structure, enum Density density, typename View, typename ImfR, typename ImfC >
407-
void setInitialized( alp::Matrix< T, Structure, density, View, ImfR, ImfC, reference > & A, bool initialized ) noexcept {
408-
internal::setInitialized( internal::getContainer( A ), initialized );
409-
}
398+
template< typename MatrixType >
399+
void setInitialized( MatrixType &, const bool ) noexcept;
410400

411401
} // namespace internal
412402

@@ -439,6 +429,12 @@ namespace alp {
439429

440430
friend std::pair< size_t, size_t > dims<>( const MatrixBase< DerivedMatrix > &A ) noexcept;
441431

432+
template< typename MatrixType >
433+
friend bool getInitialized( const MatrixType &A ) noexcept;
434+
435+
template< typename MatrixType >
436+
friend void setInitialized( MatrixType &A, const bool initialized ) noexcept;
437+
442438
protected:
443439

444440
std::pair< size_t, size_t > dims() const noexcept {
@@ -454,6 +450,15 @@ namespace alp {
454450
template< typename MatrixType >
455451
friend typename MatrixType::storage_index_type getStorageIndex( const MatrixType &A, const size_t i, const size_t j, const size_t s, const size_t P );
456452

453+
bool getInitialized() const {
454+
return static_cast< const DerivedMatrix & >( *this ).getInitialized();
455+
}
456+
457+
void setInitialized( const bool initialized ) {
458+
static_cast< DerivedMatrix & >( *this ).setInitialized( initialized );
459+
460+
}
461+
457462
template< typename AccessType, typename StorageIndexType >
458463
const AccessType access( const StorageIndexType storageIndex ) const {
459464
static_assert( std::is_same< AccessType, typename DerivedMatrix::access_type >::value );
@@ -557,13 +562,13 @@ namespace alp {
557562
return A.container;
558563
}
559564

560-
// friend bool getInitialized( self_type & A ) noexcept {
561-
// return getInitialized( getContainer( A ) );
562-
// }
565+
bool getInitialized() const noexcept {
566+
return internal::getInitialized( container );
567+
}
563568

564-
// friend void setInitialized( self_type & A, bool initialized ) noexcept {
565-
// setInitialized( getContainer( A ), initialized );
566-
// }
569+
void setInitialized( const bool initialized ) noexcept {
570+
internal::setInitialized( container , initialized );
571+
}
567572

568573
/**
569574
* Returns a constant reference to the element corresponding to
@@ -640,12 +645,23 @@ namespace alp {
640645
typedef std::pair< size_t, size_t > storage_index_type;
641646

642647
protected:
648+
649+
const bool initialized; // Temporary solution, proper implementation pending
650+
643651
ImfR imf_r;
644652
ImfC imf_c;
645653

646654
typedef std::function< Ret( Args... ) > lambda_function_type;
647655
lambda_function_type &lambda;
648656

657+
bool getInitialized() const noexcept {
658+
return initialized;
659+
}
660+
661+
void setInitialized( const bool ) noexcept {
662+
static_assert( "Calling setInitialized on a MatrixFunctor is not allowed." );
663+
}
664+
649665
access_type access( const storage_index_type &storage_index ) const {
650666
return lambda( imf_r.map( storage_index.first ), imf_c.map( storage_index.second ) );
651667
}
@@ -659,11 +675,13 @@ namespace alp {
659675
public:
660676

661677
MatrixFunctor(
678+
const bool initialized,
662679
lambda_function_type &lambda,
663680
ImfR &&imf_r,
664681
ImfC &&imf_c
665682
) :
666683
MatrixBase< MatrixFunctor< T, ImfR, ImfC, Ret, Args... > >( imf_r.N, imf_c.N ),
684+
initialized( initialized ),
667685
lambda( lambda ) {}
668686

669687
}; // class MatrixFunctor
@@ -1645,6 +1663,16 @@ namespace alp {
16451663
/** Definitions of previously declared global methods that operate on ALP Matrix */
16461664
namespace internal {
16471665

1666+
template< typename MatrixType >
1667+
bool getInitialized( const MatrixType &A ) noexcept {
1668+
return static_cast< const MatrixBase< typename MatrixType::base_type > >( A ).template getInitialized();
1669+
}
1670+
1671+
template< typename MatrixType >
1672+
void setInitialized( MatrixType &A, const bool initialized ) noexcept {
1673+
return static_cast< MatrixBase< typename MatrixType::base_type > >( A ).template setInitialized( initialized );
1674+
}
1675+
16481676
template< typename DerivedMatrix >
16491677
std::pair< size_t, size_t > dims( const MatrixBase< DerivedMatrix > & A ) noexcept {
16501678
return A.dims();

include/alp/reference/vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace alp {
6161
const bool & getInitialized( const Vector< T, reference > & v ) noexcept;
6262

6363
template< typename T >
64-
void setInitialized( Vector< T, reference > & v, bool initialized ) noexcept;
64+
void setInitialized( Vector< T, reference > & v, const bool initialized ) noexcept;
6565

6666

6767
/**

0 commit comments

Comments
 (0)