piranha  0.10
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
piranha::series_multiplier< Series, detail::divisor_series_multiplier_enabler< Series > > Class Template Reference

Specialisation of piranha::series_multiplier for piranha::divisor_series. More...

#include <piranha/divisor_series.hpp>

Inheritance diagram for piranha::series_multiplier< Series, detail::divisor_series_multiplier_enabler< Series > >:
Inheritance graph
[legend]
Collaboration diagram for piranha::series_multiplier< Series, detail::divisor_series_multiplier_enabler< Series > >:
Collaboration graph
[legend]

Public Types

using v_ptr = std::vector< typename Series::term_type const * >
 Alias for a vector of const pointers to series terms.
 
using size_type = typename v_ptr::size_type
 The size type of base_series_multiplier::v_ptr.
 
using bucket_size_type = typename Series::size_type
 The size type of Series.
 

Public Member Functions

template<typename T = Series, call_enabler< T > = 0>
Series operator() () const
 Call operator. More...
 

Protected Member Functions

template<typename MultFunctor , typename LimitFunctor >
void blocked_multiplication (const MultFunctor &mf, const size_type &start1, const size_type &end1, const LimitFunctor &lf) const
 Blocked multiplication. More...
 
template<typename MultFunctor >
void blocked_multiplication (const MultFunctor &mf, const size_type &start1, const size_type &end1) const
 Blocked multiplication (convenience overload). More...
 
template<std::size_t MultArity, typename MultFunctor , typename LimitFunctor >
bucket_size_type estimate_final_series_size (const LimitFunctor &lf) const
 Estimate size of series multiplication. More...
 
template<std::size_t MultArity, typename MultFunctor >
bucket_size_type estimate_final_series_size () const
 Estimate size of series multiplication (convenience overload) More...
 
template<typename LimitFunctor >
Series plain_multiplication (const LimitFunctor &lf) const
 A plain series multiplication routine. More...
 
Series plain_multiplication () const
 A plain series multiplication routine (convenience overload). More...
 
void finalise_series (Series &s) const
 Finalise series. More...
 

Static Protected Member Functions

static void sanitise_series (Series &retval, unsigned n_threads)
 Sanitise series. More...
 

Protected Attributes

v_ptr m_v1
 Vector of const pointers to the terms in the larger series.
 
v_ptr m_v2
 Vector of const pointers to the terms in the smaller series.
 
const symbol_fset m_ss
 The symbol set of the series used during construction.
 
unsigned m_n_threads
 Number of threads. More...
 

Detailed Description

template<typename Series>
class piranha::series_multiplier< Series, detail::divisor_series_multiplier_enabler< Series > >

Specialisation of piranha::series_multiplier for piranha::divisor_series.

Definition at line 568 of file divisor_series.hpp.

Member Function Documentation

◆ blocked_multiplication() [1/2]

template<typename Series >
template<typename MultFunctor , typename LimitFunctor >
void piranha::base_series_multiplier< Series >::blocked_multiplication ( const MultFunctor &  mf,
const size_type start1,
const size_type end1,
const LimitFunctor &  lf 
) const
inlineprotectedinherited

Blocked multiplication.

Note
If MultFunctor or LimitFunctor do not satisfy the requirements outlined below, a compile-time error will be produced.

This method is logically equivalent to the following double loop:

for (size_type i = start1; i < end1; ++i) {
const size_type limit = std::min(lf(i),m_v2.size());
for (size_type j = 0; j < limit; ++j) {
mf(i,j);
}
}

mf must be a function object with a call operator accepting two instances of base_series_multiplier::size_type and returning void. lf must be a function object with a call operator accepting and returning a base_series_multiplier::size_type.

Internally, the double loops is decomposed in blocks of size tuning::get_multiplication_block_size() in an attempt to optimise cache memory access patterns.

This method is meant to be used for series multiplication. mf is intended to be a function object that multiplies the i-th term of the first series by the j-th term of the second series. lf is intended to be a functor that establishes how many terms in the second series have to be multiplied by the i-th term of the first series.

