Skip to content

Commit 71e657d

Browse files
authored
Add Zeros(T, n...) and Ones(T, n...) constructors (#94( (#233)
* Add Zeros(T, n...) and Ones(T, n...) constructors (#94( * increase coverage
1 parent b681ddd commit 71e657d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/FillArrays.jl

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ for (Typ, funcs, func) in ((:Zeros, :zeros, :zero), (:Ones, :ones, :one))
262262
@inline $Typ{T,N}(A::AbstractArray{V,N}) where{T,V,N} = $Typ{T,N}(size(A))
263263
@inline $Typ{T}(A::AbstractArray) where{T} = $Typ{T}(size(A))
264264
@inline $Typ(A::AbstractArray) = $Typ{eltype(A)}(A)
265+
@inline $Typ(::Type{T}, m...) where T = $Typ{T}(m...)
265266

266267
@inline axes(Z::$Typ) = Z.axes
267268
@inline size(Z::$Typ) = length.(Z.axes)

src/fillalgebra.jl

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ end
8686
*(a::ZerosMatrix, b::AbstractMatrix) = mult_zeros(a, b)
8787
*(a::AbstractMatrix, b::ZerosVector) = mult_zeros(a, b)
8888
*(a::AbstractMatrix, b::ZerosMatrix) = mult_zeros(a, b)
89-
*(a::ZerosVector, b::AbstractVector) = mult_zeros(a, b)
9089
*(a::ZerosMatrix, b::AbstractVector) = mult_zeros(a, b)
9190
*(a::AbstractVector, b::ZerosMatrix) = mult_zeros(a, b)
9291

test/runtests.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ include("infinitearrays.jl")
2020

2121
for T in (Int, Float64)
2222
Z = $Typ{T}(5)
23+
@test $Typ(T, 5) Z
2324
@test eltype(Z) == T
2425
@test Array(Z) == $funcs(T,5)
2526
@test Array{T}(Z) == $funcs(T,5)
@@ -34,6 +35,7 @@ include("infinitearrays.jl")
3435
@test $Typ(2ones(T,5)) == Z
3536

3637
Z = $Typ{T}(5, 5)
38+
@test $Typ(T, 5, 5) Z
3739
@test eltype(Z) == T
3840
@test Array(Z) == $funcs(T,5,5)
3941
@test Array{T}(Z) == $funcs(T,5,5)
@@ -508,9 +510,9 @@ end
508510
@test_throws MethodError [1,2,3]*Zeros(3) # Not defined for [1,2,3]*[0,0,0] either
509511

510512
@testset "Check multiplication by Adjoint vectors works as expected." begin
511-
@test randn(4, 3)' * Zeros(4) === Zeros(3)
512-
@test randn(4)' * Zeros(4) === zero(Float64)
513-
@test [1, 2, 3]' * Zeros{Int}(3) === zero(Int)
513+
@test randn(4, 3)' * Zeros(4) Zeros(3)
514+
@test randn(4)' * Zeros(4) transpose(randn(4)) * Zeros(4) zero(Float64)
515+
@test [1, 2, 3]' * Zeros{Int}(3) zero(Int)
514516
@test [SVector(1,2)', SVector(2,3)', SVector(3,4)']' * Zeros{Int}(3) === SVector(0,0)
515517
@test_throws DimensionMismatch randn(4)' * Zeros(3)
516518
@test Zeros(5)' * randn(5,3) Zeros(5)'*Zeros(5,3) Zeros(5)'*Ones(5,3) Zeros(3)'

0 commit comments

Comments
 (0)