All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.space.kscience.kmath.linear.LinearAlgebra.kt Maven / Gradle / Ivy

package space.kscience.kmath.linear

import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.VirtualBuffer

public typealias Point = Buffer

/**
 * A group of methods to resolve equation A dot X = B, where A and B are matrices or vectors
 */
public interface LinearSolver {
    public fun solve(a: Matrix, b: Matrix): Matrix
    public fun solve(a: Matrix, b: Point): Point = solve(a, b.asMatrix()).asPoint()
    public fun inverse(a: Matrix): Matrix
}

/**
 * Convert matrix to vector if it is possible
 */
public fun  Matrix.asPoint(): Point =
    if (this.colNum == 1)
        VirtualBuffer(rowNum) { get(it, 0) }
    else
        error("Can't convert matrix with more than one column to vector")

public fun  Point.asMatrix(): VirtualMatrix = VirtualMatrix(size, 1) { i, _ -> get(i) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy