-
Notifications
You must be signed in to change notification settings - Fork 15
/
julia_interface_test.sj
68 lines (45 loc) · 1.6 KB
/
julia_interface_test.sj
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Apply(ClearAll, UserSyms())
### Pack
a = Pack([1,2,3])
T If( BigIntInput() , J( eltype(Symata.symval(:a)) == BigInt ), J( eltype(Symata.symval(:a)) == Int ))
func = J((x,y) -> sum(u -> u[1]^2*u[2]^3, zip(margs(x),margs(y))))
#T J( eltype(Symata.symval(:a)) == Int )
a = Pack([1,2,3.0])
T J( eltype(Symata.symval(:a)) == Real )
a = Pack([1,2,3.0, "cat"])
T J( eltype(Symata.symval(:a)) == Any )
J(Core.eval(Main, :(b = 1 )))
T JVar(b) == 1
T Length(Unpack( J( [1, 2, 3] ))) == 3
T Head(Unpack( J( [1, 2, 3] ))) == List
ClearAll(a,x)
### J
# We are in Test module or something ?
T J( Symata.Cos )(1) == Cos(1)
T J( Symata.Cos )(1.0) == Cos(1.0)
T J( Symata.Cos )(1.0) == J( cos(1.0) )
T J( Symata.Cos(:a) ) == Cos(a)
func = J((x,y) -> sum(u -> u[1]^2/u[2]^3, zip(margs(x),margs(y))))
T Abs(func(Range(10.0),Range(10.0)) - 2.9289682539682538) < 10^(-8)
## Test that + in sum method has a base method that works on Mxpr.
T Head(func([a+b, c+d],[u+v,y+z])) == Plus
## Nov 2016. Add methods for * and + on symbols, etc.
## We do not import the functions from Main.
T Head(J( Symata.:+(:c,:d) )) == Plus
T Head(J( Symata.:*(:c,:d) )) == Times
T J(3) == 3
T J(3 + 2) == 5
T J( x = 1 ) == 1 ## x = 1 is rewritten from call with kw, to =
T J( x ) == 1
### Compile
T Compile([x], Cos(x) )(3) == Cos(3)
T Compile([x], Cos(x) )(0.0) == 1.0
T Compile([x], Cos(x) )(a) == Cos(a)
T Compile([x], Exp(x)*Cos(x)*x )(1.0) == J( exp(1.0) * cos(1.0) *1.0 )
### SymataCall
Apply(ClearAll, UserSyms())
f = SymataCall([x,y], y*x^2/m)
T f(p,z) == m^(-1)*p^2*z
f = SymataCall(x, x^2)
T f(a) == a^2
Apply(ClearAll, UserSyms())