Added some tests
Tests from image_filters Examples of array iterators used
This commit is contained in:
parent
c61e01f19b
commit
1a373b84eb
7 changed files with 327 additions and 0 deletions
47
test/good/convolutions.ept
Normal file
47
test/good/convolutions.ept
Normal file
|
@ -0,0 +1,47 @@
|
|||
(* Deal with matrix of size n*m, apply coeff :
|
||||
kt
|
||||
kl k kr
|
||||
kb
|
||||
centered on [>i<][>j<]. *)
|
||||
fun kernel_1 << n,m,k,kl,kt,kr,kb :int>> (t :int^n^m; i,x,j :int) returns (r :int)
|
||||
let
|
||||
r = k*t[>i<][>j<] + kl*t[>i<][>j-1<] + kt*t[>i-1<][>j<] + kr*t[>i<][>j+1<] + kb*t[>i+1<][>j<]
|
||||
tel
|
||||
|
||||
fun convol_1_h <<n,m,k,kl,kt,kr,kb :int>> (t:int^n^m; line : int^m; i :int) returns (r :int^m)
|
||||
let
|
||||
r = mapi<<m>> (kernel_1<<n,m,k,kl,kt,kr,kb>>)<(t,i)> (line)
|
||||
tel
|
||||
|
||||
fun convol_1 <<n,m,k,kl,kt,kr,kb :int>> (t:int^n^m) returns (r :int^n^m)
|
||||
let
|
||||
r = mapi<<n>> ( convol_1_h<<n,m,k,kl,kt,kr,kb>> ) <(t)> (t)
|
||||
tel
|
||||
|
||||
|
||||
(* Deal with matrix of size n*m, apply coeff :
|
||||
ktt
|
||||
klt kt ktr
|
||||
kll kl k kr krr
|
||||
kbl kb krb
|
||||
kbb
|
||||
centered on [>i<][>j<]. *)
|
||||
fun kernel_2 <<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb :int>> (t :int^n^m; i,x,j :int) returns (r :int)
|
||||
let
|
||||
r = ktt*t[>i-2<][>j<]+
|
||||
klt*t[>i-1<][>j-1<]+ kt*t[>i-1<][>j<]+ ktr*t[>i-1<][>j+1<]+
|
||||
kll*t[>i<][>j-2<]+ kl*t[>i<][>j-1<]+ k*t[>i<][>j<]+ kr*t[>i<][>j+1<]+ krr*t[>i<][>j+2<]+
|
||||
kbl*t[>i+1<][>j-1<]+ kb*t[>i+1<][>j<]+ krb*t[>i+1<][>j+1<]+
|
||||
kbb*t[>i+2<][>j<];
|
||||
tel
|
||||
|
||||
fun convol_2_h<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb :int>> (t:int^n^m; line : int^m; i :int) returns (r :int^m)
|
||||
let
|
||||
r = mapi<<m>> (kernel_2<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>>) <(t,i)> (line)
|
||||
tel
|
||||
|
||||
fun convol_2<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb :int>>(t:int^n^m) returns (r :int^n^m)
|
||||
let
|
||||
r = mapi<<n>> (convol_2_h<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>>) <(t)> (t)
|
||||
tel
|
||||
|
152
test/good/downscale.ept
Normal file
152
test/good/downscale.ept
Normal file
|
@ -0,0 +1,152 @@
|
|||
|
||||
type pixel = float^3
|
||||
|
||||
node nat() returns (n :int)
|
||||
let
|
||||
n = 0 fby n+1
|
||||
tel
|
||||
|
||||
fun pix_sum(x1,x2 :pixel) returns (r :pixel)
|
||||
let
|
||||
r = map<<3>> (+.) (x1,x2);
|
||||
tel
|
||||
|
||||
fun pix_div(x :pixel; c :float) returns (r :pixel)
|
||||
let
|
||||
r = map<<3>> (/.) (x, c^3);
|
||||
tel
|
||||
|
||||
const pix_zero :pixel = 0.0^3
|
||||
const pix_o :pixel = [1.0,1.0,1.0]
|
||||
|
||||
node counter() returns (cpt :int)
|
||||
let
|
||||
cpt = (0 fby cpt) + 1
|
||||
tel
|
||||
|
||||
node counter_r(res :bool) returns (cpt :int)
|
||||
let
|
||||
reset
|
||||
cpt = inlined counter()
|
||||
every res
|
||||
tel
|
||||
|
||||
(* count from 1 to m included, reset to 1 when [res] *)
|
||||
node mod_counter_r<<m :int>>(res :bool) returns (cpt :int)
|
||||
let
|
||||
reset
|
||||
cpt = (0 fby cpt) + 1
|
||||
every (res or (0 fby cpt = m))
|
||||
tel
|
||||
|
||||
(* count from 1 to m included *)
|
||||
node mod_counter<<m:int>>() returns (cpt :int)
|
||||
let
|
||||
cpt = inlined mod_counter_r<<m>>(false)
|
||||
tel
|
||||
|
||||
|
||||
node current(x :int; ck :bool) returns (c :int)
|
||||
let
|
||||
c = merge ck x ((0 fby c) whenot ck)
|
||||
tel
|
||||
node current_bool(x :bool; ck :bool) returns (c :bool)
|
||||
let
|
||||
c = merge ck x ((false fby c) whenot ck)
|
||||
tel
|
||||
|
||||
fun flatten_clock(x :pixel ::.on ck on ck2; ck :bool ::.; ck2 :bool ::.on ck) returns (y :pixel; ck2_flat :bool :: .)
|
||||
var x_ck, x_base : pixel;
|
||||
let
|
||||
x_ck = merge ck2 x pix_o;
|
||||
x_base = merge ck x_ck pix_o;
|
||||
ck2_flat = merge ck ck2 false;
|
||||
y = x_base when ck2_flat;
|
||||
tel
|
||||
|
||||
|
||||
node transpose<<x, y : int>>(i :pixel) returns (o :pixel)
|
||||
var store :pixel^x^y^2; (*This is the double buffer*)
|
||||
i_x, i_y, o_x, o_y :int; (*These are current buffer indexes*)
|
||||
i_line, o_line, i_img :bool; (*These define line and img beginning*)
|
||||
i_buff, o_buff :int; (*These are used to control the double buffering*)
|
||||
let
|
||||
i_x = mod_counter<<x>>() - 1;
|
||||
i_line = i_x = 0;
|
||||
i_y = current (mod_counter<<y>>() - 1, i_line);
|
||||
i_img = (i_x = 0) & (i_y = 0);
|
||||
i_buff = current(mod_counter<<2>>() - 1, i_img);
|
||||
o_buff = (i_buff + 1) % 2;
|
||||
o_y = mod_counter<<y>>() -1;
|
||||
o_line = o_y = 0;
|
||||
o_x = current (mod_counter<<x>>()-1, o_line);
|
||||
store = (pix_zero^x^y^2) fby [store with [i_buff][i_y][i_x] = i];
|
||||
o = store[>o_buff<][>o_y<][>o_x<];
|
||||
tel
|
||||
|
||||
|
||||
(* a fby-n would be nice to allow average of the last n pixels *)
|
||||
(* returns the average of the last 3 pixels when asked *)
|
||||
node down(x :pixel; out :bool) returns (r :pixel :: . on out)
|
||||
var x1, x2 : pixel;
|
||||
let
|
||||
x1 = x fby x;
|
||||
x2 = x fby x1;
|
||||
r = pix_div(pix_sum(x when out, pix_sum(x1 when out, x2 when out)), 3.0 );
|
||||
tel
|
||||
|
||||
node down_line<<ratio :int>>(x :pixel) returns (r :pixel; r_clock :bool)
|
||||
let
|
||||
r_clock = mod_counter<<ratio>>() = ratio;
|
||||
r = down(x,r_clock);
|
||||
tel
|
||||
|
||||
|
||||
node down_img <<size_x, size_y, ratio_x, ratio_y :int>> (x :pixel :: .)
|
||||
returns (y_flat :pixel; y_clock :bool;
|
||||
y, y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
ck_y_dh, ck_y_dhv :bool
|
||||
)
|
||||
var
|
||||
x_line, y_dh_t_line :bool;
|
||||
|
||||
let
|
||||
x_line = mod_counter<<size_x>>() = 1;
|
||||
reset
|
||||
(y_dh, ck_y_dh) = down_line<<ratio_x>>(x)
|
||||
every x_line;
|
||||
y_dh_t = transpose<<size_x/ratio_x, size_y>>(y_dh);
|
||||
y_dh_t_line = current_bool(mod_counter<<size_y>>() = 1, ck_y_dh);
|
||||
reset
|
||||
(y_dhv_t, ck_y_dhv) = down_line<<ratio_y>>(y_dh_t)
|
||||
every y_dh_t_line;
|
||||
y = transpose<<size_x/ratio_x, size_y/ratio_y>>(y_dhv_t);
|
||||
(*flatten clock of y, in order to return only one, instead of ck_y_dh on ck_y_dhv*)
|
||||
(y_flat, y_clock) = flatten_clock(y, ck_y_dh, ck_y_dhv);
|
||||
tel
|
||||
|
||||
|
||||
(*node main () returns (img, out : pixel; ck_out, ck_out_2 :bool)
|
||||
(*var img : pixel;*)
|
||||
let
|
||||
img = pix_o;
|
||||
(out, ck_out, ck_out_2) = down_img<<2,2,2,2>>(img);
|
||||
tel*)
|
||||
|
||||
node mainp<<size_x, size_y:int>> () returns (img, out : pixel; ck_out :bool;
|
||||
y, y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
ck_y_dh, ck_y_dhv :bool)
|
||||
(*var img : pixel;*)
|
||||
let
|
||||
(*ck_out = true fby false fby not ck_out;*)
|
||||
img = pix_o fby pix_sum(img, pix_o);
|
||||
(out, ck_out, y, y_dh, y_dh_t, y_dhv_t, ck_y_dh, ck_y_dhv) = down_img<<size_x,size_y,3,3>>(img);
|
||||
tel
|
||||
|
||||
node main() returns (img, out : pixel; ck_out :bool;
|
||||
y, y_dh, y_dh_t, y_dhv_t :pixel;
|
||||
ck_y_dh, ck_y_dhv :bool)
|
||||
let
|
||||
(img, out, ck_out, y, y_dh, y_dh_t, y_dhv_t, ck_y_dh, ck_y_dhv) = mainp<<640,480>>();
|
||||
tel
|
||||
|
24
test/good/foldi_arrays.ept
Normal file
24
test/good/foldi_arrays.ept
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
type t = A | B | C
|
||||
|
||||
const n:int = 10
|
||||
|
||||
type couple = { t1 : int^n; t2 : int^n }
|
||||
|
||||
fun f (a:t;b:float;i:int;acc_in:couple) = (acc_out:couple)
|
||||
let
|
||||
switch a
|
||||
| A do acc_out = { t1 = [ acc_in.t1 with [1] = acc_in.t1[1] + 1 ]; t2 = acc_in.t2 }
|
||||
| B do acc_out = acc_in
|
||||
| C do acc_out = { acc_in with .t2 = map<<n>> (+)(acc_in.t1,acc_in.t2) }
|
||||
end
|
||||
tel
|
||||
|
||||
|
||||
node main() returns (o:couple)
|
||||
var a:t^n; b:float^n;
|
||||
let
|
||||
a = [A, B, C, A, B, C, A, B, C, A];
|
||||
b = 0.001^n;
|
||||
o = foldi<<n>> f (a, b, { t1 = 0^n; t2 = 0^n });
|
||||
tel
|
15
test/good/mapnot.ept
Normal file
15
test/good/mapnot.ept
Normal file
|
@ -0,0 +1,15 @@
|
|||
type s = bool^10
|
||||
type t = { x : s }
|
||||
|
||||
node g() returns (c : t)
|
||||
var
|
||||
b : s;
|
||||
let
|
||||
c = {x = false^10};
|
||||
b = map <<10>> (not) (true^10);
|
||||
tel
|
||||
|
||||
node main() returns (c:t)
|
||||
let
|
||||
c = g();
|
||||
tel
|
19
test/good/pip.ept
Normal file
19
test/good/pip.ept
Normal file
|
@ -0,0 +1,19 @@
|
|||
fun pip_line<<m1,m2,y :int>> (line1 :int^m1; line2 :int^m2) returns (r :int^m1)
|
||||
let
|
||||
r = line1[0 .. y-1] @ line2 @ line1[y+m2 .. m1-1]
|
||||
tel
|
||||
|
||||
fun pip<<n1,m1,n2,m2,x,y :int>> (t1 :int^n1^m1; t2 :int^n2^m2) returns (r :int^n1^m1)
|
||||
var t12 :int^m1^n2;
|
||||
let
|
||||
t12 = map<<n2>> (pip_line<<m1,m2,y>>) (t1[x..x+n2-1], t2);
|
||||
r = t1[0 .. x-1] @ t12 @ t1[x+n2 .. n1-1];
|
||||
tel
|
||||
|
||||
node main() returns (r :int^10^10)
|
||||
var x,y:int;
|
||||
let
|
||||
x = 0 fby x+1;
|
||||
y = x*x;
|
||||
r = pip<<10,10,2,2,3,3>>(x^10^10,y^2^2);
|
||||
tel
|
19
test/good/pip_slice.ept
Normal file
19
test/good/pip_slice.ept
Normal file
|
@ -0,0 +1,19 @@
|
|||
fun pip_line<<m1,m2,y :int>> (line1 :int^m1; line2 :int^m2) returns (r :int^m1)
|
||||
let
|
||||
r = line1[0 .. y-1] @ line2 @ line1[y+m2 .. m1-1]
|
||||
tel
|
||||
|
||||
fun pip<<n1,m1,n2,m2,x,y :int>> (t1 :int^n1^m1; t2 :int^n2^m2) returns (r :int^n1^m1)
|
||||
var t12 :int^m1^n2;
|
||||
let
|
||||
t12 = map<<n2>> (pip_line<<m1,m2,y>>) (t1[x..x+n2-1], t2);
|
||||
r = t1[0 .. x-1] @ t12 @ t1[x+n2 .. n1-1];
|
||||
tel
|
||||
|
||||
node main() returns (r :int^10^10)
|
||||
var x,y:int;
|
||||
let
|
||||
x = 0 fby x+1;
|
||||
y = x*x;
|
||||
r = pip<<10,10,2,2,3,3>>(x^10^10,y^2^2);
|
||||
tel
|
51
test/good/quasi.ept
Normal file
51
test/good/quasi.ept
Normal file
|
@ -0,0 +1,51 @@
|
|||
(* include "notsameperiod2.lus" *)
|
||||
|
||||
type data = int
|
||||
|
||||
const v:data = 0
|
||||
|
||||
node current (v : data; c : bool; u : data)
|
||||
returns (o : data)
|
||||
let
|
||||
o = merge c u ((v fby o) whenot c)
|
||||
tel
|
||||
|
||||
node mem (v : data; cw : bool; u : data)
|
||||
returns (o : data)
|
||||
let
|
||||
o = v fby (current (v, cw, u))
|
||||
tel
|
||||
|
||||
node mcounter (start, limit : int)
|
||||
returns (o : int)
|
||||
let
|
||||
o = (start -> (pre o + 1)) % limit;
|
||||
tel
|
||||
|
||||
node twonodes (cw, cr : bool)
|
||||
returns (ok : bool)
|
||||
var uw, ur : int;
|
||||
let
|
||||
uw = mcounter((0, 5) when cw);
|
||||
ur = mem(v, cw, uw) when cr;
|
||||
ok = (mem(v, cr, ur) = mem(v, cw, uw))
|
||||
or (mem(v, cr, ur)= mem(v, cw, v fby uw))
|
||||
or (mem(v, cr, ur) = mem(v, cw, v fby v fby uw));
|
||||
tel
|
||||
|
||||
(*
|
||||
node verify (cw, cr : bool)
|
||||
returns (ok : bool)
|
||||
let
|
||||
ok = twonodes(cw, cr);
|
||||
assert(not notsameperiod2(cw, cr));
|
||||
tel
|
||||
*)
|
||||
|
||||
node main() returns (ok:bool)
|
||||
var cw, cr : bool;
|
||||
let
|
||||
cw = false fby not cw;
|
||||
cr = not cw;
|
||||
ok = twonodes(cw,cr);
|
||||
tel
|
Loading…
Reference in a new issue