Parameters
mfthe multiplication functor.
start1start index in the first series.
end1end index in the first series.
lfthe limit functor.
Exceptions
std::invalid_argumentif start1 is greater than end1 or greater than the size of base_series_multiplier::m_v1, or if end1 is greater than the size of base_series_multiplier::m_v1.
unspecifiedany exception thrown by the call operator of mf or sf, or piranha::safe_cast.

Definition at line 442 of file base_series_multiplier.hpp.

◆ blocked_multiplication() [2/2]

template<typename Series >
template<typename MultFunctor >
void piranha::base_series_multiplier< Series >::blocked_multiplication ( const MultFunctor &  mf,
const size_type start1,
const size_type end1 
) const
inlineprotectedinherited

Blocked multiplication (convenience overload).

This method is equivalent to the other overload with a limit functor that will unconditionally always return the size of the second series.

Parameters
mfthe multiplication functor.
start1start index in the first series.
end1end index in the first series.
Exceptions
unspecifiedany exception thrown by the other overload.

Definition at line 509 of file base_series_multiplier.hpp.

◆ estimate_final_series_size() [1/2]

template<typename Series >
template<std::size_t MultArity, typename MultFunctor , typename LimitFunctor >
bucket_size_type piranha::base_series_multiplier< Series >::estimate_final_series_size ( const LimitFunctor &  lf) const
inlineprotectedinherited

Estimate size of series multiplication.

Note
If MultArity, MultFunctor or LimitFunctor do not satisfy the requirements outlined below, a compile-time error will be produced.

This method expects a MultFunctor type exposing the same inteface as explained in blocked_multiplication(). Additionally, MultFunctor must be constructible from a const reference to piranha::base_series_multiplier and a mutable reference to Series. MultFunctor objects will be constructed internally by this method, passing this and a temporary local Series object as construction parameters. It will be assumed that a call mf(i,j) multiplies the i-th term of the first series by the j-th term of the second series, accumulating the result into the Series passed as second parameter for construction.

This method will apply a statistical approach to estimate the final size of the result of the multiplication of the first series by the second. It will perform random term-by-term multiplications and deduce the estimate from the number of term multiplications performed before finding the first duplicate term. The MultArity parameter represents the arity of term multiplications - that is, the number of terms generated by a single term-by-term multiplication. It must be strictly positive.

The lf parameter must be a function object exposing the same inteface as explained in blocked_multiplication(). This functor establishes how many terms in the second series must be multiplied by the i-th term of the first series.

The number returned by this function is always at least 1. Multiple threads might be used by this method: in such a case, different instances of MultFunctor are constructed in different threads, but lf is shared among all threads.

Parameters
lfthe limit functor.
Returns
the estimated size of the multiplication of the first series by the second, always at least 1.
Exceptions
std::overflow_errorin case of (unlikely) overflows in integral arithmetics.
unspecifiedany exception thrown by:

Definition at line 556 of file base_series_multiplier.hpp.

◆ estimate_final_series_size() [2/2]

template<typename Series >
template<std::size_t MultArity, typename MultFunctor >
bucket_size_type piranha::base_series_multiplier< Series >::estimate_final_series_size ( ) const
inlineprotectedinherited

Estimate size of series multiplication (convenience overload)

Returns
the output of the other overload of estimate_final_series_size(), with a limit functor whose call operator will always return the size of the second series unconditionally.
Exceptions
unspecifiedany exception thrown by the other overload of estimate_final_series_size().

Definition at line 719 of file base_series_multiplier.hpp.

◆ finalise_series()

template<typename Series >
void piranha::base_series_multiplier< Series >::finalise_series ( Series &  s) const
inlineprotectedinherited

Finalise series.

This method will finalise the output s of a series multiplication undertaken via piranha::base_series_multiplier. Currently, this method will not do anything unless the coefficient type of Series is an instance of piranha::mp_rational. In this case, the coefficients of s will be normalised with respect to the least common multiplier computed in the constructor of piranha::base_series_multiplier.

Parameters
sthe Series to be finalised.
Exceptions
unspecifiedany exception thrown by:

