Unless otherwise noted, all types described in this section live in
the vsip_csl::expr namespace.
Description. A Unary functor computes a result block from a single argument block. It is most frequently used in conjunction with the Unary template to represent non-elementwise unary block expressions.
Valid expressions.
| Expression | Requirements | Semantics |
|---|---|---|
| F<B> | B is a valid Block model. | F needs to be instantiable with arbitrary block types. |
| F<B>::dim | The dimensionality of the result block | |
| F<B>::result_type | The value-type of the result block | |
| F<B>::map_type | The map-type of the result block | |
| f.arg() | Return a const reference to the argument block. | |
| f.size() | Return the total size of the result block. | |
| f.size(X, d) | Return the size of the result block. | |
| f.map() | Return the map of the result block. | |
| f.apply(result) | Apply the functor, and store the result in result. |
Description. A Unary block is an expression block with a single argument block. It models the Block concept.
template <template <typename> class Operation,
typename ArgumentBlock,
bool Elementwise = false>
class Unary;Template parameters.
If Elementwise == true,
a model of the ElementwiseUnaryFunctor concept,
otherwise a model of the
UnaryFunctor concept
The interface (and implementation) of the Unary template depends slightly on whether the expression is element-wise. Thus two specializations are provided.
template <template <typename> class Operation, typename Block>
class Unary<Operation, Block, true>
{
public:
Unary(Block const &);
Unary(Operation<Block> const &, Block const &);
operation_type const &operation() const;
Block const &arg() const;
};template <template <typename> class Operation, typename Block>
class Unary<Operation, Block, false>
{
public:
Unary(Operation<Block> const &);
operation_type const &operation() const;
Block const &arg() const;
void evaluate() const;
template <typename ResultBlock>
void apply(ResultBlock &result) const;
};Member functions.
Return the operation associated with this expression.
Return the argument block associated with this expression.
Evaluate the operation, storing the result in the state of this expression block.
Evaluate the operation, storing the result in the provided block argument.
Description. Unary_functor models the UnaryFunctor concept. To use it, derive from it and provide an apply() that performs the desired operation.
template <typename ArgumentBlockType>
class Unary_functor
{
public:
Unary_functor(ArgumentBlockType const &);
template <typename ResultBlockType>
void apply(ResultBlockType &r) const {} // implement in derived class
};Example 6.4. Use of Unary_functor
template <typename ArgumentBlockType>
struct Operation : Unary_functor<ArgumentBlockType>
{
Operation(ArgumentBlockType const &arg)
: Unary_functor<ArgumentBlockType>(arg) {}
template <typename ResultBlockType>
void apply(ResultBlockType &result) const
{ compute(result, this->arg());}
};
// Implement 'operate' as a lazy function
template <typename T, typename BlockType>
lazy_Vector<T, Unary<Operation, BlockType> const>
operate(const_Vector<T, BlockType> input)
{
Operation<BlockType> operation(input.block());
Unary<Operation, BlockType> block(operation);
return lazy_Vector<T, Unary<Operation, BlockType> const>(block);
};Description. A Binary functor computes a result block from two argument blocks. It is most frequently used in conjunction with the Binary template to represent non-elementwise binary block expressions.
Valid expressions.
| Expression | Requirements | Semantics |
|---|---|---|
| F<B1, B2> | B1 and B2 are valid Block models. | F needs to be instantiable with arbitrary block types. |
| F<B1, B2>::dim | The dimensionality of the result block | |
| F<B1, B2>::result_type | The value-type of the result block | |
| F<B1, B2>::map_type | The map-type of the result block | |
| f.arg1(), f.arg2() | Return const references to the argument blocks. | |
| f.size() | Return the total size of the result block. | |
| f.size(X, d) | Return the size of the result block. | |
| f.map() | Return the map of the result block. | |
| f.apply(result) | Apply the functor, and store the result in result. |
Description. A Binary block is an expression block with two argument blocks. It models the Block concept.
template <template <typename, typename> class Operation,
typename Argument1Block, typename Argument2Block,
bool Elementwise = false>
class Binary;Template parameters.
If Elementwise == true,
a model of the ElementwiseBinaryFunctor concept,
otherwise a model of the
BinaryFunctor concept
The interface (and implementation) of the Binary template depends slightly on whether the expression is element-wise. Thus two specializations are provided.
template <template <typename, typename> class Operation,
typename Arg1, typename Arg2>
class Binary<Operation, Arg1, Arg2, true>
{
public:
Unary(Arg1 const &, Arg2 const &);
Unary(Operation<Arg1, Arg2> const &, Arg1 const &, Arg2 const &);
operation_type const &operation() const;
Arg1 const &arg1() const;
Arg2 const &arg2() const;
};template <template <typename, typename> class Operation,
typename Arg1, typename Arg2>
class Binary<Operation, Arg1, Arg2, false>
{
public:
Binary(Operation<Arg1, Arg2> const &);
operation_type const &operation() const;
Arg1 const &arg1() const;
Arg2 const &arg2() const;
void evaluate() const;
template <typename ResultBlock>
void apply(ResultBlock &result) const;
};Member functions.
Return the operation associated with this expression.
Return the argument blocks associated with this expression.
Evaluate the operation, storing the result in the state of this expression block.
Evaluate the operation, storing the result in the provided block argument.