Unidata / geoapi-netcdf-java

netCDF-Java wrappers for the OGC GeoAPI
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Which library for matrices? #5

Closed desruisseaux closed 3 years ago

desruisseaux commented 3 years ago

GeoAPI needs matrices. For now only a very simple matrix object, without needs for applying operations (matrix multiplication, inversion, etc.) on it. Current proposal uses javax.vecmath. Does the UCAR library already uses a matrix library, and if yes which one?

lesserwhirls commented 3 years ago

In netCDF-Java version 5 and prior, we have the ucar.ma2 package which provides multidimensional array support:

https://docs.unidata.ucar.edu/netcdf-java/current/javadoc/ucar/ma2/package-summary.html

In version 6 (not yet release), we have a replacement array package:

https://docs.unidata.ucar.edu/netcdf-java/6.0/javadoc/ucar/array/package-summary.html

but for now we can focus on ucar.ma2.

If we can use those for the purpose of GeoAPI, that would be ideal.

desruisseaux commented 3 years ago

Yes, but is there is some classes for a matrix object capable of matrix operations? In particular matrix multiplication and matrix inversion, where the matrix size are typically not bigger than 5×5? This is a little bit different than the case of multi-dimensional arrays which are designed for very large arrays, without matrix operations on them.

The current GeoAPI wrappers are not applying matrix operations itself, but those objects are returned in a context where matrix operations make sense, so users may want to apply them.

lesserwhirls commented 3 years ago

Ah, we do indeed have Matrix class that tries to handle some basic matrix operations:

https://docs.unidata.ucar.edu/netcdf-java/current/javadoc/ucar/ma2/MAMatrix.html

We don't have a matrix inverse though, so that would need to be added. This also has not been ported to the new ucar.array package, so perhaps it's not the right way to go at this point. javax.vecmath might be the best way to go.

desruisseaux commented 3 years ago

Thanks, I think that MAMatrix will be okay even if it does not have matrix inversion yet. However I'm not sure to understand the meaning of (int i, int j) parameters in getDouble and setDouble methods. Are they in (column, row) order as the (i,j) names suggest, are are they in (row, column) order as the classical notation for matrices?

lesserwhirls commented 3 years ago

The i and j are row and column (I should update the javadoc to clarify that).

desruisseaux commented 3 years ago

May be worth to also update javadoc of MAMatrix(int nrows, int ncols) for saying that all values are initialized to 0. I was wondering if the constructor was initializing to identity matrix.

desruisseaux commented 3 years ago

vecmath dependency replaced by ucar.ma2.MAMatrix.