-
Notifications
You must be signed in to change notification settings - Fork 1
Add derivatives for RealFunctions #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fc82a10 to
142f057
Compare
Also adds RealFunctions conformance to SIMD types and their derivatives
142f057 to
448b9ce
Compare
|
Perhaps there should be some tests that use some of the generated functions to have some coverage? Otherwise LGTM |
|
Right, absolutely, good point haha. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits but otherwise LGTM; this is about as good as you can do with stringy codegen. I didn't check the implementation of the vjp`s but assume those are correct (but let's add some tests at some point!)
| ) | ||
| try realFunctionsSIMDExtension.write(to: realFunctionSIMDFileURL, atomically: true, encoding: .utf8) | ||
|
|
||
| let floatingPointTypes: [String] = ["Float", "Double"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: there are aliases Float16, Float32, Float64, so you could make this an array of bit widths rather than strings, which might clean up some other parts of the code?
| component: "\(floatingPointType)+RealFunctions+Derivatives.swift", | ||
| directoryHint: .notDirectory | ||
| ) | ||
| let type = floatingPointType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ... odd? Is this changing the type from String to something else (in which case annotate it?); or just defining a shorthand name; or ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah that was there to match the same structure as around line 65. Removed it now.
|
I also didn't check the vjps for correctness, but assuming they're right and we have some basic unit tests, everything looks good to me. |
|
Happy I added some tests cause I did find two incorrect vjps 😬 copy paste error... |
4259585 to
8fd0b5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vjps are out of my wheelhouse but otherwise LGTM
4e1643a to
6364866
Compare
6364866 to
8caa407
Compare
This MR adds derivatives to types conforming to RealFunctions such as Float and Double
This also adds RealFunctions conformance to SIMD types and their derivatives.
This is achieved through generating default implementations for the
SIMDprotocol and also generating concrete implementations that can have derivatives attached to them. This is required since we can't have default derivative implementations for protocol requirements.Most of the code is generated by a plugin.