Skip to content

Commit 016c4cd

Browse files
authored
add dependent variant dflip of flip (#302)
1 parent 229e806 commit 016c4cd

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Tensor.idr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ export
344344
(.T) : Tensor [m, n] dtype -> Tensor [n, m] dtype
345345
(MkTensor expr).T = MkTensor $ Transpose [1, 0] expr
346346

347-
public export
348-
index' : (xs : List Nat) -> (n : Nat) -> {auto 0 ok : InBounds n xs} -> Nat
349-
index' xs n = index n xs
350-
351347
||| Transpose axes of a tensor. This is a more general version of `(.T)`, in which you can transpose
352348
||| any number of axes in a tensor of arbitrary rank. The i'th axis in the resulting tensor
353349
||| corresponds to the `index i ordering`'th axis in the input tensor. For example, for
@@ -399,7 +395,7 @@ transpose :
399395
{auto 0 lengths : length ordering = length shape} ->
400396
{auto 0 unique : Sorted Neq ordering} ->
401397
{auto 0 inBounds : All (flip InBounds shape) ordering} ->
402-
Tensor (map (index' shape) ordering) dtype
398+
Tensor (map (dflip List.index shape) ordering) dtype
403399
transpose ordering (MkTensor expr) = MkTensor $ Transpose ordering expr
404400

405401
||| The identity tensor, with inferred shape and element type. For example,

src/Util.idr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ import public Data.List.Quantifiers
2121
import public Data.Nat
2222
import public Data.Vect
2323

24-
||| A `Neq x y` proves `x` is not equal to `y`.
24+
||| A dependent variant of `flip` where the return type can depend on the input values. `dflip`
25+
||| flips the order of arguments for a function, such that `dflip f x y` is the same as `f y x`.
2526
public export
27+
dflip : {0 c : a -> b -> Type} -> ((x : a) -> (y : b) -> c x y) -> (y : b) -> (x : a) -> c x y
28+
dflip f y x = f x y
29+
30+
||| A `Neq x y` proves `x` is not equal to `y`.
31+
public export 0
2632
Neq : Nat -> Nat -> Type
2733
Neq x y = Either (LT x y) (GT x y)
2834

0 commit comments

Comments
 (0)