Skip to content

Commit c4092a1

Browse files
authored
Remove some uses of @pure (#1253)
1 parent b7dee08 commit c4092a1

File tree

9 files changed

+26
-24
lines changed

9 files changed

+26
-24
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.9.3"
3+
version = "1.9.4"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

docs/src/pages/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ same vector. We can now do this with the `Scalar` type:
6060
The size of a statically sized array is a static parameter associated with the
6161
type of the array. The `Size` trait is provided as an abstract representation of
6262
the dimensions of a static array. An array `sa::SA` of size `(dims...)` is
63-
associated with `Size{(dims...)}()`. The following are equivalent (`@pure`)
63+
associated with `Size{(dims...)}()`. The following are equivalent
6464
constructors:
6565
```julia
6666
Size{(dims...,)}()

src/SHermitianCompact.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ end
4444
end
4545
end
4646

47-
Base.@pure triangularnumber(N::Int) = div(N * (N + 1), 2)
48-
Base.@pure triangularroot(L::Int) = div(isqrt(8 * L + 1) - 1, 2) # from quadratic formula
47+
triangularnumber(N::Int) = div(N * (N + 1), 2)
48+
@generated function triangularroot(::Val{L}) where {L}
49+
return div(isqrt(8 * L + 1) - 1, 2) # from quadratic formula
50+
end
4951

5052
lowertriangletype(::Type{SHermitianCompact{N, T, L}}) where {N, T, L} = SVector{L, T}
5153
lowertriangletype(::Type{SHermitianCompact{N, T}}) where {N, T} = SVector{triangularnumber(N), T}
@@ -55,7 +57,7 @@ lowertriangletype(::Type{SHermitianCompact{N}}) where {N} = SVector{triangularnu
5557
@inline SHermitianCompact{N}(lowertriangle::SVector{L, T}) where {N, T, L} = SHermitianCompact{N, T, L}(lowertriangle)
5658

5759
@inline function SHermitianCompact(lowertriangle::SVector{L, T}) where {T, L}
58-
N = triangularroot(L)
60+
N = triangularroot(Val(L))
5961
SHermitianCompact{N, T, L}(lowertriangle)
6062
end
6163

src/SOneTo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ end
3838
Base.first(::SOneTo) = 1
3939
Base.last(::SOneTo{n}) where {n} = n::Int
4040

41-
@pure function Base.iterate(::SOneTo{n}) where {n}
41+
function Base.iterate(::SOneTo{n}) where {n}
4242
if n::Int < 1
4343
return nothing
4444
else

src/SUnitRange.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct SUnitRange{Start, L} <: StaticVector{L, Int}
66
end
77
end
88

9-
@pure function check_sunitrange_params(L::Int)
9+
function check_sunitrange_params(L::Int)
1010
if L < 0
1111
error("Static unit range length is negative")
1212
end
@@ -16,9 +16,9 @@ function check_sunitrange_params(L)
1616
throw(TypeError(:SUnitRange, "type parameters must be `Int`", Tuple{Int,}, Tuple{typeof(L),}))
1717
end
1818

19-
@pure SUnitRange(a::Int, b::Int) = SUnitRange{a, max(0, b - a + 1)}()
19+
SUnitRange(a::Int, b::Int) = SUnitRange{a, max(0, b - a + 1)}()
2020

21-
@pure @propagate_inbounds function getindex(x::SUnitRange{Start, L}, i::Int) where {Start, L}
21+
@propagate_inbounds function getindex(x::SUnitRange{Start, L}, i::Int) where {Start, L}
2222
@boundscheck if i < 1 || i > L
2323
throw(BoundsError(x, i))
2424
end

src/abstractarray.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
length(a::StaticArrayLike) = prod(Size(a))::Int
22
length(a::Type{SA}) where {SA <: StaticArrayLike} = prod(Size(SA))::Int
33

4-
@pure size(::Type{SA}) where {SA <: StaticArrayLike} = Tuple(Size(SA))
4+
size(::Type{SA}) where {SA <: StaticArrayLike} = Tuple(Size(SA))
55
@inline function size(t::Type{<:StaticArrayLike}, d::Int)
66
S = size(t)
77
d > length(S) ? 1 : S[d]
88
end
99
@inline size(a::StaticArrayLike) = Tuple(Size(a))
1010

1111
Base.axes(s::StaticArrayLike) = _axes(Size(s))
12-
@pure function _axes(::Size{sizes}) where {sizes}
12+
@generated function _axes(::Size{sizes}) where {sizes}
1313
map(SOneTo, sizes)
1414
end
1515

@@ -83,9 +83,9 @@ sizedarray_similar_type(::Type{T},s::Size{S},::Type{Val{D}}) where {T,S,D} = Siz
8383
# Utility for computing the eltype of an array instance, type, or type
8484
# constructor. For type constructors without a definite eltype, the default
8585
# value is returned.
86-
Base.@pure _eltype_or(a::AbstractArray, default) = eltype(a)
87-
Base.@pure _eltype_or(::Type{<:AbstractArray{T}}, default) where {T} = T
88-
Base.@pure _eltype_or(::Type{<:AbstractArray}, default) = default # eltype not available
86+
_eltype_or(a::AbstractArray, default) = eltype(a)
87+
_eltype_or(::Type{<:AbstractArray{T}}, default) where {T} = T
88+
_eltype_or(::Type{<:AbstractArray}, default) = default # eltype not available
8989

9090
"""
9191
_construct_similar(a, ::Size, elements::NTuple)

src/convert.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const BadArgs = Args{<:Tuple{Tuple{<:Tuple}}}
1111

1212
# Some help functions.
1313
@pure has_ndims(::Type{<:StaticArray{<:Tuple,<:Any,N}}) where {N} = @isdefined N
14-
@pure has_ndims(::Type{<:StaticArray}) = false
14+
has_ndims(::Type{<:StaticArray}) = false
1515
if VERSION < v"1.7"
1616
Base.ndims(::Type{<:StaticArray{<:Tuple,<:Any,N}}) where {N} = N
1717
end
1818
@pure has_eltype(::Type{<:StaticArray{<:Tuple,T}}) where {T} = @isdefined T
19-
@pure has_eltype(::Type{<:StaticArray}) = false
19+
has_eltype(::Type{<:StaticArray}) = false
2020
@pure has_size(::Type{<:StaticArray{S}}) where {S<:Tuple} = @isdefined S
21-
@pure has_size(::Type{<:StaticArray}) = false
21+
has_size(::Type{<:StaticArray}) = false
2222
# workaround for https://github.com/JuliaArrays/StaticArrays.jl/issues/1047
2323
has_size(::Type{SVector}) = false
2424
has_size(::Type{MVector}) = false
@@ -28,10 +28,10 @@ has_size(::Type{SMatrix{N}}) where {N} = false
2828
has_size(::Type{MMatrix{N}}) where {N} = false
2929

3030
@pure has_size1(::Type{<:StaticMatrix{M}}) where {M} = @isdefined M
31-
@pure has_size1(::Type{<:StaticMatrix}) = false
31+
has_size1(::Type{<:StaticMatrix}) = false
3232
_size1(::Type{<:StaticMatrix{M}}) where {M} = M
3333
@generated function _sqrt(::Length{L}) where {L}
34-
N = round(Int, sqrt(L))
34+
N = isqrt(L)
3535
N^2 == L && return :($N)
3636
throw(DimensionMismatch("Input's length must be perfect square"))
3737
end

src/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ end
7171
## Indexing utilities ##
7272
#########################
7373

74-
@pure unpack_size(::Type{Size{S}}) where {S} = map(Size, S)
74+
@generated unpack_size(::Type{Size{S}}) where {S} = map(Size, S)
7575

7676
@inline index_size(::Size, ::Int) = Size()
7777
@inline index_size(::Size, a::StaticArray) = Size(a)

src/traits.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ Base.show(io::IO, ::Length{L}) where {L} = print(io, "Length(", L, ")")
3636

3737
Length(a::AbstractArray) = Length(Size(a))
3838
Length(::Type{A}) where {A <: AbstractArray} = Length(Size(A))
39-
@pure Length(L::Int) = Length{L}()
39+
Length(L::Int) = Length{L}()
4040
Length(::Size{S}) where {S} = _Length(S...)
4141
_Length(S::Int...) = Length{prod(S)}()
4242
@inline _Length(S...) = Length{Dynamic()}()
4343

4444
# Some convenience functions for `Size`
4545
(::Type{Tuple})(::Size{S}) where {S} = S
4646

47-
@pure getindex(::Size{S}, i::Int) where {S} = i <= length(S) ? S[i] : 1
47+
getindex(::Size{S}, i::Int) where {S} = i <= length(S) ? S[i] : 1
4848

4949
length(::Size{S}) where {S} = length(S)
5050
length_val(::Size{S}) where {S} = Val{length(S)}
@@ -59,8 +59,8 @@ Base.LinearIndices(::Size{S}) where {S} = LinearIndices(S)
5959

6060
size_tuple(::Size{S}) where {S} = Tuple{S...}
6161

62-
# Some @pure convenience functions for `Length`
63-
@pure (::Type{Int})(::Length{L}) where {L} = Int(L)
62+
# Some convenience functions for `Length`
63+
(::Type{Int})(::Length{L}) where {L} = Int(L)
6464

6565
Base.:(==)(::Length{L}, l::Int) where {L} = L == l
6666
Base.:(==)(l::Int, ::Length{L}) where {L} = l == L

0 commit comments

Comments
 (0)