0

I need to work with large Double and Boolean arrays / vectors and apply simple operations on them. E.g. additions, subtractions, multiplications, smaller, larger etc. on the Doubles and AND, OR, NOT etc. on the Bool ones.

While I have found vDSP from Accelerate quite performant for the simple arithmetic ones, the larger/smaller as well as the logical ones are very slow, which probably has to do with the fact that I use the map function to apply these.

Is there any better way to do this more efficient?

See below some code examples:

import Accelerate

let myDoubleArray1: [Double] = Array<Double>(repeating: 1.123, count: 1000000)
let myDoubleArray2: [Double] = Array<Double>(repeating: 2.123, count: 1000000)
let myBoolArray1: [Bool] = Array<Bool>(repeating: false, count: 1000000)
let myBoolArray2: [Bool] = Array<Bool>(repeating: true, count: 1000000)

_ = vDSP.multiply(myDoubleArray1, myDoubleArray2) // Takes about 0.5sec - very good
_ = zip(myDoubleArray1, myDoubleArray2).map {$0 > $1} // Takes about 7sec - too slow
_ = zip(myBoolArray1, myBoolArray2).map {$0 && $1} // Takes about 7sec - too slow
_ = zip(myBoolArray1, myBoolArray2).map {$0 == $1} // Takes about 7sec - too slow
_ = myBoolArray1.map {!$0} // Takes about 7sec - too slow
Jay
  • 59
  • 6

1 Answers1

1

A kindly Apple engineer has posted an answer to this question here: https://developer.apple.com/forums/thread/719117?answerId=734789022#734789022

Flex Monkey
  • 3,583
  • 17
  • 19