Skip to content
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
1 change: 0 additions & 1 deletion src/Scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const Scalar{T} = SArray{Tuple{},T,0,1}
end
@inline convert(::Type{SA}, sa::SA) where {SA <: Scalar} = sa

getindex(v::Scalar) = v.data[1]
@propagate_inbounds function getindex(v::Scalar, i::Int)
@boundscheck if i != 1
error("Attempt to index Scalar at index $i")
Expand Down
14 changes: 14 additions & 0 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ setindex!(a::StaticArray, value, i::Int) = error("setindex!(::$(typeof(a)), valu
end

@generated function _getindex_scalar(::Size{S}, a::StaticArray, inds::Int...) where S
if length(inds) == 0
return quote
@_propagate_inbounds_meta
a[1]
end
end

stride = 1
ind_expr = :()
for i ∈ 1:length(inds)
Expand All @@ -36,6 +43,13 @@ end
end

@generated function _setindex!_scalar(::Size{S}, a::StaticArray, value, inds::Int...) where S
if length(inds) == 0
return quote
@_propagate_inbounds_meta
a[1] = value
end
end

stride = 1
ind_expr = :()
for i ∈ 1:length(inds)
Expand Down
7 changes: 7 additions & 0 deletions test/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,11 @@
@test @inferred(promote_type(MMatrix{2,3,Float32,6}, MMatrix{2,3,Complex{Float64},6})) === MMatrix{2,3,Complex{Float64},6}
@test @inferred(promote_type(MArray{Tuple{2, 2, 2, 2},Float32, 4, 16}, MArray{Tuple{2, 2, 2, 2}, Complex{Float64}, 4, 16})) === MArray{Tuple{2, 2, 2, 2}, Complex{Float64}, 4, 16}
end

@testset "zero-dimensional" begin
v = MArray{Tuple{}, Int, 0, 1}(1)
@test v[] == 1
v[] = 2
@test v[] == 2
end
end