Package-level declarations

Types

Link copied to clipboard
data class ContiguityAnalysis(val isContiguous: Boolean, val viewVolume: Int, val parentVolume: Int, val volumeRatio: Double, val dimensionMatches: List<Boolean>, val reason: String)

Data class containing detailed contiguity analysis results.

Link copied to clipboard

A materialization strategy that immediately copies all data from a tensor view into a new, standalone tensor with contiguous memory layout.

Link copied to clipboard
Link copied to clipboard

Default implementation of TensorViewStrategy that prefers views when possible.

Link copied to clipboard
class GradState<T : DType, V>(var requiresGrad: Boolean = false, var grad: Tensor<T, V>? = null)

Mutable holder for gradient state associated with a tensor instance.

Link copied to clipboard
interface IndexMapper

Interface for coordinate transformation between tensor view space and parent tensor space.

Link copied to clipboard

Thrown when an index value is outside the allowed range.

Link copied to clipboard
value class IndexTensor<V>(val t: Tensor<*, V>)

Lightweight wrapper marking a Tensor as index-bearing. It does not change storage, only annotates intent and guarantees validation performed by asIndices.

Link copied to clipboard

A materialization strategy that defers copying of tensor view data until individual elements are actually accessed.

Link copied to clipboard

Strategy interface for materializing tensor views into concrete tensors.

Link copied to clipboard

Memory-pressure-aware tensor view strategy.

Link copied to clipboard
class NCHWIndexMapper<T : DType, V>(parentShape: Shape, slices: List<Slice<T, V>>, viewShape: Shape) : IndexMapper

Specialized IndexMapper optimized for NCHW (Batch, Channel, Height, Width) tensor layout.

Link copied to clipboard

Detects NCHW-optimized slicing patterns for efficient memory access.

Link copied to clipboard

Thrown when an index tensor contains a non-integral value while strict validation is enabled.

Link copied to clipboard
class SegmentBuilder<T : DType, V>(dimensionIndex: Int)

Builder for configuring a single dimension slice within a segment { } block.

Link copied to clipboard
data class Shape(val dimensions: IntArray)
Link copied to clipboard
sealed class Slice<T : DType, V>

Represents a slice descriptor for tensor slicing operations.

Link copied to clipboard
class SlicedTensorView<T : DType, V>(val parentTensor: Tensor<T, V>, slices: List<Slice<T, V>>) : TensorView<T, V>

A concrete implementation of TensorView that provides zero-copy sliced access to parent tensors.

Link copied to clipboard
class SliceIndexMapper<T : DType, V>(parentShape: Shape, slices: List<Slice<T, V>>, viewShape: Shape) : IndexMapper

General-purpose IndexMapper implementation for arbitrary slice patterns.

Link copied to clipboard
interface Tensor<T : DType, V>

The core tensor abstraction in the SKaiNET framework, representing a fundamental architectural decision to compose tensors from data and operations.

Link copied to clipboard
Link copied to clipboard
interface TensorFactory<T : DType, V>
Link copied to clipboard

DSL builder for creating tensor slices with fluent syntax.

Link copied to clipboard
interface TensorView<T : DType, V> : Tensor<T, V>

A tensor view interface that represents a zero-copy slice or subset of a parent tensor.

Link copied to clipboard
interface TensorViewStrategy<T : DType, V>

Strategy interface for deciding between view creation and tensor copying.

Link copied to clipboard
class VoidOpsTensor<T : DType, V>(val data: TensorData<T, V>, val dtype: KClass<T>, val gradState: GradState<T, V> = GradState()) : Tensor<T, V>

Simple tensor implementation with void Ops as default for the DSL

