Using arbb::array inside arbb::dense

Using arbb::array inside arbb::dense

Hello,I am trying to get my first ArBB program running. My first trials ended up in weird segmentation faults, so I decided to step back and start from the "simplest code ever" and make it grow into the desired application.Right now I am stuck with using non scalar values inside arbb::dense. My test code with dense works fine, when I change f32 to arbb::array the code fails to compile and I do not understand why and how I should work around it.Could someone explain to me what is wrong in the following code, and what is correct way of doing this ?

     typedef arbb::array rgb8_t;

dense input(5,2);

        range in_range = input.write_only_range();
        int i=0;
        for(range::iterator input_it = in_range.begin();
            input_it != in_range.end();
            ++input_it, i+=1)
        {
            rgb8_t rgb = {{i, i, i}};
            (*input_it) = rgb;
        }
"(*input_it) = rgb;" turns out to be invalid code: "no match for operator="

Thanks for the support.
I already have seen the rgba examples using user defined structures, here I would like to learn to use arbb::array inside dense;
which I expected to work "out of the box".

Regards,
rodrigob.
5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Rodrigob,

I appreciate you sharing with us your sample code. To build a dense of arrays, you need to first build a few denses of scalars, then "zip" them together. The following illustrates this using your example:

dense input(5, 2);

// Three dense containers of scalars
dense R(5, 2);
dense G(5, 2);
dense B(5, 2);

// Get ranges for the three dense containers of scalars
range R_range = R.write_only_range();
range G_range = G.write_only_range();
range B_range = B.write_only_range();

// Initialize the three containers using write_only_range
int i = 0;
for (std::size_t k = 0; k < R_range.size(); ++k, i += 1) {
    R_range[k]= i;
    G_range[k]= i;
    B_range[k]= i;
}

// Zip individual dense containers into a dense of arrays
input = R.zip(G).zip(B);

Please let us know if this solves your problem.

Best,
Zhang

Thanks for the reply. I see how this code works, but it looks quite cumbersome if the array size grows.What I do not understand is how come I can make work

  boost::gil::rgb8_pixel_t rgb(i,i,i);
  (*input_it) = rgb;

when definingrgb8_t as

struct rgb8_t {
    arbb::u8 r, g, b;
};

and defining

flattened_to_structure

and

structure_to_flattened

but I cannot make it work in the same way when definingrgb8_t as arbb::array ?What puzzles me is that array_impl.hpp (part of arbb) already includes definitions of flattened_to_structure and structure_to_flatternedspecialized for arbb::array<> types. Why is it that these definitions are not "used" on my original code snippet ? Why it cannot work ? Then when are the flattened<->structure definitions in array_impl.hpp actually used ?Thanks for the explanation.Regards,rodrigob.

Rodrigob,

You're right, my code is very cumbersome. Turns out that it is the old way of doing business. This cumbersomeness is needed only in Beta 1 and Beta 2 release. In the latest release (Beta 3), the range interface has been largely improved. It does suport the simplicity you desire. You only need to modify your original code a little bit:

typedef arbb::array rgb8_t;
typedef arbb::array rgb8_uncaptured_t; // You need to add this 

dense input(5,2);
range in_range = input.write_only_range();
int i=0;
for(range::iterator input_it = in_range.begin();
    input_it != in_range.end();
    ++input_it, i+=1)
{
    rgb8_uncaptured_t rgb = {i, i, i}; // Assignment using range iterator requires uncaptured type
    (*input_it) = rgb;
}

The reason is that assignment of user-defined type (including arbb::array types) using a range iterator works only with uncaptured type.

In this particular case, where the 3 components of the array are initialized to the same value, you can further simplify the code by using arbb::make_array:

(*input_it) = arbb::make_array<3>((unsigned char)i); // No need to use rgb8_uncaptured_t

Best,
Zhang

ahh, perfect ! That exactly what I was looking for. So the trick is to correctly understand the relation between captured and uncaptured types.Thanks for the answer !rodrigob.

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen