-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add DiffResult for MArray, take 2 #35
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #35 +/- ##
=======================================
Coverage 86.84% 86.84%
=======================================
Files 1 1
Lines 76 76
=======================================
Hits 66 66
Misses 10 10 ☔ View full report in Codecov by Sentry. |
Co-authored-by: David Widmann <[email protected]>
How would you spot if there is one |
I'd define something like # It would be safer to use `false` as the default fallback...
ismutablearray(::AbstractArray) = true
ismutablearray(::SArray) = false
ismutablearray(::Diagonal{T,SMatrix{T}}) = false
...
DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(value, derivs)
function DiffResult(value::Union{Number,AbstractArray}, derivs::Tuple{Vararg{AbstractArray}})
if all(ismutablearray, derivs)
return MutableDiffResult(value, derivs)
else
return ImmutableDiffResult(value, derivs)
end
end |
Is it type-inferrable to do |
I'm sure up to a certain extent 😄 But I haven't tested it. IIRC sometimes one can help the compiler by defining such checks recursively. And if the checks only depend on types (and instances are not needed), one could use But how many orders of derivatives do people realistically work with? So I think in most cases |
FWIW, I am not sure that mixing |
Reverts #32