Giter Site home page Giter Site logo

Comments (4)

polvalente avatar polvalente commented on May 18, 2024 1

@nileshtrivedi I'm not aware of any libraries in that space (heh)
But you could build upon Nx for that. I read up a bit on Clifford Algebra and this is roughly where you would start for R2:

defmodule Geometric do
  defmodule Bivector do
    @moduledoc "represents a bivector with basis (e1, e2)"
    @derive {Nx.Container, containers: [:scalar]}
    defstruct [:scalar]
  end
  
  defmodule Multivector do
    @moduledoc "represents a multivector with a grade-0 (scalar) part and a grade-2 (bivector) part"
    @derive {Nx.Container, containers: [:scalar, :bivector]}
    defstruct [:scalar, :bivector]
  end
  
  import Nx.Defn
    
  defn wedge_product(%Nx.Tensor{shape: {n}} = v1, %Nx.Tensor{shape: {n}} = v2) do
    a = v1[0]
    b = v1[1]
    c = v2[0]
    d = v2[1]
    
    %Bivector{scalar: a * d - b * c}
  end
     
  defn geometric_product(%Nx.Tensor{shape: {n}} = v1, %Nx.Tensor{shape: {n}} = v2) do
    %MultiVector{scalar: Nx.dot(v1, v2), bivector: wedge_product(v1, v2)}
  end
end

Nx.Container allows you to define structs that work inside defn, and then you can compose things accordingly, even defining a custom add function that works differently based on the different input combinations.

from nx.

polvalente avatar polvalente commented on May 18, 2024

This is not currently possible in Nx, nor is planned.
For what it's worth, the example you showed only uses numpy for getting constants like e and pi, while the actual algebra is handled by the clifford library.

from nx.

nileshtrivedi avatar nileshtrivedi commented on May 18, 2024

@polvalente True. Are you aware of any elixir libraries that I can use in conjunction with Nx to do this kind of work?

from nx.

nileshtrivedi avatar nileshtrivedi commented on May 18, 2024

@polvalente Oh, thank you so much for taking the time to look into this (much more than I was expecting). This helps a lot. :-)

from nx.

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.