TorchLean API

NN.IR.DType

IR element types #

An IR value has a tensor shape and an element type. These descriptors identify the element representation without choosing a device, storage buffer, or kernel. Binary and decimal descriptors reuse FloatLib's validated formats. A configured binary128 or custom binary format is not a separate IR constructor.

context preserves scalar-polymorphic Lean graphs: the caller chooses their element type through the existing Storage and Context instances. Captured mixed-dtype programs use explicit descriptors instead.

Named types provide an extension point for a frontend or backend with another representation. Describing a type does not supply its arithmetic implementation; an interpreter must register the corresponding semantics or reject execution.

inductive NN.IR.DType :

Device-independent element representation of a tensor value.

  • context : DType

    Scalar type supplied by a homogeneous Lean graph's caller.

  • bool : DType

    Boolean values, distinct from numeric zero/one tensors.

  • integer (signed : Bool) (width : Option ℕ := none) : DType

    Signed or unsigned integers; none means unbounded, and a width must be positive.

  • binary (format : FloatLib.Floats.Formats.BinaryInterchange.FloatFormat) : DType

    A validated FloatLib binary format, including its bias and exceptional-value encoding.

  • decimal (format : FloatLib.Floats.Formats.DecimalInterchange.Format) : DType

    A validated FloatLib decimal interchange format.

  • posit (bits : ℕ) : DType

    A Posit Standard encoding of at least two bits.

  • rational : DType

    Exact rational values.

  • real : DType

    Mathematical real values, for specification interpreters.

  • complex (component : DType) : DType

    Real and imaginary components have the same explicitly described element type.

  • named (name : Lean.Name) (parameters : Array ℕ := #[]) : DType

    An extension identified by a qualified name and static natural-number parameters.

Instances For
    @[instance_reducible]
    def NN.IR.instDecidableEqDType.decEq (x✝ x✝¹ : DType) :
    Decidable (x✝ = x✝¹)
    Instances For
      @[instance_reducible]
      @[instance_reducible]

      IEEE binary16.

      Instances For

        Brain floating point with eight exponent bits and seven fraction bits.

        Instances For

          IEEE binary32.

          Instances For

            IEEE binary64.

            Instances For

              Whether parameters not already validated by FloatLib form a usable descriptor.

              Instances For

                Check descriptor parameters before accepting a graph or registering an implementation.

                Instances For

                  Compact type spelling for errors and graph displays, including custom format parameters.

                  Instances For
                    @[instance_reducible]

                    Preserve numeric and escaped name components, rather than parsing a display spelling.

                    Instances For

                      Component arrays are lossless; qualified strings are also accepted from frontend producers.

                      Instances For
                        @[irreducible]

                        JSON nesting depth, computed without the partial printer or proof-only SizeOf code.

                        Instances For
                          @[irreducible]

                          Maximum nesting among an array's entries.

                          Instances For
                            @[irreducible]

                            Maximum nesting among an object's values; keys do not add a component level.

                            Instances For

                              Decode nested components with a budget derived from the JSON structure, not a fixed depth.

                              Instances For

                                Encode the complete element representation, including format bias and name components.

                                Instances For

                                  Decode and validate a descriptor without selecting a numerical implementation.

                                  Instances For
                                    theorem NN.IR.DType.fromJson_valid {value : Lean.Json} {dtype : DType} (h : fromJson value = Except.ok dtype) :
                                    dtype.valid = true

                                    Successful decoding cannot introduce invalid element-type parameters.

                                    @[instance_reducible]
                                    @[instance_reducible]