Skip to content

Commit

Permalink
Add complex scale factors
Browse files Browse the repository at this point in the history
This change change the `bml_scale*` APIs so that the scale factor is
matrix type dependent. This means that a complex matrix type will
require a complex scaling factor.

Fixes: #75
  • Loading branch information
nicolasbock committed Jul 24, 2017
1 parent 2dabc00 commit b93a366
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 177 deletions.
6 changes: 3 additions & 3 deletions src/C-interface/bml_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
bml_matrix_t *
bml_scale_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A)
{
bml_matrix_t *B = NULL;
Expand Down Expand Up @@ -50,7 +50,7 @@ bml_scale_new(
*/
void
bml_scale(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A,
bml_matrix_t * B)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ bml_scale(
*/
void
bml_scale_inplace(
const double scale_factor,
const void *scale_factor,
bml_matrix_t * A)
{
switch (bml_get_type(A))
Expand Down
8 changes: 3 additions & 5 deletions src/C-interface/bml_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@

#include "bml_types.h"

// Scales A and returns a new B
bml_matrix_t *bml_scale_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A);

// Scales A and returns in existing B
void bml_scale(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A,
bml_matrix_t * B);

void bml_scale_inplace(
const double scale_factor,
const void *scale_factor,
bml_matrix_t * A);

#endif
4 changes: 3 additions & 1 deletion src/C-interface/dense/bml_add_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void TYPED_FUNC(
const double alpha,
const double beta)
{
bml_scale_inplace_dense(alpha, A);
REAL_T _alpha = (REAL_T) alpha;

bml_scale_inplace_dense(&_alpha, A);
bml_add_identity_dense(A, beta);
}
6 changes: 3 additions & 3 deletions src/C-interface/dense/bml_scale_dense.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
bml_matrix_dense_t *
bml_scale_dense_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A)
{
bml_matrix_dense_t *B = NULL;
Expand Down Expand Up @@ -57,7 +57,7 @@ bml_scale_dense_new(
*/
void
bml_scale_dense(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B)
{
Expand Down Expand Up @@ -85,7 +85,7 @@ bml_scale_dense(

void
bml_scale_inplace_dense(
const double scale_factor,
const void *scale_factor,
bml_matrix_dense_t * A)
{
switch (A->matrix_precision)
Expand Down
32 changes: 17 additions & 15 deletions src/C-interface/dense/bml_scale_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,71 @@

#include "bml_types_dense.h"

#include <complex.h>

bml_matrix_dense_t *bml_scale_dense_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_single_complex(
const double scale_factor,
const float complex * scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_double_complex(
const double scale_factor,
const double complex * scale_factor,
const bml_matrix_dense_t * A);

void bml_scale_dense(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_single_complex(
const double scale_factor,
const float complex * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_double_complex(
const double scale_factor,
const double complex * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_inplace_dense(
const double scale_factor,
const void *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_single_real(
const double scale_factor,
const float *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_double_real(
const double scale_factor,
const double *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_single_complex(
const double scale_factor,
const float complex * scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_double_complex(
const double scale_factor,
const double complex * scale_factor,
bml_matrix_dense_t * A);

#endif
23 changes: 6 additions & 17 deletions src/C-interface/dense/bml_scale_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@
*/
bml_matrix_dense_t *TYPED_FUNC(
bml_scale_dense_new) (
const double scale_factor,
const REAL_T * scale_factor,
const bml_matrix_dense_t * A)
{
REAL_T sfactor = (REAL_T) scale_factor;

bml_matrix_dense_t *B = TYPED_FUNC(bml_copy_dense_new) (A);
REAL_T *B_matrix = B->matrix;
int myRank = bml_getMyRank();
//int nElems = B->N * B->N;
int nElems = B->domain->localRowExtent[myRank] * B->N;
int startIndex = B->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&nElems, &sfactor, &(B_matrix[startIndex]), &inc);
//C_BLAS(SCAL) (&nElems, &sfactor, B->matrix, &inc);
C_BLAS(SCAL) (&nElems, scale_factor, &(B_matrix[startIndex]), &inc);

return B;
}
Expand All @@ -54,40 +50,33 @@ bml_matrix_dense_t *TYPED_FUNC(
*/
void TYPED_FUNC(
bml_scale_dense) (
const double scale_factor,
const REAL_T * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B)
{
REAL_T sfactor = scale_factor;

if (A != B)
TYPED_FUNC(bml_copy_dense) (A, B);

REAL_T *B_matrix = B->matrix;
int myRank = bml_getMyRank();
//int nElems = B->N * B->N;
int nElems = B->domain->localRowExtent[myRank] * B->N;
int startIndex = B->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&nElems, &sfactor, &(B_matrix[startIndex]), &inc);
//C_BLAS(SCAL) (&nElems, &sfactor, B->matrix, &inc);
C_BLAS(SCAL) (&nElems, scale_factor, &(B_matrix[startIndex]), &inc);
}

void TYPED_FUNC(
bml_scale_inplace_dense) (
const double scale_factor,
const REAL_T * scale_factor,
bml_matrix_dense_t * A)
{
REAL_T scale_factor_ = (REAL_T) scale_factor;
REAL_T *A_matrix = A->matrix;
int myRank = bml_getMyRank();
//int number_elements = A->N * A->N;
int number_elements = A->domain->localRowExtent[myRank] * A->N;
int startIndex = A->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&number_elements, &scale_factor_, &(A_matrix[startIndex]),
C_BLAS(SCAL) (&number_elements, scale_factor, &(A_matrix[startIndex]),
&inc);
//C_BLAS(SCAL) (&number_elements, &scale_factor_, A->matrix, &inc);
}
4 changes: 2 additions & 2 deletions src/C-interface/ellpack/bml_normalize_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void TYPED_FUNC(
{
double maxminusmin = maxeval - mineval;
double gershfact = maxeval / maxminusmin;
double scalar = (double) -1.0 / maxminusmin;
REAL_T scalar = (REAL_T) - 1.0 / maxminusmin;
double threshold = 0.0;

bml_scale_inplace_ellpack(scalar, A);
bml_scale_inplace_ellpack(&scalar, A);
bml_add_identity_ellpack(A, gershfact, threshold);
}

Expand Down
6 changes: 3 additions & 3 deletions src/C-interface/ellpack/bml_scale_ellpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
bml_matrix_ellpack_t *
bml_scale_ellpack_new(
const double scale_factor,
const void * scale_factor,
const bml_matrix_ellpack_t * A)
{
bml_matrix_ellpack_t *B = NULL;
Expand Down Expand Up @@ -51,7 +51,7 @@ bml_scale_ellpack_new(
*/
void
bml_scale_ellpack(
const double scale_factor,
const void * scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B)
{
Expand All @@ -77,7 +77,7 @@ bml_scale_ellpack(

void
bml_scale_inplace_ellpack(
const double scale_factor,
const void * scale_factor,
bml_matrix_ellpack_t * A)
{
switch (A->matrix_precision)
Expand Down
32 changes: 17 additions & 15 deletions src/C-interface/ellpack/bml_scale_ellpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,71 @@

#include "bml_types_ellpack.h"

#include <complex.h>

bml_matrix_ellpack_t *bml_scale_ellpack_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_ellpack_t * A);

bml_matrix_ellpack_t *bml_scale_ellpack_new_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_ellpack_t * A);

bml_matrix_ellpack_t *bml_scale_ellpack_new_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_ellpack_t * A);

bml_matrix_ellpack_t *bml_scale_ellpack_new_single_complex(
const double scale_factor,
const float complex * scale_factor,
const bml_matrix_ellpack_t * A);

bml_matrix_ellpack_t *bml_scale_ellpack_new_double_complex(
const double scale_factor,
const double complex * scale_factor,
const bml_matrix_ellpack_t * A);

void bml_scale_ellpack(
const double scale_factor,
const void *scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B);

void bml_scale_ellpack_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B);

void bml_scale_ellpack_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B);

void bml_scale_ellpack_single_complex(
const double scale_factor,
const float complex *scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B);

void bml_scale_ellpack_double_complex(
const double scale_factor,
const double complex *scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B);

void bml_scale_inplace_ellpack(
const double scale_factor,
const void *scale_factor,
bml_matrix_ellpack_t * A);

void bml_scale_inplace_ellpack_single_real(
const double scale_factor,
const float *scale_factor,
bml_matrix_ellpack_t * A);

void bml_scale_inplace_ellpack_double_real(
const double scale_factor,
const double *scale_factor,
bml_matrix_ellpack_t * A);

void bml_scale_inplace_ellpack_single_complex(
const double scale_factor,
const float complex *scale_factor,
bml_matrix_ellpack_t * A);

void bml_scale_inplace_ellpack_double_complex(
const double scale_factor,
const double complex *scale_factor,
bml_matrix_ellpack_t * A);

#endif
Loading

0 comments on commit b93a366

Please sign in to comment.