Code Monkey home page Code Monkey logo

Comments (2)

mcabbott avatar mcabbott commented on June 12, 2024

It does assume they are AbstractVectors; I see that the name-less constructor has an explicit check:

julia> table = KeyedArray(rand(3,3), ([1,2,3], (:cv_diff, :se_cv_diff, :weight)))
ERROR: ArgumentError: key vectors must all be AbstractVectors
Stacktrace:
 [1] construction_check(data::Matrix{Float64}, keys::Tuple{Vector{Int64}, Tuple{Symbol, Symbol, Symbol}})
   @ AxisKeys ~/.julia/dev/AxisKeys/src/struct.jl:28
 [2] KeyedArray(data::Matrix{Float64}, keys::Tuple{Vector{Int64}, Tuple{Symbol, Symbol, Symbol}})
   @ AxisKeys ~/.julia/dev/AxisKeys/src/struct.jl:13

The reason for this is that it wants to allow OffsetArrays, for which it needs always to think about axes not size, and Tuples have only the latter. It's possible that this could be worked around, but I'm not sure how much work it would be.

The named constructor accepts any number of keywords, and I didn't think you could also impose a type constraint:

julia> @less KeyedArray(rand(3,3); model=[1,2,3], statistic=(:cv_diff, :se_cv_diff, :weight))

julia> f1(; kw...) = kw;

julia> f1(; a=1, b=2)
pairs(::NamedTuple) with 2 entries:
  :a => 1
  :b => 2

julia> f2(; kw::Int...) = kw;
ERROR: syntax: "kw::Int" is not a valid function argument name around REPL[163]:1

It could perhaps be arranged that this hit the construction_check error first, though.

from axiskeys.jl.

ParadaCarleton avatar ParadaCarleton commented on June 12, 2024

@mcabbott I would think you could replace the types in the constructor that say AbstractVector with AbstractVecOrTuple, then just insert this at the top of the constructor:

for kwarg in kwargs
    if kwarg isa Tuple
        kwarg = [kwarg[i] for i in length(kwarg)]
    end
end

Which will convert the tuples to vectors.

from axiskeys.jl.

Related Issues (20)

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.