Code Monkey home page Code Monkey logo

Comments (7)

petrelharp avatar petrelharp commented on September 16, 2024 2

FWIW, I can't think of a single function in R that overloads arguments like that - i.e., takes either a vector of indices or a vector of booleans. Indexing works like that, but only indexing. Overloading can lead to nasty corner cases.

from tskit.

jeromekelleher avatar jeromekelleher commented on September 16, 2024

It's a bunch of work to do, and not that much different? Seems to me that you'd have to explain more by adding the boolean selector for nodes as well as the list of nodes option.

from tskit.

hyanwong avatar hyanwong commented on September 16, 2024

It's only a 5 line addition at the top of tables.simplify(), isn't it?

try:
    if len(samples) == ts.num_nodes and samples.dtype == bool:
        samples = np.where(samples)[0]
except AttributeError:
   pass

You're right that it's not that different, and it's not really a priority, but I'm finding that every extra barrier to new tskit users puts some of them off (and takes an extra few minutes to explain). There's a reason why numpy allows both boolean and numerical indexing. I'm not sure I would actually explain in a practical that you can use both: it's obvious from the context, right?

from tskit.

jeromekelleher avatar jeromekelleher commented on September 16, 2024

As usual with these things, implementation is by far the easiest thing and something like 5% of the actual effort. Testing, documenting and making sure there are no regressions against existing code make the majority of the work.

from tskit.

petrelharp avatar petrelharp commented on September 16, 2024

I agree. Higher on my list would be adding an individuals argument.

from tskit.

hyanwong avatar hyanwong commented on September 16, 2024

I guess part of the problem is nothing to do with tskit, but the very unintuitive np.where syntax which requires the [0] at the end (which I always forget). The other option is

ts.simplify(np.flatnonzero(ts.nodes_time == 0))

but that's hardly more intuitive, IMO. Or alternatively

ts.simplify((ts.nodes_time == 0).nonzero()[0])

Which is equally cryptic, but at least doesn't need you to use the np prefix, which again requires explanation when it's in the first few lines of a beginner's tutorial.

Anyway, if no-one thinks it's a good idea, I'll close this. However, it's worth pointing out that I'm finding it hard to introduce tskit to new users (especially from R, and if they don't know numpy).

from tskit.

petrelharp avatar petrelharp commented on September 16, 2024

Another option is

today_nodes = np.arange(ts.num_nodes)[ts.nodes_time == 0]
ts.simplify(today_nodes)

from tskit.

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.