Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mllib/src/main/scala/org/apache/spark/ml/ann/BreezeUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,40 @@ import breeze.linalg.{DenseMatrix => BDM, DenseVector => BDV}
import com.github.fommil.netlib.BLAS.{getInstance => NativeBLAS}

/**
* In-place DGEMM and DGEMV for Breeze
* In-place DGEMM and DGEMV for Breeze.
*/
private[ann] object BreezeUtil {

// TODO: switch to MLlib BLAS interface
private def transposeString(a: BDM[Double]): String = if (a.isTranspose) "T" else "N"

/**
* DGEMM: C := alpha * A * B + beta * C
* DGEMM: C := alpha * A * B + beta * C.
* @param alpha alpha
* @param a A
* @param b B
* @param beta beta
* @param c C
*/
def dgemm(alpha: Double, a: BDM[Double], b: BDM[Double], beta: Double, c: BDM[Double]): Unit = {
// TODO: add code if matrices isTranspose!!!
require(a.cols == b.rows, "A & B Dimension mismatch!")
require(a.rows == c.rows, "A & C Dimension mismatch!")
require(b.cols == c.cols, "A & C Dimension mismatch!")
require(b.cols == c.cols, "B & C Dimension mismatch!")
NativeBLAS.dgemm(transposeString(a), transposeString(b), c.rows, c.cols, a.cols,
alpha, a.data, a.offset, a.majorStride, b.data, b.offset, b.majorStride,
beta, c.data, c.offset, c.rows)
}

/**
* DGEMV: y := alpha * A * x + beta * y
* DGEMV: y := alpha * A * x + beta * y.
* @param alpha alpha
* @param a A
* @param x x
* @param beta beta
* @param y y
*/
def dgemv(alpha: Double, a: BDM[Double], x: BDV[Double], beta: Double, y: BDV[Double]): Unit = {
require(a.cols == x.length, "A & b Dimension mismatch!")
require(a.cols == x.length, "A & x Dimension mismatch!")
NativeBLAS.dgemv(transposeString(a), a.rows, a.cols,
alpha, a.data, a.offset, a.majorStride, x.data, x.offset, x.stride,
beta, y.data, y.offset, y.stride)
Expand Down
Loading