Convolutions and pip working.

This commit is contained in:
Léonard Gérard 2011-03-22 17:43:04 +01:00
parent 0aef6fcb5b
commit 46ed02416b
8 changed files with 84 additions and 78 deletions

View file

@ -37,19 +37,16 @@ let program p =
let integer = Eval(Pclass(Names.pervasives_qn "Integer")) in
let args1 = Eval(Parray_elem(pat_args, Sint 1)) in
let out = Eval(Pclass(Names.qualname_of_string "java.lang.System.out")) in
let vd_r, pat_r = mk_var Tint "r" in
let step_call = Anewvar(vd_r, Emethod_call(e_main, "step", [])) in
[ Anewvar(vd_main, Enew (Tclass q_main, []));
Aifelse( Efun(Names.pervasives_qn ">", [Eval (Pfield (pat_args, "length")); Sint 1])
, mk_block [Aassgn(pat_step, Emethod_call(integer, "parseInt", [args1]))]
, mk_block [Aassgn(pat_step, Eval (Pvar id_step_dnb))]);
Obc2java.fresh_for (Eval pat_step)
(fun i ->
let printing =
if !Compiler_options.verbose
then [Amethod_call(out, "printf", [Sstring "%d => %d\\n"; Eval (Pvar i); Eval pat_r])]
else []
in step_call::printing )
[ Amethod_call(out, "printf", [ Sstring "%d => %s\\n";
Eval (Pvar i);
Emethod_call(Emethod_call(e_main, "step", []), "toString", [])])]
)
]
in
mk_block ~locals:[vd_step] acts
@ -59,11 +56,3 @@ let program p =
let c = mk_classe ~fields:[field_step_dnb] ~methodes:[main_methode] class_name in
output_program dir [c]
)

View file

@ -7,6 +7,12 @@ import java.util.concurrent.TimeUnit;
public class Pervasives {
public static int between(int i, int m) {
if (i<0) return 0;
else if (i>=m) return m-1;
else return i;
}
public static final ExecutorService executor_cached = Executors.newCachedThreadPool();
public static class StaticFuture<V> implements Future<V> {
@ -125,4 +131,6 @@ public class Pervasives {
}
return x;
}
}

View file

@ -28,4 +28,4 @@ val fun (xor)(bool;bool) returns (bool)
val fun (~-)(int) returns (int)
val fun (~-.)(float) returns (float)
val fun do_stuff(int) returns (int)
val between(int;int) returns (int)
val fun between(int;int) returns (int)

View file

@ -93,7 +93,7 @@ launch_check () {
done
echo
echo "Tests goods"
for f in ../good/*.ept; do
for f in ../good/*.ept ../image_filters/*.ept; do
echec=0
if [ $verbose = 0 ]; then
echo -n "."

View file

@ -43,16 +43,17 @@ let
tel
node test1() returns (r1,r2: int^3)
var x,y : int^10; z,t : int^20;
node main() returns (r :int)
var x,y : int^10; z,t : int^20; r1,r2 :int^3;
let
x = ten(3);
y = ten(4);
(z,t) = concatenate(x,y);
(r1,r2) = slicing(x);
r = r1[>0<];
tel
node elt_trunc (a:int^m^m; i,j:int) returns (o : int)
let
o = a[>i<][>j<];
tel
tel

View file

@ -1,58 +0,0 @@
(* 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 >> (t :int^n^m; i,j :int; x :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>> (t:int^n^m; i :int; line : int^m) returns (r :int^m)
let
r = mapi<<m>> (kernel_1_1<<n,m,k,kl,kt,kr,kb>>) (<t,i>) (line)
tel
fun convol_1 <<n,m,k,kl,kt,kr,kb>> (t:int^n^m) returns (r :int^n^m)
let
r = mapi<<n>> (convol_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>> (t :int^n^m; i,j :int; x :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_1_h<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>> (t:int^n^m; i :int; line : int^m) returns (r :int^m)
let
r = mapi<<m>> (kernel_1_1<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>>) (<t,i>) (line)
tel
fun convol_1<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>>(t:int^n^m) returns (r :int^n^m)
let
r = mapi<<n>> (convol_h<<n,m,ktt,klt,kt,ktr,kll,kl,k,kr,krr,kbl,kb,krb,kbb>>) (<t>) (t)
tel
fun pip_line<<m1,m2,y>> (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>> (t1 :int^n1^m1; t2 :int^n2^m2) returns (r :int^n1^m1)
let
t12 = map2<<n2>> (pip_line<<m1,m2,y>>) (t1[x..x+n2-1], t2);
r = t1[0 .. x-1] @ t12 @ t1[x+n2 .. n1-1];
tel

View 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

View 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