Skip to content

Conversation

@gselzer
Copy link
Contributor

@gselzer gselzer commented Jun 3, 2025

It seems to me like the RandomAccessible API makes perfect sense when applied to a RealRandomAccessible.

  • In other words, a f:Rn→T is also a f:Zn→T.

For that reason, shouldn't a RealRandomAccessible also be a RandomAccessible?

@gselzer gselzer requested a review from tpietzsch June 3, 2025 19:53
@gselzer gselzer self-assigned this Jun 3, 2025
Comment on lines -125 to -130
* @return a {@link RandomAccessibleOnRealRandomAccessible} wrapping source.
* @return source
*/
public static < T > RandomAccessibleOnRealRandomAccessible< T > raster( final RealRandomAccessible< T > source )
public static < T > RandomAccessible< T > raster( final RealRandomAccessible< T > source )
{
return new RandomAccessibleOnRealRandomAccessible<>( source );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider removing this method entirely, as the return type change already warrants a major version bump.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want this method, but I would be happy with the return type change. We could make this a separate PR though, and also break more API while we are at it. For example, I think it would be better if the Views methods would all return interface types instead of concrete classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emphatic yes to returning interface types!

We could make this a separate PR though, and also break more API while we are at it.

Are you suggesting leaving the return type as is for this PR then?

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/99

@tpietzsch
Copy link
Member

Ha! After thinking about it a bit, this makes sense, yes. A RealRandomAccessible can be accessed as a RandomAccessible.

It wouldn't extend to ReadRandomAccessibleRealInterval extends RandomAccessibleInterval though, because intervals also work in the "read-as" direction (Interval extends RealInterval).

I'm not sure about unintended side effects. For example Views.interval(RRA) would be possible and would "accidentally" also make the result Iterable. Do we want that?

I'm a bit reluctant. Could you give more context on why you need this? (I know it's somehow related to imglib2-meta, but I still haven't had time to dig into that.

@tpietzsch tpietzsch marked this pull request as draft June 30, 2025 08:31
@gselzer
Copy link
Contributor Author

gselzer commented Jun 30, 2025

It wouldn't extend to ReadRandomAccessibleRealInterval extends RandomAccessibleInterval though, because intervals also work in the "read-as" direction (Interval extends RealInterval).

To be honest I hadn't fully thought that situation through, but yes, since Interval extends RealInterval I agree we cannot have RRARI extend RAI.

I'm not sure about unintended side effects. For example Views.interval(RRA) would be possible and would "accidentally" also make the result Iterable. Do we want that?

I guess I don't see the problem, at least as is... Views.interval suggests you can get a RAI from a RA. If you pass through a RRA acting as an RA, you'll get back an object that is no longer in real space, but that's within the guarantees of the method...

Where it gets trickier in that case is if we later want some Views.interval(RRA, RealInterval) -> RRARI. In that, case if you wrote

		BiConsumer<Localizable, DoubleType> c = (pos, out) -> out.setZero();
		RealRandomAccessible<DoubleType> rra = new FunctionRealRandomAccessible<>(2, c, () -> new DoubleType());
		RealRandomAccessibleRealInterval<DoubleType> rrari = Views.interval(rra, new FinalInterval(10, 10));

you'll get method clashing, which is unfortunate. Of course, we could just implement this interval solution on the fluent Views API side and avoid the problem...

I'm a bit reluctant. Could you give more context on why you need this? (I know it's somehow related to imglib2-meta, but I still haven't had time to dig into that.

Yeah, my motivations with this PR come from imglib2-meta.

One of the main goals of that project is to create a simple user-facing class Dataset, containing a delegate RandomAccessible along with a metadata container, to promote metadata-aware computation. Importantly, the Dataset is a RandomAccessible such that it can be passed as-is to all existing SciJava/ImgLib functionality.

Ideally, the RealDataset type, offering the same functionality a delegate RealRandomAccessible, would also be a Dataset, but for that to work its delegate would have to be a RandomAccessible.

Does that provide any helpful context?

@gselzer gselzer marked this pull request as ready for review August 4, 2025 18:53
@ctrueden ctrueden force-pushed the rra-implements-ra branch from bc73d61 to 5011f13 Compare August 8, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants