20 #include <tensor/tensor.h>
21 #include <tensor/detail/common.h>
25 template<
class Tensor>
26 static const Tensor change_dimension_inner(
const Tensor &a,
int dim, index new_size)
28 typedef typename Tensor::elt_t elt_t;
30 dim = normalize_index(dim, a.rank());
31 Indices d = a.dimensions();
32 index old_size = d[dim];
33 if (old_size == new_size)
38 elt_t *p1 = output.begin();
39 const elt_t *p2 = a.begin();
41 surrounding_dimensions(d, dim, &i_len, &new_size, &k_len);
42 if (old_size > new_size) {
43 output.fill_with_zeros();
44 index dp2 = (old_size - new_size) * i_len;
45 for (index k = 0; k < k_len; k++) {
46 for (index j = 0; j < new_size; j++) {
47 memcpy(p1, p2, i_len *
sizeof(*p1));
54 index dp1 = (new_size - old_size) * i_len;
55 for (index k = 0; k < k_len; k++) {
56 for (index j = 0; j < old_size; j++) {
57 memcpy(p1, p2, i_len *
sizeof(*p1));
61 for (index i = 0; i < dp1; i++, p1++)
62 *p1 = number_zero<elt_t>();