Skip to content

Commit

Permalink
use indexing rather than broadcast in Array (#170)
Browse files Browse the repository at this point in the history
* use indexing rather than broadcast

* also add collect method

* handle zero dimensional
  • Loading branch information
rafaqz authored May 29, 2024
1 parent 255aff6 commit 1ccac39
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ macro implement_array_methods(t)
t = esc(t)
quote
Base.Array(a::$t) = $_Array(a)
Base.collect(a::$t) = $_Array(a)
Base.copyto!(dest::$t, source::AbstractArray) = $_copyto!(dest, source)
Base.copyto!(dest::AbstractArray, source::$t) = $_copyto!(dest, source)
Base.copyto!(dest::$t, source::$t) = $_copyto!(dest, source)
Expand Down Expand Up @@ -46,11 +47,8 @@ macro implement_array_methods(t)
end

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

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

2 comments on commit 1ccac39

@meggart
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107884

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" 1ccac39e6a9115869b1027094fe1a2f1940198bf
git push origin v0.4.3

Please sign in to comment.