#include // Shows support for many required ways a user can index into a new array. // // A successful run of this test on 32 bit is necessary, before concluding // that a relevant change has good quality. Even though the test has no // differentiated 64/32-bit versions. // // Repetition, within this test, beween indexing directly into an `array(...)` // and indexing into a `A`, as in `forall(A...|ar(A...))`, represents indexing // into a (statically programmer-known) contiguous view, and a (potentially) // noncontiguous view, respectively. Users obtain noncontiguous views by // slicing or transposing higher-dimensional arrays. The limited uses of // `a[..., all, ...]` within this test create such situations. Working via // the `ar` trait is the first of two ways that users depend on the array // implementation tunneling subscript operators through the CFA assertion // system. // // This test uses the `a[i,j]` form for subscriping higher-dimensional arrays, // which is the "new" form, compared with the C-style `a[i][j]` form. The // "new" subscripting form is the second of two ways that users depend on the // array implementation tunneling subscript operators through the CFA // assertion system. // // This test covers types and syntactic forms that can convey a numeric value // to `a[-]` or `a[-,-,-]`. The array-md-sbscr-cases test covers combinations // of `a[i][j,k]` vs `a[i,j,k]` and `a[all,3][42]` vs `a[42,3]`, though // generally using ptrdiff_t-typed variables to convey numeric values. #define show( expr ) printf( "%.1f\n", expr ) #define singleDimTestBody(testName) { \ \ printf(testName "\n\n"); \ \ assert( 3 < N ); \ \ show( a[i1] ); \ show( a[i2] ); \ printf("\n"); \ \ for( i_dynbounded; N ) show( a[i_dynbounded] ); \ printf("\n"); \ \ for( i_stabounded; 4 ) show( a[i_stabounded] ); \ printf("\n"); \ } forall( [N] ) void test_common_arg_types(array(float, N) & a, ptrdiff_t i1, size_t i2) singleDimTestBody("Simple array") forall( [N], A& | ar(A, float, N) ) void test_common_arg_types__via_trait(A & a, ptrdiff_t i1, size_t i2) singleDimTestBody("Via trait") void do1dimTest() { array(float, 5) a; a[0] = 100.0; a[1] = 100.1; a[2] = 100.2; a[3] = 100.3; a[4] = 100.4; test_common_arg_types(a, 3, 3); test_common_arg_types__via_trait(a, 3, 3); } #define multiDimTestBody(testName) { \ \ printf(testName "\n\n"); \ \ assert( 3 < M ); \ assert( 3 < N ); \ \ show(( a[x1,x1] )); \ show(( a[x1,x2] )); \ show(( a[x2,x1] )); \ show(( a[x2,x2] )); \ printf("\n"); \ \ for( i_dynbounded; M ) show(( a[i_dynbounded, 3] )); \ printf("\n"); \ \ for( i_stabounded; 4 ) show(( a[i_stabounded, 3] )); \ printf("\n"); \ \ for( j_dynbounded; N ) show(( a[3, j_dynbounded] )); \ printf("\n"); \ \ for( j_stabounded; 4 ) show(( a[3, j_stabounded] )); \ printf("\n"); \ } forall( [M], [N] ) void test_common_arg_types__md(array(float, M, N) & a, ptrdiff_t x1, size_t x2) multiDimTestBody("Simple array, multidim") forall( [M], [N], A_outer &, A_inner & | ar(A_outer, A_inner, M) | ar(A_inner, float, N) ) void test_common_arg_types__md__via_trait(A_outer & a, ptrdiff_t x1, size_t x2) multiDimTestBody("Via trait, multidim") void doMdimTest() { array(float, 5, 4) b; b[ix0,ix0] = 0.0; b[ix0,1] = 0.1; b[ix0,2] = 0.2; b[ix0,3] = 0.3; b[ 1,ix0] = 1.0; b[ 1,1] = 1.1; b[ 1,2] = 1.2; b[ 1,3] = 1.3; b[ 2,ix0] = 2.0; b[ 2,1] = 2.1; b[ 2,2] = 2.2; b[ 2,3] = 2.3; b[ 3,ix0] = 3.0; b[ 3,1] = 3.1; b[ 3,2] = 3.2; b[ 3,3] = 3.3; b[ 4,ix0] = 4.0; b[ 4,1] = 4.1; b[ 4,2] = 4.2; b[ 4,3] = 4.3; test_common_arg_types__md(b, 3, 3); test_common_arg_types__md__via_trait(b, 3, 3); printf("Transposed, "); test_common_arg_types__md__via_trait(b[all], 3, 3); printf("Slice giving "); test_common_arg_types(b[2], 3, 3); printf("Same slice "); test_common_arg_types__via_trait(b[2], 3, 3); printf("Strided slice "); test_common_arg_types__via_trait(b[all,2], 3, 3); } int main() { // can't be inlined in same func due to Trac #175. do1dimTest(); doMdimTest(); }