| 112 | } |
| 113 | |
| 114 | af_err af_join_many(af_array *out, const int dim, const unsigned n_arrays, |
| 115 | const af_array *inputs) { |
| 116 | try { |
| 117 | ARG_ASSERT(3, inputs != nullptr); |
| 118 | |
| 119 | if (n_arrays == 1) { |
| 120 | af_array ret{nullptr}; |
| 121 | AF_CHECK(af_retain_array(&ret, *inputs)); |
| 122 | std::swap(*out, ret); |
| 123 | return AF_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | ARG_ASSERT(1, dim >= 0 && dim < AF_MAX_DIMS); |
| 127 | ARG_ASSERT(2, n_arrays > 0); |
| 128 | |
| 129 | const af_array *inputIt{inputs}; |
| 130 | const af_array *inputEnd{inputs + n_arrays}; |
| 131 | while ((inputIt != inputEnd) && (getInfo(*inputIt).elements() == 0)) { |
| 132 | ++inputIt; |
| 133 | } |
| 134 | if (inputIt == inputEnd) { |
| 135 | // All arrays have 0 elements |
| 136 | af_array ret = nullptr; |
| 137 | AF_CHECK(af_retain_array(&ret, *inputs)); |
| 138 | std::swap(*out, ret); |
| 139 | return AF_SUCCESS; |
| 140 | } |
| 141 | |
| 142 | // inputIt points to first non empty array |
| 143 | const af_dtype assertType{getInfo(*inputIt).getType()}; |
| 144 | const dim4 &assertDims{getInfo(*inputIt).dims()}; |
| 145 | |
| 146 | // Check all remaining arrays on assertType and assertDims |
| 147 | while (++inputIt != inputEnd) { |
| 148 | const ArrayInfo &info = getInfo(*inputIt); |
| 149 | if (info.elements() > 0) { |
| 150 | ARG_ASSERT(3, assertType == info.getType()); |
| 151 | const dim4 &infoDims{getInfo(*inputIt).dims()}; |
| 152 | // All dimensions except join dimension must be equal |
| 153 | for (int i{0}; i < AF_MAX_DIMS; i++) { |
| 154 | if (i != dim) { |
| 155 | DIM_ASSERT(3, assertDims.dims[i] == infoDims.dims[i]); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | af_array output; |
| 161 | |
| 162 | switch (assertType) { |
| 163 | case f32: output = join_many<float>(dim, n_arrays, inputs); break; |
| 164 | case c32: output = join_many<cfloat>(dim, n_arrays, inputs); break; |
| 165 | case f64: output = join_many<double>(dim, n_arrays, inputs); break; |
| 166 | case c64: output = join_many<cdouble>(dim, n_arrays, inputs); break; |
| 167 | case b8: output = join_many<char>(dim, n_arrays, inputs); break; |
| 168 | case s32: output = join_many<int>(dim, n_arrays, inputs); break; |
| 169 | case u32: output = join_many<uint>(dim, n_arrays, inputs); break; |
| 170 | case s64: output = join_many<intl>(dim, n_arrays, inputs); break; |
| 171 | case u64: output = join_many<uintl>(dim, n_arrays, inputs); break; |
no test coverage detected