O
Oliver Block
I have a (9x9) valarray
std::valarray<int> va(81);
va = 0; // fil all elements with zeros
I am taking row slices like that:
std::slice_array<int> slr = va[std::slice(r-1,9,9)]; // r = row; a
value between 1 and 9
std::valarray<int> row = slr;
and column slices like that:
std::slice_array<int> slc = va[std::slice((c-1)*9, 9, 1)]; // c =
col; a value between 1 and 9
std::valarray<int> col = slc;
which does work without any problem.
But when I try to extract a subarray:
size_t len[] = {3,3};
size_t dist[] = {9, 1};
std::valarray<size_t> lens(len, 2);
std::valarray<size_t> dists(dist, 2);
int st_r = ((r-1)/3)*3+1; // r (s.o.)
int st_c = ((c-1)/3)*3+1; // c (s.o.)
int st_i = rc2i( st_r, st_c ); // int rc2i(int row, int col) {
return (col-1) * 9 + (row-1); }
std::gslice_array<int> gslsa = va[std::gslice(st_i, lens, dists)];
std::valarray<int> subarray = gslsa;
the first element is always the value of element 0 of the valarray,
even if my function rc2i calculates the correct values for st_i!
Is it likely, that there is a bug in the sources of the library or did
I just not fully understand the concept of gslice_array/gslice?
I mean I'am sure I didn't understant it completely but I don't see the
mistake I possibly make!
Hoping for some hints.
bye,
Oliver
std::valarray<int> va(81);
va = 0; // fil all elements with zeros
I am taking row slices like that:
std::slice_array<int> slr = va[std::slice(r-1,9,9)]; // r = row; a
value between 1 and 9
std::valarray<int> row = slr;
and column slices like that:
std::slice_array<int> slc = va[std::slice((c-1)*9, 9, 1)]; // c =
col; a value between 1 and 9
std::valarray<int> col = slc;
which does work without any problem.
But when I try to extract a subarray:
size_t len[] = {3,3};
size_t dist[] = {9, 1};
std::valarray<size_t> lens(len, 2);
std::valarray<size_t> dists(dist, 2);
int st_r = ((r-1)/3)*3+1; // r (s.o.)
int st_c = ((c-1)/3)*3+1; // c (s.o.)
int st_i = rc2i( st_r, st_c ); // int rc2i(int row, int col) {
return (col-1) * 9 + (row-1); }
std::gslice_array<int> gslsa = va[std::gslice(st_i, lens, dists)];
std::valarray<int> subarray = gslsa;
the first element is always the value of element 0 of the valarray,
even if my function rc2i calculates the correct values for st_i!
Is it likely, that there is a bug in the sources of the library or did
I just not fully understand the concept of gslice_array/gslice?
I mean I'am sure I didn't understant it completely but I don't see the
mistake I possibly make!
Hoping for some hints.
bye,
Oliver