Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java slicing multidimensional array library

Tags:

java

arrays

slice

Is there a Java array library which supports slicing? I just need regular n x n' x n'' x ... arrays and either taking one slice from given dimension or whole dimension (i.e. no need for ranges).

Notes (read replies to potential comments):

  • I know that regular Java arrays are not supporting it and I'm not willing to write my own slicing library.
  • Using Collection (suggested in comment to other question) based shifts the problem
  • Using System.arraycopy does not help in high dimension as it does not lower the nesting of loops significantly
  • This is (sort of - long story) numerical problem so OO approach for inner code is not necessary the best one - the most usable abstraction boils down to slicing anyway
  • I would prefer R/W view from slice (if it will only be R/O copy I won't complain though)

EDIT: Unfortunaly I need to store objects inside array - not only double's.

like image 383
Maciej Piechotka Avatar asked Dec 03 '25 23:12

Maciej Piechotka


1 Answers

Vectorz is a vector/matrix library supports slicing and is a good choice if you are doing numerical work with arrays of double values. It is specifically designed for vector/matrix maths in 3D modelling, gaining, simulation or machine learning contexts.

Advantages:

  • Very fast (everything backed by primitive doubles and double[] arrays)
  • 100% Pure Java
  • Supports arbitrary slicing and dicing, mostly as O(1) operations (i.e. no data copying required)
  • Slices are fully read/write enabled, i.e. you can use them to modify the original structures
  • You can also join vectors together, take subvector views etc.
  • Specialised classes for numerical work, e.g. diagonal matrices etc.

It currently supports 0, 1 and 2 dimensional arrays, higher dimensional arrays are planned but not yet implemented.

like image 114
mikera Avatar answered Dec 06 '25 12:12

mikera