From 46ed02416b2cfe62aa00aaf7c8dbf573467a1032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Tue, 22 Mar 2011 17:43:04 +0100 Subject: [PATCH] Convolutions and pip working. --- compiler/obc/java/java_main.ml | 19 ++-------- lib/java/jeptagon/Pervasives.java | 8 ++++ lib/pervasives.epi | 2 +- test/check | 2 +- test/good/array1.ept | 7 ++-- test/good/image_filters.ept | 58 ----------------------------- test/image_filters/convolutions.ept | 47 +++++++++++++++++++++++ test/image_filters/pip.ept | 19 ++++++++++ 8 files changed, 84 insertions(+), 78 deletions(-) delete mode 100644 test/good/image_filters.ept create mode 100644 test/image_filters/convolutions.ept create mode 100644 test/image_filters/pip.ept diff --git a/compiler/obc/java/java_main.ml b/compiler/obc/java/java_main.ml index 6dc8851..fea7fd6 100644 --- a/compiler/obc/java/java_main.ml +++ b/compiler/obc/java/java_main.ml @@ -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] ) - - - - - - - - diff --git a/lib/java/jeptagon/Pervasives.java b/lib/java/jeptagon/Pervasives.java index 6508a64..f3c8f0b 100644 --- a/lib/java/jeptagon/Pervasives.java +++ b/lib/java/jeptagon/Pervasives.java @@ -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 implements Future { @@ -125,4 +131,6 @@ public class Pervasives { } return x; } + + } diff --git a/lib/pervasives.epi b/lib/pervasives.epi index c8e7442..9351f5f 100644 --- a/lib/pervasives.epi +++ b/lib/pervasives.epi @@ -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) diff --git a/test/check b/test/check index 37bbf3c..af5c853 100755 --- a/test/check +++ b/test/check @@ -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 "." diff --git a/test/good/array1.ept b/test/good/array1.ept index 4ec9c26..15a6ce2 100644 --- a/test/good/array1.ept +++ b/test/good/array1.ept @@ -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 \ No newline at end of file +tel diff --git a/test/good/image_filters.ept b/test/good/image_filters.ept deleted file mode 100644 index e156eb0..0000000 --- a/test/good/image_filters.ept +++ /dev/null @@ -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 <> (t:int^n^m; i :int; line : int^m) returns (r :int^m) -let - r = mapi<> (kernel_1_1<>) () (line) -tel - -fun convol_1 <> (t:int^n^m) returns (r :int^n^m) -let - r = mapi<> (convol_h<>) () (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 <> (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<> (t:int^n^m; i :int; line : int^m) returns (r :int^m) -let - r = mapi<> (kernel_1_1<>) () (line) -tel - -fun convol_1<>(t:int^n^m) returns (r :int^n^m) -let - r = mapi<> (convol_h<>) () (t) -tel - - -fun pip_line<> (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<> (t1 :int^n1^m1; t2 :int^n2^m2) returns (r :int^n1^m1) -let - t12 = map2<> (pip_line<>) (t1[x..x+n2-1], t2); - r = t1[0 .. x-1] @ t12 @ t1[x+n2 .. n1-1]; -tel diff --git a/test/image_filters/convolutions.ept b/test/image_filters/convolutions.ept new file mode 100644 index 0000000..9ad9217 --- /dev/null +++ b/test/image_filters/convolutions.ept @@ -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 <> (t:int^n^m; line : int^m; i :int) returns (r :int^m) +let + r = mapi<> (kernel_1<>)() (line) +tel + +fun convol_1 <> (t:int^n^m) returns (r :int^n^m) +let + r = mapi<> ( convol_1_h<> ) () (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 <> (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<> (t:int^n^m; line : int^m; i :int) returns (r :int^m) +let + r = mapi<> (kernel_2<>) () (line) +tel + +fun convol_2<>(t:int^n^m) returns (r :int^n^m) +let + r = mapi<> (convol_2_h<>) () (t) +tel + diff --git a/test/image_filters/pip.ept b/test/image_filters/pip.ept new file mode 100644 index 0000000..87c7c67 --- /dev/null +++ b/test/image_filters/pip.ept @@ -0,0 +1,19 @@ +fun pip_line<> (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<> (t1 :int^n1^m1; t2 :int^n2^m2) returns (r :int^n1^m1) +var t12 :int^m1^n2; +let + t12 = map<> (pip_line<>) (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