Skip to content

Explain how ArrayView2D works? #1464

@delverOne25

Description

@delverOne25

Question

How is the data arranged? Where is x,y located - [x,y] or [y,x]?
I don't use this class at all; instead, I create my own wrapper over ArrayView1D, because when copying to a Bitmap with 2D, the image gets corrupted—it's either rotated 90 degrees or completely incomprehensible. If you ask ChatGPT to create any project with ArrayView2D, it will create it incorrectly for you.

The examples indicate addressing as [x,y]! BUT any C# example from textbooks, and by default, uses addressing as [y,x] since the linear address is y*width + x. When trying to get an array using the GetAsArray2D method, it's always incorrect, no matter how I try to test it.
why the code below doesn't work, the image is incorrect, though everything seems logical.
` public byte[] RenderJuliaSet(int width, int height, double cReal, double cImag,
double viewMinX, double viewMaxX, double viewMinY, double viewMaxY)
{
if (width <= 0 || height <= 0)
return new byte[0];

        var buffer = _accelerator.Allocate2DDenseX<byte>(new Index2D(height, width * 4));
        
        _kernel(new Index2D(width, height), buffer.View, cReal, cImag, 
               viewMinX, viewMaxX, viewMinY, viewMaxY);
        
        _accelerator.Synchronize();

        var result = buffer.GetAsArray2D();
        buffer.Dispose();

        var flatArray = new byte[width * height * 4];
        int index = 0;
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width * 4; x++)
            {
                flatArray[index++] = result[y, x];
            }
        }

        return flatArray;
    }`

Environment

  • ILGPU version: [e.g., 1.5.1]
  • .NET version: [e.g., .NET 8]
  • Operating system: [e.g., Windows 10]
  • Hardware (if GPU-related): [e.g., NVIDIA GeForce GTX 1080]

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions