Example #1
0
static void print(af_array arr)
{
    const ArrayInfo info = getInfo(arr);
    T *data = new T[info.elements()];

    af_array arrT;
    AF_CHECK(af_reorder(&arrT, arr, 1, 0, 2, 3));

    //FIXME: Use alternative function to avoid copies if possible
    AF_CHECK(af_get_data_ptr(data, arrT));
    const ArrayInfo infoT = getInfo(arrT);
    AF_CHECK(af_destroy_array(arrT));

    std::ios_base::fmtflags backup = std::cout.flags();

    std::cout << "[" << info.dims() << "]\n";
#ifndef NDEBUG
    std::cout <<"   Offsets: ["<<info.offsets()<<"]"<<std::endl;
    std::cout <<"   Strides: ["<<info.strides()<<"]"<<std::endl;
#endif

    printer(std::cout, data, infoT, infoT.ndims() - 1);

    delete[] data;

    std::cout.flags(backup);
}
Example #2
0
static void print(const char *exp, af_array arr, const int precision, std::ostream &os = std::cout, bool transpose = true)
{
    if(exp == NULL) {
        os << "No Name Array" << std::endl;
    } else {
        os << exp << std::endl;
    }

    const ArrayInfo info = getInfo(arr);
    vector<T> data(info.elements());

    af_array arrT;
    if(transpose) {
        AF_CHECK(af_reorder(&arrT, arr, 1, 0, 2, 3));
    } else {
        arrT = arr;
    }

    //FIXME: Use alternative function to avoid copies if possible
    AF_CHECK(af_get_data_ptr(&data.front(), arrT));
    const ArrayInfo infoT = getInfo(arrT);

    if(transpose) {
        AF_CHECK(af_release_array(arrT));
    }

    std::ios_base::fmtflags backup = os.flags();

    os << "[" << info.dims() << "]\n";
#ifndef NDEBUG
    os <<"   Offsets: [" << info.offsets() << "]" << std::endl;
    os <<"   Strides: [" << info.strides() << "]" << std::endl;
#endif

    printer(os, &data.front(), infoT, infoT.ndims() - 1, precision);

    os.flags(backup);
}
Example #3
0
static void printer(ostream &out, const T* ptr, const ArrayInfo &info, unsigned dim)
{

    dim_type stride =   info.strides()[dim];
    dim_type d      =   info.dims()[dim];
    ToNum<T> toNum;

    if(dim == 0) {
        for(dim_type i = 0, j = 0; i < d; i++, j+=stride) {
            out<<   std::fixed <<
                    std::setw(10) <<
                    std::setprecision(4) << toNum(ptr[j]) << " ";
        }
        out << endl;
    }
    else {
        for(dim_type i = 0; i < d; i++) {
            printer(out, ptr, info, dim - 1);
            ptr += stride;
        }
        out << endl;
    }
}