@[reducible, inline]
Type of tensor dimensions and indexes into tensor dimensions.
NOTE: see interaction with linarith
where we need to unfold Index
into ℕ
https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Ergonomics.3A.20linarith.20does.20not.20work.20on.20Nat.20alias/near/365631549
Equations
Instances For
- size : Tensor1D.Index
- val : Tensor1D.Index → α
- spec : ∀ ix ≥ self.size, self.val ix = default
Instances For
theorem
Tensor1D.Tensor1d.spec
{α : Type}
[Inhabited α]
(self : Tensor1D.Tensor1d α)
(ix : Tensor1D.Index)
:
Equations
- Tensor1D.Tensor1d.empty = { size := 0, val := fun (x : Tensor1D.Index) => default, spec := ⋯ }
Instances For
def
Tensor1D.Tensor1d.extract
{α : Type}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
(left : Tensor1D.Index)
(len : Tensor1D.Index)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Tensor1D.Tensor1d.map f t = { size := t.size, val := fun (ix : Tensor1D.Index) => if ix < t.size then f (t.val ix) else default, spec := ⋯ }
Instances For
theorem
Tensor1D.Tensor1d.extract_map
{α : Type}
{f : α → α}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
(left : Tensor1D.Index)
(len : Tensor1D.Index)
:
Tensor1D.Tensor1d.map f (t.extract left len) = (Tensor1D.Tensor1d.map f t).extract left len
Equations
- t.fill v = { size := t.size, val := fun (ix : Tensor1D.Index) => if ix < t.size then v else default, spec := ⋯ }
Instances For
theorem
Tensor1D.Tensor1d.extract_fill
{α : Type}
{left : Tensor1D.Index}
{len : Tensor1D.Index}
{v : α}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
:
(t.extract left len).fill v = (t.fill v).extract left len
def
Tensor1D.Tensor1d.insertslice
{α : Type}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
(sliceix : ℕ)
(slice : Tensor1D.Tensor1d α)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
theorem
Tensor1D.extractslice_insertslice
{α : Type}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
(sliceix : ℕ)
(slice : Tensor1D.Tensor1d α)
(CORRECT : ((t.insertslice sliceix slice).extract sliceix slice.size).size ≠ 0)
:
(t.insertslice sliceix slice).extract sliceix slice.size = slice
Equations
Instances For
theorem
Tensor1D.Tensor2d.transpose_involutive
{α : Type}
(t : Tensor1D.Tensor2d α)
:
t.transpose.transpose = t
theorem
Tensor1D.Tensor1d.map_fusion
{α : Type}
{g : α → α}
{f : α → α}
[Inhabited α]
(t : Tensor1D.Tensor1d α)
:
Tensor1D.Tensor1d.map (g ∘ f) t = Tensor1D.Tensor1d.map g (Tensor1D.Tensor1d.map f t)
Equations
- Tensor1D.scf.for.loop f n 0 acc = acc
- Tensor1D.scf.for.loop f n n_minus_i'.succ acc = Tensor1D.scf.for.loop f n n_minus_i' (f (n - n_minus_i'.succ) acc)
Instances For
Equations
- Tensor1D.scf.for n f seed = Tensor1D.scf.for.loop f n (n - 0) seed
Instances For
theorem
Tensor1D.scf.for.peel_begin
{β : Sort u_1}
(n : ℕ)
(f : ℕ → β → β)
(seed : β)
:
Tensor1D.scf.for.loop f (n + 1) n (f 0 seed) = Tensor1D.scf.for.loop f (n + 1) (n + 1) seed
theorem
Tensor1D.scf.for.peel_end
{β : Sort u_1}
(n : ℕ)
(f : ℕ → β → β)
(seed : β)
:
Tensor1D.scf.for.loop f (n + 1) 0 (f n seed) = f n (Tensor1D.scf.for.loop f n 0 seed)
theorem
Tensor1D.scf.for.zero_n
{β : Sort u_1}
(f : ℕ → β → β)
(seed : β)
:
Tensor1D.scf.for 0 f seed = seed
def
Tensor1D.scf.for.one_n
{β : Sort u_1}
(f : ℕ → β → β)
(seed : β)
:
Tensor1D.scf.for 1 f seed = f 0 seed
Equations
- ⋯ = ⋯
Instances For
We make the following simplifying assumptions in the IR:
- Currently, there is no way to build a tensor, we only have operations on them.
- Constants are only natural numbers, which represent indexing into tensors.
- 1D tensors are functions from indexes (natural) to tensor values (integers).
This matches the MLIR model, which has a separate index
type for indexing
and iXX/f32/f64
types for values held in tensors.
- add_int: Tensor1D.Op
add two integers
- const_ix: Tensor1D.Index → Tensor1D.Op
create a constant index
- sub_int: Tensor1D.Op
subtract two integers
- map1d: Tensor1D.Op
map a function onto a tensor
- extract1d: Tensor1D.Op
extract a value at an index of a tensor
Instances For
- int: Tensor1D.Ty
values held in tensors
- ix: Tensor1D.Ty
shapes and indexes of tensors
- tensor1d: Tensor1D.Ty
tensor type
Instances For
Equations
- Tensor1D.instDecidableEqTy x y = if h : x.toCtorIdx = y.toCtorIdx then isTrue ⋯ else isFalse ⋯
Equations
- Tensor1D.instInhabitedTy = { default := Tensor1D.Ty.int }
Equations
- One or more equations did not get rendered due to their size.
@[reducible]
Equations
Instances For
@[reducible]
Equations
Instances For
@[reducible]
Equations
- Tensor1D.Op.map1d.regSig = [([Tensor1D.Ty.int], Tensor1D.Ty.int)]
- x.regSig = []
Instances For
Equations
- Tensor1D.Tensor1D = { Op := Tensor1D.Op, Ty := Tensor1D.Ty, m := Id }
Instances For
Equations
- One or more equations did not get rendered due to their size.