0

Hi I have a few boost::multi_array defined as below:

typedef boost::multi_array<double, 3> region_prior_integral_image

I am trying to create an array of region_prior_integral_image like the following:

unordered_map<string, int> filename_to_hash_key_map = get_filename_to_hash_key_map();

unordered_map<string, region_prior_integral_image> filename_to_region_prior_map = get_region_prior_integral_images();

region_prior_integral_image* image_cache = new region_prior_integral_image[5];
for(unordered_map<string, int>::iterator it = filename_to_hash_key_map.begin(); it != filename_to_hash_key_map.end(); it++){
    image_cache[it->second] = filename_to_region_prior_map[it->first];
}

However the program is terminating with the following: SemanticTextonForest: /home/aly/libs/boost_1_51_0/stage/include/boost/multi_array/multi_array_ref.hpp:488: boost::multi_array_ref<T, NumDims>& boost::multi_array_ref<T, NumDims>::operator=(const ConstMultiArray&) [with ConstMultiArray = boost::multi_array<double, 3ul>, T = double, long unsigned int NumDims = 3ul, boost::multi_array_ref<T, NumDims> = boost::multi_array_ref<double, 3ul>]: Assertionstd::equal(other.shape(),other.shape()+this->num_dimensions(), this->shape())' failed.`

And I have no idea why?

I know I could just use a vector, but for arguments sake lets say I wanted to have an array of region_prior_integral_images

Thanks

1 Answer 1

1

Let's say we have two region_prior_integral_image instances: A and B. If you want to assign B to A, like A = B;, the shapes of A and B must be equal. The error message is saying that, in your code image_cache[it->second] = filename_to_region_prior_map[it->first];, the two arrays are of different shapes.

How do you created the arrays in filename_to_region_prior_map? I guess you used this constructor to specify the shapes: multi_array<double,3> B(boost::extents[i][j][k]). Hence their shape is [i][j][k]. But when you create the image_cache, the default constructor is invoked. So the two shapes mismatch.

My opinion is to store pointers of region_prior_integral_image in your code, which will save a lot of copy as well.

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

4 Comments

any idea how to get the dimensions of an already created region_prior_image?
Use const size_type* shape() const; like: auto s = A.shape();, then u can access it by s[0], s[1] and s[2] in your case. Better read through the official reference: boost.org/doc/libs/1_52_0/libs/multi_array/doc/reference.html
How do I create the array of region_prior_images of a given size?
It is impossible. Only the default constructor will be invoked when using a primitive array. I suggest use std::vector instead, then u can use std::vector::resize(n, region_prior_image(boost::extents[i][j][k])) to fill it.

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.