GithubHelp home page GithubHelp logo

Comments (5)

ducky427 avatar ducky427 commented on May 28, 2024

I can work around this issue by keeping a map of {<vertex-id> <my-id>...}. But it'll be nice to have that support as part of the graph.

from fabric.

postspectacular avatar postspectacular commented on May 28, 2024

Hiya, thanks for your interest & a good question. Custom vertex IDs are supported, but not exactly as what you're after...

  1. when you create a new compute-graph, you can specify an ::id-gen-fn option. This is a single-arg function (taking nil or the previous ID) and produces the next vertex ID. By default this is simply a counter, but you could e.g. use this to generate UUIDs as vertex IDs:
(require '[thi.ng.fabric.core :as f])

(defn random-uuid (fn [_] (java.util.UUID/randomUUID)))

(def g (f/compute-graph {::f/id-gen-fn random-uuid}))

This however doesn't directly do what you asked for and I guess this is something which could be refactored (but would have to be supplied at construction time and couldn't be changed afterwards).

  1. The other solution is to just add a custom a user field to each vertex:
(def VAT (f/add-vertex! g 1.2 {:cell-id :vat-rate}))

Then to obtain that (e.g. inside a collection function, whilst processing the signal map):

(->> sig-id (f/vertex-for-id g) f/state :cell-id)

Does this help?

from fabric.

ducky427 avatar ducky427 commented on May 28, 2024

Thanks a lot for your response.

In the local context, for example inside a collection function, I think approach 2) would definitely work to get a mapping from vertex-id to :cell-id as you know the former.

In the longer term, I think I think vspec could probably be checked if it has a key called :id (or something) and only use ::next-id if it is not present.

This would also really help the end user in introspecting the values of the vertices in a large enough graph.

Thanks again.

from fabric.

postspectacular avatar postspectacular commented on May 28, 2024

That's a great idea and I will refactor this asap... would also be faster to acess during processing, but would too need to include a check that the user specified ID is unique during construction. cheers!

from fabric.

ducky427 avatar ducky427 commented on May 28, 2024

Thanks a lot!

from fabric.

Related Issues (6)

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.