#ifndef MLPP_LIN_ALG_H #define MLPP_LIN_ALG_H // // LinAlg.hpp // // Created by Marc Melikyan on 1/8/21. // //TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds #include "core/math/math_defs.h" #include "core/object/reference.h" #include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_vector.h" #include #include class MLPPLinAlg : public Reference { GDCLASS(MLPPLinAlg, Reference); public: // MATRIX FUNCTIONS //std::vector> gramMatrix(std::vector> A); //bool linearIndependenceChecker(std::vector> A); Ref gaussian_noise(int n, int m); Ref additionnm(const Ref &A, const Ref &B); Ref subtractionnm(const Ref &A, const Ref &B); Ref matmultnm(const Ref &A, const Ref &B); Ref hadamard_productnm(const Ref &A, const Ref &B); Ref kronecker_productnm(const Ref &A, const Ref &B); Ref division_element_wisenvnm(const Ref &A, const Ref &B); Ref transposenm(const Ref &A); Ref scalar_multiplynm(real_t scalar, const Ref &A); Ref scalar_addnm(real_t scalar, const Ref &A); Ref lognm(const Ref &A); Ref log10nm(const Ref &A); Ref expnm(const Ref &A); Ref erfnm(const Ref &A); Ref exponentiatenm(const Ref &A, real_t p); Ref sqrtnm(const Ref &A); Ref cbrtnm(const Ref &A); //std::vector> matrixPower(std::vector> A, int n); Ref absnm(const Ref &A); real_t detm(const Ref &A, int d); //real_t trace(std::vector> A); Ref cofactornm(const Ref &A, int n, int i, int j); Ref adjointnm(const Ref &A); Ref inversenm(const Ref &A); Ref pinversenm(const Ref &A); Ref zeromatnm(int n, int m); Ref onematnm(int n, int m); Ref fullnm(int n, int m, int k); Ref sinnm(const Ref &A); Ref cosnm(const Ref &A); //std::vector> rotate(std::vector> A, real_t theta, int axis = -1); Ref maxnm(const Ref &A, const Ref &B); //real_t max(std::vector> A); //real_t min(std::vector> A); //std::vector> round(std::vector> A); //real_t norm_2(std::vector> A); Ref identitym(int d); Ref covnm(const Ref &A); struct EigenResult { Ref eigen_vectors; Ref eigen_values; }; EigenResult eigen(Ref A); struct SVDResult { Ref U; Ref S; Ref Vt; }; SVDResult svd(const Ref &A); //std::vector vectorProjection(std::vector a, std::vector b); //std::vector> gramSchmidtProcess(std::vector> A); /* struct QRDResult { std::vector> Q; std::vector> R; }; */ //QRDResult qrd(std::vector> A); /* struct CholeskyResult { std::vector> L; std::vector> Lt; }; CholeskyResult cholesky(std::vector> A); */ //real_t sum_elements(std::vector> A); Ref flattenvvnv(const Ref &A); /* std::vector solve(std::vector> A, std::vector b); bool positiveDefiniteChecker(std::vector> A); bool negativeDefiniteChecker(std::vector> A); bool zeroEigenvalue(std::vector> A); */ // VECTOR FUNCTIONS Ref flattenmnv(const Vector> &A); Ref hadamard_productnv(const Ref &a, const Ref &b); void hadamard_productv(const Ref &a, const Ref &b, Ref out); Ref division_element_wisenv(const Ref &a, const Ref &b); Ref scalar_multiplynv(real_t scalar, const Ref &a); void scalar_multiplyv(real_t scalar, const Ref &a, Ref out); Ref scalar_addnv(real_t scalar, const Ref &a); void scalar_addv(real_t scalar, const Ref &a, Ref out); Ref additionnv(const Ref &a, const Ref &b); void additionv(const Ref &a, const Ref &b, Ref out); Ref subtractionnv(const Ref &a, const Ref &b); void subtractionv(const Ref &a, const Ref &b, Ref out); Ref lognv(const Ref &a); Ref log10nv(const Ref &a); Ref expnv(const Ref &a); Ref erfnv(const Ref &a); Ref exponentiatenv(const Ref &a, real_t p); Ref sqrtnv(const Ref &a); Ref cbrtnv(const Ref &a); real_t dotnv(const Ref &a, const Ref &b); //std::vector cross(std::vector a, std::vector b); Ref absv(const Ref &a); Ref zerovecnv(int n); Ref onevecnv(int n); Ref fullnv(int n, int k); Ref sinnv(const Ref &a); Ref cosnv(const Ref &a); Ref maxnvv(const Ref &a, const Ref &b); real_t maxvr(const Ref &a); real_t minvr(const Ref &a); //std::vector round(std::vector a); real_t euclidean_distance(const Ref &a, const Ref &b); real_t euclidean_distance_squared(const Ref &a, const Ref &b); /* real_t norm_2(std::vector a); */ real_t norm_sqv(const Ref &a); real_t sum_elementsv(const Ref &a); //real_t cosineSimilarity(std::vector a, std::vector b); // MATRIX-VECTOR FUNCTIONS Ref mat_vec_multnv(const Ref &A, const Ref &b); Ref subtract_matrix_rowsnv(const Ref &a, const Ref &B); Ref outer_product(const Ref &a, const Ref &b); // This multiplies a, bT Ref mat_vec_addnm(const Ref &A, const Ref &b); Ref diagnm(const Ref &a); // TENSOR FUNCTIONS Vector> additionnvt(const Vector> &A, const Vector> &B); Vector> division_element_wisenvnvt(const Vector> &A, const Vector> &B); Vector> sqrtnvt(const Vector> &A); Vector> exponentiatenvt(const Vector> &A, real_t p); //std::vector> tensor_vec_mult(std::vector>> A, std::vector b); //std::vector flatten(std::vector>> A); Vector> scalar_multiplynvt(real_t scalar, Vector> A); Vector> scalar_addnvt(real_t scalar, Vector> A); Vector> resizenvt(const Vector> &A, const Vector> &B); //std::vector>> hadamard_product(std::vector>> A, std::vector>> B); Vector> maxnvt(const Vector> &A, const Vector> &B); Vector> absnvt(const Vector> &A); //real_t norm_2(std::vector>> A); //std::vector>> vector_wise_tensor_product(std::vector>> A, std::vector> B); protected: static void _bind_methods(); }; #endif /* LinAlg_hpp */