api / koma.ndarray / NDArray

NDArray

interface NDArray<T>

A general N-dimensional container for arbitrary types. For this container to be useful, you'll probably want to import koma.extensions.*, which includes e.g. element getter/setters which are non boxed for primitives.

If you are looking for a 2D container supporting linear algebra, please look at Matrix.

Properties

Name Summary
size open val size:Int

Functions

Name Summary
copy abstract fun copy():NDArray<T>
getBaseArray abstract fun getBaseArray():Any
getByte open fun getByte(vararg indices:Int):Byte
open fun getByte(i:Int):Byte
getDouble open fun getDouble(vararg indices:Int):Double
open fun getDouble(i:Int):Double
getFloat open fun getFloat(vararg indices:Int):Float
open fun getFloat(i:Int):Float
getGeneric open fun getGeneric(vararg indices:Int):T
abstract fun getGeneric(i:Int):T
getInt open fun getInt(vararg indices:Int):Int
open fun getInt(i:Int):Int
getLinear open fun ~~getLinear~~(index:Int):T
getLong open fun getLong(vararg indices:Int):Long
open fun getLong(i:Int):Long
getShort open fun getShort(vararg indices:Int):Short
open fun getShort(i:Int):Short
iterateIndices open fun iterateIndices():Iterable<IndexIterator>
setByte open fun setByte(vararg indices:Int, v:Byte):Unit
open fun setByte(i:Int, v:Byte):Unit
setDouble open fun setDouble(vararg indices:Int, v:Double):Unit
open fun setDouble(i:Int, v:Double):Unit
setFloat open fun setFloat(vararg indices:Int, v:Float):Unit
open fun setFloat(i:Int, v:Float):Unit
setGeneric open fun setGeneric(vararg indices:Int, v:T):Unit
abstract fun setGeneric(i:Int, v:T):Unit
setInt open fun setInt(vararg indices:Int, v:Int):Unit
open fun setInt(i:Int, v:Int):Unit
setLinear open fun ~~setLinear~~(index:Int, value:T):Unit
setLong open fun setLong(vararg indices:Int, v:Long):Unit
open fun setLong(i:Int, v:Long):Unit
setShort open fun setShort(vararg indices:Int, v:Short):Unit
open fun setShort(i:Int, v:Short):Unit
shape abstract fun shape():List<Int>
toIterable open fun toIterable():Iterable<T>
toList open fun toList():List<T>
Converts this NDArray into a one-dimensional List in row-major order.
toMutableList open fun toMutableList():MutableList<T>
Converts this NDArray into a one-dimensional MutableList in row-major order.

Companion Object Properties

Name Summary
byteFactory var byteFactory:NumericalNDArrayFactory<Byte>
doubleFactory var doubleFactory:NumericalNDArrayFactory<Double>
floatFactory var floatFactory:NumericalNDArrayFactory<Float>
intFactory var intFactory:NumericalNDArrayFactory<Int>
longFactory var longFactory:NumericalNDArrayFactory<Long>
shortFactory var shortFactory:NumericalNDArrayFactory<Short>

Companion Object Functions

Name Summary
createGeneric fun <T> createGeneric(vararg dims:Int, filler: (IntArray) ->T):DefaultGenericNDArray<T>
createGenericNulls fun <T> createGenericNulls(vararg dims:Int):DefaultGenericNDArray<T?>
invoke operator fun <T> invoke(vararg dims:Int, filler: (IntArray) ->T):NDArray<T>

Extension Functions

