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
26 changes: 20 additions & 6 deletions include/alp/reference/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,20 @@ namespace alp {
>::amf_type type;
};

/** Specialization for containers that allocate storage */
template< typename Structure, typename ImfC, enum Backend backend, typename Lambda >
struct determine_amf_type< Structure, view::Functor< Lambda >, imf::Id, ImfC, backend > {

static_assert(
std::is_same< ImfC, imf::Id >::value || std::is_same< ImfC, imf::Zero >::value,
"Incompatible combination of parameters provided to determine_amf_type."
);

typedef typename storage::AMFFactory::FromPolynomial<
storage::polynomials::None_type
>::amf_type type;
};

} // namespace internal

/**
Expand Down Expand Up @@ -1117,7 +1131,7 @@ namespace alp {
> * = nullptr
>
Matrix( std::function< bool() > initialized, const size_t rows, const size_t cols, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, rows, cols, lambda ) {}
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, imf::Id( rows ), imf::Id( cols ), lambda ) {}

/**
* Constructor for a view over another functor-based matrix.
Expand Down Expand Up @@ -1321,8 +1335,8 @@ namespace alp {
internal::requires_allocation< ViewType >::value
> * = nullptr
>
Matrix( bool initialized, const size_t dim, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, dim, dim, lambda ) {}
Matrix( std::function< bool() > initialized, const size_t dim, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, imf::Id( dim ), imf::Id( dim ), lambda ) {}

/**
* Constructor for a view over another functor-based matrix.
Expand Down Expand Up @@ -1499,7 +1513,7 @@ namespace alp {
> * = nullptr
>
Matrix( std::function< bool() > initialized, const size_t dim, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, dim, dim, lambda ) {}
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, imf::Id( dim ), imf::Id( dim ), lambda ) {}

/**
* Constructor for a view over another functor-based matrix.
Expand Down Expand Up @@ -1691,8 +1705,8 @@ namespace alp {
internal::requires_allocation< ViewType >::value
> * = nullptr
>
Matrix( bool initialized, const size_t dim, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, dim, lambda ) {}
Matrix( std::function< bool() > initialized, const size_t dim, typename ViewType::applied_to lambda ) :
internal::FunctorBasedMatrix< T, ImfR, ImfC, typename View::applied_to >( initialized, imf::Id( dim ), imf::Id( dim ), lambda ) {}

/**
* Constructor for a view over another functor-based matrix.
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ add_grb_executables( dense_mxm dense_mxm.cpp
BACKENDS alp_reference
)

# Temporarily disable until views on functor-based containers are fully functional
#add_grb_executables( dense_outer dense_outer.cpp
# BACKENDS alp_reference
#)
add_grb_executables( dense_outer dense_outer.cpp
BACKENDS alp_reference
)

add_grb_executables( dense_structured_matrix dense_structured_matrix.cpp
BACKENDS alp_reference
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/dense_outer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void outer_stdvec_as_matrix(
const Operator oper
) {

print_stdvec_as_matrix("vA", vA, n, 1, 1);
print_stdvec_as_matrix("vA", vA, m, 1, 1);
print_stdvec_as_matrix("vB", vB, 1, n, n);
print_stdvec_as_matrix("vC - PRE", vC, m, n, n);

Expand Down Expand Up @@ -129,13 +129,18 @@ void alpProgram( const size_t &n, alp::RC &rc ) {

alp::Semiring< alp::operators::add< T >, alp::operators::mul< T >, alp::identities::zero, alp::identities::one > ring;

T one = ring.getOne< T >();
T zero = ring.getZero< T >();

// allocate
const size_t m = 2 * n;
std::vector< T > u_data( m, one );
std::vector< T > v_data( n, one );
std::vector< T > u_data( m );
for( size_t i = 0; i < u_data.size(); ++i ) {
u_data[ i ] = i + 1;
}
std::vector< T > v_data( n );
for( size_t i = 0; i < v_data.size(); ++i ) {
v_data[ i ] = i + 1;
}
std::vector< T > M_data( n, zero );

alp::Vector< T > u( m );
Expand All @@ -153,14 +158,16 @@ void alpProgram( const size_t &n, alp::RC &rc ) {

std::cout << "Is uvT initialized after initializing source containers? " << alp::internal::getInitialized( uvT ) << "\n";

print_matrix( "uvT", uvT );

std::vector< T > uvT_test( m * n, zero );
outer_stdvec_as_matrix( uvT_test, n, u_data, v_data, m, n, ring.getMultiplicativeOperator() );
diff_stdvec_matrix( uvT_test, m, n, n, uvT );

// Example when outer product takes the same vector as both inputs.
// This operation results in a symmetric positive definite matrix.
auto vvT = alp::outer( v, ring.getMultiplicativeOperator() );
print_matrix( "vvT", uvT );
print_matrix( "vvT", vvT );

std::vector< T > vvT_test( n * n, zero );
outer_stdvec_as_matrix( vvT_test, n, v_data, v_data, n, n, ring.getMultiplicativeOperator() );
Expand Down