https://github.com/hakkelt/ndarrays
N-dimensional arrays holding either complex or real values.
https://github.com/hakkelt/ndarrays
complex-numbers java multi-dimensional-array
Last synced: 6 months ago
JSON representation
N-dimensional arrays holding either complex or real values.
- Host: GitHub
- URL: https://github.com/hakkelt/ndarrays
- Owner: hakkelt
- License: apache-2.0
- Created: 2021-06-08T12:14:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T13:07:14.000Z (almost 3 years ago)
- Last Synced: 2023-09-16T09:28:12.500Z (over 2 years ago)
- Topics: complex-numbers, java, multi-dimensional-array
- Language: Java
- Homepage:
- Size: 3.13 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# General Multi-dimensional arrays
[](https://hakkelt.github.io/NDArrays/)
[](https://hakkelt.github.io/NDArrays/tutorial/NDArrays.html)
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
```java
ComplexNDArray 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 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
- It presents NDArray features through examples, and illustrates how the task would be solved in Matlab, Python and Julia: [Tutorial](https://hakkelt.github.io/NDArrays/tutorial/)
- For more examples, see tests in [src/test/java/com/github/hakkelt/ndarrays/basic](https://github.com/hakkelt/NDArrays/tree/main/src/test/java/io/github/hakkelt/ndarrays/basic).
- For a complete list of features, please refer to the [javadoc documentation](https://hakkelt.github.io/NDArrays/).
## Installation
### Maven
```
io.github.hakkelt
ndarrays
2.2.0
...
```
### Manual
Download jar files from [latest release](https://github.com/hakkelt/NDArrays/releases/latest), 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
- [Vectorz](https://github.com/mikera/vectorz)
- [DeepJavaLibrary](https://github.com/deepjavalibrary/djl) -> [documentation](https://javadoc.io/doc/ai.djl/api/latest/ai/djl/ndarray/NDArray.html)
- [Jep - Java Embedded Python](https://github.com/ninia/jep) -> [Numpy Usage](https://github.com/ninia/jep/wiki/Numpy-Usage)
## Inspiration from other languages
- Python's [numpy.ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html)
- Julia's native [multidimensional array type](https://docs.julialang.org/en/v1/manual/arrays/)