1 //------------------------------------------------------------------------------
2 // SLIP_LU/slip_matrix_mul: multiplies a matrix by a scalar
3 //------------------------------------------------------------------------------
4
5 // SLIP_LU: (c) 2019-2020, Chris Lourenco, Jinhao Chen, Erick Moreno-Centeno,
6 // Timothy A. Davis, Texas A&M University. All Rights Reserved. See
7 // SLIP_LU/License for the license.
8
9 //------------------------------------------------------------------------------
10
11 /* Purpose: This function multiplies the matrix x (CSC, triplet, or dense) by a
12 * scalar. This function requires x to have type mpz_t.
13 *
14 * On output the values of x are modified.
15 */
16
17 #include "slip_internal.h"
18
slip_matrix_mul(SLIP_matrix * x,const mpz_t scalar)19 SLIP_info slip_matrix_mul // multiplies x by a scalar
20 (
21 SLIP_matrix *x, // matrix to be multiplied
22 const mpz_t scalar // scalar to multiply by
23 )
24 {
25
26 //--------------------------------------------------------------------------
27 // check inputs
28 //--------------------------------------------------------------------------
29
30 SLIP_info info ;
31 SLIP_REQUIRE_TYPE (x, SLIP_MPZ) ;
32
33 //--------------------------------------------------------------------------
34 // x = x * scalar
35 //--------------------------------------------------------------------------
36
37 int64_t nz = SLIP_matrix_nnz (x, NULL) ;
38 for (int64_t i = 0; i < nz; i++)
39 {
40 // x[i] = x[i]*scalar
41 SLIP_CHECK( SLIP_mpz_mul( x->x.mpz[i], x->x.mpz[i], scalar));
42 }
43
44 return (SLIP_OK) ;
45 }
46
47