Giter VIP home page Giter VIP logo

lazystack.jl's People

Contributors

devmotion avatar github-actions[bot] avatar juliatagbot avatar mcabbott avatar mzgubic avatar oscardssmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lazystack.jl's Issues

Faster access for tuple of arrays

This is currently much slower than LazyArrays.Hcat, surely it can be fixed:

@btime hcat($t1...); # 178.379 ns (4 allocations: 1.03 KiB)
@btime collect(stack($t1)); # 1.032 μs (2 allocations: 912 bytes) -- was quicker I swear
@btime collect($(stack(t1))); # 1.065 μs (1 allocation: 896 bytes)
@btime collect(Hcat($t1...)); # 149.001 ns (3 allocations: 1008 bytes) -- match this

`Base.stack`

Now that JuliaLang/julia#43334 is merged, and available on Compat.jl, this package needs to decide what to do.

  • Perhaps the lazy struct is still useful for some purposes. If the next step is broadcasting, then this can be fast.
  • The eager code should just be deleted, and call Base. This was supposed to be called automatically on e.g. a stack of CuArrays, but I'm not sure that works right now.
  • The name stack should not be exported. Should it be LazyStack.stack, or export lazystack?

Edit: Mostly done in #14 now. The remaining piece is:

  • Base supports dims which the lazy struct does not. Perhaps it should learn, in order to have exactly the same rules?

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Don't call `vec` in `stack_rest`?

From https://discourse.julialang.org/t/efficient-way-of-turning-iterator-into-a-matrix/38309:

julia> nums = (i^2 for i in Iterators.filter(_->rand(Bool), 1:100));

julia> Base.haslength(nums)
false

julia> stack(nums)'
1×44 LinearAlgebra.Adjoint{Int64,Array{Int64,1}}:
 1  4  9  49  81  144  196  324  361  400  484  529    6241  6561  7396  7744  7921  8649  10000

julia> vecs = ([i,i^2] for i in Iterators.filter(_->rand(Bool), 1:100));

julia> stack(vecs)
2×54 Array{Int64,2}:
 2   7   9   10   11   13   14   16   17   18   20      90    92    94    95    96    98    100
 4  49  81  100  121  169  196  256  289  324  400     8100  8464  8836  9025  9216  9604  10000

julia> tups = ((i,i^2) for i in Iterators.filter(_->rand(Bool), 1:100));

julia> stack(tups)
ERROR: MethodError: no method matching vec(::Tuple{Int64,Int64})

julia> stack((i,i^2) for i in  1:100) # with a length, no problem
2×100 Array{Int64,2}:
 1  2  3   4   5   6   7   8   9   10   11   12      94    95    96    97    98    99    100
 1  4  9  16  25  36  49  64  81  100  121  144     8836  9025  9216  9409  9604  9801  10000

Check axes not size?

Perhaps the first of these should be an error:

julia> stack(OffsetArray(fill(i,5), rand(-2:2)) for i in 1:10)
5×10 OffsetArray(::Array{Int64,2}, 0:4, 1:10) with eltype Int64 with indices 0:4×1:10:
 1  2  3  4  5  6  7  8  9  10
 1  2  3  4  5  6  7  8  9  10
 1  2  3  4  5  6  7  8  9  10
 1  2  3  4  5  6  7  8  9  10
 1  2  3  4  5  6  7  8  9  10

julia> rstack(OffsetArray(fill(i,5), rand(-2:2)) for i in 1:10)
9×10 OffsetArray(::Array{Int64,2}, -1:7, 1:10) with eltype Int64 with indices -1:7×1:10:
 1  0  0  4  0  6  7  8  0   0
 1  0  0  4  5  6  7  8  0  10
 1  0  0  4  5  6  7  8  0  10
 1  2  0  4  5  6  7  8  9  10
 1  2  3  4  5  6  7  8  9  10
 0  2  3  0  5  0  0  0  9  10
 0  2  3  0  0  0  0  0  9   0
 0  2  3  0  0  0  0  0  9   0
 0  0  3  0  0  0  0  0  0   0

Gradients for generators

Despite claiming to work with Zygote, generators currently don’t work:

julia> using Zygote, LazyStack

julia> gradient(x -> sum(stack([x,x'])), rand(2,2)) # vector of arrays
([2.0 2.0; 2.0 2.0],)

julia> gradient(x -> sum(stack(x,x')), rand(2,2)) # tuple of arrays
([2.0 2.0; 2.0 2.0],)

julia> gradient(x -> sum(stack(x' for x in [x,x])), rand(2,2)) # generator
ERROR: not yet!

Errors with stack(...) * vector?

In trying to solve FluxML/Zygote.jl#399,

using Zygote, SliceMap
gradient(x -> sum(hcat(x...) * sum(x)), [rand(2), rand(2)]) # errors, as in linked issue
gradient(x -> sum(reduce(hcat, x) * sum(x)), [rand(2), rand(2)]) # ok!

using LazyStack
gradient(x -> sum(stack(x) * sum(x)), [rand(2), rand(2)]) # BoundsError: attempt to access (1,) at index [2]
gradient(x -> sum(stack(x...) * sum(x)), [rand(2), rand(2)]) 
gradient(x -> sum(collect(stack(x)) * sum(x)), [rand(2), rand(2)]) # MethodError: no method matching view(::NamedTuple{(:slices,),Tuple{Array{SubArray
gradient(x -> sum(collect(stack(x...)) * sum(x)), [rand(2), rand(2)]) # Mutating arrays is not supported

Simpler:

rr = rand(2,2); vv = rand(2);
gradient(x -> sum(rr * stack(x)), [rand(2), rand(2)])[1][1] # ok
gradient(x -> sum(rr * stack(x...)), [rand(2), rand(2)])[1][1] # ok

gradient(x -> sum(stack(x) * rr), [rand(2), rand(2)])[1][1] # ok
gradient(x -> sum(stack(x) * vv), [rand(2), rand(2)])[1][1] # BoundsError: attempt to access (1,) at index [2]
gradient(x -> sum(stack(x...) * vv), [rand(2), rand(2)])[1][1] # error!

Even simpler:

xx = [rand(2), rand(2)];
stack(xx) * vv # BoundsError: attempt to access (1,) at index [2]
stack(xx)[1] # same

`lazystack(Array{<:Number})` introduces an extra dimension

This is a bug, perhaps a new one:

julia> using LazyStack

julia> lazystack([1,2,3])
3×1 lazystack(::Tuple{Vector{Int64}}) with eltype Int64:
 1
 2
 3

julia> Base.stack([1,2,3])  # correctly regards numbers as zero-dim
3-element Vector{Int64}:
 1
 2
 3

It thinks you are doing this, for which Base requires another pair of brackets:

julia> lazystack([1,2,3], [4,5,6])  # too clever by half
3×2 lazystack(::Tuple{Vector{Int64}, Vector{Int64}}) with eltype Int64:
 1  4
 2  5
 3  6

julia> Base.stack(([1,2,3], [4,5,6]))
3×2 Matrix{Int64}:
 1  4
 2  5
 3  6

julia> Base.stack(([1,2,3],))  # also unambiguous
3×1 Matrix{Int64}:
 1
 2
 3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.