Scale Apple Accelerate Framework and Normalize Vector

What functions can I use in Accelerate.frameworkto scale the vector with a scalar and normalize the vector? I found one that I think can work for scaling in the documentation, but I'm confused about that.

vDSP_vsma
Vector scalar multiply and vector add; single precision.

void vDSP_vsma (
   const float *__vDSP_A,
   vDSP_Stride __vDSP_I,
   const float *__vDSP_B,
   const float *__vDSP_C,
   vDSP_Stride __vDSP_K,
   float *__vDSP_D,
   vDSP_Stride __vDSP_L,
   vDSP_Length __vDSP_N
);
+3
source share
1 answer

The easiest way to normalize a vector in place is something like

int n = 3;
float v[3] = {1, 2, 3};
cblas_sscal(n, 1.0 / cblas_snrm2(n, v, 1), v, 1);

You need

#include <cblas.h>

or

#include <vblas.h>

(or both). Note that some functions are located in the "matrix" section when they work with vectors.

vDSP, . "-" . , :

  • vDSP_dotpr(), sqrt() vDSP_vsdiv()
  • vDSP_dotpr(), vrsqrte_f32() vDSP_vsmul() (vrsqrte_f32() NEON GCC, , armv7).
  • vDSP_rmsqv(), sqrt(n) vDSP_vsdiv()

, , , "" vDSP " " ( 4096/8192) "" . 1024 -, 3 - -, , .

vDSP 1024 2 - 3 - . :

  • vDSP_vdist() , vDSP_vdiv(). vDSP_vdist() 2.
  • vDSP_vsq(), , vDSP_vadd() , , vDSP_vsqrt() vDSP_vrsqrt() vDSP_vmul() vDSP_vdiv(), . vDSP_vsqrt() vDSP_vrsqrt().
  • , , . , .

, 1024 , .

:

  • "2-" "3-", " " .
  • n - , L1. ; 32K ( , / 16K), 8192 . , , , , , ; 1024 2048 , , . , ...
+5

Source: https://habr.com/ru/post/1776351/


All Articles