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

Define copyto! for ShapedView that's no-op for 0-length arrays #12

Open
colinxs opened this issue Jan 7, 2020 · 0 comments
Open

Define copyto! for ShapedView that's no-op for 0-length arrays #12

colinxs opened this issue Jan 7, 2020 · 0 comments

Comments

@colinxs
Copy link
Collaborator

colinxs commented Jan 7, 2020

using Shapes, BenchmarkTools

@inline maybecopyto!(shape, dst, src) = _maybecopyto!(Length(shape), dst, src)
@inline _maybecopyto!(::Shapes.Length{0}, dst, src) = dst
@inline _maybecopyto!(::Shapes.Length, dst, src) = copyto!(dst, src)

function bench()
    dst = rand(9,0)
    src = rand(9,0)
    shape = MatrixShape(Float64, 9, 0)
    @btime maybecopyto!($shape, $dst, $src)
    @btime copyto!($dst, $src)
end
julia> bench()
  2.794 ns (0 allocations: 0 bytes)
  4.331 ns (0 allocations: 0 bytes)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant