Adding a reduction to VecTcl.

jima
Published

Goal.

To have a new reduction function in VecTcl called prod.

This new function will work in a similar way to sum but using the product instead of the addition as the reduction function.

Places that need to be touched.

  • vectclInt.h

Add the following declaration before the final #endif.

SUBCOMMAND(NumArrayProdCmd);
  • vectcl.tcl.c

This file shall be expanded in the build process to vectcl.c.

Add the following inside the implementationMap definition, hopefully inside the reductions section:

static const EnsembleMap implementationMap[] = {
...
/* Reductions */
    {"prod", NumArrayProdCmd, NULL},
...
};

Add in an independent section:

#define CMD NumArrayProd
#define INIT ;
#define FIRST accum=op;
#define INTOP accum*=op;
#define DBLOP accum*=op;
#define CPLXOP accum=NumArray_ComplexMultiply(accum, op);
#define RETURN ;
#include "reduction.h"

Customarily, that might go before the final definition:

int Vectcl_Init(Tcl_Interp* interp) {...};

Build.

The usual:

make
make install

Test.

The expected:

package require vectcl
set x {1 2 3 4}
vectcl::vexpr {prod(x)}

Should give 24.