Liking cljdoc? Tell your friends :D

sicmutils.expression.compile

This namespace contains tools for compiling functions implemented with the numeric operations defined in sicmutils.generic down to fast, native functions.

This namespace contains tools for compiling functions implemented with the
numeric operations defined in [[sicmutils.generic]] down to fast, native
functions.
raw docstring

compile-fnclj/s

(compile-fn f)
(compile-fn f n)

Returns a compiled, simplified version of f, given a function f of arity n (ie, able to accept n symbolic arguments).

n defaults to ([[f/arity]] f).

The returned, compiled function expects n Double (or js/Number) arguments. The function body is simplified and all common subexpressions identified during compilation are extracted and computed only once.

NOTE: that this function makes use of a global compilation cache, keyed by the vector [f n]. See compile-fn* to avoid the cache.

Returns a compiled, simplified version of `f`, given a function `f` of arity
`n` (ie, able to accept `n` symbolic arguments).

`n` defaults to `([[f/arity]] f)`.

The returned, compiled function expects `n` `Double` (or `js/Number`)
arguments. The function body is simplified and all common subexpressions
identified during compilation are extracted and computed only once.

NOTE: that this function makes use of a global compilation cache, keyed by the
vector `[f n]`. See `compile-fn*` to avoid the cache.
sourceraw docstring

compile-fn*clj/s

(compile-fn* f)
(compile-fn* f n)

Returns a compiled, simplified version of f, given a function f of arity n (ie, able to accept n symbolic arguments).

n defaults to ([[f/arity]] f).

The returned, compiled function expects n Double (or js/Number) arguments. The function body is simplified and all common subexpressions identified during compilation are extracted and computed only once.

NOTE: this function uses no cache. To take advantage of the global compilation cache, see compile-fn.

Returns a compiled, simplified version of `f`, given a function `f` of arity
`n` (ie, able to accept `n` symbolic arguments).

`n` defaults to `([[f/arity]] f)`.

The returned, compiled function expects `n` `Double` (or `js/Number`)
arguments. The function body is simplified and all common subexpressions
identified during compilation are extracted and computed only once.

NOTE: this function uses no cache. To take advantage of the global compilation
cache, see `compile-fn`.
sourceraw docstring

compile-state-fnclj/s

(compile-state-fn f params initial-state)

Returns a compiled, simplified function, given:

  • a state function that can accept a symbolic arguments

  • params; really any sequence of count equal to the number of arguments taken by f. The values are ignored.

  • initial-state: Some structure of the same shape as the argument expected by the fn returned by the state function f. Only the shape matters; the values are ignored.

The returned, compiled function expects Double (or js/Number) arguments. The function body is simplified and all common subexpressions identified during compilation are extracted and computed only once.

NOTE that this function makes use of a global compilation cache, keyed by the value of f. Passing in the same f twice, even with different arguments for param and initial-state, will return the cached value. See compile-state-fn* to avoid the cache.

Returns a compiled, simplified function, given:

- a state function that can accept a symbolic arguments

- `params`; really any sequence of count equal to the number of arguments
  taken by `f`. The values are ignored.

- `initial-state`: Some structure of the same shape as the argument expected
  by the fn returned by the state function `f`. Only the shape matters; the
  values are ignored.

The returned, compiled function expects `Double` (or `js/Number`) arguments.
The function body is simplified and all common subexpressions identified
during compilation are extracted and computed only once.

NOTE that this function makes use of a global compilation cache, keyed by the
value of `f`. Passing in the same `f` twice, even with different arguments for
`param` and `initial-state`, will return the cached value. See
`compile-state-fn*` to avoid the cache.
sourceraw docstring

compile-state-fn*clj/s

(compile-state-fn* f params initial-state)

Returns a compiled, simplified function, given:

  • a state function that can accept a symbolic arguments

  • params; really any sequence of count equal to the number of arguments taken by f. The values are ignored.

  • initial-state: Some structure of the same shape as the argument expected by the fn returned by the state function f. Only the shape matters; the values are ignored.

The returned, compiled function expects Double (or js/Number) arguments. The function body is simplified and all common subexpressions identified during compilation are extracted and computed only once.

NOTE this function uses no cache. To take advantage of the global compilation cache, see compile-state-fn.

Returns a compiled, simplified function, given:

- a state function that can accept a symbolic arguments

- `params`; really any sequence of count equal to the number of arguments
  taken by `f`. The values are ignored.

