Skip to content
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

Closed
vicuna opened this issue Dec 18, 2018 · 12 comments · May be fixed by #8618
Closed

Check if a bigarray is physically a part of an other bigarray #7882

vicuna opened this issue Dec 18, 2018 · 12 comments · May be fixed by #8618

Comments

@vicuna
Copy link

vicuna commented Dec 18, 2018

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.

@vicuna
Copy link
Author

vicuna commented Dec 19, 2018

Comment author: @nojb

Do you have a particular use in mind for this function?

@vicuna
Copy link
Author

vicuna commented Dec 19, 2018

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.

@vicuna
Copy link
Author

vicuna commented Dec 19, 2018

Comment author: @nojb

So a simple val is_sub: t -> t -> bool would suffice for your use-case, right?

@vicuna
Copy link
Author

vicuna commented Dec 19, 2018

Comment author: dinosaure

Indeed :)

@vicuna
Copy link
Author

vicuna commented Dec 20, 2018

Comment author: dinosaure

I wrote a code in my specific task here: mirage/encore@bf65045#diff-4c81e542930264570f2a0bcfb18a0177R7

@vicuna
Copy link
Author

vicuna commented Dec 20, 2018

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.

@vicuna
Copy link
Author

vicuna commented Dec 22, 2018

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:

  fun x y ->
     let r = !y in
        x := v;
        (* do we still have !y == r? *)

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.

@vicuna
Copy link
Author

vicuna commented Dec 27, 2018

Comment author: dinosaure

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.

Which signature you have in your mind?

@vicuna
Copy link
Author

vicuna commented Dec 27, 2018

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.

@github-actions
Copy link

github-actions bot commented May 7, 2020

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.

@github-actions github-actions bot added the Stale label May 7, 2020
@yallop
Copy link
Member

yallop commented May 7, 2020

We should keep this open, because there's an implementation underway (#8618).

@yallop yallop self-assigned this May 7, 2020
@github-actions github-actions bot closed this as completed Jun 8, 2020
@nojb nojb reopened this Jun 8, 2020
@nojb nojb removed the Stale label Jun 8, 2020
@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants