Class NativeND4JLinearAlgebraBackend
java.lang.Object
org.episteme.nativ.mathematics.linearalgebra.backends.NativeND4JLinearAlgebraBackend
- All Implemented Interfaces:
AutoCloseable, LinearAlgebraProvider<Real>, AlgorithmProvider, Backend, ComputeBackend, CPUBackend, NativeBackend
@AutoService({Backend.class,ComputeBackend.class,NativeBackend.class,LinearAlgebraProvider.class,CPUBackend.class})
public class NativeND4JLinearAlgebraBackend
extends Object
implements LinearAlgebraProvider<Real>, NativeBackend, CPUBackend
NativeND4J Linear Algebra Backend (Dense).
When the ND4J library (org.nd4j:nd4j-native-platform) is on the classpath,
this backend delegates to ND4J's optimized BLAS/LAPACK backends (Native/AVX/CUDA).
Decompositions (eigen, SVD, LU) are implemented natively using ND4J array operations.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionComputes the Cholesky decomposition of the specified matrix.Creates an execution context for running operations.determinant(Matrix<Real> a) Determinant via Gaussian elimination on ND4J arrays.Computes the eigenvalue decomposition of the specified matrix.Returns the type of hardware accelerator used by this backend.Returns the unique category of the algorithm.Returns a string describing the execution environment (e.g., "CPU (AVX2)", "GPU (CUDA 12.0)").getId()Returns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").getName()Returns the display name for UI presentation.Returns the name of the native library this backend depends on.intPriority of this provider (higher means more preferred).getType()Returns the backend type category (e.g., "plotting", "molecular", "tensor", "math").booleanChecks if the provider is available in the current environment.booleanisCompatible(Ring<?> ring) Checks if this provider is compatible with the given ring.booleanChecks if this backend is specifically disabled via a system property:"episteme.backend.disable." + getId().booleanisLoaded()Checks if the native library is loaded and available.LU decomposition via Gaussian elimination on ND4J arrays.QR decomposition via ND4J's 'qr' custom op.doublescore(OperationContext context) Scores this provider for a specific operation context.voidshutdown()Called when the provider is no longer needed (e.g., application shutdown).Solve Ax=b via ND4J's LU decomposition.solveTriangular(Matrix<Real> A, Vector<Real> b, boolean upper, boolean transpose, boolean conjugate, boolean unit) Solves the triangular system Ax = b.SVD using ND4J's built-in Svd custom op.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AlgorithmProvider
description, getMetadataMethods inherited from interface Backend
getAlgorithmProviders, getStatusMessageMethods inherited from interface ComputeBackend
createBackend, getDescriptionMethods inherited from interface CPUBackend
supportsComplexNumbers, supportsFloatingPoint, supportsParallelOps
-
Constructor Details
-
NativeND4JLinearAlgebraBackend
public NativeND4JLinearAlgebraBackend()
-
-
Method Details
-
getPriority
public int getPriority()Description copied from interface:LinearAlgebraProviderPriority of this provider (higher means more preferred). Used for automatic backend selection.- Specified by:
getPriorityin interfaceAlgorithmProvider- Specified by:
getPriorityin interfaceBackend- Specified by:
getPriorityin interfaceLinearAlgebraProvider<Real>
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceLinearAlgebraProvider<Real>
-
getAcceleratorType
Description copied from interface:ComputeBackendReturns the type of hardware accelerator used by this backend.- Specified by:
getAcceleratorTypein interfaceComputeBackend- Specified by:
getAcceleratorTypein interfaceCPUBackend- Returns:
- the accelerator type
-
getEnvironmentInfo
Description copied from interface:LinearAlgebraProviderReturns a string describing the execution environment (e.g., "CPU (AVX2)", "GPU (CUDA 12.0)").- Specified by:
getEnvironmentInfoin interfaceLinearAlgebraProvider<Real>
-
isLoaded
public boolean isLoaded()Description copied from interface:NativeBackendChecks if the native library is loaded and available.- Specified by:
isLoadedin interfaceNativeBackend- Returns:
- true if the native library has been successfully loaded
-
createContext
Description copied from interface:ComputeBackendCreates an execution context for running operations.The context should be used within a try-with-resources block to ensure proper cleanup of resources.
- Specified by:
createContextin interfaceComputeBackend- Returns:
- new execution context
-
getNativeLibraryName
Description copied from interface:NativeBackendReturns the name of the native library this backend depends on.- Specified by:
getNativeLibraryNamein interfaceNativeBackend- Returns:
- library name (e.g., "openblas", "cuda", "fftw3")
-
getAlgorithmType
Description copied from interface:AlgorithmProviderReturns the unique category of the algorithm.- Specified by:
getAlgorithmTypein interfaceAlgorithmProvider- Specified by:
getAlgorithmTypein interfaceLinearAlgebraProvider<Real>
-
isAvailable
public boolean isAvailable()Description copied from interface:AlgorithmProviderChecks if the provider is available in the current environment.- Specified by:
isAvailablein interfaceAlgorithmProvider- Specified by:
isAvailablein interfaceBackend
-
getId
-
isExplicitlyDisabled
public boolean isExplicitlyDisabled()Description copied from interface:BackendChecks if this backend is specifically disabled via a system property:"episteme.backend.disable." + getId().It also checks specialized properties like
"episteme.linearalgebra.disable." + getId().- Specified by:
isExplicitlyDisabledin interfaceBackend- Returns:
- true if explicitly disabled
-
getType
Description copied from interface:BackendReturns the backend type category (e.g., "plotting", "molecular", "tensor", "math").- Specified by:
getTypein interfaceBackend- Specified by:
getTypein interfaceComputeBackend- Specified by:
getTypein interfaceCPUBackend
-
shutdown
public void shutdown()Description copied from interface:AlgorithmProviderCalled when the provider is no longer needed (e.g., application shutdown). Use this to release local resources or close native segments.- Specified by:
shutdownin interfaceAlgorithmProvider- Specified by:
shutdownin interfaceBackend
-
isCompatible
Description copied from interface:LinearAlgebraProviderChecks if this provider is compatible with the given ring.- Specified by:
isCompatiblein interfaceLinearAlgebraProvider<Real>
-
score
Description copied from interface:AlgorithmProviderScores this provider for a specific operation context.Higher scores indicate better suitability. Used by
ProviderSelectorfor context-aware selection.Default implementation returns
AlgorithmProvider.getPriority(), so existing providers behave identically without changes.- Specified by:
scorein interfaceAlgorithmProvider- Specified by:
scorein interfaceLinearAlgebraProvider<Real>- Parameters:
context- the operation context (data size, hints, etc.)- Returns:
- suitability score (higher = better)
-
add
-
subtract
-
multiply
-
dot
-
norm
-
add
-
subtract
-
multiply
-
solveTriangular
public Vector<Real> solveTriangular(Matrix<Real> A, Vector<Real> b, boolean upper, boolean transpose, boolean conjugate, boolean unit) Description copied from interface:LinearAlgebraProviderSolves the triangular system Ax = b.- Specified by:
solveTriangularin interfaceLinearAlgebraProvider<Real>- Parameters:
A- the triangular matrixb- the right-hand side vectorupper- true if A is upper triangular, false if lowertranspose- true if solving A^T x = bconjugate- true if solving A^H x = b (only if transpose is true and complex)unit- true if A is unit triangular (diagonal is all ones)
-
multiply
-
inverse
-
determinant
Determinant via Gaussian elimination on ND4J arrays. O(n^3), no external lib.- Specified by:
determinantin interfaceLinearAlgebraProvider<Real>
-
solve
-
transpose
-
qr
-
scale
-
svd
-
lu
-
cholesky
Description copied from interface:LinearAlgebraProviderComputes the Cholesky decomposition of the specified matrix.- Specified by:
choleskyin interfaceLinearAlgebraProvider<Real>
-
eigen
Description copied from interface:LinearAlgebraProviderComputes the eigenvalue decomposition of the specified matrix.- Specified by:
eigenin interfaceLinearAlgebraProvider<Real>
-
trace
-