Giter VIP home page Giter VIP logo

Comments (4)

MikeInnes avatar MikeInnes commented on June 11, 2024 1

It might also be a good idea to use Mjolnir to extract symbolic expressions from Julia code, over the current operator overloading approach. This would be better able to support type constraints, intrinsics (ifelse), higher-order functions (map/reduce/sum etc.) and even simple control flow (the branches could be lowered to a functional or ifelse representation if that's easier for SymbolicUtils to work with). I plan to throw up a prototype of that idea soon.

from symbolicutils.jl.

MikeInnes avatar MikeInnes commented on June 11, 2024 1

the branches could be lowered to a functional or ifelse representation

By the way, the XLA work effectively has a proof of concept for this:

julia> using XLA

julia> relu(x) = x > 0 ? x : 0
relu (generic function with 1 method)

julia> ir = XLA.@code_xla relu(5)
1: (%1 :: Int64)
  %2 = (XLA.Gt())(%1, 0)
  br 2 unless %2
  br 3 (%1)
2:
  br 3 (0)
3: (%3 :: Int64)
  return %3

julia> XLA.controlflow(ir)
1: (%1 :: Int64)
  %2 = (XLA.Gt())(%1, 0)
  %4 = (XLA.Not())(%2)
  %5 = 
    1: (%1)
      %2 = (XLA.XTuple())(0)
  %6 = 
    1: (%1)
  %7 = (XLA.XTuple())()
  %8 = (XLA.XTuple())(%1)
  %9 = (XLA.Conditional())(%4, %7, %5, %8, %6)
  %10 = (XLA.GetTupleElement(0))(%9)

The XLA representation is a bit fiddly, but the controlflow transformed IR is equivalent to

julia> cond(c, t, f) = c ? t() : f() # XLA's `cond`, roughly

julia> relu(x) = cond(x > 0, () -> x, () -> 0)

Which is equivalent to a piecewise function definition. I'm not sure if you support things like lambdas, piecewise functions, list comprehensions etc., or if you plan to, but at any rate there's no issue using pulling those things out of Julia code.

from symbolicutils.jl.

shashi avatar shashi commented on June 11, 2024

Awesome! Yes this could be a fix for #16 cc @MasonProtter

from symbolicutils.jl.

shashi avatar shashi commented on June 11, 2024

the branches could be lowered to a functional or ifelse representation if that's easier for SymbolicUtils to work with

Just added cond in #75

from symbolicutils.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.