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
93 changes: 74 additions & 19 deletions include/alp/reference/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ namespace alp {
/** Expose static properties */

typedef T value_type;
typedef ImfR imf_r_type;
typedef ImfC imf_c_type;
/** Type returned by access function */
typedef T &access_type;
/** Type of the index used to access the physical storage */
Expand Down Expand Up @@ -799,7 +801,9 @@ namespace alp {
public std::conditional<
internal::is_view_over_functor< View >::value,
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >,
internal::StorageBasedMatrix< T, ImfR, ImfC, storage::polynomials::Full_type, internal::requires_allocation< View >::value >
internal::StorageBasedMatrix< T, ImfR, ImfC,
typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type,
internal::requires_allocation< View >::value >
>::type {

protected:
Expand All @@ -823,7 +827,7 @@ namespace alp {
public:
/** Exposes the types and the static properties. */
typedef structures::General structure;
typedef storage::polynomials::Full_type mapping_polynomial_type;
typedef typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type mapping_polynomial_type;
/**
* Indicates if a matrix needs to allocate data-related memory
* (for the internal container or functor object).
Expand Down Expand Up @@ -927,6 +931,26 @@ namespace alp {
imf::Id( nrows ( target_matrix ) ),
imf::Id( ncols ( target_matrix ) ) ) {}

/**
* Constructor for a view over another storage-based matrix.
*
* @tparam ViewType The dummy View type of the constructed matrix.
* Uses SFINAE to enable this constructor only for
* a view over a storage-based matrix.
*/
template<
typename ViewType = View,
std::enable_if_t<
internal::is_view_over_storage< ViewType >::value &&
!internal::requires_allocation< ViewType >::value
> * = nullptr
>
Matrix( typename ViewType::applied_to &target_matrix, storage::AMF< ImfR, ImfC, mapping_polynomial_type > amf ) :
internal::StorageBasedMatrix< T, ImfR, ImfC, mapping_polynomial_type, requires_allocation >(
getContainer( target_matrix ),
amf
) {}

/**
* Constructor for a functor-based matrix that allocates memory.
*
Expand Down Expand Up @@ -993,7 +1017,9 @@ namespace alp {
public std::conditional<
internal::is_view_over_functor< View >::value,
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >,
internal::StorageBasedMatrix< T, ImfR, ImfC, storage::polynomials::Full_type, internal::requires_allocation< View >::value >
internal::StorageBasedMatrix< T, ImfR, ImfC,
typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type,
internal::requires_allocation< View >::value >
>::type {

protected:
Expand All @@ -1017,7 +1043,7 @@ namespace alp {
public:
/** Exposes the types and the static properties. */
typedef structures::Square structure;
typedef storage::polynomials::Full_type mapping_polynomial_type;
typedef typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type mapping_polynomial_type;
/**
* Indicates if a matrix needs to allocate data-related memory
* (for the internal container or functor object).
Expand Down Expand Up @@ -1109,6 +1135,26 @@ namespace alp {
imf::Id( nrows ( target_matrix ) ),
imf::Id( ncols ( target_matrix ) ) ) {}

/**
* Constructor for a view over another storage-based matrix.
*
* @tparam ViewType The dummy View type of the constructed matrix.
* Uses SFINAE to enable this constructor only for
* a view over a storage-based matrix.
*/
template<
typename ViewType = View,
std::enable_if_t<
internal::is_view_over_storage< ViewType >::value &&
!internal::requires_allocation< ViewType >::value
> * = nullptr
>
Matrix( typename ViewType::applied_to &target_matrix, storage::AMF< ImfR, ImfC, mapping_polynomial_type > amf ) :
internal::StorageBasedMatrix< T, ImfR, ImfC, mapping_polynomial_type, requires_allocation >(
getContainer( target_matrix ),
amf
) {}

/**
* Constructor for a functor-based matrix that allocates memory.
*/
Expand Down Expand Up @@ -1163,7 +1209,9 @@ namespace alp {
public std::conditional<
internal::is_view_over_functor< View >::value,
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >,
internal::StorageBasedMatrix< T, ImfR, ImfC, storage::polynomials::Full_type, internal::requires_allocation< View >::value >
internal::StorageBasedMatrix< T, ImfR, ImfC,
typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type,
internal::requires_allocation< View >::value >
>::type {

protected:
Expand All @@ -1187,7 +1235,7 @@ namespace alp {
public:
/** Exposes the types and the static properties. */
typedef structures::Symmetric structure;
typedef storage::polynomials::Full_type mapping_polynomial_type;
typedef typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type mapping_polynomial_type;
/**
* Indicates if a matrix needs to allocate data-related memory
* (for the internal container or functor object).
Expand Down Expand Up @@ -1333,7 +1381,9 @@ namespace alp {
public std::conditional<
internal::is_view_over_functor< View >::value,
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >,
internal::StorageBasedMatrix< T, ImfR, ImfC, storage::polynomials::Full_type, internal::requires_allocation< View >::value >
internal::StorageBasedMatrix< T, ImfR, ImfC,
typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type,
internal::requires_allocation< View >::value >
>::type {

protected:
Expand All @@ -1357,7 +1407,7 @@ namespace alp {
public:
/** Exposes the types and the static properties. */
typedef structures::UpperTriangular structure;
typedef storage::polynomials::Full_type mapping_polynomial_type;
typedef typename storage::polynomials::apply_view< View::type_id, storage::polynomials::Full_type >::type mapping_polynomial_type;
/**
* Indicates if a matrix needs to allocate data-related memory
* (for the internal container or functor object).
Expand Down Expand Up @@ -1592,12 +1642,13 @@ namespace alp {
*
*/
template<
typename T, typename Structure, enum Density density, typename View, typename ImfR, typename ImfC, enum Backend backend >
typename Matrix< T, Structure, density, View, ImfR, ImfC, backend >::template view_type< view::original >::type
get_view( Matrix< T, Structure, density, View, ImfR, ImfC, backend > & source ) {
typename SourceMatrixType,
std::enable_if_t< is_matrix< SourceMatrixType >::value, void > * = nullptr
>
typename SourceMatrixType::template view_type< view::original >::type
get_view( SourceMatrixType &source ) {

using source_strmat_t = Matrix< T, Structure, density, View, ImfR, ImfC, backend >;
using target_strmat_t = typename source_strmat_t::template view_type< view::original >::type;
using target_strmat_t = typename SourceMatrixType::template view_type< view::original >::type;

target_strmat_t target( source );

Expand Down Expand Up @@ -1635,14 +1686,18 @@ namespace alp {
*/
template<
enum view::Views target_view,
typename T, typename Structure, enum Density density, typename View, typename ImfR, typename ImfC, enum Backend backend >
typename Matrix< T, Structure, density, View, ImfR, ImfC, backend >::template view_type< target_view >::type
get_view( Matrix< T, Structure, density, View, ImfR, ImfC, backend > &source ) {
typename SourceMatrixType,
std::enable_if_t< is_matrix< SourceMatrixType >::value, void > * = nullptr
>
typename SourceMatrixType::template view_type< target_view >::type
get_view( SourceMatrixType &source ) {

using source_strmat_t = Matrix< T, Structure, density, View, ImfR, ImfC, backend >;
using target_strmat_t = typename source_strmat_t::template view_type< target_view >::type;
using target_strmat_t = typename SourceMatrixType::template view_type< target_view >::type;

target_strmat_t target( source );
target_strmat_t target(
source,
storage::AMFFactory::Transform< target_view, decltype( source.amf ) >::Create( source.amf )
);

return target;
}
Expand Down
25 changes: 25 additions & 0 deletions include/alp/reference/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <alp/imf.hpp>
#include <alp/matrix.hpp>
#include <alp/density.hpp>
#include <alp/storage.hpp>
#include <alp/views.hpp>

#include <alp/base/vector.hpp>
Expand Down Expand Up @@ -465,6 +466,30 @@ namespace alp {
Vector( typename ViewType::applied_to &vec_view ) :
base_type( vec_view ) {}

/**
* Constructor for a view over another storage-based vector.
*
* @tparam ViewType The dummy View type of the constructed vector.
* Uses SFINAE to enable this constructor only for
* a view over a storage-based vector.
*/
template<
typename ViewType = View,
typename std::enable_if_t<
internal::is_view_over_storage< ViewType >::value &&
!internal::requires_allocation< ViewType >::value
> * = nullptr
>
Vector(
typename ViewType::applied_to &vec_view,
storage::AMF<
typename base_type::imf_r_type,
typename base_type::imf_c_type,
typename base_type::mapping_polynomial_type
> amf
) :
base_type( vec_view, amf ) {}

/**
* Constructor for a functor-based vector that allocates memory.
*
Expand Down
Loading