提交 3ff683f9 编写于 作者: W wangmeng28

Merge branch 'add_rowScale_for_CpuSparseMatrix' into factorization_machine_layer

...@@ -260,6 +260,23 @@ void CpuSparseMatrix::printOneRow(std::ostream& os, size_t idx) const { ...@@ -260,6 +260,23 @@ void CpuSparseMatrix::printOneRow(std::ostream& os, size_t idx) const {
os << ";"; os << ";";
} }
void CpuSparseMatrix::rowScale(size_t cCol, CpuSparseMatrix& b, Matrix& c) {
CHECK(getFormat() != SPARSE_CSC) << "Not supported";
CHECK(height_ == b.getHeight());
CHECK(width_ == b.getWidth());
real* A = getValue();
real* B = b.getValue();
for (size_t i = 0; i < height_; i++) {
size_t start = getRowStartIdx(i);
size_t end = getRowStartIdx(i + 1);
CHECK(start == b.getRowStartIdx(i));
CHECK(end == b.getRowStartIdx(i + 1));
for (size_t j = start; j < end; j++) {
A[j] = B[j] * c.getElement(i, cCol);
}
}
}
void CpuSparseMatrix::randomizeUniform() { void CpuSparseMatrix::randomizeUniform() {
CHECK_LE(elementCnt_, height_ * width_); CHECK_LE(elementCnt_, height_ * width_);
if (valueType_ == FLOAT_VALUE) { if (valueType_ == FLOAT_VALUE) {
......
...@@ -236,6 +236,15 @@ public: ...@@ -236,6 +236,15 @@ public:
const unsigned int* cols, const unsigned int* cols,
const real* values); const real* values);
/**
* @brief this_row = b_row * c_row[cCol]
*
* @param[in] cCol the column of matrix c used to scale each row of b
* @param[in] b CpuSparseMatrix
* @param[in] c Matrix
*/
void rowScale(size_t cCol, CpuSparseMatrix& b, Matrix& c);
void randomizeUniform(); void randomizeUniform();
void copyFrom(const GpuSparseMatrix& src, hl_stream_t stream); void copyFrom(const GpuSparseMatrix& src, hl_stream_t stream);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册