Code Monkey home page Code Monkey logo

Comments (3)

mcabbott avatar mcabbott commented on June 12, 2024

This is the downside of the "round brackets do lookup, square brackets do indexing" scheme -- because this is parsed as function definition, not a kind of setindex!, and can't be overloaded.

Some possible but not so pretty workarounds are:

tbl(:Estimate, :loo, :) .= mean(pointwise_ev)  # make a view
tbl[Key(:Estimate), Key(:loo)] = mean(pointwise_ev)  # use setindex!

from axiskeys.jl.

ParadaCarleton avatar ParadaCarleton commented on June 12, 2024

This is the downside of the "round brackets do lookup, square brackets do indexing" scheme -- because this is parsed as function definition, not a kind of setindex!, and can't be overloaded.

Some possible but not so pretty workarounds are:

tbl(:Estimate, :loo, :) .= mean(pointwise_ev)  # make a view
tbl[Key(:Estimate), Key(:loo)] = mean(pointwise_ev)  # use setindex!

Is there another way to do lookups? Worth noting that the first suggestion didn't work -- I still got the same error about methods. If this is a frequent problem, maybe this should be a macro so we don't get collisions like this?

from axiskeys.jl.

mcabbott avatar mcabbott commented on June 12, 2024

Oh, it's backwards, the order needs to match the definition. But that gives a different error:

julia> tbl(:Estimate, :loo, :) .= 0
ERROR: ArgumentError: could not find key :Estimate in vector [:loo, :p_loo, :loo_ic]

julia> tbl(:loo, :Estimate, :) .= 99  # note the .=
0-dimensional view(::Matrix{Float64}, 1, 1) with eltype Float64:
99.0

I agree it's a bit awkward, but I'm not so sure a macro is going to make this simpler. It could simply guess whether to index or lookup, and for Symbols this is not very confusing -- this is the line taken by other packages, but this one is a bit of an experiment to see if you can keep them more separate.

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.