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

Overview

Converts a floating point number to a 32-bit integer after applying a scaling factor.

Dispatcher Prototype

void volk_32f_s32f_convert_32i(int32_t* outputVector, const float* inputVector, const
float scalar, unsigned int num_points)

Inputs

  • inputVector: the input vector of floats.
  • scalar: The value multiplied against each point in the input buffer.
  • num_points: The number of data points.

Outputs

  • outputVector: The output vector.

Example Convert floats from [-1,1] to integers with a scale of 5 to maintain smallest delta

int N = 10;
unsigned int alignment = volk_get_alignment();
float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
int32_t* out = (int32_t*)volk_malloc(sizeof(int32_t)*N, alignment);
for(unsigned int ii = 0; ii < N; ++ii){
increasing[ii] = 2.f * ((float)ii / (float)N) - 1.f;
}
// Normalize by the smallest delta (0.2 in this example)
float scale = 5.f;
volk_32f_s32f_convert_32i(out, increasing, scale, N);
for(unsigned int ii = 0; ii < N; ++ii){
printf("out[%u] = %i\n", ii, out[ii]);
}
volk_free(increasing);
volk_free(out);
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