Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross platform tests #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Test/matBasic_real_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ i_real_matrix genTestMatrixb(const std::size_t nAnt, const std::size_t nEq)
return resMat;
}


bool CheckIdentity(const i_real_matrix& mat)
{
const float EPS = 1.0e-20;

double sumErrSqr = 0;
for (std::size_t r = 0; r < mat.size(); r++)
{
const i_real_vector& row = mat[r];
for (std::size_t c = 0; c < row.size(); c++)
{
i_float_t diff = c == r ? row[c] - i_float_t(1.0) : row[c];
sumErrSqr = diff * diff;
}
}

return sumErrSqr < EPS;
}



void pinvTest(bool doLargeMatTest = true)
{
std::cout << "\n\n******************** pinv test ********************\n\n";
Expand Down Expand Up @@ -106,7 +127,13 @@ void pinvTest(bool doLargeMatTest = true)
{-6.0, 3.0, 9.0, 1.0}};
std::cout << "rank(matC) = " << rank(matC) << "\n";
showMatrix(matC, "matC");
showMatrix(inv(matC), "inv(matC)");

i_real_matrix invMatC = inv(matC);
showMatrix(invMatC, "inv(matC)");
bool isIdentity = CheckIdentity(matMul(matC, invMatC));
if (!isIdentity)
std::cout << "not identity";

showMatrix(pinv(matC), "pinv(matC)");
showMatrix(pinv2(matC), "pinv2(matC)");
std::cout << "\n\n";
Expand Down
21 changes: 8 additions & 13 deletions Test/matBasic_testUtil.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <iostream>
#include <sys/time.h> // Performance test timer
#include <chrono>


class TestTimer
Expand All @@ -13,17 +13,19 @@ class TestTimer
void tic()
{
m_running = true;
gettimeofday(&m_time_start, NULL);
m_time_start = std::chrono::steady_clock::now();
}

double toc(const char *printInfo = nullptr)
{
double res = 0.0;
if (m_running)
{
gettimeofday(&m_time_end, NULL);
m_time_end = std::chrono::steady_clock::now();
m_running = false;
res = static_cast<double>(m_time_end.tv_sec - m_time_start.tv_sec) + static_cast<double>(m_time_end.tv_usec - m_time_start.tv_usec) / 1000000.0;
auto time_diff = m_time_end - m_time_start;
auto microSecs = std::chrono::duration_cast<std::chrono::microseconds>(time_diff).count();
res = static_cast<double>(microSecs) / 1.0e6;
if (nullptr != printInfo)
{
std::cout << "Time elapsed - " << printInfo << ": ";
Expand All @@ -45,15 +47,8 @@ class TestTimer
}

private:
struct timeval m_time_start
{
0, 0
};

struct timeval m_time_end
{
0, 0
};
std::chrono::steady_clock::time_point m_time_start;
std::chrono::steady_clock::time_point m_time_end;

bool m_running{false};
};