Skip to content

Fix sizeof for non-Array subarrays #36715

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

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ size(V::SubArray) = (@_inline_meta; map(n->Int(unsafe_length(n)), axes(V)))

similar(V::SubArray, T::Type, dims::Dims) = similar(V.parent, T, dims)

sizeof(V::SubArray) = length(V) * elsize(V.parent)
sizeof(V::SubArray) = length(V) * sizeof(eltype(V))
sizeof(V::SubArray{<:Any,<:Any,<:Array}) = length(V) * elsize(V.parent)

copy(V::SubArray) = V.parent[V.indices...]

Expand Down
6 changes: 5 additions & 1 deletion test/subarray.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test, Random
using Test, Random, LinearAlgebra

######## Utilities ###########

Expand Down Expand Up @@ -601,6 +601,10 @@ end
arrayOfUInt48 = [a, b, c];

@test sizeof(view(arrayOfUInt48, 1:2)) == 16

@test sizeof(view(Diagonal(zeros(UInt8, 10)), 1:4)) == 4
@test sizeof(view(Diagonal(zeros(UInt8, 10)), 1:3)) == 3
@test sizeof(view(Diagonal(zeros(Float64, 10)), 1:3, 2:6)) == 120
end


Expand Down