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

make copy correctly handle 0-dimensional SubArray #39809

Merged
merged 3 commits into from
Feb 25, 2021

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Feb 24, 2021

The current definition of copy for SubArray here has the following consequence:

julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1

which is inconsistent with the contract for copy that promises to produce an array when array is copied, e.g.:

julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1

The current definition of `copy` for `SubArray` [here](https://github.com/JuliaLang/julia/blob/master/base/subarray.jl#L70) has the following consequence:
```
julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1
```

which is inconsistent with the contract for `copy` that promises to produce an array when array is copied, e.g.:
```
julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1
```
@bkamins
Copy link
Member Author

bkamins commented Feb 24, 2021

CC @mbauman as you have merged #30889. Should this be backported to 1.6 if we agree that what I propose is the correct behavior?

base/subarray.jl Outdated Show resolved Hide resolved
@mbauman mbauman added backport 1.6 Change should be backported to release-1.6 bugfix This change fixes an existing bug labels Feb 24, 2021
@KristofferC KristofferC merged commit a12d0ff into JuliaLang:master Feb 25, 2021
@bkamins bkamins deleted the patch-25 branch February 25, 2021 12:11
KristofferC pushed a commit that referenced this pull request Mar 2, 2021
* make copy correctly handle 0-dimensional SubArray

The current definition of `copy` for `SubArray` [here](https://github.com/JuliaLang/julia/blob/master/base/subarray.jl#L70) has the following consequence:
```
julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1
```

which is inconsistent with the contract for `copy` that promises to produce an array when array is copied, e.g.:
```
julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1
```

(cherry picked from commit a12d0ff)
@KristofferC KristofferC mentioned this pull request Mar 2, 2021
52 tasks
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Mar 14, 2021
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
* make copy correctly handle 0-dimensional SubArray

The current definition of `copy` for `SubArray` [here](https://github.com/JuliaLang/julia/blob/master/base/subarray.jl#L70) has the following consequence:
```
julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1
```

which is inconsistent with the contract for `copy` that promises to produce an array when array is copied, e.g.:
```
julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1
```
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
* make copy correctly handle 0-dimensional SubArray

The current definition of `copy` for `SubArray` [here](https://github.com/JuliaLang/julia/blob/master/base/subarray.jl#L70) has the following consequence:
```
julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1
```

which is inconsistent with the contract for `copy` that promises to produce an array when array is copied, e.g.:
```
julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1
```
staticfloat pushed a commit that referenced this pull request Dec 23, 2022
* make copy correctly handle 0-dimensional SubArray

The current definition of `copy` for `SubArray` [here](https://github.com/JuliaLang/julia/blob/master/base/subarray.jl#L70) has the following consequence:
```
julia> x = [1]
1-element Array{Int64,1}:
 1

julia> y = @view x[1]
0-dimensional view(::Array{Int64,1}, 1) with eltype Int64:
1

julia> copy(y)
1
```

which is inconsistent with the contract for `copy` that promises to produce an array when array is copied, e.g.:
```
julia> x = fill(1)
0-dimensional Array{Int64,0}:
1

julia> copy(x)
0-dimensional Array{Int64,0}:
1
```

(cherry picked from commit a12d0ff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants