types::ndarray<T, M> reshape(types::ndarray<T, N> const &expr, types::array<long, M> const &new_shape) { auto where = std::find(new_shape.begin(), new_shape.end(), -1); if (where != new_shape.end()) { auto auto_shape = new_shape; auto_shape[where - new_shape.begin()] = expr.flat_size() / std::accumulate(new_shape.begin(), new_shape.end(), -1L, std::multiplies<long>()); return expr.reshape(auto_shape); } else return expr.reshape(new_shape); }