1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
@noinline
def standalone_sum(xs:n=>v) -> v given (n|Ix, v|Add) =
sum xs
vec3 = [1,2,3]
vec2 = [4,5]
-- TODO: test that we only get one copy inlined (hard to without dumping IR
-- until we have logging for that sort of thing)
:p standalone_sum vec2 + standalone_sum vec3
> 15
mat23 = [[1,2,3],[4,5,6]]
mat32 = [[1,2],[3,4],[5,6]]
@noinline
def standalone_transpose(x:n=>m=>a) -> m=>n=>a given (n|Ix, m|Ix, a) =
for i j. x[j,i]
:p (standalone_transpose mat23, standalone_transpose mat32)
> ([[1, 4], [2, 5], [3, 6]], [[1, 3, 5], [2, 4, 6]])
xs = [1,2,3]
@noinline
def foo(_:()) -> Nat = sum xs
foo ()
> 6
'Regression test for #1152. The standalone function is just here to
make the size of the tables unknown. The actual bug is in Alegbra
handling an expression like `sum_{i=0}^k k * i` where the same
name occurs in the monomial and the limit.
def LowerTriMat(n|Ix, v:Type) -> Type = (i:n)=>(..i)=>v
def UpperTriMat(n|Ix, v:Type) -> Type = (i:n)=>(i..)=>v
@noinline
def bar(n: Nat) -> Float =
(for k. for j:(..k). 0.0, for k. for j:(k..). 0.0) :: (LowerTriMat (Fin n) Float, UpperTriMat (Fin n) Float)
0.0
bar 2
> 0.
|