6.6. Expression block types

Unless otherwise noted, all types described in this section live in the vsip_csl::expr namespace.

6.6.1. The UnaryFunctor concept

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. 

ExpressionRequirementsSemantics
F<B>B is a valid Block model.F needs to be instantiable with arbitrary block types.
F<B>::dimThe dimensionality of the result block
F<B>::result_typeThe value-type of the result block
F<B>::map_typeThe 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.

6.6.2. The Unary class template

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. 

Operation

If Elementwise == true, a model of the ElementwiseUnaryFunctor concept, otherwise a model of the UnaryFunctor concept

ArgumentBlock

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. 

operation()

Return the operation associated with this expression.

arg()

Return the argument block associated with this expression.

evaluate()

Evaluate the operation, storing the result in the state of this expression block.

apply()

Evaluate the operation, storing the result in the provided block argument.

6.6.3. The Unary_functor class template

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);
};

6.6.4. The BinaryFunctor concept

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. 

ExpressionRequirementsSemantics
F<B1, B2>B1 and B2 are valid Block models.F needs to be instantiable with arbitrary block types.
F<B1, B2>::dimThe dimensionality of the result block
F<B1, B2>::result_typeThe value-type of the result block
F<B1, B2>::map_typeThe 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.

6.6.5. The Binary class template

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. 

Operation

If Elementwise == true, a model of the ElementwiseBinaryFunctor concept, otherwise a model of the BinaryFunctor concept

Argument1Block, Argument2Block

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. 

operation()

Return the operation associated with this expression.

arg1(), arg2()

Return the argument blocks associated with this expression.

evaluate()

Evaluate the operation, storing the result in the state of this expression block.

apply()

Evaluate the operation, storing the result in the provided block argument.