#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 "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_vector.h" #include #include class MLPPLinAlg { public: // MATRIX FUNCTIONS std::vector> gramMatrix(std::vector> A); bool linearIndependenceChecker(std::vector> A); std::vector> gaussianNoise(int n, int m); std::vector> addition(std::vector> A, std::vector> B); std::vector> subtraction(std::vector> A, std::vector> B); std::vector> matmult(std::vector> A, std::vector> B); Ref additionm(const Ref &A, const Ref &B); Ref subtractionm(const Ref &A, const Ref &B); Ref matmultm(const Ref &A, const Ref &B); std::vector> hadamard_product(std::vector> A, std::vector> B); std::vector> kronecker_product(std::vector> A, std::vector> B); std::vector> elementWiseDivision(std::vector> A, std::vector> B); Ref hadamard_productm(const Ref &A, const Ref &B); Ref kronecker_productm(const Ref &A, const Ref &B); Ref element_wise_divisionm(const Ref &A, const Ref &B); std::vector> transpose(std::vector> A); std::vector> scalarMultiply(real_t scalar, std::vector> A); std::vector> scalarAdd(real_t scalar, std::vector> A); Ref transposem(const Ref &A); Ref scalar_multiplym(real_t scalar, const Ref &A); Ref scalar_addm(real_t scalar, const Ref &A); std::vector> log(std::vector> A); std::vector> log10(std::vector> A); std::vector> exp(std::vector> A); std::vector> erf(std::vector> A); std::vector> exponentiate(std::vector> A, real_t p); std::vector> sqrt(std::vector> A); std::vector> cbrt(std::vector> A); Ref logm(const Ref &A); Ref log10m(const Ref &A); Ref expm(const Ref &A); Ref erfm(const Ref &A); Ref exponentiatem(const Ref &A, real_t p); Ref sqrtm(const Ref &A); Ref cbrtm(const Ref &A); std::vector> matrixPower(std::vector> A, int n); std::vector> abs(std::vector> A); Ref absm(const Ref &A); real_t det(std::vector> A, int d); real_t trace(std::vector> A); std::vector> cofactor(std::vector> A, int n, int i, int j); std::vector> adjoint(std::vector> A); std::vector> inverse(std::vector> A); std::vector> pinverse(std::vector> A); std::vector> zeromat(int n, int m); std::vector> onemat(int n, int m); std::vector> full(int n, int m, int k); Ref zeromatm(int n, int m); Ref onematm(int n, int m); Ref fullm(int n, int m, int k); std::vector> sin(std::vector> A); std::vector> cos(std::vector> A); Ref sinm(const Ref &A); Ref cosm(const Ref &A); std::vector> rotate(std::vector> A, real_t theta, int axis = -1); std::vector> max(std::vector> A, std::vector> 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); std::vector> identity(real_t d); std::vector> cov(std::vector> A); std::tuple>, std::vector>> eig(std::vector> A); struct EigenResult { std::vector> eigen_vectors; std::vector> eigen_values; }; EigenResult eigen(std::vector> A); std::tuple>, std::vector>, std::vector>> SVD(std::vector> A); struct SDVResult { std::vector> U; std::vector> S; std::vector> Vt; }; SDVResult svd(std::vector> A); std::vector vectorProjection(std::vector a, std::vector b); std::vector> gramSchmidtProcess(std::vector> A); std::tuple>, std::vector>> QRD(std::vector> A); struct QRDResult { std::vector> Q; std::vector> R; }; QRDResult qrd(std::vector> A); std::tuple>, std::vector>> chol(std::vector> A); struct CholeskyResult { std::vector> L; std::vector> Lt; }; CholeskyResult cholesky(std::vector> A); real_t sum_elements(std::vector> A); std::vector flatten(std::vector> A); Ref flattenv(const Vector> &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); void printMatrix(std::vector> A); // VECTOR FUNCTIONS std::vector> outerProduct(std::vector a, std::vector b); // This multiplies a, bT std::vector hadamard_product(std::vector a, std::vector b); Ref hadamard_productnv(const Ref &a, const Ref &b); void hadamard_productv(const Ref &a, const Ref &b, Ref out); std::vector elementWiseDivision(std::vector a, std::vector b); Ref element_wise_division(const Ref &a, const Ref &b); std::vector scalarMultiply(real_t scalar, std::vector a); Ref scalar_multiplynv(real_t scalar, const Ref &a); void scalar_multiplyv(real_t scalar, const Ref &a, Ref out); std::vector scalarAdd(real_t scalar, std::vector a); Ref scalar_addnv(real_t scalar, const Ref &a); void scalar_addv(real_t scalar, const Ref &a, Ref out); std::vector addition(std::vector a, std::vector b); Ref additionnv(const Ref &a, const Ref &b); void additionv(const Ref &a, const Ref &b, Ref out); std::vector subtraction(std::vector a, std::vector b); Ref subtractionnv(const Ref &a, const Ref &b); void subtractionv(const Ref &a, const Ref &b, Ref out); std::vector subtractMatrixRows(std::vector a, std::vector> B); std::vector log(std::vector a); std::vector log10(std::vector a); std::vector exp(std::vector a); std::vector erf(std::vector a); std::vector exponentiate(std::vector a, real_t p); std::vector sqrt(std::vector a); std::vector cbrt(std::vector a); Ref logv(const Ref &a); Ref log10v(const Ref &a); Ref expv(const Ref &a); Ref erfv(const Ref &a); Ref exponentiatev(const Ref &a, real_t p); Ref sqrtv(const Ref &a); Ref cbrtv(const Ref &a); real_t dot(std::vector a, std::vector b); std::vector cross(std::vector a, std::vector b); std::vector abs(std::vector a); std::vector zerovec(int n); std::vector onevec(int n); std::vector full(int n, int k); Ref absv(const Ref &a); Ref zerovecv(int n); Ref onevecv(int n); Ref fullv(int n, int k); std::vector> diag(std::vector a); std::vector sin(std::vector a); std::vector cos(std::vector a); Ref sinv(const Ref &a); Ref cosv(const Ref &a); std::vector max(std::vector a, std::vector b); real_t max(std::vector a); real_t min(std::vector a); std::vector round(std::vector a); real_t euclideanDistance(std::vector a, std::vector b); 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_sq(std::vector a); real_t norm_sqv(const Ref &a); real_t sum_elements(std::vector a); real_t cosineSimilarity(std::vector a, std::vector b); void printVector(std::vector a); // MATRIX-VECTOR FUNCTIONS std::vector> mat_vec_add(std::vector> A, std::vector b); std::vector mat_vec_mult(std::vector> A, std::vector b); // TENSOR FUNCTIONS std::vector>> addition(std::vector>> A, std::vector>> B); std::vector>> elementWiseDivision(std::vector>> A, std::vector>> B); std::vector>> sqrt(std::vector>> A); std::vector>> exponentiate(std::vector>> A, real_t p); std::vector> tensor_vec_mult(std::vector>> A, std::vector b); std::vector flatten(std::vector>> A); void printTensor(std::vector>> A); std::vector>> scalarMultiply(real_t scalar, std::vector>> A); std::vector>> scalarAdd(real_t scalar, std::vector>> A); std::vector>> resize(std::vector>> A, std::vector>> B); std::vector>> hadamard_product(std::vector>> A, std::vector>> B); std::vector>> max(std::vector>> A, std::vector>> B); std::vector>> abs(std::vector>> A); real_t norm_2(std::vector>> A); std::vector>> vector_wise_tensor_product(std::vector>> A, std::vector> B); private: }; #endif /* LinAlg_hpp */