本文整理汇总了C++中el::Matrix::LockedBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::LockedBuffer方法的具体用法?C++ Matrix::LockedBuffer怎么用?C++ Matrix::LockedBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类el::Matrix
的用法示例。
在下文中一共展示了Matrix::LockedBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: L1DistanceMatrix
void L1DistanceMatrix(direction_t dirA, direction_t dirB, T alpha,
const El::Matrix<T> &A, const El::Matrix<T> &B,
T beta, El::Matrix<T> &C) {
// TODO verify sizes
const T *a = A.LockedBuffer();
El::Int ldA = A.LDim();
const T *b = B.LockedBuffer();
El::Int ldB = B.LDim();
T *c = C.Buffer();
El::Int ldC = C.LDim();
El::Int d = A.Height();
/* Not the most efficient way... but mimicking BLAS is too much work! */
if (dirA == base::COLUMNS && dirB == base::COLUMNS) {
for (El::Int j = 0; j < B.Width(); j++)
for (El::Int i = 0; i < A.Width(); i++) {
T v = 0.0;
for (El::Int k = 0; k < d; k++)
v += std::abs(b[j * ldB + k] - a[i * ldA + k]);
c[j * ldC + i] = beta * c[j * ldC + i] + alpha * v;
}
}
// TODO the rest of the cases.
}
示例2: SymmetricL1DistanceMatrix
void SymmetricL1DistanceMatrix(El::UpperOrLower uplo, direction_t dir, T alpha,
const El::Matrix<T> &A, T beta, El::Matrix<T> &C) {
const T *a = A.LockedBuffer();
El::Int ldA = A.LDim();
T *c = C.Buffer();
El::Int ldC = C.LDim();
El::Int n = A.Width();
El::Int d = A.Height();
/* Not the most efficient way... but mimicking BLAS is too much work! */
if (dir == base::COLUMNS) {
for (El::Int j = 0; j < n; j++)
for(El::Int i = ((uplo == El::UPPER) ? 0 : j);
i < ((uplo == El::UPPER) ? (j + 1) : n); i++)
for (El::Int i = 0; i < A.Width(); i++) {
T v = 0.0;
for (El::Int k = 0; k < d; k++)
v += std::abs(a[j * ldA + k] - a[i * ldA + k]);
c[j * ldC + i] = beta * c[j * ldC + i] + alpha * v;
}
}
// TODO the rest of the cases.
}
示例3: Gemv
inline void Gemv(El::Orientation oA,
T alpha, const sparse_matrix_t<T>& A, const El::Matrix<T>& x,
T beta, El::Matrix<T>& y) {
// TODO verify sizes etc.
const int* indptr = A.indptr();
const int* indices = A.indices();
const double *values = A.locked_values();
double *yd = y.Buffer();
const double *xd = x.LockedBuffer();
int n = A.width();
if (oA == El::NORMAL) {
El::Scale(beta, y);
# if SKYLARK_HAVE_OPENMP
# pragma omp parallel for
# endif
for(int col = 0; col < n; col++) {
T xv = alpha * xd[col];
for (int j = indptr[col]; j < indptr[col + 1]; j++) {
int row = indices[j];
T val = values[j];
yd[row] += val * xv;
}
}
} else {
# if SKYLARK_HAVE_OPENMP
# pragma omp parallel for
# endif
for(int col = 0; col < n; col++) {
double yv = beta * yd[col];
for (int j = indptr[col]; j < indptr[col + 1]; j++) {
int row = indices[j];
T val = values[j];
yv += alpha * val * xd[row];
}
yd[col] = yv;
}
}
}