[swift-users] Extending Arrays of specific type, and specialization

Rick Mann rmann at latencyzero.com
Mon Nov 21 18:32:35 CST 2016


My googling is not turning up an answer that works in Xcode 8.1. I'd like to do this:


import Accelerate

extension
Array
	where Element == Double
{
	func
	sum()
		-> Double
	{
		var result: Double = 0.0
		vDSP_sveD(self, 1, &result, vDSP_Length(self.count))
		return result
	}
}

But I get "same-type requirement makes generic parameter 'Element' non-generic."

Also, will there ever be any way to specialize something like

	let numbers: [Double] = ...
	let sum = numbers.reduce(0.0, +)

Into a call to vDSP_sveD()? Would it require compiler optimizations for Accelerate?

Thanks!

-- 
Rick Mann
rmann at latencyzero.com




More information about the swift-users mailing list