Module: Numo::GSL::SpBlas
- Defined in:
- ext/numo/gsl/spmatrix/gsl_spmatrix.c
Constant Summary
- NOTRANS =
INT2FIX(CblasNoTrans)
- TRANS =
INT2FIX(CblasTrans)
Class Method Summary collapse
-
.dgemm(alpha, a, b) ⇒ Numo::DFloat
This function computes the sparse matrix-matrix product C = \alpha A B.
-
.dgemv(trans_a, alpha, a, x, beta, y) ⇒ Numo::DFloat
This function computes the matrix-vector product and sum y \leftarrow \alpha op(A) x + \beta y, where op(A) = A, A^T for TransA = CblasNoTrans, CblasTrans.
Class Method Details
.dgemm(alpha, a, b) ⇒ Numo::DFloat
This function computes the sparse matrix-matrix product C = \alpha A B. The matrices must be in compressed format.
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
# File 'ext/numo/gsl/spmatrix/gsl_spmatrix.c', line 656
static VALUE
spblas_s_dgemm(VALUE mod, VALUE valpha, VALUE va, VALUE vb)
{
// C = A B
double alpha;
gsl_spmatrix *A;
gsl_spmatrix *B;
gsl_spmatrix *C;
VALUE vc;
alpha = NUM2DBL(valpha);
TypedData_Get_Struct(va, gsl_spmatrix, &spmatrix_data_type, A);
TypedData_Get_Struct(vb, gsl_spmatrix, &spmatrix_data_type, B);
C = gsl_spmatrix_alloc_nzmax(A->size1,B->size2,A->nzmax+B->nzmax,A->sptype);
vc = TypedData_Wrap_Struct(cSpMatrix, &spmatrix_data_type, C);
gsl_spblas_dgemm(alpha, A, B, C);
RB_GC_GUARD(va);
RB_GC_GUARD(vb);
return vc;
}
|
.dgemv(trans_a, alpha, a, x, beta, y) ⇒ Numo::DFloat
This function computes the matrix-vector product and sum y \leftarrow \alpha op(A) x + \beta y, where op(A) = A, A^T for TransA = CblasNoTrans, CblasTrans. In-place computations are not supported, so x and y must be distinct vectors. The matrix A may be in triplet or compressed format.
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'ext/numo/gsl/spmatrix/gsl_spmatrix.c', line 614
static VALUE
spblas_s_dgemv(VALUE mod, VALUE vTransA, VALUE valpha, VALUE va, VALUE vx, VALUE vbeta, VALUE vy)
{
// y = alpha A x + beta y
CBLAS_TRANSPOSE_t TransA;
double alpha;
gsl_spmatrix *A;
gsl_vector *x;
double beta;
gsl_vector *y;
TransA = NUM2INT(vTransA);
alpha = NUM2DBL(valpha);
beta = NUM2DBL(vbeta);
TypedData_Get_Struct(va, gsl_spmatrix, &spmatrix_data_type, A);
vx = cast_1d_contiguous(vx, cDF);
ALLOCA_GSL_VECTOR_FROM_NARRAY_R(vx, x);
vy = cast_1d_contiguous(vy, cDF);
if (!TEST_INPLACE(vy)) {
vy = na_copy(vy);
}
ALLOCA_GSL_VECTOR_FROM_NARRAY_RW(vy, y);
gsl_spblas_dgemv(TransA, alpha, A, x, beta, y);
RB_GC_GUARD(vx);
return vy;
}
|