Class AbstractNativeCPULinearAlgebraBackend<E>
java.lang.Object
org.episteme.nativ.mathematics.linearalgebra.backends.AbstractNativeCPULinearAlgebraBackend<E>
- All Implemented Interfaces:
AutoCloseable, LinearAlgebraProvider<E>, AlgorithmProvider, Backend, ComputeBackend, CPUBackend, NativeBackend
- Direct Known Subclasses:
NativeCPULinearAlgebraComplexBackend, NativeCPULinearAlgebraRealBackend
public abstract class AbstractNativeCPULinearAlgebraBackend<E>
extends Object
implements LinearAlgebraProvider<E>, NativeBackend, CPUBackend
Standalone Native Linear Algebra backend using bundled episteme_native library.
- Since:
- 1.1
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the angle between two vectors in radians.Computes the Cholesky decomposition of the specified matrix.Creates and returns the backend instance (or returns self if it is the backend).Creates an execution context for running operations.Returns the cross product of two 3D vectors.doubleddot(int n, DoubleBuffer x, int incx, DoubleBuffer y, int incy) determinant(Matrix<E> a) intdgels(char trans, int m, int n, int nrhs, DoubleBuffer A, int lda, DoubleBuffer B, int ldb) voiddgemm(int m, int n, int k, DoubleBuffer A, int lda, DoubleBuffer B, int ldb, DoubleBuffer C, int ldc, double alpha, double beta) voiddgemv(int m, int n, double alpha, DoubleBuffer A, int lda, DoubleBuffer x, int incx, double beta, DoubleBuffer y, int incy) intdgeqrf(int m, int n, DoubleBuffer A, int lda, DoubleBuffer tau) intdgesv(int n, int nrhs, DoubleBuffer A, int lda, IntBuffer ipiv, DoubleBuffer B, int ldb) intdgesvd(byte jobu, byte jobvt, int m, int n, DoubleBuffer A, int lda, DoubleBuffer S, DoubleBuffer U, int ldu, DoubleBuffer VT, int ldvt, DoubleBuffer superb) intdgetrf(int m, int n, DoubleBuffer A, int lda, IntBuffer ipiv) intdgetri(int n, DoubleBuffer A, int lda, IntBuffer ipiv) doublednrm2(int n, DoubleBuffer x, int incx) intdorgqr(int m, int n, int k, DoubleBuffer A, int lda, DoubleBuffer tau) intdpotrf(int n, DoubleBuffer A, int lda) voiddscal(int n, double alpha, DoubleBuffer x, int incx) intdsyev(int n, DoubleBuffer A, int lda, DoubleBuffer W) Computes the eigenvalue decomposition of the specified matrix.Computes the matrix exponential e^A.Returns theAlgorithmProviders exposed by this backend.Returns a description of the backend.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).Returns a human-readable status message for this backend.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.Computes the LU decomposition of the specified matrix.Returns the normalized vector (unit vector).projection(Vector<E> a, Vector<E> b) Returns the projection of vector a onto vector b.Computes the QR decomposition of the specified matrix.doublescore(OperationContext context) Scores this provider for a specific operation context.voidshutdown()Called when the provider is no longer needed (e.g., application shutdown).solveTriangular(Matrix<E> A, Vector<E> b, boolean upper, boolean transpose, boolean conjugate, boolean unit) Solves the triangular system Ax = b.Computes the Singular Value Decomposition (SVD) of the specified matrix.intzgeqrf(int m, int n, DoubleBuffer A, int lda, DoubleBuffer tau) intzgesvd(byte jobu, byte jobvt, int m, int n, DoubleBuffer A, int lda, DoubleBuffer S, DoubleBuffer U, int ldu, DoubleBuffer VT, int ldvt, DoubleBuffer superb) intzungqr(int m, int n, int k, DoubleBuffer A, int lda, DoubleBuffer tau) 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 CPUBackend
getAcceleratorType, supportsComplexNumbers, supportsFloatingPoint, supportsParallelOpsMethods inherited from interface LinearAlgebraProvider
add, close, conditionNumber, configure, conjugateTranspose, getAlgorithmType, rank, solve, solve, solve, subtract
-
Field Details
-
CblasRowMajor
public static final int CblasRowMajor- See Also:
-
CblasColMajor
public static final int CblasColMajor- See Also:
-
CblasNoTrans
public static final int CblasNoTrans- See Also:
-
CblasTrans
public static final int CblasTrans- See Also:
-
CblasConjTrans
public static final int CblasConjTrans- See Also:
-
CblasUpper
public static final int CblasUpper- See Also:
-
CblasLower
public static final int CblasLower- See Also:
-
CblasUnit
public static final int CblasUnit- See Also:
-
CblasNonUnit
public static final int CblasNonUnit- See Also:
-
CblasLeft
public static final int CblasLeft- See Also:
-
CblasRight
public static final int CblasRight- See Also:
-
LAPACK_ROW_MAJOR
public static final int LAPACK_ROW_MAJOR- See Also:
-
LAPACK_COL_MAJOR
public static final int LAPACK_COL_MAJOR- See Also:
-
ring
-
-
Constructor Details
-
AbstractNativeCPULinearAlgebraBackend
-
-
Method Details
-
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
-
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")
-
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
-
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
-
getId
-
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
-
getStatusMessage
Description copied from interface:BackendReturns a human-readable status message for this backend. Useful for debugging "Unavailable" states.- Specified by:
getStatusMessagein interfaceBackend- Returns:
- status message (e.g., "Ready", "Native library missing", etc.)
-
getEnvironmentInfo
Description copied from interface:LinearAlgebraProviderReturns a string describing the execution environment (e.g., "CPU (AVX2)", "GPU (CUDA 12.0)").- Specified by:
getEnvironmentInfoin interfaceLinearAlgebraProvider<E>
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceLinearAlgebraProvider<E>
-
getDescription
Description copied from interface:BackendReturns a description of the backend.- Specified by:
getDescriptionin interfaceBackend- Specified by:
getDescriptionin interfaceComputeBackend
-
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<E>
-
createBackend
Description copied from interface:BackendCreates and returns the backend instance (or returns self if it is the backend).- Specified by:
createBackendin interfaceBackend- Specified by:
createBackendin interfaceComputeBackend- Returns:
- The backend implementation object
-
getAlgorithmProviders
Description copied from interface:BackendReturns theAlgorithmProviders exposed by this backend.This bridges the Backend discovery system (ServiceLoader<Backend>) with the Algorithm discovery system (ServiceLoader<AlgorithmProvider>), allowing
AlgorithmManagerto find providers registered through either path.Default implementation checks if
Backend.createBackend()returns an AlgorithmProvider instance.- Specified by:
getAlgorithmProvidersin interfaceBackend- Returns:
- list of algorithm providers (may be empty, never null)
-
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<E>- Parameters:
context- the operation context (data size, hints, etc.)- Returns:
- suitability score (higher = better)
-
isCompatible
Description copied from interface:LinearAlgebraProviderChecks if this provider is compatible with the given ring.- Specified by:
isCompatiblein interfaceLinearAlgebraProvider<E>
-
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
-
solveTriangular
public Vector<E> solveTriangular(Matrix<E> A, Vector<E> b, boolean upper, boolean transpose, boolean conjugate, boolean unit) Description copied from interface:LinearAlgebraProviderSolves the triangular system Ax = b.- Specified by:
solveTriangularin interfaceLinearAlgebraProvider<E>- 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)
-
dgemm
public void dgemm(int m, int n, int k, DoubleBuffer A, int lda, DoubleBuffer B, int ldb, DoubleBuffer C, int ldc, double alpha, double beta) -
dgemv
public void dgemv(int m, int n, double alpha, DoubleBuffer A, int lda, DoubleBuffer x, int incx, double beta, DoubleBuffer y, int incy) -
ddot
-
dnrm2
-
dscal
-
dgetrf
-
dgetri
-
dgesv
-
dsyev
-
dpotrf
-
dgeqrf
-
dorgqr
-
dgesvd
public int dgesvd(byte jobu, byte jobvt, int m, int n, DoubleBuffer A, int lda, DoubleBuffer S, DoubleBuffer U, int ldu, DoubleBuffer VT, int ldvt, DoubleBuffer superb) -
zgeqrf
-
zungqr
-
zgesvd
public int zgesvd(byte jobu, byte jobvt, int m, int n, DoubleBuffer A, int lda, DoubleBuffer S, DoubleBuffer U, int ldu, DoubleBuffer VT, int ldvt, DoubleBuffer superb) -
dgels
public int dgels(char trans, int m, int n, int nrhs, DoubleBuffer A, int lda, DoubleBuffer B, int ldb) -
multiply
-
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
-
add
-
subtract
-
scale
-
multiply
-
inverse
-
solve
-
transpose
-
determinant
- Specified by:
determinantin interfaceLinearAlgebraProvider<E>
-
lu
Description copied from interface:LinearAlgebraProviderComputes the LU decomposition of the specified matrix.- Specified by:
luin interfaceLinearAlgebraProvider<E>
-
eigen
Description copied from interface:LinearAlgebraProviderComputes the eigenvalue decomposition of the specified matrix.- Specified by:
eigenin interfaceLinearAlgebraProvider<E>
-
cholesky
Description copied from interface:LinearAlgebraProviderComputes the Cholesky decomposition of the specified matrix.- Specified by:
choleskyin interfaceLinearAlgebraProvider<E>
-
dot
-
norm
-
normalize
Description copied from interface:LinearAlgebraProviderReturns the normalized vector (unit vector).- Specified by:
normalizein interfaceLinearAlgebraProvider<E>
-
cross
Description copied from interface:LinearAlgebraProviderReturns the cross product of two 3D vectors.- Specified by:
crossin interfaceLinearAlgebraProvider<E>
-
angle
Description copied from interface:LinearAlgebraProviderReturns the angle between two vectors in radians.- Specified by:
anglein interfaceLinearAlgebraProvider<E>
-
projection
Description copied from interface:LinearAlgebraProviderReturns the projection of vector a onto vector b.- Specified by:
projectionin interfaceLinearAlgebraProvider<E>
-
multiply
-
qr
Description copied from interface:LinearAlgebraProviderComputes the QR decomposition of the specified matrix.- Specified by:
qrin interfaceLinearAlgebraProvider<E>
-
svd
Description copied from interface:LinearAlgebraProviderComputes the Singular Value Decomposition (SVD) of the specified matrix.- Specified by:
svdin interfaceLinearAlgebraProvider<E>
-
trace
-
exp
Description copied from interface:LinearAlgebraProviderComputes the matrix exponential e^A.- Specified by:
expin interfaceLinearAlgebraProvider<E>
-
log
-
log10
-
sin
-
cos
-
tan
-
asin
-
acos
-
atan
-
sinh
-
cosh
-
tanh
-
asinh
-
acosh
-
atanh
-
sqrt
-
cbrt
-
pow
-