除了 Daniel Sobrado 的良好响应之外,Spark 2.4 还附带 Breeze 支持 Breeze Linear Algebra
这个库的好处是矩阵默认为列主要排序,如 Matlab,但索引是从 0 开始的,如 Numpy。
Breeze 支持索引和切片、线性代数函数
(Linear solve, transpose, Determinant, Inverse, Eigenvalues , Eigenvectors, Singular Value Decomposition) 和运营(Vector dot product, Elementwise addition, Shaped/Matrix multiplication, Elementwise multiplication, Elementwise max, Elementwise argmax), etc.
值得注意的是,Breeze 使用 netlib-java 作为其核心线性代数例程
下面是一个使用 Breeze 的 scala 代码示例
import breeze.linalg.DenseVector
import com.github.fommil.netlib.BLAS
import org.slf4j.LoggerFactory
object Breeze1 {
def main(args:Array[String]): Unit = {
println("Init logging...")
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
val log = LoggerFactory.getLogger("main")
log.trace("Starting...")
val b = BLAS.getInstance()
log.trace(s"BLAS = $b")
val v = DenseVector(1,2,3,4)
log.trace("Ending.")
}
}