Functions

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.abs(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> GradState<T, V>.accumulate(next: Tensor<T, V>)

Accumulate a gradient tensor onto this state.

Link copied to clipboard

Provides a more detailed contiguity analysis with diagnostic information.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.asIndices(strict: Boolean = true): IndexTensor<V>

Validates this tensor as an index tensor and wraps it into IndexTensor.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.avgPool2d(kernelSize: Pair<Int, Int>, stride: Pair<Int, Int> = kernelSize, padding: Pair<Int, Int> = 0 to 0, countIncludePad: Boolean = true): Tensor<T, V>
Link copied to clipboard

Materializes a list of tensor views into a list of standalone tensors efficiently.

Materializes a list of tensor views using a specific materialization strategy.

Link copied to clipboard

Checks if this tensor view can be materialized using the default strategy.

Checks if this tensor view can be materialized using a specific strategy.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.clamp(minVal: Float, maxVal: Float): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.cosineDistance(other: Tensor<T, V>, dim: Int = -1, eps: Double = 1.0E-8): Tensor<T, V>

Calculates the cosine distance between two tensors along a given dimension. Cosine distance is defined as 1 - cosine similarity. Formula: 1 - (A dot B) / (||A|| * ||B||)

Link copied to clipboard

Detects the NCHW slicing pattern for optimization purposes.

Link copied to clipboard
operator fun <T : DType, V> Number.div(t: Tensor<T, V>): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.div(v: Number): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.div(other: Tensor<T, V>): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.elu(alpha: Float = 1.0f): Tensor<T, V>
Link copied to clipboard

Estimates the total memory overhead for batch materializing a list of views.

Estimates the total memory overhead using a specific materialization strategy.

Link copied to clipboard

Estimates the memory overhead of materializing this tensor view.

Estimates the memory overhead of materializing this tensor view with a specific strategy.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.flatten(startDim: Int = 0, endDim: Int = -1): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.ge(value: Float): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.gelu(): Tensor<T, V>
Link copied to clipboard

Determines if this tensor view represents a contiguous memory layout.

Link copied to clipboard
fun <T : DType, V> isContiguousSlice(slices: List<Slice<T, V>>): Boolean

Determines if a list of slices results in a contiguous memory access pattern.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.isMatrix(): Boolean
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.isScalar(): Boolean
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.isVector(): Boolean
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.leakyRelu(negativeSlope: Float = 0.01f): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.logSoftmax(dim: Int = -1): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.lt(value: Float): Tensor<T, V>
Link copied to clipboard

Materializes this tensor view into a standalone tensor using the default strategy.

Materializes this tensor view using a specific materialization strategy.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.matmul(other: Tensor<T, V>): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.mean(dim: Int? = null): Tensor<T, V>
Link copied to clipboard
operator fun <T : DType, V> Number.minus(t: Tensor<T, V>): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.minus(v: Number): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.minus(other: Tensor<T, V>): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.narrow(dim: Int, start: Int, length: Int): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.pad2d(padLeft: Int, padRight: Int, padTop: Int, padBottom: Int): Tensor<T, V>
Link copied to clipboard
operator fun <T : DType, V> Number.plus(t: Tensor<T, V>): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.plus(v: Number): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.plus(other: Tensor<T, V>): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.pprint(): String
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.relu(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.reshape(newShape: Shape): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sigmoid(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sign(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.silu(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.slice(slices: List<Slice<T, V>>): TensorView<T, V>

Creates a tensor view using a direct list of slice descriptors.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sliceAt(vararg indices: Int): TensorView<T, V>

Convenience method for extracting specific indices across dimensions.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sliceCopy(builder: TensorSliceBuilder<T, V>.() -> Unit): Tensor<T, V>

Creates a new tensor by copying data from the sliced region of this tensor.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sliceRanges(vararg ranges: Pair<Int, Int>): TensorView<T, V>

Convenience method for creating simple range slices across all dimensions.

Link copied to clipboard
fun <T : DType, V> TensorView<T, V>.sliceView(builder: TensorSliceBuilder<T, V>.() -> Unit): TensorView<T, V>

Creates a view of an existing tensor view, enabling view chaining.

fun <T : DType, V> Tensor<T, V>.sliceView(builder: TensorSliceBuilder<T, V>.() -> Unit): TensorView<T, V>

Creates a zero-copy view of this tensor using the provided slicing DSL.

Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.softmax(dim: Int = -1): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sqrt(): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.squeeze(dim: Int? = null): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.sum(dim: Int? = null): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.t(): Tensor<T, V>
Link copied to clipboard
operator fun <T : DType, V> Number.times(t: Tensor<T, V>): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.times(v: Number): Tensor<T, V>
operator fun <T : DType, V> Tensor<T, V>.times(other: Tensor<T, V>): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.tril(k: Int = 0): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.unfold(dim: Int, size: Int, step: Int): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.unsqueeze(dim: Int): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.upsample2d(scale: Pair<Int, Int> = 2 to 2, mode: UpsampleMode = UpsampleMode.Nearest, alignCorners: Boolean = false): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.variance(dim: Int? = null): Tensor<T, V>
Link copied to clipboard
fun <T : DType, V> Tensor<T, V>.withRequiresGrad(flag: Boolean = true): Tensor<T, V>

Mark a tensor as requiring gradients and return it for chaining.

Link copied to clipboard
fun <T : DType, V> GradState<T, V>.zero()

Clear the stored gradient.