Using Accelerate to operate on ArraySlice<Complex>

for var stack:[Double]

for i in 1...N {
	stack[sp+i] += stack[sp+b+i]

conveniently becomes

vDSP.add(stack[sp+1 ... sp+N], stack[sp+b+1 ... sp+b+N], &stack[sp+1 ... sp+N])

since ArraySlice<Double> conforms to AccelerateBuffer.

What would be the equivalent Accelerate magic for var stack: [Complex] (where Complex is defined the usual way).

Bonus points if it is simple to use in a generic. i.e.

func evaluate(T:Computable) { // Double and Complex conform to Computable  
      var stack:[T]

vDSP_zvaddD looks promising, but [Complex] interleaves real and imaginary parts, and to use vDSP_zvaddD would seem to require getting an UnsafePointer<DSPDoubleSplitComplex> from ArraySlice<Double>.

(I will be needing all the usual arithmetic and transcendental operations on double precision Double and Complex, and mixed vector-scalar operations, as well....)

1 Like

My initial thought here is to provide a split complex buffer type that conforms to Collection with Element == Complex, but also has contiguous real and imaginary parts that can be used to make nice wrappers for the vDSP interfaces. This is something that I've been meaning to design out and add, but simply haven't gotten around to yet.


Extremely sketchy draft of what I'm talking about here:

Note that the actual implementation here is not at all what I would end up doing eventually, but it at least outlines what such a project would look like and how it could interoperate with Accelerate.

Terms of Service

Privacy Policy

Cookie Policy