Skip to content

N-dimensional arrays holding either complex or real values.

License

Notifications You must be signed in to change notification settings

hakkelt/NDArrays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

General Multi-dimensional arrays

Documentation Tutorial

General framework for multi-dimensional arrays holding either complex, floating point and integer values.

Goals

  1. Provide an easy way to create minimal wrappers for n-dimensinal array implementations,
  2. Give a rich interface to query and modify data, and
  3. Allow effortless conversion between wrapped data structures.

Features

  • Can be parametrized with Float, Double, Byte, Short, Integer, Long, BigInteger, BigDecimal, and Complex from org.apache.commons.math3 package
  • Easy initialization: copying data from (multi-dimensional) arrays of primitive values or NDArrays of any kind, and also filling with a scalar value
  • Lightweight views: slice (select a specific slice or range of slices along arbitrary dimension), permuteDims (change order of indexing), reshape (change shape of data)
  • Basic linear algebra operations: add, subtract, multiply, and divide an NDArray with scalar or another NDArray (element-wise)
  • Implements streaming and iterations of values or indices
  • Implemented fully in native Java

Examples

ComplexNDArray<Double> array = new ComplexDoubleNDArray(4, 5, 3)
    .fillUsingLinearIndices(i -> new Complex(Math.random(), Math.random()));

array.slice("2:3", ":", 1).fill(2); // updates the selected range in the original array
ComplexNDArray<Double> sum = array.sum(2); // Calculates sum along axis 2, producing a 4 x 5 NDarray

// Euclidean norm of element-wise product of two slices:
array.slice("0:2", ":", 1).multiply(array.slice("2:4", ":", 1)).norm();

// Assign zero to elements where the first coordinate is an even number:
array.streamCartesianIndices() 
    .filter(idx -> idx[0] % 2 == 0)
    .forEach(idx -> array.set(0, idx));
// Alternative solution:
array.applyWithCartesianIndices((value, idx) -> idx[0] % 2 == 0 ? 0 : value);

array.addInplace(new Complex(1, 3.5)); // Adds 1 + 3.5i to all elements

Documentation

Installation

Maven

<dependencies>
    <dependency>
        <groupId>io.github.hakkelt</groupId>
        <artifactId>ndarrays</artifactId>
        <version>2.2.0</version>
    </dependency>
    ...
</dependencies>

Manual

Download jar files from latest release, and add their path to java path. You should also take care of the dependencies (org.apache.commons.commons-math3, org.apache.commons.commons-lang3).

Similar packages

Inspiration from other languages