Skip to content

Commit 0f9bffe

Browse files
authored
Add inline, SquareEye to work around type inferrence issues (#80)
* Add inline, SquareEye to work around type inferrence issues * Update runtests.jl * v0.8.2
1 parent 2f4b90e commit 0f9bffe

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.8.1"
3+
version = "0.8.2"
44

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

src/FillArrays.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ for (Typ, funcs, func) in ((:Zeros, :zeros, :zero), (:Ones, :ones, :one))
185185
@inline $Typ{T}(sz::SZ) where SZ<:Tuple{Vararg{Any,N}} where {T, N} = $Typ{T, N}(sz)
186186
@inline $Typ(sz::Vararg{Any,N}) where N = $Typ{Float64,N}(sz)
187187
@inline $Typ(sz::SZ) where SZ<:Tuple{Vararg{Any,N}} where N = $Typ{Float64,N}(sz)
188+
@inline $Typ{T}(n::Integer) where T = $Typ{T,1}(n)
189+
@inline $Typ(n::Integer) = $Typ{Float64,1}(n)
190+
188191

189192
@inline $Typ{T,N}(A::AbstractArray{V,N}) where{T,V,N} = $Typ{T,N}(size(A))
190193
@inline $Typ{T}(A::AbstractArray) where{T} = $Typ{T}(size(A))
@@ -287,8 +290,11 @@ const RectOrDiagonal{T,V,Axes} = Union{RectDiagonal{T,V,Axes}, Diagonal{T,V}}
287290
const SquareEye{T,Axes} = Diagonal{T,Ones{T,1,Tuple{Axes}}}
288291
const Eye{T,Axes} = RectOrDiagonal{T,Ones{T,1,Tuple{Axes}}}
289292

290-
Eye{T}(n::Integer) where T = Diagonal(Ones{T}(n))
291-
Eye(n::Integer) = Diagonal(Ones(n))
293+
@inline SquareEye{T}(n::Integer) where T = Diagonal(Ones{T}(n))
294+
@inline SquareEye(n::Integer) = Diagonal(Ones(n))
295+
296+
@inline Eye{T}(n::Integer) where T = Diagonal(Ones{T}(n))
297+
@inline Eye(n::Integer) = Diagonal(Ones(n))
292298

293299
# function iterate(iter::Eye, istate = (1, 1))
294300
# (i::Int, j::Int) = istate

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using FillArrays, LinearAlgebra, SparseArrays, Random, Base64, Test
2-
import FillArrays: AbstractFill, RectDiagonal
2+
import FillArrays: AbstractFill, RectDiagonal, SquareEye
33

44
@testset "fill array constructors and convert" begin
55
for (Typ, funcs) in ((:Zeros, :zeros), (:Ones, :ones))
@@ -90,7 +90,8 @@ import FillArrays: AbstractFill, RectDiagonal
9090
end
9191

9292
@test Eye(5) isa Diagonal{Float64}
93-
@test Eye(5) == Eye{Float64}(5)
93+
@test SquareEye(5) isa Diagonal{Float64}
94+
@test Eye(5) == Eye{Float64}(5) == SquareEye(5) == SquareEye{Float64}(5)
9495
@test Eye(5,6) == Eye{Float64}(5,6)
9596
@test Eye(Ones(5,6)) == Eye{Float64}(5,6)
9697
@test eltype(Eye(5)) == Float64

0 commit comments

Comments
 (0)