65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#ifndef FESA_MATH_VECTOR_H_
|
|
#define FESA_MATH_VECTOR_H_
|
|
|
|
#include <cstddef>
|
|
#include <vector>
|
|
|
|
namespace fesa {
|
|
|
|
/// @brief Owns a contiguous dense vector while keeping MKL private.
|
|
class Vector {
|
|
public:
|
|
/// @brief Constructs a vector with all entries initialized to one value.
|
|
explicit Vector(std::size_t size, double value = 0.0);
|
|
|
|
/// @brief Copies vector values into independent contiguous storage.
|
|
Vector(const Vector& other);
|
|
|
|
/// @brief Moves vector storage and leaves other empty.
|
|
Vector(Vector&& other) noexcept;
|
|
|
|
/// @brief Copies vector values into independent contiguous storage.
|
|
Vector& operator=(const Vector& other);
|
|
|
|
/// @brief Moves vector storage and leaves other empty.
|
|
Vector& operator=(Vector&& other) noexcept;
|
|
|
|
/// @brief Returns the number of entries.
|
|
std::size_t Size() const noexcept;
|
|
|
|
/// @brief Returns mutable contiguous storage.
|
|
double* Data() noexcept;
|
|
|
|
/// @brief Returns immutable contiguous storage.
|
|
const double* Data() const noexcept;
|
|
|
|
/// @brief Returns a bounds-checked mutable entry.
|
|
/// @throws std::out_of_range if index is outside the vector.
|
|
double& operator[](std::size_t index);
|
|
|
|
/// @brief Returns a bounds-checked immutable entry.
|
|
/// @throws std::out_of_range if index is outside the vector.
|
|
const double& operator[](std::size_t index) const;
|
|
|
|
/// @brief Computes the Euclidean dot product with rhs.
|
|
/// @throws std::invalid_argument if the vector sizes differ.
|
|
double Dot(const Vector& rhs) const;
|
|
|
|
/// @brief Computes the Euclidean norm.
|
|
double Norm() const;
|
|
|
|
/// @brief Scales each entry by alpha through the dense backend.
|
|
void Scale(double alpha);
|
|
|
|
/// @brief Accumulates alpha times x into this vector.
|
|
/// @throws std::invalid_argument if the vector sizes differ.
|
|
void Axpy(double alpha, const Vector& x);
|
|
|
|
private:
|
|
std::vector<double> values_;
|
|
};
|
|
|
|
} // namespace fesa
|
|
|
|
#endif // FESA_MATH_VECTOR_H_
|