add ElementaryFunctions conformance to SIMD types #312
+289
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adresses #103
There's a few parts that probably require discussion.
ElementaryFunctions
requires conformance toAdditiveArithmetic
The concrete SIMD2, 4, etc types from the standard library have a conformance to
AdditiveArithmetic
defined in the Differentiation module so this conformance is only visible when_Differentiation
is imported.It's defined as follows:
extension SIMD${n}: @retroactive AdditiveArithmetic where Scalar: FloatingPoint {}
In some of our code that would be used with swift toolchains both with and without access to the
_Differentiation
module we'd get around this by using the following:My main worry here is that the conformance to
AdditiveArithmetic
in the standard library will conflict with the one provided here. Either the full one or the one that's limited to types conforming toFloatingPoint
. But as far as I understand this should be ok due to the@retroactive
attribute.Furthermore, technically we could be more generic (here and in the stdlib _Differentiation module) by requiring
Scalar
to conform to justAdditiveArithmetic
but that would require more boilerplate, now we get the implementation for free from the standard library. The other solution is more complete however and would look something like:Ideally the
AdditiveArithmetic
conformance would live in the stdlib itself. That way none of the Differentiation code would break and there's no longer the need for this duplication. But I'm not sure if just a "completeness" argument warrants that change.Aside from the above I also added implementations for most of the
RealFunction
except forstatic func signGamma(_ x: Self) -> FloatingPointSign
since it can't implemented for simd types. So unfortunately we can't conform the simdtypes to the protocol.Let me know your thoughts/questions!