Skip to content

v0.1-preview

Pre-release
Pre-release

Choose a tag to compare

@CH-Abhinav CH-Abhinav released this 20 May 08:31
· 30 commits to main since this release

JNum v0.1.0-PREVIEW: The Pure Java Tensor Engine

We are incredibly excited to announce the first preview release of JNum, a high-performance, N-dimensional numerical computing library built entirely in pure Java.

JNum was engineered to answer a specific question: Can modern Java replace C++ math backends? By leveraging Java 25, the Foreign Function & Memory (FFM) API, and the Vector API (Project Panama), JNum completely eliminates the need for JNI (Java Native Interface) and the deprecated sun.misc.Unsafe.

The result is a hardware-accelerated tensor engine that runs vector pipelines directly on the CPU from within the JVM, all packaged in a single ~100KB artifact.


Key Features & Capabilities

1. Hardware-Accelerated Vector Operations

  • SIMD Matrix Multiplication: Fast, hardware-accelerated matmul and dot products for INTEGER, FLOAT, and DOUBLE data types.
  • Vectorized Element-wise Math: Full SIMD support for arithmetic (add, sub, mul, div), including in-place zero-allocation variants (addi, subi, etc.).
  • Advanced Mathematical Kernels: Vectorized lanes for exponents (exp, log, log10, sqrt, abs), and trigonometry (sin, cos, tan, sinh, cosh, tanh).
  • Axis Reductions: Fast vectorized aggregations (sum, max, min) globally or mapped across specific structural axes.

2. Zero-Copy Views & Memory Architecture

  • Strided N-Dimensional Arrays: Full architectural support for non-contiguous memory layouts, slicing, and matrix transposition (.transpose()).
  • Advanced Broadcasting: Dynamic shape broadcasting (.broadcastTo()) with highly descriptive, context-aware validation exceptions.
  • Contiguity Enforcement: Smart memory routing that uses isContiguous() to seamlessly switch between blistering-fast hardware SIMD lanes and safe scalar NDIter fallback loops to prevent memory corruption on complex views.

3. Enterprise-Grade Safety

  • Zero JNI: No bloated .dll or .so binaries. No crossing the JNI boundary.
  • Strict Type Promotion: Automated, safe DType promotion (e.g., mixing Float and Double tensors safely resolves to Double).
  • Off-Heap Allocation: Uses Java's modern Arena API for zero-garbage, off-heap memory management.

Benchmarks vs. Native Backends

By avoiding the JNI crossover latency, JNum is highly competitive against traditional C++ backends (like OpenBLAS) for small-to-medium matrices.
(Tested on JDK 25 with --add-modules jdk.incubator.vector, Single-Threaded):

  • 256x256 Matmul: ~0.900 ms/op
  • 512x512 Matmul: ~4.097 ms/op
  • 1024x1024 Matmul: ~51.642 ms/op (Processes over 1 Billion calculations in ~51ms)

Getting Started

1. Maven Dependency

Add JNum to your pom.xml:

<dependency>
    <groupId>com.github.ch-abhinav</groupId>
    <artifactId>jnum</artifactId>
    <version>0.1.0-PREVIEW</version>
</dependency>