#ifndef MLPP_VECTOR_H #define MLPP_VECTOR_H #include "core/math/math_defs.h" #include "core/math/math_funcs.h" #include "core/containers/pool_vector.h" #include "core/containers/sort_array.h" #include "core/containers/vector.h" #include "core/error/error_macros.h" #include "core/os/memory.h" #include "core/object/reference.h" //REMOVE #include class MLPPMatrix; class MLPPVector : public Reference { GDCLASS(MLPPVector, Reference); public: _FORCE_INLINE_ real_t *ptrw() { return _data; } _FORCE_INLINE_ const real_t *ptr() const { return _data; } void push_back(real_t p_elem); void add_mlpp_vector(const Ref &p_other); void remove(real_t p_index); // Removes the item copying the last value into the position of the one to // remove. It's generally faster than `remove`. void remove_unordered(int p_index); void erase(const real_t &p_val); int erase_multiple_unordered(const real_t &p_val); void invert(); _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ void reset() { if (_data) { memfree(_data); _data = NULL; _size = 0; } } _FORCE_INLINE_ bool empty() const { return _size == 0; } _FORCE_INLINE_ int size() const { return _size; } void resize(int p_size); _FORCE_INLINE_ const real_t &operator[](int p_index) const { CRASH_BAD_INDEX(p_index, _size); return _data[p_index]; } _FORCE_INLINE_ real_t &operator[](int p_index) { CRASH_BAD_INDEX(p_index, _size); return _data[p_index]; } _FORCE_INLINE_ real_t get_element(int p_index) const { ERR_FAIL_INDEX_V(p_index, _size, 0); return _data[p_index]; } _FORCE_INLINE_ void set_element(int p_index, real_t p_val) { ERR_FAIL_INDEX(p_index, _size); _data[p_index] = p_val; } void fill(real_t p_val); void insert(int p_pos, real_t p_val); int find(const real_t &p_val, int p_from = 0) const; template void sort_custom() { int len = _size; if (len == 0) { return; } SortArray sorter; sorter.sort(_data, len); } void sort() { sort_custom<_DefaultComparator>(); } void ordered_insert(real_t p_val); Vector to_vector() const; PoolRealArray to_pool_vector() const; Vector to_byte_array() const; Ref duplicate() const; void set_from_mlpp_vectorr(const MLPPVector &p_from); void set_from_mlpp_vector(const Ref &p_from); void set_from_vector(const Vector &p_from); void set_from_pool_vector(const PoolRealArray &p_from); bool is_equal_approx(const Ref &p_with, real_t tolerance = static_cast(CMP_EPSILON)) const; void flatten_vectors(const Vector> &A); Ref flatten_vectorsn(const Vector> &A) const; void hadamard_product(const Ref &b); Ref hadamard_productn(const Ref &b) const; void hadamard_productb(const Ref &a, const Ref &b); void element_wise_division(const Ref &b); Ref element_wise_divisionn(const Ref &b) const; void element_wise_divisionb(const Ref &a, const Ref &b); void scalar_multiply(real_t scalar); Ref scalar_multiplyn(real_t scalar) const; void scalar_multiplyb(real_t scalar, const Ref &a); void scalar_add(real_t scalar); Ref scalar_addn(real_t scalar) const; void scalar_addb(real_t scalar, const Ref &a); void add(const Ref &b); Ref addn(const Ref &b) const; void addb(const Ref &a, const Ref &b); void sub(const Ref &b); Ref subn(const Ref &b) const; void subb(const Ref &a, const Ref &b); void log(); Ref logn() const; void logb(const Ref &a); void log10(); Ref log10n() const; void log10b(const Ref &a); void exp(); Ref expn() const; void expb(const Ref &a); void erf(); Ref erfn() const; void erfb(const Ref &a); void exponentiate(real_t p); Ref exponentiaten(real_t p) const; void exponentiateb(const Ref &a, real_t p); void sqrt(); Ref sqrtn() const; void sqrtb(const Ref &a); void cbrt(); Ref cbrtn() const; void cbrtb(const Ref &a); real_t dot(const Ref &b) const; //std::vector cross(std::vector a, std::vector b); void abs(); Ref absn() const; void absb(const Ref &a); Ref zero_vec(int n) const; Ref one_vec(int n) const; Ref full_vec(int n, int k) const; void sin(); Ref sinn() const; void sinb(const Ref &a); void cos(); Ref cosn() const; void cosb(const Ref &a); void maxv(const Ref &b); Ref maxvn(const Ref &b) const; void maxvb(const Ref &a, const Ref &b); real_t max_element() const; real_t min_element() const; //std::vector round(std::vector a); real_t euclidean_distance(const Ref &b) const; real_t euclidean_distance_squared(const Ref &b) const; /* real_t norm_2(std::vector a); */ real_t norm_sq() const; real_t sum_elements() const; //real_t cosineSimilarity(std::vector a, std::vector b); void subtract_matrix_rows(const Ref &B); Ref subtract_matrix_rowsn(const Ref &B) const; void subtract_matrix_rowsb(const Ref &a, const Ref &B); // This multiplies a, bT Ref outer_product(const Ref &b) const; // as_diagonal_matrix / to_diagonal_matrix Ref diagnm() const; String to_string(); MLPPVector(); MLPPVector(const MLPPVector &p_from); MLPPVector(const Vector &p_from); MLPPVector(const PoolRealArray &p_from); ~MLPPVector(); // TODO: These are temporary std::vector to_std_vector() const; void set_from_std_vector(const std::vector &p_from); MLPPVector(const std::vector &p_from); protected: static void _bind_methods(); protected: int _size; real_t *_data; }; #endif