Ejemplo n.º 1
0
/** Deallocate a matrix.
 *
 * \ingroup allocate_group_C
 *
 * \param A The matrix.
 */
void
bml_deallocate(
    bml_matrix_t ** A)
{
    if (A == NULL)
    {
        LOG_DEBUG("A is NULL\n");
    }
    else if (*A == NULL)
    {
        LOG_DEBUG("*A is NULL\n");
    }
    else
    {
        switch (bml_get_type(*A))
        {
            case dense:
                bml_deallocate_dense(*A);
                break;
            case ellpack:
                bml_deallocate_ellpack(*A);
                break;
            default:
                LOG_ERROR("unknown matrix type (%d)\n", bml_get_type(*A));
                break;
        }
        *A = NULL;
    }
}
Ejemplo n.º 2
0
/** Matrix multiply.
 *
 * \f$ C \leftarrow \alpha A \, B + \beta C \f$
 *
 * \ingroup multiply_group
 *
 * \param A Matrix A
 * \param B Matrix B
 * \param C Matrix C
 * \param alpha Scalar factor multiplied by A * B
 * \param beta Scalar factor multiplied by C
 * \param threshold Used for sparse multiply
 */
void TYPED_FUNC(
    bml_multiply_ellpack) (
    const bml_matrix_ellpack_t * A,
    const bml_matrix_ellpack_t * B,
    bml_matrix_ellpack_t * C,
    const double alpha,
    const double beta,
    const double threshold)
{
    const double ONE = 1.0;
    const double ZERO = 0.0;

    if (A != NULL && A == B && alpha == ONE && beta == ZERO)
    {
        TYPED_FUNC(bml_multiply_x2_ellpack) (A, C, threshold);
    }
    else
    {
        bml_matrix_ellpack_t *A2 =
            TYPED_FUNC(bml_zero_matrix_ellpack) (C->N, C->M);

        if (A != NULL && A == B)
        {
            TYPED_FUNC(bml_multiply_x2_ellpack) (A, A2, threshold);
        }
        else
        {
            TYPED_FUNC(bml_multiply_AB_ellpack) (A, B, A2, threshold);
        }

        TYPED_FUNC(bml_add_ellpack) (C, A2, beta, alpha, threshold);

        bml_deallocate_ellpack(A2);
    }
}
Ejemplo n.º 3
0
/** Matrix addition.
 *
 *  A = A + beta * I
 *
 *  \ingroup add_group
 *
 *  \param A Matrix A
 *  \param beta Scalar factor multiplied by A
 *  \param threshold Threshold for matrix addition
 */
void TYPED_FUNC(
    bml_add_identity_ellpack) (
    const bml_matrix_ellpack_t * A,
    const double beta,
    const double threshold)
{
    REAL_T alpha = (REAL_T) 1.0;

    bml_matrix_ellpack_t *Id =
        TYPED_FUNC(bml_identity_matrix_ellpack) (A->N, A->M);

    TYPED_FUNC(bml_add_ellpack) (A, Id, alpha, beta, threshold);

    bml_deallocate_ellpack(Id);
}