imate
C++/CUDA Reference
c_vector_operations.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3  * SPDX-License-Identifier: BSD-3-Clause
4  * SPDX-FileType: SOURCE
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the license found in the LICENSE.txt file in the root
8  * directory of this source tree.
9  */
10 
11 
12 #ifndef _C_BASIC_ALGEBRA_C_VECTOR_OPERATIONS_H_
13 #define _C_BASIC_ALGEBRA_C_VECTOR_OPERATIONS_H_
14 
15 // =======
16 // Headers
17 // =======
18 
19 #include "../_definitions/types.h" // LongIndexType
20 
21 
22 // =================
23 // Vector Operations
24 // =================
25 
33 
34 template <typename DataType>
36 {
37  public:
38 
39  // copy vector
40  static void copy_vector(
41  const DataType* input_vector,
42  const LongIndexType vector_size,
43  DataType* output_vector);
44 
45  // copy scaled vector
46  static void copy_scaled_vector(
47  const DataType* input_vector,
48  const LongIndexType vector_size,
49  const DataType scale,
50  DataType* output_vector);
51 
52  // subtract scaled vector
53  static void subtract_scaled_vector(
54  const DataType* input_vector,
55  const LongIndexType vector_size,
56  const DataType scale,
57  DataType* output_vector);
58 
59  // inner product
60  static DataType inner_product(
61  const DataType* vector1,
62  const DataType* vector2,
63  const LongIndexType vector_size);
64 
65  // euclidean norm
66  static DataType euclidean_norm(
67  const DataType* vector,
68  const LongIndexType vector_size);
69 
70  // normalize vector in place
71  static DataType normalize_vector_in_place(
72  DataType* vector,
73  const LongIndexType vector_size);
74 
75  // normalize vector and copy
76  static DataType normalize_vector_and_copy(
77  const DataType* vector,
78  const LongIndexType vector_size,
79  DataType* output_vector);
80 };
81 
82 #endif // _C_BASIC_ALGEBRA_C_VECTOR_OPERATIONS_H_
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.
int LongIndexType
Definition: types.h:60