Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw DimensionMismatch for broadcast on mixed dimensions #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ function common_chunks(s,args...)
return map(i->i[1],tt),map(i->i[2],tt)
end
end
subsetarg(x, a) = x
function subsetarg(x::AbstractArray,a)
ashort = maybeonerange(size(x),a)
subsetarg(x, ranges) = x
function subsetarg(x::Tuple, ranges)
length(x) !== 1 && length(ranges) !== 1 && throw(DimensionMismatch("DiskArrays can only broadcast a Tuple of length > 1 with a 1 dimensional Array"))
x
end
function subsetarg(x::AbstractArray,ranges)
(length(ranges) === ndims(x) || length(x) === 1) || throw(DimensionMismatch("Can only broadcast with arrays of matching size"))
ashort = maybeonerange(size(x),ranges)
view(x,ashort...) #Maybe making a copy here would be faster, need to check...
end
repsingle(s,r) = s==1 ? (1:1) : r
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ end
@testset "Broadcast" begin
a_disk1 = _DiskArray(rand(10,9,2), chunksize=(5,3,2))
test_broadcast(a_disk1)
a = ones(10,9,2);
a_disk = _DiskArray(a, chunksize=(5,3,2));
tup = ntuple(x -> x, 10)
mat = reshape(1:90, 10, 9)
@test_throws DimensionMismatch a_disk .* tup |> collect
@test_throws DimensionMismatch a_disk .* mat |> collect
end

@testset "Broadcast with length 1 final dim" begin
Expand Down