Einsum_parserEntry point for the einsum parser library.
This module provides functions to parse einsum notation specifications using a Menhir-based parser.
Use_padding specification for convolutions.
val sexp_of_use_padding_spec : use_padding_spec -> Sexplib0.Sexp.ttype conv_spec = {dilation : Base.string;kernel_label : Base.string;use_padding : use_padding_spec;}Convolution component for affine axis specifications. Note: dilation is a string because it can be an identifier at parse time, and is resolved to an int at runtime.
val sexp_of_conv_spec : conv_spec -> Sexplib0.Sexp.ttype axis_spec = | Label of Base.stringA variable axis label.
*)| Fixed_index of Base.intA fixed index, used for projection.
*)| Affine_spec of {stride : Base.string;Coefficient for the over dimension (string to allow identifiers).
*)over_label : Base.string;The output/iteration dimension label.
*)conv : conv_spec Base.option;Optional convolution: dilation*kernel.
*)stride_offset : Base.int;Constant offset added after stride*over.
*)}Affine axis specification: stride*over + stride_offset + dilation*kernel. Corresponds to Row.Affine in shape inference.
| Concat_spec of concat_component Base.listConcatenation of several components into a single axis. Corresponds to Row.Concat in shape inference.
Specification for individual axes in the einsum notation. Note: stride is a string because it can be an identifier at parse time, and is resolved to an int at runtime.
val sexp_of_axis_spec : axis_spec -> Sexplib0.Sexp.tval sexp_of_concat_component : concat_component -> Sexplib0.Sexp.tmodule AxisKey : sig ... endAn index pointing to any of a shape's axes, including the kind of the axis (Batch, Input, Output) and the position (which is counted from the end to facilitate broadcasting).
val sexp_of_axis_map :
'a. ('a -> Sexplib0.Sexp.t) ->
'a axis_map ->
Sexplib0.Sexp.ttype parsed_axis_labels = {bcast_batch : Base.string Base.option;bcast_input : Base.string Base.option;bcast_output : Base.string Base.option;implicit_batch : Base.bool;implicit_input : Base.bool;given_batch : axis_spec Base.list;given_input : axis_spec Base.list;given_output : axis_spec Base.list;given_beg_batch : axis_spec Base.list;given_beg_input : axis_spec Base.list;given_beg_output : axis_spec Base.list;labels : axis_spec axis_map;}The labels are strings assigned to AxisKey axes. Moreover the bcast_ fields represent whether additional leading/middle axes are allowed (corresponding to the dot-ellipsis syntax for broadcasting). The string can be used to identify a row variable; parsing "..." yields the reserved per-kind names "...batch", "...input", "...output", which cannot collide with user-written identifiers. The implicit_ fields record that the row was omitted together with its kind separator, in which case it reads as the context ellipsis but its row variable may be silently closed to an empty row (even on parameters) when nothing else constrains it — unlike an explicitly written ellipsis. The given_ fields are lists of axis specs of the corresponding kind in labels where from_end=true, given_beg_ where from_end=false.
val sexp_of_parsed_axis_labels : parsed_axis_labels -> Sexplib0.Sexp.tval axis_labels : parsed_axis_labels -> axis_spec axis_mapThe unqualified DSL operators whose literal specifications the OCANNL PPXs pass through identifier substitution. The PPX dispatch tables and source-policy scans share these values so adding a syntax form cannot silently update only one consumer.
Determine if a spec uses multichar mode. Multichar mode is triggered by presence of: ',', '*', '+', '^', '&', '<', or a '=' that does not begin "=>". In multichar mode axes are separated by commas; whitespace does not separate them.
val axis_labels_of_spec : Base.string -> parsed_axis_labelsParse an axis labels specification.
Examples:
val einsum_of_spec :
Base.string ->
parsed_axis_labels Base.list * parsed_axis_labelsParse an einsum specification. Returns a list of RHS specs and the LHS (result) spec.
Examples: