-
Notifications
You must be signed in to change notification settings - Fork 118
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
Dtype mod #327
base: master
Are you sure you want to change the base?
Conversation
This is more or less what we need to support images. The data type we'd use would be a float. Since users have often asked to do weird things with images that you can't do with ints. What questions do you need answered from me? Given a row/color_channel it's very easy for me to fill a float array with pixel values. I can also easily fill a column. |
I don't have to know what data type you want to hold,
I think, we are pretty much on the same page. Let me iron out the implementation, and we can then pick it up from there. |
@kwagyeman @iabdalkader What should happen with this construct, if the one wants to use the buffer protocol? Some context can be found here #335, and here #328, The problem is that in micropython-ulab/code/ndarray.c Lines 2031 to 2040 in 4221262
self->array will not point to actual data.
I think the cleanest solution is to simply bail out, if the special flag is set for an |
We have a buffer protocol for the image object already. There is no need to duplicate it. So bailing makes sense. |
OK, thanks! |
@v923z Would you like to get on our slack? Email [email protected] |
@kwagyeman Thanks for the invitation! Sure! |
You need to email me since you hide all contact info on your public profile. |
@kwagyeman, @iabdalkader I have updated my original comment, and uploaded a working prototype. At the moment, only
creates an micropython-ulab/code/user/user.c Lines 95 to 98 in 3227831
I think this solution is quite flexible (by which I mean that the What would, perhaps, be great is, if we could call the micropython-ulab/code/blocks/blocks.c Lines 51 to 65 in 3227831
transformer is used in a particular block. I haven't yet found a way of doing this, however.
|
@v923z This is very interesting. I am unsure: is this only for reading out-of-RAM data? Do you need a corresponding write function? |
At the moment, this would only read; we could think about adding a write function. |
This PR adds the option to extend
ulab
in a transparent way. This means that the user is able to add their own data container in the C implementation, and if they supply a readout function, then variousnumpy
methods should be able to access the data in the container. Such a facility could be exploited to process data that do not reside in RAM, either because they are not available, or because the amount would be prohibitive.Two possible use cases are
The type definition of
ndarray
is extended with ablocks_block_obj_t
structure:micropython-ulab/code/ndarray.h
Lines 70 to 94 in 3227831
In
blocks_block_obj_t
, a pointer to the readout function can be attached,*arrfunc
, as well as a temporary container,*subarray
, can be pointed to. Thesubarray
has to be able to hold a single line of data, i.e.,subarray
must be at least as long as the longest axis of the tensor. This single line can than be passed to the innermost loop of all numerical functions, binary operators, etc. An example is the summation macromicropython-ulab/code/numpy/numerical/numerical.h
Lines 61 to 78 in 3227831
The user can then simply attach their readout function by defining a type
micropython-ulab/code/user/user.c
Lines 86 to 127 in 3227831
The example above calculates the sum of squares.
In
python
, the mock-up looks like thisSlicing, indexing and the like happens in the usual way, since even in the standard case, such operations only update the array header, and move the position pointer.
In a numerical operation, a tensor is always traversed along an axis. Given the position of the data pointer, the coordinates of the pointer position can be calculated with the help of the
size_t *blocks_coords_from_pointer(void *p1, ndarray_obj_t *ndarray)
function:micropython-ulab/code/blocks/blocks.c
Lines 30 to 49 in 3227831
imreader
can easily fill up thesubarray
.Such a construct should not support the buffer protocol, since there might not be an easy way of resolving what should happen:
#327 (comment), #327 (comment)
Passing arguments to the type (
imreader
above) should be possible as, e.g., withndarray
.Outstanding issues:
float
type, but I am not sure, whether this would lead to problems later on.dtype
. This last question is probably sorted out by attaching the extra structure to thendarray
only then, when it is needed. We carry only a pointer, but RAM is reserved for it only inmicropython-ulab/code/blocks/blocks.c
Line 115 in 3227831
Functions and features