API Reference‎ > ‎

vector_t

templateclass T = double > class vector_t
            This class wraps a std::vector to basically make it capable to perform math operations used by learning algorithms




Header


Namespace

  • nu


Type definitions

  • using item_t = T;
  • using vr_t = std::vector < item_t >;
  • using iterator = typename vr_t::iterator;
  • using const_iterator = typename vr_t::const_iterator;

Exceptions

   enum class exception_t {
      size_mismatch
 };


Constructors

  • vector_t() = default;
    Construct an empty vector, with no elements
  • vector_t(const vector_t&) = default;
    Copy constructor
  • vector_t(const double* v, size_t v_lennoexcept;
    Construct a vector coping elements of a given c-style vector
  • vector_t(vector_t&& othernoexcept;
    Move constructor
  • vector_t(const size_t & sizeitem_t v = 0.0) noexcept;
    Fill constructor
  • vector_t(const vr_tvnoexcept;
    std::vector constructor
  • vector_t(const std::initializer_list<Tlnoexcept;
    Initializer list constructor

Assignment operators

  • vector_t& operator=(const vector_t&) = default;
    Copy assignment operator
  • vector_t& operator=(const T& valuenoexcept;
    Fill assignment operator
  • vector_t& operator=(vector_t&& othernoexcept;
    Move assignment operator

Access operators

  • item_t operator[](size_t idxconst noexcept;
  • item_t& operator[](size_t idxnoexcept;
    Access element

Public Methods

  • size_t size() const noexcept;
    Return vector size
  • bool empty() const noexcept;
    Return whether the vector is empty
  • void resize(const size_t & size, item_t v = 0.0) noexcept;
    Change vector size
  • iterator begin() noexcept;
    Return iterator to beginning
  • const_iterator cbegin() const noexcept;
    Return const_iterator to beginning
  • iterator end() noexcept; 
    Return iterator to end
  • const_iterator cend() const noexcept;
    Return const_iterator to end
  • void push_back(const item_t& item);
    Add element at the end
  • size_t maxarg() noexcept;
    Return index of highest vector element
  • item_t dot(const vector_t& other);
    Return dot product
  • const vector_t& apply(const std::function<T(T)> & f);
    Apply the function f to each vector element of the vector.
  • const vector_t& abs() noexcept;
    Apply the function abs to each vector item
  • const vector_t& log() noexcept;
    Apply the function std::log to each vector item
  • const vector_t& negate() noexcept;
    Negates each vector item
  • T sum() const noexcept;
    Returns the sum of all vector items
  • item_t euclidean_norm2() const noexcept;
    Return the square euclidean norm of vector
  • item_t euclidean_norm() const noexcept;
    Return the euclidean norm of vector
  • const std::vector<T>& to_stdvec() const noexcept;
    Return a const reference to standard vector
  • std::vector<T>& to_stdvec() noexcept;
    Return a reference to standard vector

Relational operator

  • bool operator==(const vector_t& other) const noexcept;
  • bool operator!=(const vector_totherconst noexcept;
  • bool operator<(const vector_t& other) const noexcept; 
  • bool operator>(const vector_totherconst noexcept;
  • bool operator<=(const vector_t& other) const noexcept;
  • bool operator>=(const vector_t& other) const noexcept;
    Based on std::vector relational operators

Math operator

  • vector_t& operator+=(const vector_tother);
    Operator +=
    If other.size() != size() this method will throw an exception exception_t::size_mismatch 
  • vector_t& operator*=(const vector_t& other);
    Operator (Hadamard product) *=
    If other.size() != size() this method will throw an exception exception_t::size_mismatch 
  • vector_t& operator-=(const vector_t& other);
    Operator -=
    If other.size() != size() this method will throw an exception exception_t::size_mismatch 
  • vector_t& operator/=(const vector_t& other);
    Operator /= (entrywise division)
    If other.size() != size() this method will throw an exception exception_t::size_mismatch 
  • vector_t& operator*=(const item_t& s) noexcept;
    Multiply a scalar s to the vector
  • vector_t& operator+=(const item_t& s) noexcept;
    Sum scalar s to each vector element
  • vector_t& operator-=(const item_t& s) noexcept;
    Subtract scalar s to each vector element
  • vector_t& operator/=(const item_t& s) noexcept;
    Divide each vector element by s
  • friend vector_t operator+(const vector_tv1const vector_tv2);
    Binary sum vector operator
    If v1.size() != v2.size() this method will throw an exception exception_t::size_mismatch 
  • friend vector_t operator-(const vector_tv1const vector_tv2);
    Binary sub vector operator
    If v1.size() != v2.size() this method will throw an exception exception_t::size_mismatch 

String Stream Operators

  • friend std::stringstreamoperator<<(std::stringstreamssconst vector_tvnoexcept;
    Writes the vector v status into the give string stream ss
  • friend std::stringstream& operator>>(std::stringstream& ss, vector_t& v) noexcept;
    Copies the vector status from the stream ss into vector v
     

Output Stream Operators

  • friend std::ostream& operator<<(std::ostream& os, const vector_t& v) noexcept;
    Prints out to the os stream vector
Comments