<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for your responses!<div class=""><br class=""></div><div class="">Yes, it is true that I would like to use the Accelerate framework as much as possible. And since Surge is just a thin wrapper for that I wanted to reuse that functionality.</div><div class=""><br class=""></div><div class="">Dmitri, your suggestion is interesting regarding protocols, but I was giving it a try and I’m not sure exactly how you could accomplish it. For example, I tried the following.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> Summable: </span>ArrayLiteralConvertible<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span>CollectionType<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span>_DestructorSafeContainer<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typealias</span> T: FloatingPointType, FloatLiteralConvertible</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sum() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>Summable<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sum() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> result: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">vDSP_sve</span>(<font color="#bb2ca2" class="">self</font>, <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, &amp;result, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">vDSP_Length</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.count))&nbsp;<span style="color: rgb(0, 132, 0);" class="">// Cannot convert value of type 'Self' to expected argument type 'UnsafePointer&lt;Float&gt;'</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">Well not only did that produce an error, but it doesn’t really makes sense or accomplish the goal because I haven’t distinguished between Float and Double. Neither does the following which has a vague error message.</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> Summable: </span>CollectionType<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typealias</span> Element: FloatingPointType, FloatLiteralConvertible</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sum() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Summable</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> { </span>// Type 'Array&lt;Element&gt;' does not conform to protocol 'Summable'</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sum() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> result: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Element</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">vDSP_sve</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, &amp;result, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">vDSP_Length</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.count))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">I suspect I’m misunderstanding your suggestion since I can’t quite work out how to do this. I’ve been wrangling the type checker here for a while, but I don’t know what the devil to do. With the different syntax for associated types, generic parameters, and constraints it’s a bit difficult to explore different without knowing exactly what to do.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Tyler</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 18, 2016, at 5:09 PM, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Mon, Jan 18, 2016 at 5:06 PM, David Turnbull via swift-users<br class="">&lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class="">How about this...<br class=""><br class="">public func dot&lt;genType:FloatingPointVectorType&gt;(x:genType, _ y:genType) -&gt;<br class="">genType.Element {<br class=""><br class=""> &nbsp;&nbsp;&nbsp;let a = genType(x, y, *)<br class=""><br class=""> &nbsp;&nbsp;&nbsp;return a.reduce(genType.Element(0)) { $0 + ($1 as! genType.Element) }<br class=""><br class="">}<br class=""></blockquote><br class="">This won't be calling into Accelerate. &nbsp;The assumption is that<br class="">Accelerate is manually-optimized and heavily tuned, and it will be<br class="">faster than a naive Swift implementation.<br class=""><br class="">Dmitri<br class=""><br class="">-- <br class="">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;*/<br class=""></div></div></blockquote></div><br class=""></div></body></html>