/* Unit Test for SCSprf_take */ /* take (shape(x), x) should fold into x * take (0*shape(x), x) should fold into empty array of shape x * As of 2009-07-28, the z2 test fails. * */ /* RESULT: take 3 1 -noprelude */ int[*] id(int[*] y) { return(y); } int plus(int x, int y) { return( _add_SxS_(x,y)); } int sum(int[.] y) { z = with { ([0] <= iv < _shape_A_(y)) : _sel_VxA_(iv,y); } : fold (plus, 0); return(z); } int main() { z = 0; siz = id(10); vec = with { ([0] <= [iv] < [siz]) : iv; } : genarray([siz], 0); z1 = _take_SxV_(0, vec); /* Should CF into empty vector */ z = plus(z, _toi_S_(_eq_SxS_(_sel_VxA_([0],_shape_A_(z1)), 0))); z2 = _take_SxV_(siz, vec); /* should CF into vec */ z = plus(z, _toi_S_(_eq_SxS_(_sel_VxA_([0],_shape_A_(z2)), siz))); /* We have to reference data portion of z1 and z2, or they vanish, * and we never actually do test the CF drop code. */ z3 = _sel_VxA_([0], _cat_VxV_( z1, z2)); z = _add_SxS_( z3, z); z = _sub_SxS_(z,2); /* 0 = success */ return(z); }