Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:35:53+00:00 2026-05-18T08:35:53+00:00

What functions can I use in Accelerate.framework to scale a vector by a scalar,

  • 0

What functions can I use in Accelerate.framework to scale a vector by a scalar, and normalize a vector? I found one I think might work for scaling in the documentation but I am confused about it’s operation.

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
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:35:54+00:00Added an answer on May 18, 2026 at 8:35 am

    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’ll need to

    #include <cblas.h>
    

    or

    #include <vblas.h>
    

    (or both). Note that several of the functions are in the “matrix” section when they operate on vectors.

    If you want to use the vDSP functions, see the Vector-Scalar Division section. There are several things you can do:

    • vDSP_dotpr(), sqrt(), and vDSP_vsdiv()
    • vDSP_dotpr(), vrsqrte_f32(), and vDSP_vsmul() (vrsqrte_f32() is a NEON GCC built-in, though, so you need to check you’re compiling for armv7).
    • vDSP_rmsqv(), multiply by sqrt(n), and vDSP_vsdiv()

    The reason why there isn’t a vector-normalization function is because the “vector” in vDSP means “lots of things at once” (up to around 4096/8192) and necessarily the “vector” from linear algebra. It’s pretty meaningless to normalize a 1024-element vector, and a quick function for normalizing a 3-element vector isn’t something that will make your app significantly faster, which is why there isn’t one.

    The intended usage of vDSP is more like normalizing 1024 2– or 3-element vectors. I can spot a handful of ways to do this:

    • Use vDSP_vdist() to get a vector of lengths, followed by vDSP_vdiv(). You have to use vDSP_vdist() multiple times for vectors of length greater than 2, though.
    • Use vDSP_vsq() to square all the inputs, vDSP_vadd() multiple times to add all of them, the equivalent of vDSP_vsqrt() or vDSP_vrsqrt(), and vDSP_vmul() or vDSP_vdiv() as appropriate. It shouldn’t be too hard to write the equivalent of vDSP_vsqrt() or vDSP_vrsqrt().
    • Various ways which pretend your input is a complex vector. Not likely to be faster.

    Of course, if you don’t have 1024 vectors to normalize, don’t overcomplicate things.

    Notes:

    1. I don’t use “2-vector” and “3-vector” to avoid confusion with the “four-vector” from relativity.
    2. A good choice of n is one that nearly fills your L1 data cache. It’s not difficult; they’ve been relatively fixed at 32K for around a decade or more (they may be shared between virtual cores in a hyperthreaded CPU and some older/cheaper processors might have 16K), so the most you should do is around 8192 for in-place operation on floats. You might want to subtract a little for stack space, and if you’re doing several sequential operations you probably want to keep it all in cache; 1024 or 2048 seem pretty sensible and any more will probably hit diminishing returns. If you care, measure performance…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP's Image and GD functions you can use the following method to finally
I have a .NET DLL containing functions that I can use in PHP. Though
On Unix, everything is a file, so you can use file i/o functions with
I can't use the Get*Profile functions because I'm using an older version of the
I know why I want to use private virtual functions, but how exactly can
to use cas, gcc provides some useful functions such as __sync_bool_compare_and_swap but we can
I'm trying to use the Accelerate framework on iOS to bypass the fact that
From the SQL::Statement::Functions documentation: Creating User-Defined Functions ... More complex functions can make use
Also, are there any functions I can use keyboard to control in order to
How can I use threads in Ada95? What functions can I use to create,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.