/* Dan's tester for Ti-array operations */ public class arrayops { public static void main(String[]args) { if (Ti.thisProc() == 0) System.out.println("Running array operations tests.."); { /* test some descriptor operations */ long [1d] x = new long [0 : 99 : 1]; // x has domain 0..99 for (int i=0; i <= 99; i++) x[i] = i; // init to easy values foreach (p in x.domain()) { if (x[p] != p[1]) System.out.println("Mismatch detected in x at " + p + ": expected: " + p[1] + " got: " + x[p]); } { PrivateRegion pr = new PrivateRegion(); SharedRegion sr = new SharedRegion(); int [1d] A = new int[1:10]; int [1d] B = new (pr) int [1:10]; int [1d] C = new (sr) int [1:10]; if (A.regionOf() != null || ((int[1d]local)A).regionOf() != null) System.out.println("Incorrect array regionOf() GC"); if (B.regionOf() != pr || ((int[1d]local)B).regionOf() != pr) System.out.println("Incorrect array regionOf() private"); if (C.regionOf() != sr || ((int[1d]local)C).regionOf() != sr) System.out.println("Incorrect array regionOf() shared"); } RectDomain<1> interiorpts = x.domain().shrink(5); long [1d] y = x.restrict(interiorpts); // y has domain 5..94 if (y.domain().min()[1] != 5 || y.domain().max()[1] != 94) System.out.println("Restrict failed. y.domain=" + y.domain()); foreach (p in y.domain()) { if (y[p] != p[1]) System.out.println("Mismatch detected in y at " + p + ": expected: " + p[1] + " got: " + y[p]); } // test translation long [1d] z = y.translate([100]); // z has domain 105..194 if (z.domain().min()[1] != 105 || z.domain().max()[1] != 194) System.out.println("Translate failed. z.domain=" + z.domain()); foreach (p in z.domain()) { if (z[p] != p[1]-100) System.out.println("Mismatch detected in z at " + p + ": expected: " + (p[1]-100) + " got: " + z[p]); } long [1d] z2 = z.translate([100]); // z2 has domain 205..294 if (z2.domain().min()[1] != 205 || z2.domain().max()[1] != 294) System.out.println("Translate failed. z2.domain=" + z2.domain()); foreach (p in z2.domain()) { if (z2[p] != p[1]-200) System.out.println("Mismatch detected in z2 at " + p + ": expected: " + (p[1]-200) + " got: " + z2[p]); } long [1d] z3 = z2.translate([-250]); // z has domain -45..44 if (z3.domain().min()[1] != -45 || z3.domain().max()[1] != 44) System.out.println("Translate failed. z3.domain=" + z3.domain()); foreach (p in z3.domain()) { if (z3[p] != p[1]+50) System.out.println("Mismatch detected in z3 at " + p + ": expected: " + (p[1]+50) + " got: " + z3[p]); } } /* some basic array copy tests */ { /* contiguous copy with differing base */ int [1d] x = new int[1:100]; int [1d] y = new int[50:150]; foreach (p in x.domain()) { x[p] = p[1]; } foreach (p in y.domain()) { y[p] = p[1]+1000; } x.copy(y); foreach (p in x.domain()) { int expected; if (p[1] < 50) expected = p[1]; else expected = p[1]+1000; if (x[p] != expected) System.out.println("Mismatch detected in copy test 1 at " + p + ": expected: " + expected + " got: " + x[p]); } } { /* contiguous copy with non-trivial stride */ int [1d] x = new int[10:100:10]; int [1d] y = (new int[1:10]).inject([10]); foreach (p in x.domain()) { x[p] = p[1]; } foreach (p in y.domain()) { y[p] = p[1]+1000; } x.copy(y); foreach (p in x.domain()) { int expected = p[1]+1000; if (x[p] != expected) System.out.println("Mismatch detected in copy test 2 at " + p + ": expected: " + expected + " got: " + x[p]); } } { /* tranpose from contiguous -> contiguous */ int [2d] x = new int[1:5,11:20]; int [2d] y = (new int[11:20,1:5]).permute([2,1]); foreach (p in x.domain()) { x[p] = p[1]*100+p[2]; } foreach (p in y.domain()) { y[p] = p[1]*100+p[2]+1000; } x.copy(y); foreach (p in x.domain()) { int expected = p[1]*100+p[2]+1000; if (x[p] != expected) System.out.println("Mismatch detected in copy test 3 at " + p + ": expected: " + expected + " got: " + x[p]); } } { /* equal sideFactor/stride ratio */ int [2d] x = new int[1:5:2,11:20:1]; int [2d] y = new int[1:5,11:15]; foreach (p in x.domain()) { x[p] = p[1]*100+p[2]; } foreach (p in y.domain()) { y[p] = p[1]*100+p[2]+1000; } x.copy(y); foreach (p in x.domain()) { int expected; if (p[2] > 15) expected = p[1]*100+p[2]; else expected = p[1]*100+p[2]+1000; if (x[p] != expected) System.out.println("Mismatch detected in copy test 4 at " + p + ": expected: " + expected + " got: " + x[p]); } } { // test overlap (contiguous) int [1d] x = new int[0:6]; foreach (p in x.domain()) { x[p] = 100+p[1]; } int [1d] y = x.translate([2]); x.copy(y); foreach (p in x.domain()) { int expected; if (p[1] < 2) expected = 100+p[1]; else expected = 100+p[1]-2; if (x[p] != expected) System.out.println("Mismatch detected in copy overlap test 1 at " + p + ": expected: " + expected + " got: " + x[p]); } } { // test overlap (non-contiguous) int [1d] x = (new int[0:60]).restrict([0:60:10]); foreach (p in x.domain()) { x[p] = 100+p[1]; } int [1d] y = x.translate([20]); x.copy(y); foreach (p in x.domain()) { int expected; if (p[1] < 20) expected = 100+p[1]; else expected = 100+p[1]-20; if (x[p] != expected) System.out.println("Mismatch detected in copy overlap test 2 at " + p + ": expected: " + expected + " got: " + x[p]); } } Ti.barrier(); if (Ti.thisProc() == 0) System.out.println("done."); }}