Class ND4JBaseTensorBackend

java.lang.Object
org.episteme.nativ.mathematics.linearalgebra.tensors.backends.ND4JBaseTensorBackend
All Implemented Interfaces:
TensorBackend, TensorProvider, AlgorithmProvider, Backend, ComputeBackend
Direct Known Subclasses:
NativeND4JCUDATensorBackend, NativeND4JTensorBackend

public abstract class ND4JBaseTensorBackend extends Object implements TensorBackend
Abstract base for ND4J-backed Tensor backends.

Sub-classes target specific ND4J device backends (native CPU, CUDA GPU).

  • Field Details

    • isAvailable

      protected final boolean isAvailable
  • Constructor Details

    • ND4JBaseTensorBackend

      protected ND4JBaseTensorBackend()
  • Method Details

    • checkAvailability

      protected abstract boolean checkAvailability()
    • supportsGPU

      public abstract boolean supportsGPU()
      Description copied from interface: TensorBackend
      Returns true if this provider supports GPU acceleration.
      Specified by:
      supportsGPU in interface TensorBackend
      Returns:
      true if GPU is available
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: Backend
      Checks if this backend is currently available (libraries loaded, etc.).

      Default implementation checks Backend.isExplicitlyDisabled() and returns false if it is.

      Specified by:
      isAvailable in interface AlgorithmProvider
      Specified by:
      isAvailable in interface Backend
      Specified by:
      isAvailable in interface TensorBackend
    • supportsParallelOps

      public boolean supportsParallelOps()
      Description copied from interface: ComputeBackend
      Checks if this backend supports parallel operations.
      Specified by:
      supportsParallelOps in interface ComputeBackend
      Returns:
      true if parallel execution is supported
    • checkCommonClasses

      protected boolean checkCommonClasses()
    • doGetContext

      protected abstract ExecutionContext doGetContext()
    • createContext

      public ExecutionContext createContext()
      Description copied from interface: ComputeBackend
      Creates 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:
      createContext in interface ComputeBackend
      Returns:
      new execution context
    • zeros

      public <T> Tensor<T> zeros(Class<T> elementType, int... shape)
      Description copied from interface: TensorBackend
      Creates a tensor with the given shape, filled with zeros.
      Specified by:
      zeros in interface TensorBackend
      Specified by:
      zeros in interface TensorProvider
      Type Parameters:
      T - the element type
      Parameters:
      elementType - the class of field elements
      shape - the tensor shape
      Returns:
      zero-initialized tensor
    • ones

      public <T> Tensor<T> ones(Class<T> elementType, int... shape)
      Description copied from interface: TensorBackend
      Creates a tensor with the given shape, filled with ones.
      Specified by:
      ones in interface TensorBackend
      Specified by:
      ones in interface TensorProvider
      Type Parameters:
      T - the element type
      Parameters:
      elementType - the class of field elements
      shape - the tensor shape
      Returns:
      one-initialized tensor
    • create

      public <T> Tensor<T> create(T[] data, int... shape)
      Description copied from interface: TensorBackend
      Creates a tensor from a flat array and shape.
      Specified by:
      create in interface TensorBackend
      Specified by:
      create in interface TensorProvider
      Type Parameters:
      T - the element type
      Parameters:
      data - the flat data array
      shape - the tensor shape
      Returns:
      tensor with given data
    • toINDArray

      public org.nd4j.linalg.api.ndarray.INDArray toINDArray(Tensor<Real> tensor)
    • fromINDArray

      public Tensor<Real> fromINDArray(org.nd4j.linalg.api.ndarray.INDArray indArray)
    • convertShape

      protected long[] convertShape(int[] shape)