Definition at line 1120 of file base_series_multiplier.hpp.

◆ operator()()

template<typename Series >
template<typename T = Series, call_enabler< T > = 0>
Series piranha::series_multiplier< Series, detail::divisor_series_multiplier_enabler< Series > >::operator() ( ) const
inline

Call operator.

Note
This operator is enabled only if the coefficient and key types of Series satisfy piranha::key_is_multipliable.

The call operator will use base_series_multiplier::plain_multiplication().

Returns
the result of the multiplication.
Exceptions
unspecifiedany exception thrown by base_series_multiplier::plain_multiplication().

Definition at line 592 of file divisor_series.hpp.

◆ plain_multiplication() [1/2]

template<typename Series >
template<typename LimitFunctor >
Series piranha::base_series_multiplier< Series >::plain_multiplication ( const LimitFunctor &  lf) const
inlineprotectedinherited

A plain series multiplication routine.

Note
If the key and coefficient types of Series do not satisfy piranha::key_is_multipliable, or LimitFunctor does not satisfy the requirements outlined in base_series_multiplier::blocked_multiplication(), a compile-time error will be produced.

This method implements a generic series multiplication routine suitable for key types that satisfy piranha::key_is_multipliable. The implementation is either single-threaded or multi-threaded, depending on the sizes of the input series, and it will use either base_series_multiplier::plain_multiplier or a similar thread-safe multiplier for the term-by-term multiplications. The lf functor will be forwarded as limit functor to base_series_multiplier::blocked_multiplication() and base_series_multiplier::estimate_final_series_size().

Note that, in multithreaded mode, lf will be shared among (and called concurrently from) all the threads.

Parameters
lfthe limit functor (see base_series_multiplier::blocked_multiplication()).
Returns
the series resulting from the multiplication of the two series used to construct this.
Exceptions
unspecifiedany exception thrown by:

Definition at line 978 of file base_series_multiplier.hpp.

◆ plain_multiplication() [2/2]

template<typename Series >
Series piranha::base_series_multiplier< Series >::plain_multiplication ( ) const
inlineprotectedinherited

A plain series multiplication routine (convenience overload).

Returns
the output of the other overload of plain_multiplication(), with a limit functor whose call operator will always return the size of the second series unconditionally.
Exceptions
unspecifiedany exception thrown by the other overload of plain_multiplication().

Definition at line 1100 of file base_series_multiplier.hpp.

◆ sanitise_series()

template<typename Series >
static void piranha::base_series_multiplier< Series >::sanitise_series ( Series &  retval,
unsigned  n_threads 
)
inlinestaticprotectedinherited

Sanitise series.

When using the low-level interface of piranha::hash_set for term insertion, invariants might be violated both in piranha::hash_set and piranha::series. In particular:

  • terms may not be checked for compatibility or for being zero upon insertion,
  • the count of elements in piranha::hash_set might not be updated.

This method can be used to fix these invariants: it will check whether each term of retval is incompatible and/or zero, and the total count of terms in the series will be set to the number of nonzero terms. Zero terms will be erased.

Note that in case of exceptions retval will likely be left in an inconsistent state which violates internal invariants. Calls to this function should always be wrapped in a try/catch block that makes sure that retval is cleared before re-throwing.

Parameters
retvalthe series to be sanitised.
n_threadsthe number of threads to be used.
Exceptions
std::invalid_argumentif n_threads is zero, or if one of the terms in retval is not compatible with the symbol set of retval.
std::overflow_errorif the number of terms in retval overflows the maximum value representable by base_series_multiplier::bucket_size_type.
unspecifiedany exception thrown by:

Definition at line 845 of file base_series_multiplier.hpp.

Member Data Documentation

◆ m_n_threads

template<typename Series >
unsigned piranha::base_series_multiplier< Series >::m_n_threads
protectedinherited

Number of threads.

This value will be set by the constructor, and it represents the number of threads that will be used by the multiplier. The value is always at least 1 and it is calculated via thread_pool::use_threads().

Definition at line 1138 of file base_series_multiplier.hpp.


The documentation for this class was generated from the following file: