-
Notifications
You must be signed in to change notification settings - Fork 26
Do gradient via mutating and unmutating cell #59
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
I think similar could be done for the |
with the dict:
|
Benchmarks
Before:222.774 ms (154790 allocations: 4.28 MiB) With this PR;212.711 ms (150807 allocations: 4.20 MiB) So only a very modest improvement. |
Codecov Report
@@ Coverage Diff @@
## master #59 +/- ##
==========================================
- Coverage 98.8% 98.24% -0.56%
==========================================
Files 4 4
Lines 167 171 +4
==========================================
+ Hits 165 168 +3
- Misses 2 3 +1
Continue to review full report at Codecov.
|
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.
Looks reasonable to me.
@@ -8,33 +8,40 @@ Approximate the gradient of `f` at `xs...` using `fdm`. Assumes that `f(xs...)` | |||
""" | |||
function grad end | |||
|
|||
function grad(fdm, f, x::AbstractArray{T}) where T <: Number | |||
function _grad(fdm, f, x::AbstractArray{T}) where T <: Number |
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.
Doesn't technically matter, but maybe change / remove the type constraint on x
, since we know it's going to be an Array
by virtue of the fact it's called from grad
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.
Could be a a few things actually.
But yes, the constraints are not needed
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.
I am going to keep it because the T
is useful
We can avoid copying every element every step if we just mutate the element we want to mutate on the original matrix, then mutate it back again after so we still have the original for the next step.
My micro benchmarks show this helps a bit.