vprod

Functions

int main(int argc, char *argv[])

vprod [ option ] [ infile ]

  • -l int

    • length of vector (1L)

  • -m int

    • order of vector (0L1)

  • -t int

    • output interval (1T)

  • -c

    • cumulative mode

  • infile str

    • double-type vectors

  • stdout

    • double-type product

The input of this command is

x1(1),,x1(L)L,x2(1),,x2(L)L,,
and the output is
p0(1),,p0(L)L,pT(1),,pT(L)L,,
where
pt(l)=τ=1Txt+τ(l).
If T is not given, the product of the whole input is computed.

echo 1 2 3 4 5 | x2x +ad | vprod | x2x +da
# 120
echo 2 3 4 5 | x2x +ad | vprod -c -t 1 | x2x +da
# 2
# 6
# 24
# 120
Parameters:
  • argc[in] Number of arguments.

  • argv[in] Argument vector.

Returns:

0 on success, 1 on failure.

See also

vsum vstat

class ProductAccumulation

Accumulate product of input vectors.

The input of is an M-th order vector:

xt(0),xt(1),,xt(M).
After running Run T times, the following statistics are obtained:
P0=T,P1(m)=t=0T1xt(m).

Public Functions

explicit ProductAccumulation(int num_order, bool numerically_stable = false)
Parameters:
  • num_order[in] Order of vector, M.

  • numerically_stable[in] If true, use a numerically stable algorithm.

inline int GetNumOrder() const
Returns:

Order of vector.

inline bool IsValid() const
Returns:

True if this object is valid.

bool GetNumData(const ProductAccumulation::Buffer &buffer, int *num_data) const
Parameters:
  • buffer[in] Buffer.

  • num_data[out] Number of accumulated data.

Returns:

True on success, false on failure.

bool GetProduct(const ProductAccumulation::Buffer &buffer, std::vector<double> *product) const
Parameters:
  • buffer[in] Buffer.

  • product[out] Product of accumulated data.

Returns:

True on success, false on failure.

bool GetGeometricMean(const ProductAccumulation::Buffer &buffer, std::vector<double> *mean) const
Parameters:
  • buffer[in] Buffer.

  • mean[out] Geometric mean of accumulated data.

Returns:

True on success, false on failure.

void Clear(ProductAccumulation::Buffer *buffer) const

Clear buffer.

Parameters:

buffer[inout] Buffer.

bool Run(const std::vector<double> &data, ProductAccumulation::Buffer *buffer) const

Accumulate product.

Parameters:
  • data[in] M-th order input vector.

  • buffer[inout] Buffer.

Returns:

True on success, false on failure.

class Buffer

Buffer for ProductAccumulation class.