Name Summary
checkIndices fun <T>NDArray<T>.checkIndices(indices:IntArray):IntArray
checkLinearIndex fun <T>NDArray<T>.checkLinearIndex(index:Int):Int
div operator funNDArray<Byte>.div(other:Byte):NDArray<Byte>
operator funNDArray<Double>.div(other:Double):NDArray<Double>
operator funNDArray<Float>.div(other:Float):NDArray<Float>
operator funNDArray<Int>.div(other:Int):NDArray<Int>
operator funNDArray<Long>.div(other:Long):NDArray<Long>
operator funNDArray<Short>.div(other:Short):NDArray<Short>
fill funNDArray<Byte>.fill(f: (idx:IntArray) ->Byte):NDArray<Byte>
funNDArray<Double>.fill(f: (idx:IntArray) ->Double):NDArray<Double>
funNDArray<Float>.fill(f: (idx:IntArray) ->Float):NDArray<Float>
fun <T>NDArray<T>.fill(f: (idx:IntArray) ->T):NDArray<T>
funNDArray<Int>.fill(f: (idx:IntArray) ->Int):NDArray<Int>
funNDArray<Long>.fill(f: (idx:IntArray) ->Long):NDArray<Long>
funNDArray<Short>.fill(f: (idx:IntArray) ->Short):NDArray<Short>
fillBoth funNDArray<Byte>.fillBoth(f: (nd:IntArray, linear:Int) ->Byte):NDArray<Byte>
funNDArray<Double>.fillBoth(f: (nd:IntArray, linear:Int) ->Double):NDArray<Double>
funNDArray<Float>.fillBoth(f: (nd:IntArray, linear:Int) ->Float):NDArray<Float>
fun <T>NDArray<T>.fillBoth(f: (nd:IntArray, linear:Int) ->T):NDArray<T>
funNDArray<Int>.fillBoth(f: (nd:IntArray, linear:Int) ->Int):NDArray<Int>
funNDArray<Long>.fillBoth(f: (nd:IntArray, linear:Int) ->Long):NDArray<Long>
funNDArray<Short>.fillBoth(f: (nd:IntArray, linear:Int) ->Short):NDArray<Short>
fillLinear funNDArray<Byte>.fillLinear(f: (idx:Int) ->Byte):NDArray<Byte>
funNDArray<Double>.fillLinear(f: (idx:Int) ->Double):NDArray<Double>
funNDArray<Float>.fillLinear(f: (idx:Int) ->Float):NDArray<Float>
fun <T>NDArray<T>.fillLinear(f: (idx:Int) ->T):NDArray<T>
funNDArray<Int>.fillLinear(f: (idx:Int) ->Int):NDArray<Int>
funNDArray<Long>.fillLinear(f: (idx:Int) ->Long):NDArray<Long>
funNDArray<Short>.fillLinear(f: (idx:Int) ->Short):NDArray<Short>
forEach funNDArray<Byte>.forEach(f: (ele:Byte) ->Unit):Unit
funNDArray<Double>.forEach(f: (ele:Double) ->Unit):Unit
funNDArray<Float>.forEach(f: (ele:Float) ->Unit):Unit
fun <T>NDArray<T>.forEach(f: (ele:T) ->Unit):Unit
funNDArray<Int>.forEach(f: (ele:Int) ->Unit):Unit
funNDArray<Long>.forEach(f: (ele:Long) ->Unit):Unit
funNDArray<Short>.forEach(f: (ele:Short) ->Unit):Unit
Takes each element in a NDArray and passes them through f.
forEachIndexed funNDArray<Byte>.forEachIndexed(f: (idx:Int, ele:Byte) ->Unit):Unit
funNDArray<Double>.forEachIndexed(f: (idx:Int, ele:Double) ->Unit):Unit
funNDArray<Float>.forEachIndexed(f: (idx:Int, ele:Float) ->Unit):Unit
fun <T>NDArray<T>.forEachIndexed(f: (idx:Int, ele:T) ->Unit):Unit
funNDArray<Int>.forEachIndexed(f: (idx:Int, ele:Int) ->Unit):Unit
funNDArray<Long>.forEachIndexed(f: (idx:Int, ele:Long) ->Unit):Unit
funNDArray<Short>.forEachIndexed(f: (idx:Int, ele:Short) ->Unit):Unit
Takes each element in a NDArray and passes them through f. Index given to f is a linear index, depending on the underlying storage major dimension.
forEachIndexedN funNDArray<Byte>.forEachIndexedN(f: (idx:IntArray, ele:Byte) ->Unit):Unit
funNDArray<Double>.forEachIndexedN(f: (idx:IntArray, ele:Double) ->Unit):Unit
funNDArray<Float>.forEachIndexedN(f: (idx:IntArray, ele:Float) ->Unit):Unit
fun <T>NDArray<T>.forEachIndexedN(f: (idx:IntArray, ele:T) ->Unit):Unit
funNDArray<Int>.forEachIndexedN(f: (idx:IntArray, ele:Int) ->Unit):Unit
funNDArray<Long>.forEachIndexedN(f: (idx:IntArray, ele:Long) ->Unit):Unit
funNDArray<Short>.forEachIndexedN(f: (idx:IntArray, ele:Short) ->Unit):Unit
Takes each element in a NDArray and passes them through f. Index given to f is the full ND index of the element.
get operator funNDArray<Byte>.get(vararg indices:IntRange):NDArray<Byte>
operator funNDArray<Byte>.get(vararg indices:Int):Byte
operator funNDArray<Double>.get(vararg indices:IntRange):NDArray<Double>
operator funNDArray<Double>.get(vararg indices:Int):Double
operator funNDArray<Float>.get(vararg indices:IntRange):NDArray<Float>
operator funNDArray<Float>.get(vararg indices:Int):Float
operator fun <T>NDArray<T>.get(vararg indices:IntRange):NDArray<T>
operator fun <T>NDArray<T>.get(vararg indices:Int):T
operator funNDArray<Int>.get(vararg indices:IntRange):NDArray<Int>
operator funNDArray<Int>.get(vararg indices:Int):Int
operator funNDArray<Long>.get(vararg indices:IntRange):NDArray<Long>
operator funNDArray<Long>.get(vararg indices:Int):Long
operator funNDArray<Short>.get(vararg indices:IntRange):NDArray<Short>
operator funNDArray<Short>.get(vararg indices:Int):Short
linearToNIdx fun <T>NDArray<T>.linearToNIdx(linear:Int):IntArray
Given the 1D index of an element in the underlying storage, find the corresponding ND index. Inverse of nIdxToLinear.
map funNDArray<Byte>.map(f: (Byte) ->Byte):NDArray<Byte>
funNDArray<Double>.map(f: (Double) ->Double):NDArray<Double>
funNDArray<Float>.map(f: (Float) ->Float):NDArray<Float>
fun <T>NDArray<T>.map(f: (T) ->T):DefaultGenericNDArray<T>
funNDArray<Int>.map(f: (Int) ->Int):NDArray<Int>
funNDArray<Long>.map(f: (Long) ->Long):NDArray<Long>
funNDArray<Short>.map(f: (Short) ->Short):NDArray<Short>
Takes each element in a NDArray, passes them through f, and puts the output of f into an output NDArray.
mapIndexed funNDArray<Byte>.mapIndexed(f: (idx:Int, ele:Byte) ->Byte):NDArray<Byte>
funNDArray<Double>.mapIndexed(f: (idx:Int, ele:Double) ->Double):NDArray<Double>
funNDArray<Float>.mapIndexed(f: (idx:Int, ele:Float) ->Float):NDArray<Float>
fun <T>NDArray<T>.mapIndexed(f: (idx:Int, ele:T) ->T):DefaultGenericNDArray<T>
funNDArray<Int>.mapIndexed(f: (idx:Int, ele:Int) ->Int):NDArray<Int>
funNDArray<Long>.mapIndexed(f: (idx:Int, ele:Long) ->Long):NDArray<Long>
funNDArray<Short>.mapIndexed(f: (idx:Int, ele:Short) ->Short):NDArray<Short>
Takes each element in a NDArray, passes them through f, and puts the output of f into an output NDArray. Index given to f is a linear index, depending on the underlying storage major dimension.
mapIndexedN funNDArray<Byte>.mapIndexedN(f: (idx:IntArray, ele:Byte) ->Byte):NDArray<Byte>
funNDArray<Double>.mapIndexedN(f: (idx:IntArray, ele:Double) ->Double):NDArray<Double>
funNDArray<Float>.mapIndexedN(f: (idx:IntArray, ele:Float) ->Float):NDArray<Float>
fun <T>NDArray<T>.mapIndexedN(f: (idx:IntArray, ele:T) ->T):NDArray<T>
funNDArray<Int>.mapIndexedN(f: (idx:IntArray, ele:Int) ->Int):NDArray<Int>
funNDArray<Long>.mapIndexedN(f: (idx:IntArray, ele:Long) ->Long):NDArray<Long>
funNDArray<Short>.mapIndexedN(f: (idx:IntArray, ele:Short) ->Short):NDArray<Short>
Takes each element in a NDArray, passes them through f, and puts the output of f into an output NDArray. Index given to f is the full ND index of the element.
minus operator funNDArray<Byte>.minus(other:Byte):NDArray<Byte>
operator funNDArray<Byte>.minus(other:NDArray<Byte>):NDArray<Byte>
operator funNDArray<Double>.minus(other:Double):NDArray<Double>
operator funNDArray<Double>.minus(other:NDArray<Double>):NDArray<Double>
operator funNDArray<Float>.minus(other:Float):NDArray<Float>
operator funNDArray<Float>.minus(other:NDArray<Float>):NDArray<Float>
operator funNDArray<Int>.minus(other:Int):NDArray<Int>
operator funNDArray<Int>.minus(other:NDArray<Int>):NDArray<Int>
operator funNDArray<Long>.minus(other:Long):NDArray<Long>
operator funNDArray<Long>.minus(other:NDArray<Long>):NDArray<Long>
operator funNDArray<Short>.minus(other:Short):NDArray<Short>
operator funNDArray<Short>.minus(other:NDArray<Short>):NDArray<Short>
nIdxToLinear fun <T>NDArray<T>.nIdxToLinear(indices:IntArray):Int
Given a ND index into this array, find the corresponding 1D index in the raw underlying 1D storage array.
plus operator funNDArray<Byte>.plus(other:Byte):NDArray<Byte>
operator funNDArray<Byte>.plus(other:NDArray<Byte>):NDArray<Byte>
operator funNDArray<Double>.plus(other:Double):NDArray<Double>
operator funNDArray<Double>.plus(other:NDArray<Double>):NDArray<Double>
operator funNDArray<Float>.plus(other:Float):NDArray<Float>
operator funNDArray<Float>.plus(other:NDArray<Float>):NDArray<Float>
operator funNDArray<Int>.plus(other:Int):NDArray<Int>
operator funNDArray<Int>.plus(other:NDArray<Int>):NDArray<Int>
operator funNDArray<Long>.plus(other:Long):NDArray<Long>
operator funNDArray<Long>.plus(other:NDArray<Long>):NDArray<Long>
operator funNDArray<Short>.plus(other:Short):NDArray<Short>
operator funNDArray<Short>.plus(other:NDArray<Short>):NDArray<Short>
pow infix funNDArray<Byte>.pow(exponent:Int):NDArray<Byte>
infix funNDArray<Double>.pow(exponent:Int):NDArray<Double>
infix funNDArray<Float>.pow(exponent:Int):NDArray<Float>
infix funNDArray<Int>.pow(exponent:Int):NDArray<Int>
infix funNDArray<Long>.pow(exponent:Int):NDArray<Long>
infix funNDArray<Short>.pow(exponent:Int):NDArray<Short>
reshape funNDArray<Double>.reshape(rows:Int, cols:Int):Matrix<Double>
funNDArray<Float>.reshape(rows:Int, cols:Int):Matrix<Float>
funNDArray<Int>.reshape(rows:Int, cols:Int):Matrix<Int>
Returns a new Matrix with the given shape, populated with the data in this array.funNDArray<Byte>.reshape(vararg dims:Int):NDArray<Byte>
funNDArray<Double>.reshape(vararg dims:Int):NDArray<Double>
funNDArray<Float>.reshape(vararg dims:Int):NDArray<Float>
fun <T>NDArray<T>.reshape(vararg dims:Int):NDArray<T>
funNDArray<Int>.reshape(vararg dims:Int):NDArray<Int>
funNDArray<Long>.reshape(vararg dims:Int):NDArray<Long>
funNDArray<Short>.reshape(vararg dims:Int):NDArray<Short>
Returns a new NDArray with the given shape, populated with the data in this array.
safeNIdxToLinear fun <T>NDArray<T>.safeNIdxToLinear(indices:IntArray):Int
set operator funNDArray<Byte>.set(vararg indices:Int, value:NDArray<Byte>):Unit
operator funNDArray<Byte>.set(vararg indices:Int, value:Byte):Unit
operator funNDArray<Double>.set(vararg indices:Int, value:NDArray<Double>):Unit
operator funNDArray<Double>.set(vararg indices:Int, value:Double):Unit
operator funNDArray<Float>.set(vararg indices:Int, value:NDArray<Float>):Unit
operator funNDArray<Float>.set(vararg indices:Int, value:Float):Unit
operator fun <T>NDArray<T>.set(vararg indices:Int, value:NDArray<T>):Unit
operator fun <T>NDArray<T>.set(vararg indices:Int, value:T):Unit
operator funNDArray<Int>.set(vararg indices:Int, value:NDArray<Int>):Unit
operator funNDArray<Int>.set(vararg indices:Int, value:Int):Unit
operator funNDArray<Long>.set(vararg indices:Int, value:NDArray<Long>):Unit
operator funNDArray<Long>.set(vararg indices:Int, value:Long):Unit
operator funNDArray<Short>.set(vararg indices:Int, value:NDArray<Short>):Unit
operator funNDArray<Short>.set(vararg indices:Int, value:Short):Unit
times operator funNDArray<Byte>.times(other:NDArray<Byte>):NDArray<Byte>
operator funNDArray<Byte>.times(other:Byte):NDArray<Byte>
operator funNDArray<Double>.times(other:NDArray<Double>):NDArray<Double>
operator funNDArray<Double>.times(other:Double):NDArray<Double>
operator funNDArray<Float>.times(other:NDArray<Float>):NDArray<Float>
operator funNDArray<Float>.times(other:Float):NDArray<Float>
operator funNDArray<Int>.times(other:NDArray<Int>):NDArray<Int>
operator funNDArray<Int>.times(other:Int):NDArray<Int>
operator funNDArray<Long>.times(other:NDArray<Long>):NDArray<Long>
operator funNDArray<Long>.times(other:Long):NDArray<Long>
operator funNDArray<Short>.times(other:NDArray<Short>):NDArray<Short>
operator funNDArray<Short>.times(other:Short):NDArray<Short>
toByteArray funNDArray<Byte>.toByteArray():ByteArray
Converts this NDArray into a one-dimensional ByteArray in row-major order.
toDoubleArray funNDArray<Double>.toDoubleArray():DoubleArray
Converts this NDArray into a one-dimensional DoubleArray in row-major order.
toFloatArray funNDArray<Float>.toFloatArray():FloatArray
Converts this NDArray into a one-dimensional FloatArray in row-major order.
toIntArray funNDArray<Int>.toIntArray():IntArray
Converts this NDArray into a one-dimensional IntArray in row-major order.
toLongArray funNDArray<Long>.toLongArray():LongArray
Converts this NDArray into a one-dimensional LongArray in row-major order.
toMatrix funNDArray<Double>.toMatrix():Matrix<Double>
funNDArray<Float>.toMatrix():Matrix<Float>
funNDArray<Int>.toMatrix():Matrix<Int>
toMatrixOrNull fun <T>NDArray<T>.toMatrixOrNull():Matrix<T>?
toShortArray funNDArray<Short>.toShortArray():ShortArray
Converts this NDArray into a one-dimensional ShortArray in row-major order.
toTypedArray fun <T>NDArray<T>.toTypedArray():Array<T>
Converts this NDArray into a one-dimensional Array in row-major order.
unaryMinus operator funNDArray<Byte>.unaryMinus():NDArray<Byte>
operator funNDArray<Double>.unaryMinus():NDArray<Double>
operator funNDArray<Float>.unaryMinus():NDArray<Float>
operator funNDArray<Int>.unaryMinus():NDArray<Int>
operator funNDArray<Long>.unaryMinus():NDArray<Long>
operator funNDArray<Short>.unaryMinus():NDArray<Short>
widthOfDims fun <T>NDArray<T>.widthOfDims():ArrayList<Int>

Inheritors

Name Summary
DefaultByteNDArray open class DefaultByteNDArray :NDArray<Byte>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultDoubleNDArray open class DefaultDoubleNDArray :NDArray<Double>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultFloatNDArray open class DefaultFloatNDArray :NDArray<Float>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultGenericNDArray open class DefaultGenericNDArray<T> :NDArray<T>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultIntNDArray open class DefaultIntNDArray :NDArray<Int>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultLongNDArray open class DefaultLongNDArray :NDArray<Long>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
DefaultShortNDArray open class DefaultShortNDArray :NDArray<Short>
An (unoptimized) implementation of NDArray in pure Kotlin, for portability between the different platforms koma supports.
Matrix interface Matrix<T> :NDArray<T>
A general facade for a Matrix type. Allows for various backend to be implemented to actually perform the computation. A koma backend must both implement this class and MatrixFactory. A matrix is guaranteed to be 2D and to have a numerical type. For storage of arbitrary types and dimensions, see koma.ndarray.NDArray.
NumericalNDArray interface ~~NumericalNDArray~~<T> :NDArray<T>
An NDArray that holds a numerical type, such that math operations are available.