0

I have a function that updates a boost::multi_array which changes size. Is there any way to update an array in a loop (i.e. update it after its initialisation) when it changes size? How can I update (assign) a boost::multi_array after initialisation?

#include <boost/multi_array.hpp>
#include <iostream>

typedef boost::multi_array<int, 2> A;

A update(const A& a) {
    auto s = a.shape()[0];
    A b{boost::extents[s+s][3]};
    auto b_mid = std::copy(a.begin(), a.end(), b.begin());
    std::copy(a.begin(), a.end(), b_mid);
    return b;
}

int main() {
    A a {boost::extents[5][3]};
    int r = 5;
    while (r--) {
        a =             // causes error because the size has changed the sizes of RHS and LHS don't match.
            update(a);  // Alternatively: a = std::move(update(a));
    }
}

The problem is that the assignment operator of type A cannot change the size of a multi_array or array. Note that I use C++14. Using std::move() did not help.

1 Answer 1

1

.reshape appesrs to be what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.