Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/google-research/dex-lang in…
Browse files Browse the repository at this point in the history
…to tutorialfinal
  • Loading branch information
srush committed Jan 19, 2021
2 parents 1116889 + 3a1d1fd commit 8a17996
Show file tree
Hide file tree
Showing 49 changed files with 1,532 additions and 832 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ or these example programs:
* [Ray tracer](https://google-research.github.io/dex-lang/examples/raytrace.html)
* [Estimating pi](https://google-research.github.io/dex-lang/examples/pi.html)
* [Hamiltonian Monte Carlo](https://google-research.github.io/dex-lang/examples/mcmc.html)
* [ODE integrator](https://google-research.github.io/dex-lang/oexamples/de-integrator.html)
* [ODE integrator](https://google-research.github.io/dex-lang/examples/ode-integrator.html)
* [Sierpinski triangle](https://google-research.github.io/dex-lang/examples/sierpinski.html)
* [Basis function regression](https://google-research.github.io/dex-lang/examples/regression.html)
* [Brownian bridge](https://google-research.github.io/dex-lang/examples/brownian_motion.html)
Expand Down Expand Up @@ -56,10 +56,10 @@ development mode:

```console
# Linux:
alias dex="stack exec dex --"
alias dex="stack exec dex -- --lib-path lib"

# macOS:
alias dex="stack exec --stack-yaml=stack-macos.yaml dex --"
alias dex="stack exec --stack-yaml=stack-macos.yaml dex -- --lib-path lib"
```

## Running
Expand Down
7 changes: 5 additions & 2 deletions dex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ maintainer: [email protected]
license-file: LICENSE
build-type: Simple

data-files: lib/*.dx

flag cuda
description: Enables building with CUDA support
default: False
Expand All @@ -31,9 +33,9 @@ library dex-resources

library
exposed-modules: Env, Syntax, Type, Inference, JIT, LLVMExec,
Parser, Util, Imp, Imp.Embed, Imp.Optimize,
Parser, Util, Imp, Imp.Builder, Imp.Optimize,
PPrint, Algebra, Parallelize, Optimize, Serialize
Actor, Cat, Embed, Export,
Actor, Builder, Cat, Export,
RenderHtml, LiveOutput, Simplify, TopLevel,
Autodiff, Interpreter, Logging, CUDA,
LLVM.JIT, LLVM.Shims
Expand All @@ -49,6 +51,7 @@ library
store,
-- Notebook support
warp, wai, blaze-html, aeson, http-types, cmark, binary
other-modules: Paths_dex
if !os(darwin)
exposed-modules: Resources
hs-source-dirs: src/resources
Expand Down
2 changes: 1 addition & 1 deletion examples/brownian_motion.dx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

include "plot.dx"
import plot

UnitInterval = Float

Expand Down
2 changes: 1 addition & 1 deletion examples/fluidsim.dx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Fluid simulation code based on
[Real-Time Fluid Dynamics for Games](https://www.josstam.com/publications) by Jos Stam

include "plot.dx"
import plot

def wrapidx (n:Type) -> (i:Int) : n =
-- Index wrapping around at ends.
Expand Down
8 changes: 4 additions & 4 deletions examples/isomorphisms.dx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ that produce isos. We will start with the first two:
:t #b : Iso {a:Int & b:Float & c:Unit} _
> (Iso {a: Int32 & b: Float32 & c: Unit} (Float32 & {a: Int32 & c: Unit}))
> === parse ===
> _ans_ =
> _ans_ =
> MkIso {bwd = \(x, r). {b = x, ...r}, fwd = \{b = x, ...r}. (,) x r}
> : Iso {a: Int & b: Float & c: Unit} _

%passes parse
:t #?b : Iso {a:Int | b:Float | c:Unit} _
> (Iso {a: Int32 | b: Float32 | c: Unit} (Float32 | {a: Int32 | c: Unit}))
> === parse ===
> _ans_ =
> _ans_ =
> MkIso
> { bwd = \v. case v
> ((Left x)) -> {| b = x |}
Expand Down Expand Up @@ -142,7 +142,7 @@ another. For instance:
> ({ &} & {a: Int32 & b: Float32 & c: Unit})
> ({a: Int32} & {b: Float32 & c: Unit}))
> === parse ===
> _ans_ =
> _ans_ =
> MkIso
> { bwd = \({a = x, ...l}, {, ...r}). (,) {, ...l} {a = x, ...r}
> , fwd = \({, ...l}, {a = x, ...r}). (,) {a = x, ...l} {, ...r}}
Expand Down Expand Up @@ -212,7 +212,7 @@ zipper isomorphisms:
> ({ |} | {a: Int32 | b: Float32 | c: Unit})
> ({a: Int32} | {b: Float32 | c: Unit}))
> === parse ===
> _ans_ =
> _ans_ =
> MkIso
> { bwd = \v. case v
> ((Left w)) -> (case w
Expand Down
2 changes: 1 addition & 1 deletion examples/mandelbrot.dx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'# Mandelbrot set

include "plot.dx"
import plot

'Escape time algorithm

Expand Down
2 changes: 1 addition & 1 deletion examples/mcmc.dx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'## General MCMC utilities

include "plot.dx"
import plot

LogProb : Type = Float

Expand Down
2 changes: 1 addition & 1 deletion examples/ode-integrator.dx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This version is a port of the [Jax implementation](https://github.com/google/jax
One difference is that it uses a lower-triangular
matrix type for the Butcher tableau, and so avoids zero-padding everywhere.

include "plot.dx"
import plot

Time = Float

Expand Down
6 changes: 3 additions & 3 deletions examples/raytrace.dx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
described
[here](https://blog.evjang.com/2019/11/jaxpt.html).

include "plot.dx"
import plot

' ### Generic Helper Functions
Some of these should probably go in prelude.
Expand Down Expand Up @@ -212,7 +212,7 @@ def sampleLightRadiance
(surfNor, surf) = osurf
(rayPos, _) = inRay
(MkScene objs) = scene
yieldAccum \radiance.
yieldAccum (AddMonoid Float) \radiance.
for i. case objs.i of
PassiveObject _ _ -> ()
Light lightPos hw _ ->
Expand All @@ -227,7 +227,7 @@ def sampleLightRadiance

def trace (params:Params) (scene:Scene n) (initRay:Ray) (k:Key) : Color =
noFilter = [1.0, 1.0, 1.0]
yieldAccum \radiance.
yieldAccum (AddMonoid Float) \radiance.
runState noFilter \filter.
runState initRay \ray.
boundedIter (getAt #maxBounces params) () \i.
Expand Down
2 changes: 1 addition & 1 deletion examples/regression.dx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'# Basis function regression

include "plot.dx"
import plot

-- Conjugate gradients solver
def solve (mat:m=>m=>Float) (b:m=>Float) : m=>Float =
Expand Down
2 changes: 1 addition & 1 deletion examples/sierpinski.dx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'# Sierpinski triangle ("chaos game")

include "plot.dx"
import plot

def update (points:n=>Point) (key:Key) ((x,y):Point) : Point =
(x', y') = points.(randIdx key)
Expand Down
2 changes: 1 addition & 1 deletion examples/tiled-matmul.dx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def matmul (k : Type) ?-> (n : Type) ?-> (m : Type) ?->
vectorTile = Fin VectorWidth
colTile = (colVectors & vectorTile)
(tile2d (\nt:(Tile n rowTile). \mt:(Tile m colTile).
ct = yieldAccum \acc.
ct = yieldAccum (AddMonoid Float) \acc.
for l:k.
for i:rowTile.
ail = broadcastVector a.(nt +> i).l
Expand Down
2 changes: 2 additions & 0 deletions lib/diagram.dx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'# Vector graphics library

import png

Point : Type = (Float & Float)

data Geom =
Expand Down
4 changes: 2 additions & 2 deletions lib/plot.dx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'# Plotting library

include "diagram.dx"
include "png.dx"
import diagram
import png

data CompactSet a:Type =
Interval a a
Expand Down
Loading

0 comments on commit 8a17996

Please sign in to comment.