Module Ops.Upat
Patterns.
A pattern describes nodes by their operation, type, argument and sources, and names the nodes it matches. A name used twice must match the same node.
type tThe type for patterns.
val v :
?op:Op.Set.t ->
?dtype:Dtype.t list ->
?src:t list ->
?perm:t list ->
?each:t ->
?allow_any_len:bool ->
?arg:arg ->
?name:string ->
?early_reject:Op.t list ->
unit ->
tv () matches the nodes of an operation in op, a type in dtype and argument arg, each when given. Sources are matched in order by src, in any order by perm, or each by each; src and perm require exactly as many sources unless allow_any_len. name names the node matched. early_reject is operations the node's sources must include for the pattern to be tried, by default the operations the source patterns require.
Arguments compare as numbers do: `Int 0, `Float 0. and `Bool false are equal, and so are two NaNs.
Raises Invalid_argument if more than one of src, perm and each is given.
val op :
?dtype:Dtype.t list ->
?src:t list ->
?perm:t list ->
?each:t ->
?allow_any_len:bool ->
?arg:arg ->
?name:string ->
?early_reject:Op.t list ->
Op.t ->
top o is v ~op:(Op.Set.of_list [o]) ().
var ~dtype name matches any node of a type in dtype, named name.
val cvar : ?dtype:Dtype.t list -> ?arg:Dtype.const -> string -> tcvar ~dtype ~arg name matches a constant, named name.
val const : ?dtype:Dtype.t list -> Dtype.const -> tconst ~dtype c matches the constant c.
f p o matches the node o of the one source p matches: f p Cast matches a cast of p to any type.
dtype p is the first type p requires, or Dtype.t.Void.
Commutative operations match their operands in either order, and the literals of O match constants of any type (cvar). cast p dt is p if p requires exactly dt. // and % match Op.t.Div and Op.t.Mod.
include Elementwise with type t := t
Arithmetic
add, mul, lt, eq, maximum, bitwise_and, bitwise_or, bitwise_xor, shl and shr are Op.t.Add, Op.t.Mul, Op.t.Cmplt, Op.t.Cmpeq, Op.t.Max, Op.t.And, Op.t.Or, Op.t.Xor, Op.t.Shl and Op.t.Shr of their promoted operands. reciprocal, trunc, sqrt, exp2 and log2 are Op.t.Recip, Op.t.Trunc, Op.t.Sqrt, Op.t.Exp2 and Op.t.Log2 of their operand. The others are built from these.
div ~rounding x y divides integers by Op.t.Truncdiv or Op.t.Div when rounding; otherwise it multiplies x, as a float, by y's reciprocal, then rounds as asked.
minimum x y is neg (maximum (neg x) (neg y)) for floats; for integers, the same through an order-reversing xor.
The operators are also at the top, so that Upat.(var "x" + cvar "c") reads as the pattern it builds.
include module type of O
match_ p u is the naming of each way p matches u, in order: the alternatives of any in turn, the orderings of a commutative operation's operands in the order of their permutations, the first operand varying slowest, and each source's namings before the next source's; [] if p does not match. Ways that differ only within a part of p that names nothing give one naming.