-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle 1D and 2D Arrays? #73
Comments
Hi @tpietzsch, Thanks for all the work and improvement! A quick info here about the dimensionnality of arrays and how it is processed below:
from memory, this does not really have an impact computationnaly in the array processing after, so we can manage it the way we want on the Java side (including hiding/removing it), especially if we assume that array of dimension [x,y,1] are always 2D. In future I will try to better manage this from the python side and remove it from the C++ side. |
Just to clarify:
|
Yes, I also like option 3 the best
Right, one would have to explicitly make a 2 by 2 by 1 image to get 3D. 👍 |
Arrays have
width
,height
, anddepth
, as well as number ofdimensions
.I wonder how to consistently handle construction and reporting of these properties. There were tests (
TestAbsolute
) that did construct arrays withwidth=2, height=2. depth=0, numDimensions=2
. However, the resulting array would reportdepth()==1
.I see the following approaches:
Use
depth=0
to indicate thatnumDimensions<3
. Usedepth=0
andheight=0
to indicate thatnumDimensions=1
. Then we don't need the numDimensions argument explicitly.However, then
ArrayJ.depth()
should be0
, too, not1
.This might be inconvenient. For example, it is nice if the number of elements of an array can always be computed as
width*height*depth
, regardless of dimensionality.Require
depth>0
always. Requiredepth=1
ifnumDimensions<3
.This is what I'm currently implementing in Revise JavaCPP bindings and core package #72.
However, it is also not super-elegant.
I also implemented a var-args alternative that takes
int... size
. That takes 1, 2, or 3 arguments and the number of arguments is the number of dimensions, the "missing" dimensions are set to1
. This is available throughDeviceJ.createArray(DataType, MemoryType, int...)
in Revise JavaCPP bindings and core package #72.For example the above TestAbsolute example (2 by 2 image, 2D) would be constructed as
device.createArray(DataType.UINT8, MemoryType.BUFFER, 2, 2)
, a 3D 4x3x2 image would be constructed withdevice.createArray(DataType.UINT8, MemoryType.BUFFER, 4, 3, 2)
, etc.If this works well, I would remove the direct ArrayJ constructor (make it package-private).
The text was updated successfully, but these errors were encountered: