Skip to content

Commit 752eb7e

Browse files
author
Michael Abbott
committed
fix threaded map over one element
1 parent 59bdcbd commit 752eb7e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/SliceMap.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ function threadmap(f::Function, vw::AbstractVector...)
297297
length(first(vw))==0 && error("can't map over empty vector, sorry")
298298
length(vw)==2 && (isequal(length.(vw)...) || error("lengths must be equal"))
299299
out1 = f(first.(vw)...)
300-
_threadmap(out1, f, vw...)
300+
if length(vw) > 1
301+
_threadmap(out1, f, vw...)
302+
else
303+
[out1]
304+
end
301305
end
302306
# NB function barrier. Plus two versions:
303307
@static if VERSION < v"1.3"

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ Zygote.refresh()
3939
@test res jcols(fun, mat)
4040
@test grad Zygote.gradient(m -> sum(sin, jcols(fun, m)), mat)[1]
4141

42+
# Case of length 1, was an error for _threadmap
43+
@test res[:,1:1] mapcols(fun, mat[:, 1:1])
44+
@test res[:,1:1] tmapcols(fun, mat[:, 1:1])
45+
@test res[:,1:1] ThreadMapCols(fun, mat[:, 1:1])
46+
4247
end
4348
@testset "columns -> scalar" begin
4449

@@ -171,7 +176,7 @@ end
171176

172177
rec(store) = x -> (push!(store, first(x)); x)
173178
A = [1,1,1] .* (1:5)'
174-
179+
175180
store = []
176181
slicemap(rec(store), A; dims=1)
177182
@test store == 1:5

0 commit comments

Comments
 (0)