by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Abbaad Haider
    @abbaad
    This seems not to be packed like the NTuple version
    There is a pointer dereference to access elements of data
    Simon
    @SimonDanisch
    yeah, you need Vec{14, Float64}
    FixedVector is the abstract type...maybe I should call it AbstractFixedVector
    Abbaad Haider
    @abbaad
    Is this in master?
    Simon
    @SimonDanisch
    if you did a pkg.update, it shouldn't be master
    Abbaad Haider
    @abbaad
    Ah. Is there a way to check out a test branch from within Julia?
    Simon
    @SimonDanisch
    you mean checking out any existing branch?
    Pkg.checkout("Package", "branch") would do this
    Abbaad Haider
    @abbaad
    So I've tried Pkg.checkout("FixedSizeArrays", "setindex"), but I'm still getting
    LoadError: MethodError: `setindex!` has no method matching setindex!(::FixedSizeArrays.Vec{14,Float64}, ::Int64, ::Int64)
    when I try to mutate an element of the Vec
    Simon
    @SimonDanisch
    master should be fine... what's not fine is, that I don't automatically convert
    so you need to set a Float64
    Abbaad Haider
    @abbaad
    Oops.
    But even with that:
    julia> using FixedSizeArrays
    
    julia> type foo
               data::Vec{14, Float64}
               metadata1::Int64
               metadata2::Int64
               foo() = new()
           end
    
    julia> f = foo()
    foo(FixedSizeArrays.Vec{14,Float64}((6.92392642468246e-310,6.92392642767056e-310,6.9239264246627e-310,6.92392642483384e-310,6.923926428665e-310,6.923926430865e-310,6.9239264269354e-310,6.9239264234635e-310,6.92392644146764e-310,6.9239264414696e-310,0.0,0.0,0.0,0.0)),0,0)
    
    julia> f.data[1] = 0.3
    ERROR: MethodError: `setindex!` has no method matching setindex!(::FixedSizeArrays.Vec{14,Float64}, ::Float64, ::Int64)
    Simon
    @SimonDanisch
    yeah that's because it's setindex (without bang), which you need to use like that: f.data = setindex(f.data, 1.9, 1)
    It's a little sad, but it's hard to do it differently right now
    you can try something like this:
    ```Julia
    a = (1,3,4,5)
    ptr = Ptr{Int}(pointer_from_objref(a))
    unsafe_store!(ptr, 232, 3)
    a 
    (1,2,232,4)
    but that's unsafe and hacky
    Abbaad Haider
    @abbaad
    which is what C is for ;)
    Simon
    @SimonDanisch
    oh and it only works with a tuple!?
    Abbaad Haider
    @abbaad
    After all this, I think I'll just end up using a normal Vector for mutability from within Julia, and when I want to talk to C, I'll have to initialize a Vec
    You would think knowing the size of a Vector would enable many optimizations, I'm surprised this is still an upcoming feature of 0.5
    Thanks for your time.
    Simon
    @SimonDanisch
    sure
    yeah, it's just a problem of limited engineering time ;)
    it is important and great to have, but other things have been importanter for the people being able to work on this
    Alex Williams
    @ahwillia
    Is this a good spot to ask a question? Seems inactive for a while... but I'll give it a shot
    I'm curious why this doesn't work: convert(FixedArray,randn(5))
    Whereas this does: convert(Vec,randn(5))
    In general, how would I convert an arbitrary Array into a fixed size array?
    Simon
    @SimonDanisch
    FixedArray is not really concrete and it's not really clear to what it should convert
    Could default to Vec, though
    Btw, you might want to specify the length, otherwise it'll be type instable
    Alex Williams
    @ahwillia
    Hmm... I would have expected that convert creates a FixedArray{Float64,1,(5)} in this example
    i.e. a length 5 vector
    Simon
    @SimonDanisch
    Yeah... But since Vector is not FixedSize, the length must be inferred at runtime
    Alex Williams
    @ahwillia
    That makes sense.
    Alex Williams
    @ahwillia

    Maybe you can help me with something specific. Right now I have the following basic pattern:

    immutable MyType{T,N}
        v::Array{T,N}
    end
    
    foo = MyType(randn(5,5,5))
    
    for iter = 1:num_iter
        for i in eachindex(foo.v)
            update!(foo.v[i], ... )
        end
    end

    Basically I have an array that starts at some initial value and is updated in-place repeatedly. The size of the array never changes after foo is created. Is this a good candidate for a FixedSizeArray? I wanted to do something like:

    immutable MyType{T,N}
        v::FixedSizeArray{T,N}
    end
    
    foo = MyType(randn(5,5,5))
    
    for iter = 1:num_iter
        for i in eachindex(foo.v)
            update!(foo.v[i], ... )
        end
    end

    But I see it isn't so straightfoward now...

    David P. Sanders
    @dpsanders
    @ahwillia No, since FixedSizeArrays.jl are immutable. What's wrong with using a standard array
    ?
    Alex Williams
    @ahwillia
    I don’t remember :smile:
    I think it was more out of curiosity...
    What is the difference between a FixedSizeArray and a Tuple if it is immutable?
    Kristoffer Carlsson
    @KristofferC
    Difference in terms of what? You cant add two tuples.
    Alex Williams
    @ahwillia
    So basically an NTuple with basic operations (add, subtract, etc?)
    Kind of handy I guess. But why not make it mutable?
    Simon
    @SimonDanisch
    Because julia (currently) cant stack allocate them in that case ;)