You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array<Float32> arrayRetMapImage = image.par().map(Float32.class, new Map<Float32, Pixel>() {
@Override
public Float32 function(Pixel pixel) {
Float32 ret = new Float32();
ret.value = pixel.rgba.red;
return ret;
}
});
float[] floatArrayRetMapImage = arrayRetMapImage.toJavaArray();
Code generated by this operation return a 4 * (image size) float array when it shouldn't.
User function returns only a single float so the right way to do this is to analyse what type user function uses and create an array with compatible size.
The text was updated successfully, but these errors were encountered:
Label updated, since this is a bug.
Just as a future reminder, I'll describe below the cause and the solution for this issue.
The problem is related to those output bind operations which automatically creates the memory allocation to move data from low-level runtime to SDK. Being a little bit more specific, in lines line this:
When translating the output bind, the compiler creates a boolean variable "somethingFromImage" to inform if this array was created after a call to a map operation in an image. If this is true, it will automatically multiply by 4 the size of its element. Thus, the solution must be implemented in three steps:
Change the boolean variable to a short variable and initialize it to 1;
Assign to the variable, after each call to "map" operations, the size of the element being manipulated by the Array at that moment. Example: Pixel = 4, Int32 = 1, Float32 = 1, Int32_2 = 2, Int32_4 = 4, etc.
In the above example, the code generated in line 2 should multiply array length by 4 in order to properly transform the result into a float[], since the array was created from an image, where each pixel takes 4 floats to be stored in user library. In line 4, though we are handling the same Array, the new reference was created from a constructor call and where the user have already provided the data as a float[] where each pixel is coded as a set of 4 elements, so it does not have to multiply the output array length.
Consider this map operation code:
Code generated by this operation return a 4 * (image size) float array when it shouldn't.
User function returns only a single float so the right way to do this is to analyse what type user function uses and create an array with compatible size.
The text was updated successfully, but these errors were encountered: