diff --git a/docs/HTML/Matrix.html b/docs/HTML/Matrix.html index 09a66a67..d51ce40a 100644 --- a/docs/HTML/Matrix.html +++ b/docs/HTML/Matrix.html @@ -54,417 +54,30 @@ // ----------------------- template<typename T, - matrix_orient MO = - matrix_orient::column_major> + matrix_orient MO = matrix_orient::column_major, + IS_SYM = false> class Matrix; - Matrix is an efficient and flat-memory implementation of matrix. It implements many numerical analysis and algorithms. It is used internally by DataFrame library to implement few of its algorithms. Also, some of DataFrame analysis results are in Matrix format.

+ Matrix is an efficient and flat-memory implementation of matrix. It implements many numerical analysis and algorithms. It is used internally by DataFrame library to implement few of its algorithms. Also, some of DataFrame analysis results are in Matrix format.
+ A structurally symmetric matrix (IS_SYM is true) requires almost half the memory size of a normal matrix. +

T: Matrix data type
- MO: Matrix memory orientation + MO: Matrix memory orientation
+ IS_SYM: Is matrix structurally symmetric
- -
Matrix() = default;
-Matrix(size_type rows,
-       size_type cols,
-       const_reference def_v = T());
-Matrix(const Matrix &) = default;
-Matrix(Matrix &&) = default;
-~Matrix() = default;
-Matrix &operator = (const Matrix &) = default;
-Matrix &operator = (Matrix &&) = default;
-
-void clear() noexcept;
-void swap(Matrix &rhs) noexcept;
-bool empty() const noexcept;
-void reserve(size_type rows, size_type cols);
-
-size_type rows() const noexcept;
-size_type cols() const noexcept;
-
-static constexpr matrix_orient orientation();
-
-void resize(size_type rows,
-            size_type cols,
-            const_reference def_v = T());
-
-reference at(size_type r, size_type c);
-const_reference at(size_type r, size_type c) const;
-reference operator() (size_type r, size_type c);
-const_reference operator() (size_type r, size_type c) const;
-
-template<typename I>
-void set_column(I col_data, size_type col);
-
-template<typename I>
-void set_row(I row_data, size_type row);
-
-bool is_square() const noexcept;
-bool is_symmetric() const noexcept;
-
-trans_result_t transpose() const noexcept;
-Matrix transpose2() const noexcept;
-
-Matrix inverse() const;
-
-Matrix covariance(bool is_unbiased = true) const;
-
-template<typename MA1, typename MA2>
-void eigen_space(MA1 &eigenvalues,
-                 MA2 &eigenvectors,
-                 bool sort_values) const;
-
-template<typename MA1, typename MA2, typename MA3>
-void svd(MA1 &U,
-         MA2 &S,
-         MA3 &V,
-         bool full_size = true) const;
+ + Matrix Header File

