{"slug": "show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api", "title": "Show HN: JNum – Pure Java 25 NumPy/BLAS via Project Panama FFM and Vector API", "summary": "JNum, a pure Java 25 and Kotlin numerical computing library built on Project Panama's Foreign Function & Memory API (JEP 454) and the Vector API, was posted to Hacker News as a NumPy/BLAS alternative with a total JAR footprint of roughly 470 KB. JNum's author reports JMH 1.37 benchmarks on Java 25 LTS against NumPy 2.4 with OpenBLAS, ND4J 1.0.0-M2.1, EJML 0.44 and ojAlgo 55.0, claiming a 0.0002 ms result on one matrix dimension versus 0.0023 ms for NumPy and 0.020 ms for ND4J, described as 11x faster than NumPy and 100x faster than ND4J. The library ships a 4-tier GEMM engine routing across Nano scalar, register-tiled, single-threaded BLIS and parallel ForkJoin kernels, O(1) zero-copy slicing, symbolic expression evaluation, Safetensors and .npy/.npz memory-mapped I/O, and a built-in jnum.nn inference module.", "body_md": "A high-performance, hardware-accelerated numerical computing library for modern Java (JDK 25+) and Kotlin, powered by **Project Panama** (Foreign Function & Memory API and the Vector API).\n\nJNum brings the ergonomics of **NumPy** and **PyTorch** to the JVM with native BLAS performance—**without native C++ build toolchains, JNI boundaries, or garbage collection overhead.**\n\nTraditional JVM numerical and tensor libraries (such as ND4J or Deeplearning4j) rely on native C++ backends. They manipulate memory using deprecated `sun.misc.Unsafe` and cross the native boundary via **JNI (Java Native Interface)**.\n\n| Metric | Legacy Java Tensor Libraries | **JNum** | \n|---|---|---|\n| **Backend Implementation** | C++ (OpenBLAS, OneDNN, LibTorch) bridged via JNI | **100% Pure Java 25 & Kotlin** | \n| **Native Library Bloat** | 100+ MB (Bundles `.dll` ,`.so` ,`.dylib` binaries) | **< 500 KB total JAR footprint (~470 KB)** | \n| **Memory Architecture** | Deprecated `sun.misc.Unsafe` (Memory corruption risk) | **Foreign Function & Memory (JEP 454)** | \n| **SIMD Acceleration** | Opaque native compiler intrinsics | **JVM Vector API (`jdk.incubator.vector`)** | \n| **Memory Safety** | Out-of-bounds causes native process crash ( `SIGSEGV` ) | **100% JVM Memory Safe (Catchable Exceptions)** | \n| **Deployment Complexity** | Fragile native dependencies, dynamic linker errors | **Drop-in JAR: Runs anywhere Java runs** | \n\n``` python\nimport jnum.DType;\nimport jnum.JNum;\nimport jnum.NDArray;\nimport jnum.Slice;\n\nvoid main() {\n    // 1. Allocate 64-byte aligned off-heap tensors\n    NDArray a = JNum.rand(1024, 512);\n    NDArray b = JNum.rand(512, 256);\n\n    // 2. Hardware SIMD matrix multiplication (4-tier BLIS engine)\n    NDArray c = a.matmul(b); // Shape: [1024, 256]\n\n    // 3. Zero-copy subviews and Pythonic slicing\n    NDArray slice = c.slice(\"0:10, 0:5\");\n\n    // 4. In-place zero-allocation mutations\n    slice.muli(2.0f);\n\n    IO.println(\"Top-left block:\\n\" + slice);\n}\npython\nimport jnum.*\n\nfun main() {\n    val x = JNum.rand(128, 64)\n    val w = JNum.rand(64, 10)\n    val b = JNum.zeros(10)\n\n    // Natural operator overloading and infix linear algebra\n    val logits = (x matmul w) + b\n\n    // Python-style multidimensional range slicing\n    val topScores = logits[0 until 5, all]\n\n    println(\"Top scores:\\n$topScores\")\n}\n```\n\n- \n**Hardware SIMD Vector Lanes** : Automatically probes your CPU to schedule AVX-512 (16 lanes), AVX2 (8 lanes), or ARM NEON (4 lanes) instructions via the Vector API.\n- \n**4-Tier GEMM Engine** : Hardware-adaptive matrix multiplication routing across Nano scalar, Direct register-tiled, Single-threaded BLIS, and Parallel ForkJoin macro-kernels.\n- \n**Zero-Copy Layouts & Slicing** : Transposition, reshaping, subviews, and strided slices are constant-time$O(1)$ operations with zero memory copying.\n- \n**Symbolic Expression Evaluation** : Compile formulas like`JNum.eval(\"$0 * $1 + $2\", a, b, c)` or`JNum.eval(\"x * w + b\", map)` into hardware FMA instructions with automatic buffer recycling.\n- \n**Modern AI Checkpoint I/O** : Direct zero-copy memory mapping for**Hugging Face Safetensors** (`.safetensors` ) and**NumPy binaries** (`.npy` ,`.npz` ), plus high-throughput CSV/TSV parsing.\n- \n**Pure-Java Neural Network Inference** : Built-in`jnum.nn` modules (`Linear` with sequence rank preservation,`ReLU` ,`Sigmoid` ,`Tanh` ,`Softmax` , and`Sequential` ).\n\nAll benchmarks were measured via OpenJDK **JMH 1.37** on **Java 25 LTS** (`-Xms8g -Xmx8g -XX:+AlwaysPreTouch -XX:+UseParallelGC --add-modules jdk.incubator.vector`), comparing JNum against **NumPy 2.4** (OpenBLAS/C backend) and standard JVM numerical engines (**EJML 0.44**, **ojAlgo 55.0**, and **ND4J 1.0.0-M2.1** with native OpenBLAS backend).\n\n| Matrix Dimensions | JNum (Pure Java 25) | NumPy (C / OpenBLAS) | ND4J (OpenBLAS C++) | EJML (Pure Java) | Performance Highlights | \n|---|---|---|---|---|---|\n|  | **0.0002 ms** | 0.0023 ms | 0.020 ms | ≈ 0.0001 ms | **11× faster** than NumPy,**100× faster** than ND4J | \n|  | **0.0004 ms** | 0.0028 ms | 0.019 ms | 0.003 ms | **7× faster** than NumPy,**47× faster** than ND4J | \n|  | **0.015 ms** | 0.013 ms | 0.190 ms | 0.140 ms | On-par with NumPy, **9.3× faster** than EJML | \n|  | **0.138 ms** | 0.254 ms | 0.499 ms | 1.028 ms | **1.8× faster** than NumPy,**7.4× faster** than EJML | \n|  | **2.50 ms** | 1.86 ms | 2.67 ms | 27.16 ms | Matches C++ BLAS, **10.8× faster** than EJML | \n|  | **13.85 ms** | 8.98 ms | 12.18 ms | 216.56 ms | Near-native speed, **15.6× faster** than EJML | \n|  | **94.62 ms** | 62.99 ms | 85.29 ms | 2,049.86 ms | Pure Java competitive with C BLAS, **21.6× faster** than EJML | \n|  | **942.38 ms** | 487.92 ms | 857.41 ms | 17,419.52 ms | Matches ND4J C++, **18.4× faster** than EJML | \n|  | **6,784.15 ms** | 5,967.30 ms | 6,317.97 ms | 141,500.0 ms | **~88% of NumPy C BLAS** ,**20.8× faster** than EJML | \n\nNote\n\n**Why JNum wins on small-to-medium matrices:** Legacy C++ wrappers (ND4J) and Python C-API bindings (NumPy) incur dispatch and JNI call boundary overheads. JNum's **Tier 0 nano-scalar** and **Tier 1 direct SIMD** kernels execute inside CPU vector registers without crossing native boundaries or scheduling thread pools.\n\n| Vector Math Op | JNum (Pure Java 25) | NumPy | EJML | ojAlgo | ND4J (Native C++) | JNum Advantage | \n|---|---|---|---|---|---|---|\n| **`sin(x)`** | **151.59 ms** | 154.87 ms | 1,334.80 ms | 1,338.30 ms | 1,693.35 ms | **On-par with NumPy** ,**8.8× – 11.2× faster** than JVM peers | \n| **`cos(x)`** | **170.91 ms** | 151.35 ms | 1,077.31 ms | 1,542.43 ms | 1,979.36 ms | **6.3× – 11.6× faster** than JVM peers | \n| **`exp(x)`** | **111.49 ms** | 122.10 ms | 804.97 ms | 913.84 ms | 1,988.33 ms | **1.1× faster than NumPy** ,**7.2× – 17.8× faster** than JVM peers | \n| **`log(x)`** | **121.47 ms** | 164.22 ms | 844.08 ms | 1,062.01 ms | 1,243.39 ms | **1.35× faster than NumPy** ,**6.9× – 10.2× faster** than JVM peers | \n| **`sigmoid(x)`** | **115.01 ms** | 440.49 ms | 973.74 ms | 1,033.69 ms | 1,843.23 ms | **3.8× faster than NumPy** ,**8.5× – 16.0× faster** than JVM peers | \n| **`tanh(x)`** | **301.43 ms** | 197.38 ms | 1,493.26 ms | 1,602.51 ms | 3,130.68 ms | **5.0× – 10.4× faster** than JVM peers | \n\nTip\n\n**Why JNum wins on transcendental ops:** EJML and ojAlgo process elements through scalar `Math.*` calls in a single-threaded loop. JNum utilizes **vectorized minimax Chebyshev polynomials** scheduled across AVX2/AVX-512 lanes, computing 8 or 16 transcendental operations per CPU clock cycle.\n\n| Operation | JNum (Pure Java 25) | NumPy | EJML | ND4J | JNum Advantage | \n|---|---|---|---|---|---|\n| **Matrix Inverse** | **7.271 ms** | 10.680 ms | 18.122 ms | 1,224.654 ms | **1.47× faster** than NumPy,**2.5× faster** than EJML,**168× faster** than ND4J | \n| **Linear Solve (** | **1.976 ms** | 1.003 ms | 5.331 ms | 37.278 ms | Near-native speed, **2.7× faster** than EJML,**18.8× faster** than ND4J | \n| **Determinant** | **1.839 ms** | 5.735 ms | 5.380 ms | 399.752 ms | **3.1× faster** than NumPy,**2.9× faster** than EJML | \n| **Cholesky** | **1.261 ms** | 2.328 ms | 3.545 ms | — | **1.8× faster** than NumPy,**2.8× faster** than EJML | \n| **QR Factorization** | **46.170 ms** | 12.622 ms | 7.447 ms | 586.330 ms | **12.7× faster** than ND4J | \n\nAdd JNum to your project (choose Java or Kotlin):\n\n**For Java:**\n\n```\n<dependency>\n    <groupId>io.github.ch-abhinav</groupId>\n    <artifactId>jnum</artifactId>\n    <version>0.2.0</version>\n</dependency>\n```\n\n**For Kotlin** *(bundles core + Kotlin extensions)*:\n\n```\n<dependency>\n    <groupId>io.github.ch-abhinav</groupId>\n    <artifactId>jnum-kotlin</artifactId>\n    <version>0.2.0</version>\n</dependency>\n```\n\n**For Java:**\n\n```\ndependencies {\n    implementation(\"io.github.ch-abhinav:jnum:0.2.0\")\n}\n```\n\n**For Kotlin** *(bundles core + Kotlin extensions)*:\n\n```\ndependencies {\n    implementation(\"io.github.ch-abhinav:jnum-kotlin:0.2.0\")\n}\n```\n\nImportant\n\nBecause JNum leverages Project Panama, compilation requires `--add-modules jdk.incubator.vector`, and runtime execution requires `--add-modules jdk.incubator.vector --enable-native-access=ALL-UNNAMED`.\n\n👉 **[Read the Full Installation & Setup Guide](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/01-getting-started.md)** for copy-paste Maven/Gradle compiler plugins and single-file runner configurations.\n\nJNum ships with a complete, progressive documentation suite structured like *The Rust Book*, paired with an advanced systems engineering deep dive:\n\n1. **[Getting Started](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/01-getting-started.md)** — JDK 25 prerequisites, Panama JVM flags, Maven & Gradle setup.\n2. **[Tensors & Fundamentals](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/02-tensors-and-fundamentals.md)** — Off-heap mental model, DTypes, and scoped`Arena` lifecycles.\n3. **[Layouts, Strides, and Slicing](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/03-layouts-strides-and-slicing.md)** — Strides, subviews, Slice tokens, and zero-copy views vs copies.\n4. **[SIMD Arithmetic & Broadcasting](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/04-simd-arithmetic-and-broadcasting.md)** — Vector lanes, broadcasting rules, and zero-GC output buffers.\n5. **[Comparisons & Boolean Logic](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/05-comparisons-and-boolean-logic.md)** — Clamping (`maximum` /`minimum` ), boolean masks, and truth reductions.\n6. **[Transcendental & Unary Operations](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/06-transcendental-and-unary-ops.md)** — Vectorized`exp` ,`log` ,`sigmoid` , and circular/hyperbolic trigonometry.\n7. **[Linear Algebra & Decompositions](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/07-linear-algebra-and-decompositions.md)** — 4-tier GEMM, matrix properties (`det` ,`norm` ), solvers, and factorizations (QR, SVD, Cholesky, Eig).\n8. **[Descriptive & Inferential Statistics](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/08-descriptive-and-inferential-stats.md)** — The`Stats` facade, moments, 5 quantile algorithms, and covariance.\n9. **[Symbolic Expression Engine](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/09-symbolic-expression-engine.md)** — Eliminating temporary arrays with`JNum.eval()` and AST buffer reuse.\n10. **[Tabular & NumPy I/O](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/10-tabular-and-numpy-io.md)** — CSV/TSV with`CsvOptions` ,`.npy` files with memory mapping (`mmap` ), and`.npz` archives.\n11. **[Safetensors & Asynchronous I/O](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/11-safetensors-and-async-io.md)** — Hugging Face checkpoints, scoped mmap (`MmapTensors` ), and async pipelines.\n12. **[Neural Network Inference](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/12-neural-network-inference.md)** —`Module` ,`Linear` with sequence rank preservation, activations, and`Sequential` .\n13. **[Idiomatic Kotlin DSL](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/13-idiomatic-kotlin-dsl.md)** — First-class operator overloads (`+` ,`*` ), infix math (`matmul` ,`dot` ), and range slicing.\n14. **[Safety & Error Diagnostics](https://github.com/CH-Abhinav/JNum/blob/main/docs/guide/14-safety-and-error-diagnostics.md)** — Memory safety, closed arena states, shape mismatches, and`NaN` /`Inf` diagnostics.\n\n- \n**[Off-Heap Memory & Stride Calculus](https://github.com/CH-Abhinav/JNum/blob/main/docs/internals/01-memory-strides-and-ffm.md)** — Native`MemorySegment` mechanics, row-major stride proofs, and 64-byte cache alignment.\n- \n**[Pure Java GEMM & SIMD Micro-Kernels](https://github.com/CH-Abhinav/JNum/blob/main/docs/internals/02-pure-java-gemm-and-simd.md)** — The 4-tier dispatch matrix, BLIS cache hierarchy, and register-blocked micro-panels ($M_R \\times N_R = 6 \\times 2 \\cdot VL$ ).\n- \n**[Dynamic Hardware & Cache Probing](https://github.com/CH-Abhinav/JNum/blob/main/docs/internals/03-dynamic-hardware-and-cache-probing.md)** — Probing Linux`sysfs` , macOS`sysctl` , and Windows`WMI` to derive analytical$K_C, M_C, N_C$ cache tiles.\n- \n**[Zero-Copy I/O & Custom Parsers](https://github.com/CH-Abhinav/JNum/blob/main/docs/internals/04-zero-copy-io-architecture.md)** — Virtual memory paging, safe deterministic unmapping, and zero-heap byte parsers.\n- \n**[AST Compilation & The Symbolic Engine](https://github.com/CH-Abhinav/JNum/blob/main/docs/internals/05-eval-engine-ast-compilation.md)** — Shunting-Yard AST generation, hardware FMA optimization, and topological buffer recycling.\n\n- **[NumPy to JNum Rosetta Stone](https://github.com/CH-Abhinav/JNum/blob/main/docs/reference/numpy-to-jnum-rosetta-stone.md)** — Side-by-side syntax comparison across NumPy (Python), JNum (Java 25), and JNum (Kotlin).\n- **[JVM & Project Panama Tuning Flags](https://github.com/CH-Abhinav/JNum/blob/main/docs/reference/jvm-panama-tuning-flags.md)** — JVM flags, AVX-512/NEON verification, and overriding cache heuristics.\n\n- **JDK 25 or later** (Temurin, OpenJDK, or Zulu)\n- Architectures supported: **x86_64** (SSE4.2, AVX, AVX2, AVX-512) and**AArch64 / ARM64** (NEON, SVE).\n\nThis project is licensed under the Apache License 2.0. See the [LICENSE](https://github.com/CH-Abhinav/JNum/blob/main/LICENSE) file for details.", "url": "https://wpnews.pro/news/show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api", "canonical_source": "https://github.com/CH-Abhinav/JNum", "published_at": "2026-11-12 06:28:26+00:00", "updated_at": "2026-11-12 06:55:18.315383+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["JNum", "Java 25", "Kotlin", "Project Panama", "NumPy", "ND4J", "EJML", "ojAlgo"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api", "markdown": "https://wpnews.pro/news/show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api.md", "text": "https://wpnews.pro/news/show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api.txt", "jsonld": "https://wpnews.pro/news/show-hn-jnum-pure-java-25-numpy-blas-via-project-panama-ffm-and-vector-api.jsonld"}}