Skip to contents

Create a new primitive. For details on how to do this, see the article on Adding a Primitive. Like every jitted function it runs on the active backend when called.

Usage

new_primitive(
  name,
  fn,
  subgraphs = character(),
  static = character(),
  register = TRUE
)

Arguments

name

(character(1))
Primitive name.

fn

(function)
Body of the primitive. Its formals become the formals of the returned JIT-compiled callable. Inside fn, the primitive is accessible via the lexically-bound symbol self (an AnvlPrimitive); pass it as the first argument to graph_desc_add().

subgraphs

(character())
Names of parameters that are subgraphs (for higher-order primitives).

static

(character() | integer())
Passed to jit().

register

(logical(1))
If TRUE (default), register the result under name in the primitive registry.

Value

(JitPrimitive)
A callable of class c("JitPrimitive", "JitFunction").