xuyang1706 commented on a change in pull request #9732: [FLINK-14153][ml] Add
to BLAS a method that performs DenseMatrix and SparseVector multiplication.
URL: https://github.com/apache/flink/pull/9732#discussion_r336986571
##########
File path:
flink-ml-parent/flink-ml-lib/src/main/java/org/apache/flink/ml/common/linalg/BLAS.java
##########
@@ -131,19 +168,56 @@ public static void gemm(double alpha, DenseMatrix matA,
boolean transA, DenseMat
}
/**
- * y := alpha * A * x + beta * y .
+ * Check the compatibility of matrix and vector sizes in
<code>gemv</code>.
*/
- public static void gemv(double alpha, DenseMatrix matA, boolean transA,
- DenseVector x, double
beta, DenseVector y) {
+ private static void gemvDimensionCheck(DenseMatrix matA, boolean
transA, Vector x, Vector y) {
if (transA) {
- assert (matA.numCols() == y.size() && matA.numRows() ==
x.size()) : "Matrix and vector size mismatched.";
+ Preconditions.checkArgument(matA.numCols() == y.size()
&& matA.numRows() == x.size(),
+ "Matrix and vector size mismatched.");
} else {
- assert (matA.numRows() == y.size() && matA.numCols() ==
x.size()) : "Matrix and vector size mismatched.";
+ Preconditions.checkArgument(matA.numRows() == y.size()
&& matA.numCols() == x.size(),
+ "Matrix and vector size mismatched.");
}
+ }
+
+ /**
+ * y := alpha * A * x + beta * y .
+ */
+ public static void gemv(double alpha, DenseMatrix matA, boolean transA,
+ DenseVector x, double
beta, DenseVector y) {
+ gemvDimensionCheck(matA, transA, x, y);
final int m = matA.numRows();
final int n = matA.numCols();
final int lda = matA.numRows();
final String ta = transA ? "T" : "N";
NATIVE_BLAS.dgemv(ta, m, n, alpha, matA.getData(), lda,
x.getData(), 1, beta, y.getData(), 1);
Review comment:
We consistently use F2J_BLAS for level-1 routines such as scal/axpy/asum,
and use NATIVE_BLAS for level-2/level-3 routines such as gemv, gemm. As for the
gemv case here, we use NATIVE_BLAS for the dense case. But for the sparse case,
the BLAS library is not directly applicable because it is a library for dense
linear algebra. So we implement gemv for SparseVector by hand, using F2J_BLAS
to do axpy(level-1 routine) during the course.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services