Code Monkey home page Code Monkey logo

Comments (5)

cgarciae avatar cgarciae commented on May 22, 2024

The intention of the code makes sense, however according to the current semantics of Vector the operation seems weird because v has shape (15,) but the after the norm per leaf it has shape (2,), and division between such vectors would make no sense.

Maybe we need a looser abstraction (e.g. Numeric) that just lets you do leaf wise math operations but doesn't have array-like semantics.

from tree-math.

GeoffNN avatar GeoffNN commented on May 22, 2024

I think I see. I was somehow expecting Vector to allow leaf-wise math. The abstraction you suggest could be nice to avoid tree_map calls in general. For the above example, having something like
normalized_tree = tree / tm.norm(tree), with tree an instance of Numeric may be ideal. One example use-case is implementing power iteration with a pytree input.

from tree-math.

shoyer avatar shoyer commented on May 22, 2024

Leaf-wise math sounds potentially useful but as @cgarciae notes it's definitely a different data model. I would love to see a more fully fleshed out use-case for this functionality.

from tree-math.

cgarciae avatar cgarciae commented on May 22, 2024

Since a lot of the operations from Vector are also leaf-wise there is the possibility that Numeric / NumericMixin might serve as a base class to Vector and friends. One of the big differences with Vector would be the dot method, it would either have to also be leaf-wise and return a pytree or just not included as an operation.

from tree-math.

shoyer avatar shoyer commented on May 22, 2024

My mental model for objects like this is that they are something closer to ragged arrays, e.g., a 2D matrix where the first dimension corresponds to the number of pytree leaves, and the second dimension corresponds to the (variable) size of each leaf.

from tree-math.

Related Issues (11)

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.