Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/alp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
// #include <alp/ops.hpp>
// #include <alp/pinnedvector.hpp>
// #include <alp/properties.hpp>
#include <alp/rels.hpp>
// #include <alp/semiring.hpp>
// #include <alp/spmd.hpp>

Expand Down
1 change: 1 addition & 0 deletions include/alp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ set( root_files
"ops.hpp"
"phase.hpp"
"rc.hpp"
"rels.hpp"
"scalar.hpp"
"semiring.hpp"
"storage.hpp"
Expand Down
21 changes: 5 additions & 16 deletions include/alp/algorithms/symm_tridiag_eigensolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// TEMPDISABLE should be removed in the final version
#define TEMPDISABLE


namespace alp {

namespace algorithms {
Expand Down Expand Up @@ -484,24 +485,12 @@ namespace alp {
print_vector( " z ", z );
#endif

// permutations which sort dtmp
std::vector< size_t > isort_dtmp( n, 0 );
std::vector< size_t > no_permute_data( n, 0 );
for( size_t i = 0; i < n; ++i ) {
isort_dtmp[ i ] = i;
no_permute_data[ i ] = i;
}
std::sort(
isort_dtmp.begin(),
isort_dtmp.end(),
[ &dtmp ]( const size_t &a, const size_t &b ) {
return ( dtmp[ a ] < dtmp[ b ] );
}
);
// permutation that sorts dtmp
alp::Vector< size_t > permutation_vec( n );
rc = rc ? rc : alp::sort( permutation_vec, dtmp, alp::relations::lt< D >() );

alp::Vector< size_t > no_permutation_vec( n );
alp::buildVector( permutation_vec, isort_dtmp.begin(), isort_dtmp.end() );
alp::buildVector( no_permutation_vec, no_permute_data.begin(), no_permute_data.end() );
rc = rc ? rc : alp::set< alp::descriptors::use_index >( no_permutation_vec, alp::Scalar< size_t >( 0 ) );

auto dtmp2 = alp::get_view< alp::structures::General >(
dtmp,
Expand Down
253 changes: 245 additions & 8 deletions include/alp/amf-based/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,38 @@ namespace alp {
return getInitialized( static_cast< const typename alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend >::base_type & >( v ) );
}

template< typename T, typename Structure, typename View, typename ImfR, typename ImfC, enum Backend backend >
void setInitialized( alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > & v, bool initialized ) noexcept {
template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
void setInitialized(
alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > &v, bool initialized
) noexcept {
setInitialized( static_cast< typename alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend >::base_type &>( v ), initialized );
}

template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
typename alp::Vector<
T, Structure, Density::Dense, View, ImfR, ImfC, backend
>::iterator
begin(
alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > &v
) noexcept;

template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
typename alp::Vector<
T, Structure, Density::Dense, View, ImfR, ImfC, backend
>::iterator
end(
alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > &v
) noexcept;

} // end namespace ``alp::internal''

/**
Expand Down Expand Up @@ -95,22 +123,188 @@ namespace alp {
* accessible via functions.
*
*/
template< typename T, typename Structure, typename View, typename ImfR, typename ImfC, enum Backend backend >
template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
class Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > { };

/*
* ALP vector with a general structure
*/
template< typename T, typename View, typename ImfR, typename ImfC, enum Backend backend >
class Vector< T, structures::General, Density::Dense, View, ImfR, ImfC, backend > :
public Matrix< T, structures::General, Density::Dense, View, ImfR, ImfC, backend > {
template<
typename T, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
class Vector<
T, structures::General, Density::Dense, View, ImfR, ImfC, backend
> : public Matrix< T, structures::General, Density::Dense, View, ImfR, ImfC, backend > {

public:

typedef Vector< T, structures::General, Density::Dense, View, ImfR, ImfC, backend > self_type;
typedef Matrix< T, structures::General, Density::Dense, View, ImfR, ImfC, backend > base_type;
typedef Vector<
T, structures::General, Density::Dense,
View, ImfR, ImfC, backend
> self_type;

typedef Matrix<
T, structures::General, Density::Dense,
View, ImfR, ImfC, backend
> base_type;

private:
class VectorIterator:
public std::iterator< std::random_access_iterator_tag, T > {

friend class Vector<
T, structures::General, Density::Dense,
View, ImfR, ImfC, backend
>;

private:

typedef typename self_type::storage_index_type index_type;
typedef std::iterator<
std::random_access_iterator_tag, T
> std_base_class;

self_type *vec;
index_type position;

VectorIterator( self_type *vptr ) noexcept :
vec( vptr ), position( 0 )
{}

VectorIterator( self_type *vptr, index_type pos ) noexcept :
vec( vptr ), position( pos )
{}

bool equal( const VectorIterator &other ) const noexcept {
return ( vec == other.vec ) && ( position == other.position );
}

bool lessThen( const VectorIterator &other ) const noexcept {
return ( vec == other.vec ) && ( position < other.position );
}

public:
typedef typename std_base_class::pointer pointer;
typedef typename std_base_class::reference reference;
typedef typename std_base_class::difference_type difference_type;

/** Default constructor. */
VectorIterator() noexcept :
vec( nullptr ), position( 0 )
{}

/** Copy constructor. */
VectorIterator( const VectorIterator &other ) noexcept :
vec( other.vec ),
position( other.position )
{}

/** Move constructor. */
VectorIterator( VectorIterator &&other ) :
vec( nullptr ), position( 0 )
{
std::swap( vec, other.vec );
std::swap( position, other.position );
}

/** Copy assignment. */
VectorIterator& operator=( const VectorIterator &other ) noexcept {
vec = other.vec;
position = other.position;
return *this;
}

/** Move assignment. */
VectorIterator& operator=( VectorIterator &&other ) {
vec = nullptr;
position = 0;
std::swap( vec, other.vec );
std::swap( position, other.position );
return *this;
}

reference operator*() const {
return ( *vec )[ position ];
}

VectorIterator& operator++() {
++position;
return *this;
}

VectorIterator& operator--() {
--position;
return *this;
}

VectorIterator operator++( int ) {
return VectorIterator( vec, position++ );
}

VectorIterator operator--( int ) {
return VectorIterator( vec, position-- );
}

VectorIterator operator+( const difference_type &n ) const {
return VectorIterator( vec, ( position + n ) );
}

VectorIterator& operator+=( const difference_type &n ) {
position += n;
return *this;
}

VectorIterator operator-( const difference_type &n ) const {
return VectorIterator( vec, ( position - n ) );
}

VectorIterator& operator-=( const difference_type &n ) {
position -= n;
return *this;
}

reference operator[]( const difference_type &n ) const {
return ( *vec )[ position + n ];
}

bool operator==( const VectorIterator &other ) const {
return equal( other );
}

bool operator!=( const VectorIterator &other ) const {
return !equal( other );
}

bool operator<( const VectorIterator &other ) const {
return lessThen( other );
}

bool operator>( const VectorIterator &other ) const {
return !( lessThen( other ) || equal( other ) );
}

bool operator<=( const VectorIterator &other ) const {
return lessThen( other ) || equal( other );
}

bool operator>=( const VectorIterator &other ) const {
return !lessThen( other );
}

difference_type operator+( const VectorIterator &other ) const {
assert( other.vec == vec );
return position + other.position;
}

difference_type operator-( const VectorIterator &other ) const {
assert( other.vec == vec );
return position - other.position;
}
};

/*********************
Storage info friends
Expand All @@ -123,8 +317,21 @@ namespace alp {
return nrows( static_cast< const base_type & >( *this ) );
}

VectorIterator begin() noexcept {
return VectorIterator( this );
}

VectorIterator end() noexcept {
return VectorIterator( this, _length() );
}


public:

typedef VectorIterator iterator;

friend iterator internal::begin<>( self_type &v ) noexcept;
friend iterator internal::end<>( self_type &v ) noexcept;

/** @see Vector::value_type. */
using value_type = T;
Expand Down Expand Up @@ -307,6 +514,36 @@ namespace alp {

}; // class Vector with physical container

namespace internal {

template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
typename alp::Vector<
T, Structure, Density::Dense, View, ImfR, ImfC, backend
>::iterator
begin(
alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > &v
) noexcept {
return v.begin();
}

template<
typename T, typename Structure, typename View,
typename ImfR, typename ImfC, enum Backend backend
>
typename alp::Vector<
T, Structure, Density::Dense, View, ImfR, ImfC, backend
>::iterator
end(
alp::Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > &v
) noexcept {
return v.end();
}

} // end namespace ``alp::internal''

/** Identifies any backend's implementation of ALP vector as an ALP vector. */
template< typename T, typename Structure, typename View, typename ImfR, typename ImfC, enum Backend backend >
struct is_vector< Vector< T, Structure, Density::Dense, View, ImfR, ImfC, backend > > : std::true_type {};
Expand Down
1 change: 0 additions & 1 deletion include/alp/base/internalops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,6 @@ namespace alp {
* At the end of the operation, \f$ c = \min\{a,b\} \f$.
*/
static void apply( const left_type * __restrict__ const a, const right_type * __restrict__ const b, result_type * __restrict__ const c ) {
printf( "Hello from mul\n" );
if( *a || *b ) {
*c = static_cast< OUT >( true );
} else {
Expand Down
Loading