18 #include "../_definitions/definitions.h"
38 template <
typename DataType>
40 const DataType* input_vector,
42 DataType* output_vector)
50 cblas_interface::xcopy(vector_size, input_vector, incx, output_vector,
58 output_vector[i] = input_vector[i];
80 template <
typename DataType>
82 const DataType* input_vector,
85 DataType* output_vector)
93 cblas_interface::xcopy(vector_size, input_vector, incx, output_vector,
96 cblas_interface::xscal(vector_size, scale, output_vector, incy);
103 output_vector[i] = scale * input_vector[i];
134 template <
typename DataType>
136 const DataType* input_vector,
138 const DataType scale,
139 DataType* output_vector)
148 DataType neg_scale = -scale;
149 cblas_interface::xaxpy(vector_size, neg_scale, input_vector, incx,
150 output_vector, incy);
162 output_vector[i] -= scale * input_vector[i];
203 template <
typename DataType>
205 const DataType* vector1,
206 const DataType* vector2,
215 DataType inner_prod = cblas_interface::xdot(vector_size, vector1, incx,
223 long double inner_prod = 0.0;
225 LongIndexType vector_size_chunked = vector_size - (vector_size % chunk);
229 inner_prod += vector1[i] * vector2[i] +
230 vector1[i+1] * vector2[i+1] +
231 vector1[i+2] * vector2[i+2] +
232 vector1[i+3] * vector2[i+3] +
233 vector1[i+4] * vector2[i+4];
236 for (
LongIndexType i=vector_size_chunked; i < vector_size; ++i)
238 inner_prod += vector1[i] * vector2[i];
241 return static_cast<DataType
>(inner_prod);
280 template <
typename DataType>
282 const DataType* vector,
290 DataType norm = cblas_interface::xnrm2(vector_size, vector, incx);
297 long double norm2 = 0.0;
299 LongIndexType vector_size_chunked = vector_size - (vector_size % chunk);
303 norm2 += vector[i] * vector[i] +
304 vector[i+1] * vector[i+1] +
305 vector[i+2] * vector[i+2] +
306 vector[i+3] * vector[i+3] +
307 vector[i+4] * vector[i+4];
310 for (
LongIndexType i=vector_size_chunked; i < vector_size; ++i)
312 norm2 += vector[i] * vector[i];
316 DataType norm = sqrt(
static_cast<DataType
>(norm2));
337 template <
typename DataType>
346 vector, vector_size);
349 DataType scale = 1.0 / norm;
351 cblas_interface::xscal(vector_size, scale, vector, incx);
388 template <
typename DataType>
390 const DataType* vector,
392 DataType* output_vector)
398 vector, vector_size);
401 DataType scale = 1.0 / norm;
416 output_vector[i] = vector[i] / norm;
A static class for vector operations, similar to level-1 operations of the BLAS library....
static void copy_vector(const DataType *input_vector, const LongIndexType vector_size, DataType *output_vector)
Copies a vector to a new vector. Result is written in-place.
static void copy_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Scales a vector and stores to a new vector.
static void subtract_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Subtracts the scaled input vector from the output vector.
static DataType normalize_vector_in_place(DataType *vector, const LongIndexType vector_size)
Normalizes a vector based on Euclidean 2-norm. The result is written in-place.
static DataType inner_product(const DataType *vector1, const DataType *vector2, const LongIndexType vector_size)
Computes Euclidean inner product of two vectors.
static DataType euclidean_norm(const DataType *vector, const LongIndexType vector_size)
Computes the Euclidean norm of a 1D array.
static DataType normalize_vector_and_copy(const DataType *vector, const LongIndexType vector_size, DataType *output_vector)
Normalizes a vector based on Euclidean 2-norm. The result is written into another vector.