0

I have a vector v and a scalar s (either float or double). I am looking for a func that will achieve min(v, s) in Accelerate, that should return a vector u, such that

u[0] = min(v[0], s)
u[1] = min(v[1], s) 

etc. 

I browsed thru the documentation, i only see in vDSP that take in 2 vectors min(v, v). Although, i can indirectly create a vector of same length with repeating element of s, and then call this API. But i think that will be inefficient.

kawingkelvin
  • 3,649
  • 2
  • 30
  • 50
  • you can use vDSP_vfill(_:_:_:_:) to fill the scalar to an array, and then min. That should be quick. – E.Coms Jan 25 '19 at 00:03
  • @E.Coms. Unfortunately, you need to allocate this first and then remember to deallocate. And this may loss out to raw C doing it the "right" way. – kawingkelvin Jan 25 '19 at 07:25
  • vDSP is relatively a low level api. So it is normal if you try to use it. – E.Coms Jan 25 '19 at 13:51
  • @E.Coms. I just don't like needing an intermediate array filled in with scalar, it may not scale. For specific situation, it may be ok (after one profile it). But if this is to be part of a more general library, i do worry about this. It will be great if Accelerate has a highly optimized 1 API to do this. – kawingkelvin Jan 25 '19 at 19:10

0 Answers0