Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed May 22, 2024
1 parent 4d66c00 commit 5a17d28
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# system-a

[system-a] `flatten`
[system-a] test `extend1` by `flatten`

# the-book

Interlude V: Extensio Magnifico!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ function extend1(
implicit outputRank: Nat,
x: Tensor(inputRank)
) => Tensor(outputRank) {
return function extendedFn(implicit inputRank, implicit outputRank, x) {
function extendedFn(implicit inputRank, implicit outputRank, x) {
if (inputRank === baseRank) {
return fn(x)
fn(x)
}
let Tensor::Array(xs) = x
return arrayMap(xs, extendedFn)
arrayMap(xs, extendedFn)
}
}
```
Expand Down Expand Up @@ -127,13 +127,45 @@ function extend1(
fn: (Tensor) -> Tensor,
baseRank: Nat
): (Tensor) -> Tensor {
return function extendedFn(x) {
function extendedFn(x) {
if (natEqual(rank(x), baseRank)) {
return fn(x)
fn(x)
}
let Tensor::Array(xs) = x
return arrayMap(xs, extendedFn)
arrayMap(xs, extendedFn)
}
}
```

也许 Tensor 应该直接被定义为一个函数:

```cicada
function Tensor(n: Nat): Type {
match (n) {
case Nat::Zero => Scalar
case Nat::Add1(prev) => Array(Tensor(prev))
}
}
check 1: Tensor(0)
check [1, 2, 3]: Tensor(1)
```

好像还是不行,并且没法用 implicit 了。

```cicada
function extend1(
baseRank: Nat
resultRank: Nat
fn: (Tensor(baseRank)) -> Tensor(resultRank),
): (Tensor) -> Tensor {
function extendedFn(x) {
if (natEqual(rank(x), baseRank)) {
fn(x)
}
TODO
}
}
```

0 comments on commit 5a17d28

Please sign in to comment.