diff --git a/include/alp/reference/matrix.hpp b/include/alp/reference/matrix.hpp index 8b946ed56..bbc140a8a 100644 --- a/include/alp/reference/matrix.hpp +++ b/include/alp/reference/matrix.hpp @@ -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 /** @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 70eeb1121..eceae4497 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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 diff --git a/tests/unit/dense_outer.cpp b/tests/unit/dense_outer.cpp index 2280ecac0..6640e26e4 100644 --- a/tests/unit/dense_outer.cpp +++ b/tests/unit/dense_outer.cpp @@ -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); @@ -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 ); @@ -153,6 +158,8 @@ 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 ); @@ -160,7 +167,7 @@ void alpProgram( const size_t &n, alp::RC &rc ) { // 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() );