aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/math/Vector.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/math/Vector.h')
-rw-r--r--meowpp/math/Vector.h267
1 files changed, 0 insertions, 267 deletions
diff --git a/meowpp/math/Vector.h b/meowpp/math/Vector.h
deleted file mode 100644
index f72b043..0000000
--- a/meowpp/math/Vector.h
+++ /dev/null
@@ -1,267 +0,0 @@
-#ifndef math_Vector_H__
-#define math_Vector_H__
-
-#include "../Self.h"
-#include "Matrix.h"
-
-#include <vector>
-
-#include <cmath>
-
-namespace meow {
-
-/*!
- * @brief \b vector
- *
- * @author cat_leopard
- */
-template<class Scalar>
-class Vector {
-public:
- typedef typename Matrix<Scalar>::EntryRefK ScalarRefK;
- typedef typename Matrix<Scalar>::EntryRef ScalarRef ;
-private:
- Matrix<Scalar> matrix_;
-public:
- /*!
- * @brief constructor
- *
- * With \b dimension=0, which means \b invalid.
- */
- Vector() {
- }
-
- /*!
- * @brief constructor
- *
- * Copy from another vector
- *
- * @param [in] v another vector
- */
- Vector(Vector const& v): matrix_(v.matrix_) {
- }
-
- /*!
- * @brief constructor
- *
- * From matrix's first column
- *
- * @param [in] m matrix
- */
- Vector(Matrix<Scalar> const& m): matrix_(m.col(0)) {
- }
-
- /*!
- * @brief constructor
- *
- * Copy from another std::vector
- *
- * @param [in] v vector
- */
- Vector(std::vector<Scalar> const& v): matrix_(v.size(), 1, Scalar(0)) {
- for (size_t i = 0, I = v.size(); i < I; i++) {
- matrix_.entry(i, 0, v[i]);
- }
- }
-
- /*!
- * @brief constructor
- *
- * setup dimension and inital value
- *
- * @param [in] d dimension
- * @param [in] e inital value
- */
- Vector(size_t d, Scalar const& e): matrix_(d, 1, e) {
- }
-
- //! @brief destructor
- ~Vector() {
- }
-
- //! @brief copy from ...
- Vector& copyFrom(Vector const& v) {
- matrix_.copyFrom(v.matrix_);
- return *this;
- }
-
- //! @brief reference from ...
- Vector& referenceFrom(Vector const& v) {
- matrix_.referenceFrom(v.matrix_);
- return *this;
- }
-
- //! @brief Return a \a dimension x 1 matrix form of it
- Matrix<Scalar> matrix() const {
- return matrix_;
- }
-
- //! @brief return dimension
- size_t dimension() const {
- return matrix_.rows();
- }
-
- /*!
- * @brief resize the dimension
- *
- * @param [in] d new dimension
- * @param [in] s inital entry
- * @return new dimension
- */
- size_t dimension(size_t d, Scalar const& s) {
- matrix_.rows(d, s);
- return dimension();
- }
-
- /*!
- * @brief Return whether \c dimension>0 is true or not
- * @return \c true/false
- */
- bool valid() const {
- return (dimension() > 0);
- }
-
- //! @brief return \a i -th scalar
- Scalar scalar(size_t i) const {
- return matrix_.entry(i, 0);
- }
-
- /*!
- * @brief change \a i -th scalar
- *
- * @param [in] i i-th
- * @param [in] s new value
- */
- Scalar scalar(size_t i, Scalar const& s) {
- matrix_.entry(i, 0, s);
- return scalar(i);
- }
-
- //! @brief return \a i -th scalar with non-constant type
- ScalarRef scalarGet(size_t i) {
- return matrix_.entryGet(i);
- }
-
- /*!
- * @brief change \a i -th to \a j -th scalars
- *
- * @param [in] i i-th
- * @param [in] j j-th
- * @param [in] s new value
- */
- void scalars(size_t i, size_t j, Scalar const& s) {
- for (size_t it = i; it <= j; ++it) {
- matrix_.entry(it, 0, s);
- }
- }
-
- //! @brief subvector form i-th to j-th
- Vector subVector(size_t i, size_t j) {
- return Vector(matrix_.subMatrix(i, 0, j, 0));
- }
-
- //! @brief return +\a (*this)
- Vector positive() const {
- return *this;
- }
-
- //! @brief return -\a (*this)
- Vector negative() const {
- return Vector(matrix_.negative());
- }
-
- //! @brief return \a (*this)+v
- Vector add(Vector const& v) const {
- return Vector(matrix_.add(v.matrix_));
- }
-
- //! @brief return \a (*this)-v
- Vector sub(Vector const& v) const {
- return Vector(matrix_.sub(v.matrix_));
- }
-
- //! @brief return \a (*this)*s , where s is a scalar
- Vector mul(Scalar const& s) const {
- return Vector(matrix_.mul(s));
- }
-
- //! @brief return \a (*this)/s , where s is a scalar
- Vector div(Scalar const& s) const {
- return Vector(matrix_.div(s));
- }
-
- //! @brief dot
- Scalar dot(Vector const& v) const {
- return matrix_.transpose().mul(v.matrix_).entry(0, 0);
- }
-
- //! @brief sqrt of \a length2
- Scalar length() const {
- return Scalar(sqrt((double)length2()));
- }
-
- //! @brief same as \a (*this).dot(*this)
- Scalar length2() const {
- return dot(*this);
- }
-
- //! @brief return a normalize form of itself
- Vector normalize() const {
- return div(length());
- }
-
- //! @brief Let itself be normalize form
- Vector& normalized() {
- copyFrom(normalize());
- return *this;
- }
-
- //! @brief same as copyFrom
- Vector& operator=(Vector const& v) {
- return copyFrom(v);
- }
-
- //! @brief same as entry(i)
- Scalar operator()(size_t i) const {
- return scalar(i);
- }
-
- //! @brief same as positive()
- Vector operator+() const {
- return positive();
- }
-
- //! @brief same as negative()
- Vector operator-() const {
- return negative();
- }
-
- //! @brief same as add(v)
- Vector operator+(Vector const& v) const {
- return add(v);
- }
-
- //! @brief same as sub(v)
- Vector operator-(Vector const& v) const {
- return sub(v);
- }
-
- //! @brief same as dot(v)
- Scalar operator*(Vector const& v) const {
- return dot(v);
- }
-
- //! @brief same as mul(s)
- Vector operator*(Scalar const& s) const {
- return mul(s);
- }
-
- //! @brief same as div(s)
- Vector operator/(Scalar const& s) const {
- return div(s);
- }
-};
-
-} // meow
-
-#endif // math_Vector_H__