1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
// Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
// This program is free software: you can redistribute it and/or modify it under
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
#ifndef SCALING_HH
#define SCALING_HH
#include <blas.hh>
// -----------------------------------------------------------------------------
/// Does column scaling:
/// A[:, j] *= Beta[j] for j = 0, ..., n-1.
/// A is m-by-n. Beta is n-length vector.
template <typename scalar_t, typename data_t>
void col_scale(
int m, int n,
data_t* A, int lda,
scalar_t const* Beta )
{
for (int j = 0; j < n; ++j) {
blas::scal( m, Beta[ j ], &A[ j*lda ], 1 );
}
}
// -----------------------------------------------------------------------------
/// Does row scaling:
/// A[i, :] *= Alpha[i] for i = 0, ..., m-1.
/// A is m-by-n. Alpha is m-length vector.
template <typename scalar_t, typename data_t>
void row_scale(
int m, int n,
data_t const* Alpha,
scalar_t* A, int lda )
{
for (int j = 0; j < m; ++j) {
for (int i = 0; i < n; ++i) {
A[ i + j*lda ] *= Alpha[ i ];
}
}
}
// -----------------------------------------------------------------------------
/// Does row and column scaling:
/// A[i, j] *= Alpha[i] * Beta[j] for i = 0, ..., m-1 and j = 0, ..., n-1.
/// A is m-by-n. Alpha is m-length vector. Beta is n-length vector.
template <typename scalar_t, typename data_t>
void row_col_scale(
int m, int n,
scalar_t const* Alpha,
data_t* A, int lda,
scalar_t const* Beta )
{
for (int j = 0; j < m; ++j) {
scalar_t beta_j = Beta[ j ];
for (int i = 0; i < n; ++i) {
A[ i + j*lda ] *= Alpha[ i ] * beta_j;
}
}
}
#endif // #ifndef SCALING_HH
|