Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels

Overview

Calculates the unscaled area under a fourth order polynomial using the rectangular method. The result is the sum of y-values. To get the area, multiply by the rectangle/bin width.

Expressed as a formula, this function calculates $ \sum f(x) = \sum (c_0 + c_1 \cdot x + c_2 \cdot x^2 + c_3 \cdot x^3 + c_4 \cdot x^4)$

Dispatcher Prototype

void volk_32f_x3_sum_of_poly_32f(float* target, float* src0, float* center_point_array,
float* cutoff, unsigned int num_points)

Inputs

  • src0: x values
  • center_point_array: polynomial coefficients in order {c1, c2, c3, c4, c0}
  • cutoff: the minimum x value to use (will clamp to cutoff if input < cutoff)
  • num_points: The number of values in both input vectors.

Outputs

  • complexVector: The sum of y values generated by polynomial.

Example The following estimates $\int_0^\pi e^x dx$ by using the Taylor expansion centered around $x=1.5$, $ e^x = e^1.5 * (1 + x + \frac{1}{2} x^2 + \frac{1}{6}x^3 + \frac{1}{24}x^4) $

int npoints = 4096;
float* coefficients = (float*)volk_malloc(sizeof(float) * 5, volk_get_alignment());
float* input = (float*)volk_malloc(sizeof(float) * npoints,
volk_get_alignment()); float* result = (float*)volk_malloc(sizeof(float),
volk_get_alignment()); float* cutoff = (float*)volk_malloc(sizeof(float),
// load precomputed Taylor series coefficients
coefficients[0] = 4.48168907033806f; // c1
coefficients[1] = coefficients[0] * 0.5f; // c2
coefficients[2] = coefficients[0] * 1.0f/6.0f; // c3
coefficients[3] = coefficients[0] * 1.0f/24.0f; // c4
coefficients[4] = coefficients[0]; // c0
*cutoff = -2.0;
*result = 0.0f;
// generate uniform input data
float dx = (float)M_PI/ (float)npoints;
for(unsigned int ii=0; ii < npoints; ++ii){
input[ii] = dx * (float)ii - 1.5f;
}
volk_32f_x3_sum_of_poly_32f(result, input, coefficients, cutoff, npoints);
// multiply by bin width to get approximate area
std::cout << "result is " << *result * (input[1]-input[0]) << std::endl;
volk_free(coefficients);
volk_free(input);
volk_free(result);
volk_free(cutoff);
size_t volk_get_alignment(void)
Get the machine alignment in bytes.
Definition: volk.tmpl.c:90
__VOLK_DECL_BEGIN VOLK_API void * volk_malloc(size_t size, size_t alignment)
Allocate size bytes of data aligned to alignment.
Definition: volk_malloc.c:38
VOLK_API void volk_free(void *aptr)
Free's memory allocated by volk_malloc.
Definition: volk_malloc.c:80