Skip to content
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 rule for copy #472

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

CarloLucibello
Copy link
Contributor

Copy link
Member

@mzgubic mzgubic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Do you know why the Zygote integration is failing? Seems to be some higher order AD thing?

src/rulesets/Base/base.jl Outdated Show resolved Hide resolved
test/rulesets/Base/base.jl Outdated Show resolved Hide resolved
@CarloLucibello
Copy link
Contributor Author

no idea why Zygote is failing

@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2021

Codecov Report

Merging #472 (b4663c7) into master (0d55c54) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #472   +/-   ##
=======================================
  Coverage   98.12%   98.13%           
=======================================
  Files          22       22           
  Lines        2350     2353    +3     
=======================================
+ Hits         2306     2309    +3     
  Misses         44       44           
Impacted Files Coverage Δ
src/rulesets/Base/base.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d55c54...b4663c7. Read the comment docs.

@mcabbott
Copy link
Member

Should this be here or in Zygote? i.e. is this a mathematical property of copy or something more specific?

Within Zygote, copy(::Array) could presumably be a no-op, since you can't mutate them. That's Zygote-specific. But copy(::Buffer) means something else...

Finally, testing this by finite-differences doesn't achieve much. But testing that it does what you want on a Dict would at least ensure that an over-zealous cleanup doesn't (say) restrict this to ::AbstractArray.

Not much of a review, but maybe things to think about.

@CarloLucibello
Copy link
Contributor Author

CarloLucibello commented Jul 28, 2021

Should this be here or in Zygote? i.e. is this a mathematical property of copy or something more specific?

I would say it is a convention of the language, the Base's docstring reads

    copy(x)

Create a shallow copy of x: the outer structure is copied, but not all
internal values. For example, copying an array produces a new array with
identically-same elements as the original.

Within Zygote, copy(::Array) could presumably be a no-op, since you can't mutate them. That's Zygote-specific. But copy(::Buffer) means something else...

copy(::Buffer) kind of breaks the convention above since it returns the underlying array. But maybe the rrule defined here is still reasonable since Buffer itself is an AbstactArray therefore it is ok it gets an array-like sensitivity?

Finally, testing this by finite-differences doesn't achieve much. But testing that it does what you want on a Dict would at least ensure that an over-zealous cleanup doesn't (say) restrict this to ::AbstractArray.

agree

Not much of a review, but maybe things to think about.

@mcabbott
Copy link
Member

I think we should do this. But the Zygote error in "nested AD hitting identity(::Tuple) pullback " is weird.

@mcabbott mcabbott closed this Feb 19, 2022
@mcabbott mcabbott reopened this Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error with copy(dict)
4 participants