Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
docs: Vector.h
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaima committed Dec 15, 2023
1 parent edaf018 commit d4a4137
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CustomMath_lib/Matrix/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Matrix {
[[nodiscard]] Matrix sub_lowerTriangle() const;

/// Set the sub-matrix of the matrix [start, end) x [start, end), both use index that start from 0
/// \warning this is often used in conjunction with sub_matrix() to set a sub-matrix to another matrix
/// \warning this is often used in conjunction with sub_matrix()
void set(ull start_row, ull end_row, ull start_col, ull end_col, const Matrix &other);

/*
Expand All @@ -112,7 +112,7 @@ class Matrix {
/// A.rows == A.cols
[[nodiscard]] bool isSquare() const;

/// (a_{ij}^2)^(1/2)
/// 2-norm
[[nodiscard]] lld norm() const;

/// min{a_{ij}}
Expand Down
4 changes: 4 additions & 0 deletions CustomMath_lib/Vector/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ lld Vector::operator*(const Vector &other) const {
return result;
}

Vector operator*(lld scalar, const Vector &vector) {
return vector * scalar;
}

bool Vector::operator==(const Vector &other) const {
if (this->size != other.size) {
return false;
Expand Down
26 changes: 22 additions & 4 deletions CustomMath_lib/Vector/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,57 @@ class Vector {
/// Copy constructor
Vector(const Vector &other);

/// size, 0
explicit Vector(ull size);

/// size, default_value
explicit Vector(ull size, lld default_value);

/// size, [lower_bound, upper_bound]
explicit Vector(ull size, double lower_bound, double upper_bound);

/// 1d vector
explicit Vector(const std::vector<lld> &array);

/// \warning this constructor is not robust / time-efficient
explicit Vector(std::string matlab_array);

/// Return a sub-vector of this vector [start, end)
[[nodiscard]] Vector sub_vector(ull start, ull end) const;

/// Set a sub-vector of this vector [start, end)
/// \warning this is often used in conjunction with sub_vector()
void set(ull start, ull end, const Vector &other);

/// Print the vector
void print();

/// u == v
[[nodiscard]] bool operator==(const Vector &other) const;

/// 2-norm
[[nodiscard]] lld norm() const;

/// u + v
[[nodiscard]] Vector operator+(const Vector &other) const;

/// u - v
[[nodiscard]] Vector operator-(const Vector &other) const;

/// u * v -> Real
[[nodiscard]] lld operator*(const Vector &other) const;

/// u * scalar
[[nodiscard]] Vector operator*(lld scalar) const;

/// u / scalar
[[nodiscard]] Vector operator/(lld scalar) const;

[[nodiscard]] bool operator==(const Vector &other) const;

[[nodiscard]] lld norm() const;
};

/// [1,2,3,0,2] -> [1,1,1,0,1]
Vector sign(const Vector &vector);

/// scalar * u
Vector operator*(lld scalar, const Vector &vector);

#endif //NUMERICAL_ALGEBRA_VECTOR_H

0 comments on commit d4a4137

Please sign in to comment.