-
using namespace hmdf;
-
-// ----------------------------------------------------------------------------
-
-using row_mat_t = Matrix<std::size_t, matrix_orient::row_major>;
-using col_mat_t = Matrix<std::size_t, matrix_orient::column_major>;
-
-static constexpr long   ROWS = 5;
-static constexpr long   COLS = 6;
-
-// ----------------------------------------------------------------------------
-
-int main(int, char *[]) {
-
-    // ThreadGranularity::set_optimum_thread_level();
-
-    row_mat_t   row_mata { 3, 3 };
-    col_mat_t   col_mata { 3, 3 };
-    std::size_t value { 0 };
-
-    for (long r = 0; r < row_mata.rows(); ++r)
-        for (long c = 0; c < row_mata.cols(); ++c)  {
-            row_mata(r, c) = ++value;
-            col_mata(r, c) = value;
-        }
-
-    row_mat_t   row_matb  = row_mata * row_mata;
-    col_mat_t   col_matb  = col_mata * col_mata;
-
-    assert((row_matb(0, 0) == col_matb(0, 0) && row_matb(0, 0) == 30));
-    assert((row_matb(0, 2) == col_matb(0, 2) && row_matb(0, 2) == 42));
-    assert((row_matb(1, 1) == col_matb(1, 1) && row_matb(1, 1) == 81));
-    assert((row_matb(2, 1) == col_matb(2, 1) && row_matb(2, 1) == 126));
-    assert((row_matb(2, 2) == col_matb(2, 2) && row_matb(2, 2) == 150));
-
-    row_mat_t   row_mat { ROWS, COLS };
-    col_mat_t   col_mat { ROWS, COLS };
-
-    value = 0;
-    for (long r = 0; r < row_mat.rows(); ++r)
-        for (long c = 0; c < row_mat.cols(); ++c)
-            row_mat(r, c) = value++;
-
-    value = 0;
-    for (long c = 0; c < col_mat.cols(); ++c)
-        for (long r = 0; r < col_mat.rows(); ++r)
-            col_mat(r, c) = value++;
-
-    // Print the stuff out
-    //
-    std::cout << "Row matrix\n";
-    for (long r = 0; r < row_mat.rows(); ++r)  {
-        for (long c = 0; c < row_mat.cols(); ++c)  {
-            std::cout << row_mat(r, c) << ", ";
-        }
-        std::cout << '\n';
-    }
-    std::cout << "\n\n";
-    std::cout << "Column matrix\n";
-    for (long r = 0; r < col_mat.rows(); ++r)  {
-        for (long c = 0; c < col_mat.cols(); ++c)  {
-            std::cout << col_mat(r, c) << ", ";
-        }
-        std::cout << '\n';
-    }
-
-    value = 0;
-    for (long r = 0; r < row_mat.rows(); ++r)
-        for (long c = 0; c < row_mat.cols(); ++c)
-            assert(row_mat(r, c) == value++);
-
-    value = 0;
-    for (long c = 0; c < col_mat.cols(); ++c)
-        for (long r = 0; r < col_mat.rows(); ++r)
-            assert(col_mat(r, c) == value++);
-
-    value = 0;
-    for (auto citer = row_mat.row_cbegin();
-             citer != row_mat.row_cend(); ++citer)
-        assert(*citer == value++);
-
-    value = 0;
-    for (auto citer = col_mat.col_cbegin();
-             citer != col_mat.col_cend(); ++citer)
-        assert(*citer == value++);
-
-    col_mat_t   empty_mat { };
-
-    assert(empty_mat.empty());
-    assert(empty_mat.rows() == 0);
-    assert(empty_mat.cols() == 0);
-    for (auto citer = empty_mat.row_cbegin(); citer != empty_mat.row_cend(); ++citer)
-        assert(*citer == value++);
-
-    auto    col_iter1 = col_mat.col_begin();
-    auto    col_iter2 = col_mat.col_begin();
-    auto    row_iter1 = col_mat.row_begin();
-    auto    row_iter2 = col_mat.row_begin();
-
-    col_iter2 += 7;
-    row_iter2 += 7;
-
-    assert(*col_iter1 == 0);
-    assert(*row_iter1 == 0);
-    assert(*col_iter2 == 7);
-    assert(*row_iter2 == 6);
-
-    assert(((col_iter1 - col_iter2) == 7));
-    assert(((row_iter1 - row_iter2) == 7));
-
-    const auto  col_mat2 = col_mat;
-
-    assert(col_mat != row_mat);
-    assert(col_mat == col_mat2);
-
-    auto    tran_mat = col_mat.transpose();
-    auto    tran_mat2 = col_mat.transpose2();
-
-    assert(tran_mat == tran_mat2);
-    for (long r = 0; r < tran_mat.rows(); ++r)
-        for (long c = 0; c < tran_mat.cols(); ++c)
-            assert(tran_mat(r, c) == col_mat(c, r));
-
-    // Test arithmetic functions
-    //
-    {
-        auto    sum_mat = col_mat + row_mat;
-
-        assert(sum_mat(0, 0) == 0);
-        assert(sum_mat(4, 5) == 58);
-        assert(sum_mat(1, 1) == 13);
-        assert(sum_mat(3, 4) == 45);
-
-        sum_mat += col_mat;
-        assert(sum_mat(0, 0) == 0);
-        assert(sum_mat(4, 5) == 87);
-        assert(sum_mat(1, 1) == 19);
-        assert(sum_mat(3, 4) == 68);
-
-        row_mat_t   lhs_mat { ROWS, COLS };
-        col_mat_t   rhs_mat { COLS, COLS };
-
-        value = 0;
-        for (long r = 0; r < lhs_mat.rows(); ++r)
-            for (long c = 0; c < lhs_mat.cols(); ++c)
-                lhs_mat(r, c) = value++;
-        value = 0;
-        for (long c = 0; c < rhs_mat.cols(); ++c)
-            for (long r = 0; r < rhs_mat.rows(); ++r)
-                rhs_mat(r, c) = value++;
-
-        auto    multi_mat = lhs_mat * rhs_mat;
-
-        assert(multi_mat(0, 0) == 55);
-        assert(multi_mat(4, 5) == 5185);
-        assert(multi_mat(1, 1) == 451);
-        assert(multi_mat(3, 4) == 3277);
-
-        col_mat_t   big_lhs_mat { 100, 100 };
-        col_mat_t   big_rhs_mat { 100, 100 };
-
-        for (long c = 0; c < 100; ++c)
-            for (long r = 0; r < 100; ++r)  {
-                big_lhs_mat(r, c) = c + 1;
-                big_rhs_mat(r, c) = c + 1;
-            }
-
-        auto    big_multi_mat = big_lhs_mat * big_rhs_mat;
-
-        assert(big_multi_mat(0, 0) == 5050);
-        assert(big_multi_mat(99, 99) == 505000);
-        assert(big_multi_mat(98, 2) == 15150);
-        assert(big_multi_mat(2, 5) == 30300);
-    }
-
-    // Test Inverse
-    //
-    {
-        using row_dmat_t = Matrix<double, matrix_orient::row_major>;
-
-        row_dmat_t  mat2 { 3, 3 };
-
-        mat2(0, 0) = 2.0;
-        mat2(0, 1) = 3.0;
-        mat2(0, 2) = 2.0;
-
-        mat2(1, 0) = 3.0;
-        mat2(1, 1) = 2.0;
-        mat2(1, 2) = 3.0;
-
-        mat2(2, 0) = 4.0;
-        mat2(2, 1) = 2.0;
-        mat2(2, 2) = 2.0;
-
-        row_dmat_t  mat2_inv = mat2.inverse();
-        auto        mat3 = mat2 * mat2_inv;
-
-        // It must result to identity matrix
-        //
-        assert((std::fabs(mat3(0, 0) - 1.0) < 0.00000001));
-        assert((std::fabs(mat3(1, 1) - 1.0) < 0.00000001));
-        assert((std::fabs(mat3(2, 2) - 1.0) < 0.00000001));
-        assert((std::fabs(mat3(0, 1) - 0.0) < 0.00000001));
-        assert((std::fabs(mat3(0, 2) - 0.0) < 0.00000001));
-        assert((std::fabs(mat3(1, 0) - 0.0) < 0.00000001));
-        assert((std::fabs(mat3(1, 2) - 0.0) < 0.00000001));
-        assert((std::fabs(mat3(2, 0) - 0.0) < 0.00000001));
-        assert((std::fabs(mat3(2, 1) - 0.0) < 0.00000001));
-    }
-
-    // Test Eigen space
-    //
-    {
-        using col_dmat_t = Matrix<double, matrix_orient::column_major>;
-
-        col_dmat_t  col_mat { 10, 10 };
-        col_dmat_t  eigenvals;
-        col_dmat_t  eigenvecs;
-        std::size_t value { 0 };
-
-        // Symmetric matrix
-        //
-        for (long r = 0; r < col_mat.rows(); ++r)
-            for (long c = 0; c < col_mat.cols(); ++c)
-                col_mat(r, c) = col_mat(c, r) = double(++value);
-
-        col_mat.eigen_space (eigenvals, eigenvecs, true);
-
-        assert(eigenvals.cols() == 10);
-        assert(eigenvals.rows() == 1);
-        assert((std::fabs(eigenvals(0, 0) - -124.177) < 0.001));
-        assert((std::fabs(eigenvals(0, 1) - -24.5492) < 0.0001));
-        assert((std::fabs(eigenvals(0, 5) - -3.4454) < 0.0001));
-        assert((std::fabs(eigenvals(0, 9) - 687.09) < 0.01));
-
-        assert(eigenvecs.cols() == 10);
-        assert(eigenvecs.rows() == 10);
-        assert((std::fabs(eigenvecs(0, 0) - -0.477637) < 0.000001));
-        assert((std::fabs(eigenvecs(2, 4) - -0.320417) < 0.000001));
-        assert((std::fabs(eigenvecs(5, 6) - 0.396209) < 0.000001));
-        assert((std::fabs(eigenvecs(8, 2) - -0.027937) < 0.000001));
-        assert((std::fabs(eigenvecs(9, 9) - 0.432927) < 0.000001));
-
-        // non-symmetric matrix
-        //
-        value = 0;
-        for (long r = 0; r < col_mat.rows(); ++r)
-            for (long c = 0; c < col_mat.cols(); ++c)
-                col_mat(r, c) = double(++value);
-
-        col_mat.eigen_space (eigenvals, eigenvecs, true);
-
-        assert(eigenvals.cols() == 10);
-        assert(eigenvals.rows() == 1);
-        assert((std::fabs(eigenvals(0, 0) - -15.8398) < 0.0001));
-        assert(eigenvals(0, 1) > -0.00000000001); // -8.34036e-15
-        assert(eigenvals(0, 5) < 0.00000000001);  // 4.83968e-15
-        assert((std::fabs(eigenvals(0, 9) - 520.84) < 0.01));
-
-        assert(eigenvecs.cols() == 10);
-        assert(eigenvecs.rows() == 10);
-        assert((std::fabs(eigenvecs(0, 0) - 0.568403) < 0.000001));
-        assert((std::fabs(eigenvecs(2, 4) - 0.088418) < 0.000001));
-        assert((std::fabs(eigenvecs(5, 6) - 0.199127) < 0.000001));
-        assert((std::fabs(eigenvecs(8, 2) - 9.34286) < 0.00001));
-        assert((std::fabs(eigenvecs(9, 9) - -0.51616) < 0.00001));
-    }
-
-    // Test Covariance matrix
-    //
-    {
-        using col_dmat_t = Matrix<double, matrix_orient::column_major>;
-
-        col_dmat_t  col_mat { 5, 4 };
-
-        col_mat(0, 0) = 4.0;
-        col_mat(0, 1) = 2.0;
-        col_mat(0, 2) = 0.6;
-        col_mat(0, 3) = 3.0;
-
-        col_mat(1, 0) = 4.2;
-        col_mat(1, 1) = 2.1;
-        col_mat(1, 2) = 0.59;
-        col_mat(1, 3) = 3.2;
-
-        col_mat(2, 0) = 3.9;
-        col_mat(2, 1) = 2.0;
-        col_mat(2, 2) = 0.58;
-        col_mat(2, 3) = 2.89;
-
-        col_mat(3, 0) = 4.3;
-        col_mat(3, 1) = 2.1;
-        col_mat(3, 2) = 0.62;
-        col_mat(3, 3) = 3.298;
-
-        col_mat(4, 0) = 4.1;
-        col_mat(4, 1) = 2.2;
-        col_mat(4, 2) = 0.63;
-        col_mat(4, 3) = 3.098;
-
-        const auto  cov = col_mat.covariance(true);
-
-        assert(cov.cols() == 4);
-        assert(cov.rows() == 4);
-        assert((std::fabs(cov(0, 0) - 0.025) < 0.001));
-        assert((std::fabs(cov(0, 3) - 0.0254) < 0.0001));
-        assert((std::fabs(cov(2, 3) - 0.001789) < 0.000001));
-        assert((std::fabs(cov(3, 1) - 0.00763) < 0.00001));
-        assert((std::fabs(cov(3, 3) - 0.0258172) < 0.0000001));
-    }
-
-    // Test SVD decomposition
-    //
-    {
-        using col_dmat_t = Matrix<double, matrix_orient::column_major>;
-
-        col_dmat_t  col_mat { 8, 4 };
-        std::size_t value { 0 };
-
-        for (long r = 0; r < col_mat.rows(); ++r)
-            for (long c = 0; c < col_mat.cols(); ++c)
-                col_mat(r, c) = double(++value);
-
-        col_dmat_t  U;
-        col_dmat_t  S;
-        col_dmat_t  V;
-
-        col_mat.svd (U, S, V);
-
-        const auto  col_mat2 = U * S * V.transpose();
-
-        for (long r = 0; r < col_mat2.rows(); ++r)
-            for (long c = 0; c < col_mat2.cols(); ++c)
-                assert((std::fabs(col_mat(r, c) - col_mat2(r, c)) < 0.0001));
-    }
-
-    return (0);
-}
-
+

+ Matrix Test File

+

C++ DataFrame diff --git a/docs/HTML/VirtualString.html b/docs/HTML/VirtualString.html index 99b5001a..a76e75f5 100644 --- a/docs/HTML/VirtualString.html +++ b/docs/HTML/VirtualString.html @@ -39,8 +39,9 @@ - + + + + + +
Signature DescriptionSignature Description Public Member Functions

@@ -59,12 +60,18 @@
 using String2K  = FixedSizeString<2047>;
 		
FixedSizeString is a fixed-size and null-terminated string. Since the size is a template parameter, each different size is a different object type. But since FixedSizeString is derived from VirtualString (which is not a templated object), different size instances can be interchanged through references to VirtualString. VirtualString implements almost all of std::string functionalities.
FixedSizeString does not do any dynamic memory allocation/deallocation.
FixedSizeString "Convenient typedefs" are among the types that DataFrame library can read/write from/to files and serialization
+ Fixed Size String Header File

+