multi_array boost library error?

707 views Asked by At

I got this error in C++. I am trying to implement Strassen matrix multiplication with multi_array. I assign one array to another which they same dimension. Like that A11[i][j][k] = A[i][j][k]. I think reason is that kind of lines.

Assertion failed: (size_type(idx - index_bases[0]) < extents[0]), function access, file /usr/local/Cellar/boost/1.65.1/include/boost/multi_array/base.hpp, line 136. Abort trap: 6

Do you know the reason? What does this error mean?

typedef boost::multi_array<int_type, 3> array_type;
array_type::extent_gen extents;

array_type A(boost::extents[size][size][noc]);
array_type B(boost::extents[size][size][noc]);
array_type C(boost::extents[size][size][noc]);

 std::fill( A.origin(), A.origin() + A.num_elements(), 0 );
 std::fill( B.origin(), B.origin() + B.num_elements(), 0 );
 std::fill( C.origin(), C.origin() + C.num_elements(), 0 );

array_type Strr(int size,int noc,array_type A,array_type B, array_type C) {

    if(size == 2) {  //2-order
       C=Matrix_Multiply(size,noc, A, B, C);

    } else {
        //
        for(int i=0; i<size/2; i++) {
            for(int j=0; j<size/2; j++) {
                 for(int k=0; k<noc; j++) {

                A11[i][j][k] = A[i][j][k] ;

                A12[i][j][k]  = A[i][j+size/2][k] ;

        }

    }

}

My code is like that: I do not know what the problem is.

Error:Assertion failed: (size_type(idx - index_bases[0]) < extents[0]), function access, file /usr/local/Cellar/boost/1.65.1/include/boost/multi_array/base.hpp, line 136.

1

There are 1 answers

0
sehe On

In the inner most loop you have:

        for (int k = 0; k < noc; j++) {

You must have meant ++k instead of ++j:

        for (int k = 0; k < noc; ++k) {

I'd simplify main too:

int dim[] = {size,size,noc};
array_type A(dim), B(dim), C(dim);

Value-initialization is done by default.

The idea of multi_array is that the arrays self-describe, instead of you passing separate parameters (size and noc e.g.):

array_type Strr(array_type A, array_type B) {
    static_assert(array_type::dimensionality == 3, "static invariant");
    size_t size = A.shape()[0];
    size_t noc  = A.shape()[2];

    assert(A.shape()[0] ==  A.shape()[1]);
    assert(std::equal_range(A.shape(), A.shape()+3, B.shape()));
    assert(std::equal_range(A.shape(), A.shape()+3, C.shape()));