This namespace compiles generic functions down into fast, native functions.
This namespace compiles generic functions down into fast, native functions.
(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,
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, will return the cached value. See `compile-state-fn*` to avoid the cache.
(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`.
(compile-univariate-fn f)
Returns a compiled, simplified version of f
, given a univariate function f
able to accept one symbolic argument.
The returned, compiled function expects a single Double (or js/Number) argument. 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,
will return the cached value. See compile-univariate-fn*
to avoid the
cache.
Returns a compiled, simplified version of `f`, given a univariate function `f` able to accept one symbolic argument. The returned, compiled function expects a single Double (or js/Number) argument. 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, will return the cached value. See `compile-univariate-fn*` to avoid the cache.
(compile-univariate-fn* f)
Returns a compiled, simplified version of f
, given a univariate function f
able to accept one symbolic argument.
The returned, compiled function expects a single Double (or js/Number) argument. 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-univariate-fn
.
Returns a compiled, simplified version of `f`, given a univariate function `f` able to accept one symbolic argument. The returned, compiled function expects a single Double (or js/Number) argument. 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-univariate-fn`.
(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.
: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. 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. `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`.
(extract-common-subexpressions expr continue)
(extract-common-subexpressions expr
continue
{:keys [symbol-generator deterministic?]
:or {symbol-generator gensym}})
Considers an S-expression from the point of view of optimizing its evaluation by isolating common subexpressions into auxiliary variables.
Accepts:
expr
continue
of two arguments:
Calls the continuation at completion and returns the continuation's value.
:symbol-generator
: side-effecting function that returns a new, unique
variable name on each invocation. 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. `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`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close