Apollo3zehn / PureHDF

A pure .NET library that makes reading and writing of HDF5 files (groups, datasets, attributes, ...) very easy.
MIT License
50 stars 18 forks source link

Add IQuerable interface to build hyperslabs? #2

Closed Apollo3zehn closed 1 year ago

Apollo3zehn commented 3 years ago

Edit (2023-01-03)

An experimental IQueryable support has been implemented as dataset.AsQueryable(). Stream support could be implemented similar in the form of dataset.AsStream();.

However, this is still an option:

dataset.Read().Execute(),
dataset.Read().Skip(1).Take(2).Execute()
dataset.Read().AsStream()

The advanage is that dataset.Read.Execute() is also a query, so there is only query and stream. But it is not quite clean to create a IQueryable first to finally get a stream.

Stream and query make mostly sense for 1-dimensional data. Stream cannot be implemented on multidimensional data since the data are not written linerarly into the memory.

Original Issue

LINQ to HDF?

// this could build a netCDF hyperslab (start, stop, stride)
dataset
   .Skip([]) // = start
   .Take(ulong[]) // = stop - start
   .Where((x, n) => n % nth == 0) // stride
   .Read<int>();
// this could build an HDF5 hyperslab (start, stride, count, block)
dataset
   .Skip([]) // = start
   .Where((x, n) => n % nth == 0) // stride
   .Repeat(y) // count (https://fuqua.io/Rx.NET/ix-docs/html/M_System_Linq_QueryableEx_Repeat__1_3.htm)
   .Take(ulong[]) // block
   .Read<int>();

https://jacopretorius.net/2010/01/implementing-a-custom-linq-provider.html

LINQ Part 3: An Introduction to IQueryable - CodeProject https://www.codeproject.com/Articles/1240553/LINQ-Part-An-Introduction-to-IQueryable

Returning IEnumerable vs. IQueryable - Stack Overflow https://stackoverflow.com/questions/2876616/returning-ienumerablet-vs-iqueryablet