void SGNDArray<T>::expand(SGNDArray &big_array, SGVector<index_t>& axes) { // TODO: A nice implementation would be a function like repmat in matlab REQUIRE(axes.size() <= 2, "Provided axes size (%d) must be smaller than 2.\n", axes.size()); REQUIRE(num_dims <= 2, "Number of dimensions (%d) must be smaller than 2. Only 1-d and 2-d array can be expanded currently.\n", num_dims); // Initialize indices in big array to zeros SGVector<index_t> inds_big(big_array.num_dims); inds_big.zero(); // Replicate the small array to the big one. // Go over the big one by one and take the corresponding value T* data_big = &big_array.array[0]; for (int32_t vi = 0; vi < big_array.len_array; vi++) { int32_t y = 0; if (axes.size() == 1) { y = inds_big[axes[0]]; } else if (axes.size() == 2) { int32_t ind1 = axes[0]; int32_t ind2 = axes[1]; y = inds_big[ind1] * dims[1] + inds_big[ind2]; } *data_big = array[y]; data_big++; // Move to the next index big_array.next_index(inds_big); } }