Skip to content

Commit e9a42b6

Browse files
committed
fix #15
1 parent 9141cba commit e9a42b6

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LazyStack"
22
uuid = "1fad7336-0346-5a1a-a56f-a06ba010965b"
33
authors = ["Michael Abbott"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/LazyStack.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ lazystack(xs::AbstractArray{IT,ON}) where {IT<:AbstractArray{T,IN}} where {T,IN,
8787
stack_slices(xs, Val(T), Val(IN+ON))
8888
lazystack(xs::Tuple{Vararg{AbstractArray{T,IN}}}) where {T,IN} =
8989
stack_slices(xs, Val(T), Val(IN+1))
90+
91+
# This lets `lazystack([1,2], [3,4])` act like hcat, slightly dodgy?
9092
lazystack(xs::AbstractArray{T}...) where {T} = lazystack(xs)
93+
# But `lazystack([1,2])` should not do this, violates equivalence with `Base.stack`.
94+
lazystack(xs::AbstractArray{<:Number}) = xs
9195

9296
function stack_slices(xs::AT, ::Val{T}, ::Val{N}) where {T,N,AT}
9397
length(xs) >= 1 || throw(ArgumentError("stacking an empty collection is not allowed"))

test/runtests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ end
3030
@test lazystack(vt) == reshape(1:6, 2,3)
3131
@test lazystack(vnt) isa Array
3232

33-
@test lazystack(vt...) isa Array
34-
@test lazystack(vnt...) isa Array
33+
@test lazystack(vt...) isa Matrix
34+
@test lazystack(vnt...) isa Matrix
35+
36+
lazystack((1,2)) isa Matrix # case of 1, but do we want this? Not sure
37+
38+
@test lazystack([1,2], [3,4], [5,6]) isa AbstractMatrix
39+
@test lazystack([1,2]) isa Vector # NB to match Base.stack, https://github.com/mcabbott/LazyStack.jl/issues/15
3540

3641
end
3742
@testset "generators" begin

0 commit comments

Comments
 (0)