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
Check if a bigarray is physically a part of an other bigarray #7882
Comments
Comment author: @nojb Do you have a particular use in mind for this function? |
Comment author: dinosaure Yes, the case is to avoid a blit operation. I have currently a bigarray M. Then, an specific operation on it consist to take a bigarray B and blit contents on M. Then, we take this sub-part of M and put it in a Queue. But in some ways, B can be physically a part of M. In this case, we can avoid to blit and just put directly B (as a sub-part of M) on the Queue. In this case (really specific), I need to know if B is physically a part of M - currently, I use Obj.magic but it could be interesting to have this kind of function. |
Comment author: @nojb So a simple |
Comment author: dinosaure Indeed :) |
Comment author: dinosaure I wrote a code in my specific task here: mirage/encore@bf65045#diff-4c81e542930264570f2a0bcfb18a0177R7 |
Comment author: @nojb My personal feeling is that this may be a bit too specific to be in the OCaml API, but feel free to propose a PR if you would like to gather feedback from more developers. |
Comment author: @yallop I think this is a fairly natural function to have. For mutable types it's always useful to know whether writing through one variable will affect the value bound to another variable:
For 'ref' and 'array' physical equality already serves that function, but physical equality isn't sufficient for bigarrays, since they can share structure. I don't think is_sub is sufficient in general, since it doesn't cover the case where the two bigarrays overlap but neither is a subarray of the other. Incidentally, it's straightforward to check for bigarray overlap with ctypes using the bigarray_start function that returns the address of the first element. |
Comment author: dinosaure
Which signature you have in your mind? |
Comment author: @yallop I think something like this could work: val overlap : t -> t -> (dim * dim * int) option where the two dimensions represent the point at which the overlapping section begins in each of the two input arrays, and where the integer represents the size of the overlap. I think this works out for all the bigarray types (Array0, Genarray0, etc.), varying the 'dim' type as necessary. For maximum generality it would be useful to allow the two bigarrays to have different shapes --- e.g. for one to be an Array1 and the other a Genarray --- but that would require more substantial changes to the Bigarray library. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
We should keep this open, because there's an implementation underway (#8618). |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Original bug ID: 7882
Reporter: dinosaure
Status: acknowledged (set by @nojb on 2018-12-20T10:41:49Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.07.1
Category: standard library
Monitored by: @nojb
Bug description
Currently,
Bigarray.Array1.sub
allocate a proxy of the given bigarray. It could be useful to know if 2 bigarray share the same physical area like:val share : b1 -> b2 -> (int * int, int * int) either option
Left case: Where the first integer is the offset on b1 where we start to overlap b2 and the second integer is the offset on b2 where we finish to overlap b1.
Right case: Where the first integer is the offset on b2 where we start to overlap b1 and the second integer is the offset on b1 where we finish to overlap b2.
Or something like this. It's mostly about
Bigarray.Array1
, then for more dimension, I don't know if this kind of function has a sense.The text was updated successfully, but these errors were encountered: