14#include "arcane/std/SimpleTableInternalComparator.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/Numeric.h"
33compare(
bool compare_dimension_too)
35 const Integer dim1 = m_simple_table_internal_mng_reference.numberOfRows();
36 const Integer dim2 = m_simple_table_internal_mng_reference.numberOfColumns();
38 const Integer dim1_to_compare = m_simple_table_internal_mng_to_compare.numberOfRows();
39 const Integer dim2_to_compare = m_simple_table_internal_mng_to_compare.numberOfColumns();
41 if (compare_dimension_too && (dim1 != dim1_to_compare || dim2 != dim2_to_compare)) {
42 m_simple_table_internal_reference->m_parallel_mng->traceMng()->warning() <<
"Dimensions not equals -- Expected dimensions: "
43 << dim1 <<
"x" << dim2 <<
" -- Found dimensions: "
44 << dim1_to_compare <<
"x" << dim2_to_compare;
49 const Integer max_error_print = 10;
51 for (
Integer i = 0; i < dim1; i++) {
52 String row = m_simple_table_internal_mng_reference.rowName(i);
55 if (!
_exploreRows(row) || m_simple_table_internal_mng_to_compare.rowPosition(row) == -1)
58 auto search_epsilons_row = m_epsilons_row.find(row);
59 Real epsilon_row = -1.0;
60 if (search_epsilons_row != m_epsilons_row.end()) {
61 epsilon_row = search_epsilons_row->second;
64 for (
Integer j = 0; j < dim2; j++) {
65 String column = m_simple_table_internal_mng_reference.columnName(j);
68 if (!
_exploreColumn(column) || m_simple_table_internal_mng_to_compare.columnPosition(column) == -1)
71 const Real val1 = m_simple_table_internal_mng_reference.element(column, row,
false);
72 const Real val2 = m_simple_table_internal_mng_to_compare.element(column, row,
false);
74 auto search_epsilons_column = m_epsilons_column.find(column);
75 Real epsilon_column = -1.0;
76 if (search_epsilons_column != m_epsilons_column.end()) {
77 epsilon_column = search_epsilons_column->second;
84 if (error_count < max_error_print) {
85 Real diff = math::abs((val1 - val2) / (math::abs(val1) + math::abs(val2)));
87 m_simple_table_internal_reference->m_parallel_mng->traceMng()->warning()
88 << std::scientific << std::setprecision(std::numeric_limits<Real>::digits10)
89 <<
"Values not equals -- Column name: \"" << column <<
"\" -- Row name: \"" << row
90 <<
"\" -- Expected value: " << val1 <<
" -- Found value: " << val2
91 <<
" -- Epsilon: " << final_epsilon <<
" -- Relative difference: " << diff;
97 if (error_count > 0) {
98 m_simple_table_internal_reference->m_parallel_mng->traceMng()->warning()
99 <<
"Number of errors: " << error_count;
108 if (m_simple_table_internal_mng_to_compare.rowPosition(row_name) == -1 || m_simple_table_internal_mng_to_compare.columnPosition(column_name) == -1)
111 const Real val2 = m_simple_table_internal_mng_to_compare.element(column_name, row_name,
false);
119 if (m_simple_table_internal_mng_reference.rowPosition(row_name) == -1 || m_simple_table_internal_mng_reference.columnPosition(column_name) == -1)
122 auto search_epsilons_row = m_epsilons_row.find(row_name);
123 Real epsilon_row = -1.0;
124 if (search_epsilons_row != m_epsilons_row.end()) {
125 epsilon_row = search_epsilons_row->second;
128 auto search_epsilons_column = m_epsilons_column.find(column_name);
129 Real epsilon_column = -1.0;
130 if (search_epsilons_column != m_epsilons_column.end()) {
131 epsilon_column = search_epsilons_column->second;
136 const Real val1 = m_simple_table_internal_mng_reference.element(column_name, row_name,
false);
148 m_is_excluding_regex_rows =
false;
150 m_regex_columns =
"";
151 m_is_excluding_regex_columns =
false;
153 m_rows_to_compare.clear();
154 m_columns_to_compare.clear();
156 m_epsilons_column.clear();
157 m_epsilons_row.clear();
163 m_columns_to_compare.add(column_name);
169 m_rows_to_compare.add(row_name);
176 m_is_excluding_array_columns = is_exclusive;
181 m_is_excluding_array_rows = is_exclusive;
187 m_regex_columns = regex_column;
192 m_regex_rows = regex_row;
198 m_is_excluding_regex_columns = is_exclusive;
203 m_is_excluding_regex_rows = is_exclusive;
212 m_epsilons_column[column_name] = epsilon;
219 m_epsilons_row[row_name] = epsilon;
229 return m_simple_table_internal_reference;
236 ARCANE_FATAL(
"The reference passed as parameter is Null.");
237 m_simple_table_internal_reference = sti_ref;
238 m_simple_table_internal_mng_reference.setInternal(m_simple_table_internal_reference);
244 return m_simple_table_internal_to_compare;
250 if (sti_to_compare.
isNull())
251 ARCANE_FATAL(
"The reference passed as parameter is Null.");
252 m_simple_table_internal_to_compare = sti_to_compare;
253 m_simple_table_internal_mng_to_compare.setInternal(m_simple_table_internal_to_compare);
271 if (m_columns_to_compare.empty() && m_regex_columns.empty()) {
275 if (m_columns_to_compare.contains(column_name)) {
276 return !m_is_excluding_array_columns;
280 else if (m_regex_columns.empty()) {
281 return m_is_excluding_array_columns;
286 std::regex self_regex(m_regex_columns.localstr(), std::regex_constants::ECMAScript | std::regex_constants::icase);
289 if (std::regex_search(column_name.
localstr(), self_regex)) {
290 return !m_is_excluding_regex_columns;
294 return m_is_excluding_regex_columns;
309 if (m_rows_to_compare.empty() && m_regex_rows.empty()) {
314 if (m_rows_to_compare.contains(row_name)) {
315 return !m_is_excluding_array_rows;
318 else if (m_regex_rows.empty()) {
319 return m_is_excluding_array_rows;
324 std::regex self_regex(m_regex_rows.localstr(), std::regex_constants::ECMAScript | std::regex_constants::icase);
325 if (std::regex_search(row_name.
localstr(), self_regex)) {
326 return !m_is_excluding_regex_rows;
329 return m_is_excluding_regex_rows;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
bool isNull() const
Indicates if the counter references a non-null instance.
Reference to an instance.
bool compare(bool compare_dimension_too) override
Method allowing comparison of the values of the two STIs.
Ref< SimpleTableInternal > internalRef() override
Method allowing retrieval of a reference to the used "reference" SimpleTableInternal object.
bool _exploreColumn(const String &column_name)
Method to determine whether the column named column_name should be explored or not.
void setInternalToCompare(const Ref< SimpleTableInternal > &simple_table_internal) override
Method allowing definition of a reference to the "to compare" SimpleTableInternal.
void isAnArrayExclusiveRows(bool is_exclusive) override
Method allowing definition of whether the row array represents rows to include in the comparison (fal...
void setInternalRef(const Ref< SimpleTableInternal > &simple_table_internal) override
Method allowing definition of a reference to a "reference" SimpleTableInternal.
void isAnArrayExclusiveColumns(bool is_exclusive) override
Method allowing definition of whether the column array represents columns to include in the compariso...
Ref< SimpleTableInternal > internalToCompare() override
Method allowing retrieval of a reference to the used "to compare" SimpleTableInternal object.
bool addEpsilonRow(const String &row_name, Real epsilon) override
Method allowing the definition of an epsilon for a given row. This epsilon must be positive to be con...
bool addRowForComparing(const String &row_name) override
Method allowing the addition of a row to the list of rows to compare.
bool _exploreRows(const String &row_name)
Method to determine whether the row named column_name should be explored or not.
bool compareElem(const String &column_name, const String &row_name) override
Method allowing comparison of a single element. Both SimpleTableInternals are represented by Refs,...
void isARegexExclusiveRows(bool is_exclusive) override
Method allowing specification that the regular expression excludes rows instead of including them.
bool addColumnForComparing(const String &column_name) override
Method allowing the addition of a column to the list of columns to compare.
void editRegexColumns(const String ®ex_column) override
Method allowing the addition of a regular expression to determine the columns to compare.
void editRegexRows(const String ®ex_row) override
Method allowing the addition of a regular expression to determine the rows to compare.
void isARegexExclusiveColumns(bool is_exclusive) override
Method allowing specification that the regular expression excludes columns instead of including them.
void clearComparator() override
Method allowing the clearing of comparison arrays and regular expressions. Does not affect the STIs.
bool addEpsilonColumn(const String &column_name, Real epsilon) override
Method allowing the definition of an epsilon for a given column. This epsilon must be positive to be ...
Unicode character string.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
constexpr __host__ __device__ bool isNearlyEqualWithEpsilon(const _Type &a, const _Type &b, const _Type &epsilon)
Tests if two values are approximately equal. For integer types, this function is equivalent to IsEqua...
constexpr __host__ __device__ bool isNearlyEqual(const _Type &a, const _Type &b)
Tests if two values are approximately equal. For integer types, this function is equivalent to IsEqua...
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.