Skip to content

Commit 1ccac39

Browse files
authored
use indexing rather than broadcast in Array (#170)
* use indexing rather than broadcast * also add collect method * handle zero dimensional
1 parent 255aff6 commit 1ccac39

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/array.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ macro implement_array_methods(t)
33
t = esc(t)
44
quote
55
Base.Array(a::$t) = $_Array(a)
6+
Base.collect(a::$t) = $_Array(a)
67
Base.copyto!(dest::$t, source::AbstractArray) = $_copyto!(dest, source)
78
Base.copyto!(dest::AbstractArray, source::$t) = $_copyto!(dest, source)
89
Base.copyto!(dest::$t, source::$t) = $_copyto!(dest, source)
@@ -46,11 +47,8 @@ macro implement_array_methods(t)
4647
end
4748

4849
# Use broadcast to copy to a new Array
49-
function _Array(a::AbstractArray{T,N}) where {T,N}
50-
dest = Array{T,N}(undef, size(a))
51-
dest .= a
52-
return dest
53-
end
50+
_Array(a::AbstractArray{T,N}) where {T,N} = a[ntuple(_ -> :, Val{N}())...]
51+
_Array(a::AbstractArray{T,0}) where {T} = fill(a[])
5452

5553
# Use broadcast to copy
5654
function _copyto!(dest::AbstractArray{<:Any,N}, source::AbstractArray{<:Any,N}) where {N}

0 commit comments

Comments
 (0)