a1 = ArrayType(af::grid<1>(3)); a1 = ArrayType(3); a1 = ArrayType(af::grid<1>(3), element_type(123)); a1 = ArrayType(3, element_type(123)); ArrayType w1(a1, af::weak_ref_flag()); check_true(__LINE__, w1.use_count() == 1); check_true(__LINE__, w1.weak_count() == 1); { AltArrayType a2(af::grid<2>(3, 4)); ArrayType a3(a2, af::grid<1>(12)); ArrayType a4(a2, 12); ArrayType a5(a2, af::grid<1>(14), element_type(1)); ArrayType a6(a2, 16, element_type(2)); check_true(__LINE__, a2.use_count() == 5); check_true(__LINE__, a2.size() == 12); check_true(__LINE__, a3.size() == 12); check_true(__LINE__, a4.size() == 12); check_true(__LINE__, a5.size() == 14); check_true(__LINE__, a6.size() == 16); check_true(__LINE__, a2.end() - a2.begin() == a2.size()); check_true(__LINE__, a3.end() - a3.begin() == a3.size()); check_true(__LINE__, a4.end() - a4.begin() == a4.size()); check_true(__LINE__, a5.end() - a5.begin() == a5.size()); check_true(__LINE__, a6.end() - a6.begin() == a6.size()); a2.resize(af::grid<2>(4, 5), element_type(3)); ArrayType a2_1d = a2.as_1d(); check_true(__LINE__, a2.use_count() == 6); af::small<element_type, 20> v; v.insert(v.end(), 12, element_type()); v.insert(v.end(), 2, element_type(1)); v.insert(v.end(), 2, element_type(2)); v.insert(v.end(), 4, element_type(3)); verify(__LINE__, a2_1d, v); check_true(__LINE__, a2(0,0) == element_type(0)); check_true(__LINE__, a2(1,1) == element_type(0)); check_true(__LINE__, a2(3,4) == element_type(3)); w1 = a2_1d.weak_ref(); check_true(__LINE__, w1.use_count() == 6); } check_true(__LINE__, w1.use_count() == 0);
check_true(__LINE__, a1.size() == 0); ArrayType a2(10); check_true(__LINE__, a2.size() == 10); ArrayType a4(10, element_type(123)); check_true(__LINE__, a4.size() == 10); ArrayType a5(a4.begin(), a4.begin()); check_true(__LINE__, a5.size() == 0); ArrayType a6(a4.begin(), a4.begin() + 3); check_true(__LINE__, a6.size() == 3);
    static void run_1() {      ArrayType a1;      a1 = ArrayType(af::grid<1>(3));      a1 = ArrayType(3);      a1 = ArrayType(af::grid<1>(3), element_type(123));      a1 = ArrayType(3, element_type(123));      ArrayType w1(a1, af::weak_ref_flag());      check_true(__LINE__, w1.use_count() == 1);      check_true(__LINE__, w1.weak_count() == 1);      {        AltArrayType a2(af::grid<2>(3, 4));        ArrayType a3(a2, af::grid<1>(12));        ArrayType a4(a2, 12);        ArrayType a5(a2, af::grid<1>(14), element_type(1));        ArrayType a6(a2, 16, element_type(2));        check_true(__LINE__, a2.use_count() == 5);        check_true(__LINE__, a2.size() == 12);        check_true(__LINE__, a3.size() == 12);        check_true(__LINE__, a4.size() == 12);        check_true(__LINE__, a5.size() == 14);        check_true(__LINE__, a6.size() == 16);        check_true(__LINE__, a2.end() - a2.begin() == a2.size());        check_true(__LINE__, a3.end() - a3.begin() == a3.size());        check_true(__LINE__, a4.end() - a4.begin() == a4.size());        check_true(__LINE__, a5.end() - a5.begin() == a5.size());        check_true(__LINE__, a6.end() - a6.begin() == a6.size());        a2.resize(af::grid<2>(4, 5), element_type(3));        ArrayType a2_1d = a2.as_1d();        check_true(__LINE__, a2.use_count() == 6);        af::small<element_type, 20> v;        v.insert(v.end(), 12, element_type());        v.insert(v.end(), 2, element_type(1));        v.insert(v.end(), 2, element_type(2));        v.insert(v.end(), 4, element_type(3));        verify(__LINE__, a2_1d, v);        check_true(__LINE__, a2(0,0) == element_type(0));        check_true(__LINE__, a2(1,1) == element_type(0));        check_true(__LINE__, a2(3,4) == element_type(3));        w1 = a2_1d.weak_ref();        check_true(__LINE__, w1.use_count() == 6);      }      check_true(__LINE__, w1.use_count() == 0);    }