Vector

class Vector<N : Nat> : Matrix<N, N1> (source)

A dimensionally type-safe column vector of doubles.

The dimension N is encoded at the type level using Nat types, allowing the compiler to catch dimension mismatches at compile time.

Example:

val a: SizedVector<N3> = SizedVector.of(N3, 1.0, 2.0, 3.0)
val b: SizedVector<N3> = SizedVector.of(N3, 4.0, 5.0, 6.0)
val c: SizedVector<N3> = a + b // Compiles!
val dot: Double = a dot b
// val d: SizedVector<N2> = a + SizedVector.zero(N2) // Won't compile - dimensions don't match

Type Parameters

N

The dimension type

Constructors

Link copied to clipboard
constructor(matrix: Matrix<N, N1>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The dimension (length) of this vector.

Link copied to clipboard
@get:JvmName(name = "inverse")
val inverse: Matrix<N, N1>

The inverse of this matrix. Only valid for square matrices.

Link copied to clipboard
@get:JvmName(name = "magnitude")
val magnitude: Double

Returns the Euclidean norm (magnitude) of this vector.

Link copied to clipboard

Natural number representing the number of columns.

Link copied to clipboard
val natRows: N

Natural number representing the number of rows.

Link copied to clipboard
@get:JvmName(name = "norm")
val norm: Double

The Frobenius norm of this matrix.

Link copied to clipboard

The number of columns in the matrix.

Link copied to clipboard

The number of rows in the matrix.

Link copied to clipboard
@get:JvmName(name = "pseudoInverse")
val pseudoInverse: Matrix<N1, N>

The pseudo-inverse of this matrix.

Link copied to clipboard

The size of the matrix as (rows, columns).

Link copied to clipboard
@get:JvmName(name = "transpose")
val transpose: Matrix<N1, N>

The transpose of this matrix, with swapped dimension types.

Functions

Link copied to clipboard
open override fun copy(): Vector<N>

Returns a copy of this vector.

Link copied to clipboard
open operator fun div(scalar: Double): Matrix<N, N1>
open operator fun div(scalar: Number): Matrix<N, N1>

Divides this matrix by a scalar.

Link copied to clipboard
infix fun dot(other: Vector<N>): Double

Computes the dot product of this vector with another vector of the same dimension.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun <N : Nat> Matrix<N, N>.exp(): Matrix<N, N>

Computes the matrix exponential of this matrix, using the Padé approximant.

Link copied to clipboard
operator fun get(i: Int, j: Int): Double

Returns the element at the given indices.

operator fun get(i: Int): Double

Returns the element at the given index.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun minus(other: Matrix<N, N1>): Matrix<N, N1>

Subtracts another matrix with the same dimensions.

operator fun minus(other: Vector<N>): Vector<N>

Subtracts another vector with the same dimension.

Link copied to clipboard

Returns a normalized (unit) vector in the same direction.

Link copied to clipboard
operator fun plus(other: Matrix<N, N1>): Matrix<N, N1>

Adds another matrix with the same dimensions.

operator fun plus(other: Vector<N>): Vector<N>

Adds another vector with the same dimension.

Link copied to clipboard
operator fun set(i: Int, j: Int, value: Double)

Sets the element at the given indices.

operator fun set(i: Int, value: Double)

Sets the element at the given index.

Link copied to clipboard
fun <K : Nat> solve(other: Matrix<N, K>): Matrix<N1, K>

Solves for X in the equation AX = B, where A is this matrix and B is other.

Link copied to clipboard
operator fun <K : Nat> times(other: Matrix<N1, K>): Matrix<N, K>

Multiplies this matrix by another matrix. The inner dimensions must match: (R x C) * (C x K) = (R x K)

operator fun times(other: Vector<N1>): Vector<N>

Multiplies this matrix by a vector. The vector's length must be equal to C.

open operator override fun times(scalar: Double): Vector<N>
open operator override fun times(scalar: Number): Vector<N>

Multiplies this vector by a scalar.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open operator override fun unaryMinus(): Vector<N>

Negates all elements of this vector.