1

I need to do comparison operations on two arrays using vDSP. I don't see any direct functions to do that.

//....sourceArray is filled up with data
float sourceArray = new float[arrayLength];

//....destArray is filled up with data
float destArray = new float[arrayLength];


//...need to compare the two arrays 
//...(for eg., how many elements are equal/greater than/less than etc., If so then 1, else 0)

Any workaround using existing vDSP functions will also help.

I have used MMX, SSE, and SSE2 Intrinsics before a lot and there are many function to do this. But unable to find similar functions here.

kid.abr
  • 320
  • 5
  • 14
  • There is no proper function for this in vDSP. But it is not clear what you want. You say “how many elements are equal”, suggesting the answer should be something like 3 elements are equal or 153 elements are equal. But you also say “If equal then 1, else 0”, suggesting you want a 1 or 0 for each element. You can use vDSP_eqvi to do a bitwise comparison, and that will give you an array in which each element contains all 1 bits or all 0 bits according to whether the compared elements are equal or not, respectively. (Since this is a bitwise comparison, +0 and –0 compare as different.) – Eric Postpischil Jun 30 '17 at 02:01
  • It is unusual to be comparing floating-point numbers for equality. Typically, floating-point numbers are the results of various calculations that accumulate rounding errors, and numbers that are the results of different processes may be unequal where exact mathematical calculations would make them equal and, conversely, they may be equal where exact mathematical calculations would make them unequal. Why do you want to compare for equality? – Eric Postpischil Jun 30 '17 at 02:02
  • yes you are right in saying that equating two float arrays may produce errors. But what I want to ask is about a general compare operations, like greater than or less than. I'll update the question accordingly. We do vDSP for performance improvement, so i think its common to load char or int values into the float buffer and doing operations on it even though "actual" float calculations aren't needed.\ – kid.abr Jul 03 '17 at 11:20
  • and I am not able to find vDSP_eqvi anywhere...can you post any link? – kid.abr Jul 03 '17 at 11:22
  • My mistake, it is vDSP_veqvi. vDSP_veqvi documentation is at . This will only be useful for bitwise equality, not less-than/greater-than. Also, you can dig into the Xcode application to find vDSP.h. That is the header for vDSP, and there are comments in it with some additional documentation about vDSP routines. (E.g., at the path “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vDSP.h”.) – Eric Postpischil Jul 03 '17 at 21:58
  • And note that bitwise equality reports that floating-point +0 is different from −0. – Eric Postpischil Jul 03 '17 at 22:01

0 Answers0