| 1 | #include "mat_checks.h" |
|---|
| 2 | |
|---|
| 3 | namespace UnitTest { |
|---|
| 4 | |
|---|
| 5 | bool AreClose ( const itpp::vec &expected, const itpp::vec &actual, |
|---|
| 6 | double tolerance ) { |
|---|
| 7 | if ( expected.length() != actual.length() ) { |
|---|
| 8 | return false; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | for ( int i = 0; i < expected.length(); ++i ) { |
|---|
| 12 | if ( !AreClose ( expected ( i ), actual ( i ), tolerance ) ) { |
|---|
| 13 | return false; |
|---|
| 14 | } |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | return true; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | bool AreClose ( const itpp::vec &expected, const itpp::vec &actual, |
|---|
| 21 | const itpp::vec &tolerance ) { |
|---|
| 22 | if ( ( expected.length() != actual.length() ) || |
|---|
| 23 | ( actual.length() != tolerance.length() ) ) { |
|---|
| 24 | return false; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | for ( int i = 0; i < expected.length(); ++i ) { |
|---|
| 28 | if ( !AreClose ( expected ( i ), actual ( i ), tolerance ( i ) ) ) { |
|---|
| 29 | return false; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | return true; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | bool AreClose ( const itpp::mat &expected, const itpp::mat &actual, double tolerance ) { |
|---|
| 37 | if ( ( expected.rows() != actual.rows() ) || |
|---|
| 38 | ( expected.cols() != actual.cols() ) ) { |
|---|
| 39 | return false; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | for ( int i = 0; i < expected.rows(); ++i ) { |
|---|
| 43 | for ( int j = 0; j < expected.cols(); ++j ) { |
|---|
| 44 | if ( !AreClose ( expected ( i, j ), actual ( i, j ), tolerance ) ) { |
|---|
| 45 | return false; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | return true; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | const char *CurrentContext::config_name = "???"; |
|---|
| 56 | |
|---|
| 57 | int CurrentContext::index = -1; |
|---|
| 58 | |
|---|
| 59 | CurrentContext::CurrentContext ( const char *name, int idx ) { |
|---|
| 60 | config_name = name; |
|---|
| 61 | index = idx; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | CurrentContext::~CurrentContext() { |
|---|
| 65 | config_name = "???"; |
|---|
| 66 | index = -1; |
|---|
| 67 | } |
|---|