CUDA Networks
vector.h
Go to the documentation of this file.
1 /**
2  * @file vector.h
3  * @brief Defines the Vector class for GPU-accelerated vector operations.
4  */
5 
6 #ifndef VECTOR_H
7 #define VECTOR_H
8 
9 /**
10  * @class Vector
11  * @brief Represents a vector with GPU-accelerated operations.
12  */
13 class Vector {
14 public:
15  /**
16  * @brief Construct a new Vector object
17  * @param rows Number of elements in the vector
18  */
19  Vector(int rows);
20 
21  /**
22  * @brief Destroy the Vector object
23  */
24  ~Vector();
25 
26  /**
27  * @brief Initialize the vector (typically sets all elements to zero)
28  */
29  void initialize();
30 
31  /**
32  * @brief Randomize the vector elements with values between -0.5 and 0.5
33  */
34  void randomize();
35 
36  /**
37  * @brief Print the vector contents
38  * @param decimals Number of decimal places to display
39  */
40  void print(int decimals);
41 
42  /**
43  * @brief Get the number of elements in the vector
44  * @return int Number of elements
45  */
46  int get_rows() const;
47 
48  /**
49  * @brief Get the raw data pointer of the vector
50  * @return double* Pointer to the vector data on the device
51  */
52  double* get_data() const;
53 
54  /**
55  * @brief Creates a deep copy of the vector.
56  * @return A new Vector object with the same content as the original.
57  */
58  Vector copy() const;
59 
60  /**
61  * @brief Multiplies all elements in the vector by a scalar.
62  * @param scalar The scalar to multiply by.
63  */
64  void multiply_scalar(double scalar);
65 
66  /**
67  * @brief Divides all elements in the vector by a scalar.
68  * @param scalar The scalar to divide by.
69  * @throws std::invalid_argument if scalar is exactly zero.
70  */
71  void divide_scalar(double scalar);
72 
73  /**
74  * @brief Subtracts a scalar value from all elements in the vector.
75  * @param scalar The scalar value to subtract.
76  */
77  void subtract_scalar(double scalar);
78 
79 private:
80  int rows; ///< Number of elements in the vector
81  double* d_data; ///< Device data pointer
82 };
83 
84 #endif // VECTOR_H
Represents a vector with GPU-accelerated operations.
Definition: vector.h:13
void subtract_scalar(double scalar)
Subtracts a scalar value from all elements in the vector.
void randomize()
Randomize the vector elements with values between -0.5 and 0.5.
int get_rows() const
Get the number of elements in the vector.
~Vector()
Destroy the Vector object.
void divide_scalar(double scalar)
Divides all elements in the vector by a scalar.
void multiply_scalar(double scalar)
Multiplies all elements in the vector by a scalar.
void initialize()
Initialize the vector (typically sets all elements to zero)
Vector(int rows)
Construct a new Vector object.
double * get_data() const
Get the raw data pointer of the vector.
Vector copy() const
Creates a deep copy of the vector.
Definition: vector_copy.cu:13
void print(int decimals)
Print the vector contents.
Definition: vector_print.cu:11