MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / toTempFormat

Function toTempFormat

test/arrayfire_test.cpp:2060–2124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2058#undef INSTANTIATE
2059
2060af::array toTempFormat(tempFormat form, const af::array &in) {
2061 af::array ret;
2062 const af::dim4 &dims = in.dims();
2063 switch (form) {
2064 case JIT_FORMAT:
2065 switch (in.type()) {
2066 case b8: ret = !(in); break;
2067 default: ret = in * 2;
2068 }
2069 // Make sure that the base array is <> form original
2070 ret.eval();
2071 switch (in.type()) {
2072 case b8: ret = !(ret); break;
2073 default: ret /= 2;
2074 }
2075 break;
2076 case SUB_FORMAT_dim0: {
2077 af::dim4 pdims(dims);
2078 pdims[0] *= 2;
2079 af::array parent = af::randu(pdims, in.type());
2080 const af::seq dim = af::seq(dims[0]) + static_cast<double>(dims[0]);
2081 parent(dim, af::span, af::span, af::span) = in;
2082 ret = parent(dim, af::span, af::span, af::span);
2083 }; break;
2084 case SUB_FORMAT_dim1: {
2085 af::dim4 pdims(dims);
2086 pdims[1] *= 2;
2087 const af::seq dim = af::seq(dims[1]) + static_cast<double>(dims[1]);
2088 af::array parent = af::randu(pdims, in.type());
2089 parent(af::span, dim, af::span, af::span) = in;
2090 ret = parent(af::span, dim, af::span, af::span);
2091 }; break;
2092 case SUB_FORMAT_dim2: {
2093 af::dim4 pdims(dims);
2094 pdims[2] *= 2;
2095 const af::seq dim = af::seq(dims[2]) + static_cast<double>(dims[2]);
2096 af::array parent = af::randu(pdims, in.type());
2097 parent(af::span, af::span, dim, af::span) = in;
2098 ret = parent(af::span, af::span, dim, af::span);
2099 }; break;
2100 case SUB_FORMAT_dim3: {
2101 af::dim4 pdims(dims);
2102 pdims[3] *= 2;
2103 const af::seq dim = af::seq(dims[3]) + static_cast<double>(dims[3]);
2104 af::array parent = af::randu(pdims, in.type());
2105 parent(af::span, af::span, af::span, dim) = in;
2106 ret = parent(af::span, af::span, af::span, dim);
2107 }; break;
2108 case REORDERED_FORMAT: {
2109 const dim_t idxs[4] = {0, 3, 1, 2};
2110 // idxs[0] has to be 0, to keep the same data in mem
2111 dim_t rev_idxs[4];
2112 for (dim_t i = 0; i < 4; ++i) { rev_idxs[idxs[i]] = i; };
2113 ret = af::reorder(in, idxs[0], idxs[1], idxs[2], idxs[3]);
2114 ret = ret.copy(); // make data linear
2115 ret = af::reorder(ret, rev_idxs[0], rev_idxs[1], rev_idxs[2],
2116 rev_idxs[3]);
2117 // ret has same content as in, although data is stored in

Callers

nothing calls this directly

Calls 15

randuFunction · 0.85
seqClass · 0.85
af_get_typeFunction · 0.85
af_notFunction · 0.85
af_mulFunction · 0.85
af_divFunction · 0.85
typeMethod · 0.80
reorderFunction · 0.50
af_get_dimsFunction · 0.50
af_get_numdimsFunction · 0.50
af_constantFunction · 0.50
af_evalFunction · 0.50

Tested by

no test coverage detected