- `initial-state`: Some structure of the same shape as the argument expected
  by the fn returned by the state function `f`. Only the shape matters; the
  values are ignored.

The returned, compiled function expects `Double` (or `js/Number`) arguments.
The function body is simplified and all common subexpressions identified
during compilation are extracted and computed only once.

NOTE this function uses no cache. To take advantage of the global compilation
cache, see `compile-state-fn`.
sourceraw docstring

cse-formclj/s

(cse-form expr)
(cse-form expr opts)

Given a symbolic expression expr, returns a new expression potentially wrapped in a let binding with one binding per extracted common subexpression.

Optional Arguments

:symbol-generator: side-effecting function that returns a new, unique symbol on each invocation. These generated symbols are used to create unique binding names for extracted subexpressions. sortable-gensym by default.

NOTE that the symbols should appear in sorted order! Otherwise we can't guarantee that the binding sequence won't contain entries that reference previous entries, resulting in "Unable to resolve symbol" errors.

:deterministic?: if true, the function will order the let-binding contents by sorting the string representations of each term before assignment. If false the function won't guarantee a consistent variable naming convention in the returned function. For tests, we recommend :deterministic? true.

Given a symbolic expression `expr`, returns a new expression potentially
wrapped in a `let` binding with one binding per extracted common
subexpression.

## Optional Arguments

`:symbol-generator`: side-effecting function that returns a new, unique symbol
on each invocation. These generated symbols are used to create unique binding
names for extracted subexpressions. `sortable-gensym` by default.

NOTE that the symbols should appear in sorted order! Otherwise we can't
guarantee that the binding sequence won't contain entries that reference
previous entries, resulting in "Unable to resolve symbol" errors.

`:deterministic?`: if true, the function will order the let-binding contents
by sorting the string representations of each term before assignment. If false
the function won't guarantee a consistent variable naming convention in the
returned function. For tests, we recommend `:deterministic? true`.
sourceraw docstring

extract-common-subexpressionsclj/s

(extract-common-subexpressions expr continue)
(extract-common-subexpressions expr
                               continue
                               {:keys [symbol-generator deterministic?]
                                :or {symbol-generator sortable-gensym}})

Considers an S-expression from the point of view of optimizing its evaluation by isolating common subexpressions into auxiliary variables.

Accepts:

  • A symbolic expression expr
  • a continuation fn continue of two arguments:
    • a new equivalent expression with possibly some subexpressions replaced by new variables (delivered by the supplied generator, see below)
    • a seq of pairs of [aux variable, subexpression] used to reconstitute the value.

Calls the continuation at completion and returns the continuation's value.

Optional Arguments

:symbol-generator: side-effecting function that returns a new, unique variable name on each invocation. sortable-gensym by default.

NOTE that the symbols should appear in sorted order! Otherwise we can't guarantee that the binding sequence passed to continue won't contain entries that reference previous entries.

:deterministic?: if true, the function will assign aux variables by sorting the string representations of each term before assignment. Otherwise, the nondeterministic order of hash maps inside this function won't guarantee a consistent variable naming convention in the returned function. For tests, set :deterministic? true.

Considers an S-expression from the point of view of optimizing its evaluation
by isolating common subexpressions into auxiliary variables.

Accepts:

- A symbolic expression `expr`
- a continuation fn `continue` of two arguments:
  - a new equivalent expression with possibly some subexpressions replaced by
    new variables (delivered by the supplied generator, see below)
  - a seq of pairs of `[aux variable, subexpression]` used to reconstitute the
    value.

Calls the continuation at completion and returns the continuation's value.

### Optional Arguments

`:symbol-generator`: side-effecting function that returns a new, unique
variable name on each invocation. `sortable-gensym` by default.

NOTE that the symbols should appear in sorted order! Otherwise we can't
guarantee that the binding sequence passed to `continue` won't contain entries
that reference previous entries.

`:deterministic?`: if true, the function will assign aux variables by sorting
the string representations of each term before assignment. Otherwise, the
nondeterministic order of hash maps inside this function won't guarantee a
consistent variable naming convention in the returned function. For tests, set
`:deterministic? true`.
sourceraw docstring

set-compiler-mode!clj/s

(set-compiler-mode! mode)

Set the default compilation mode by supplying an entry from valid-modes.

Set the default compilation mode by supplying an entry from [[valid-modes]].
sourceraw docstring

sortable-gensymclj/s

source

valid-modesclj/s

Set of all supported compilation modes.

Set of all supported compilation modes.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close