Skip to content

Commit

Permalink
test previous def range
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Apr 17, 2024
1 parent d0310f0 commit dd4ffec
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 146 deletions.
233 changes: 120 additions & 113 deletions src/tests/functional/shared_test_classes/src/base/utils/ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,121 +26,128 @@ ov::test::utils::InputGenerateData get_range_by_type(ov::element::Type temp_type
double min_start = 0 - (int32_t)round(kMaxRange / 2);
uint32_t max_range = kMaxRange - 1;

ov::test::utils::InputGenerateData inData(min_start, max_range);
#define CASE(X) \
case X: { \
auto lowest = std::numeric_limits<element_type_traits<X>::value_type>::lowest(); \
auto max = std::numeric_limits<element_type_traits<X>::value_type>::max(); \
double tmp_range = static_cast<double>(max) - static_cast<double>(lowest); \
if (tmp_range < kMaxRange) { \
inData.start_from = lowest; \
inData.range = (uint32_t)round(tmp_range); \
} else { \
inData.range = kMaxRange - 1; \
inData.start_from = lowest > min_start ? static_cast<double>(lowest) : min_start; \
} \
break; \
} \

switch (temp_type) {
case(ov::element::Type_t::undefined): {
inData.start_from = min_start;
inData.range = max_range;
break;
}
case(ov::element::Type_t::boolean): {
inData.start_from = 0;
inData.range = 1;
break;
}
case(ov::element::Type_t::bf16): {
ov::bfloat16 lowest_tmp = std::numeric_limits<ov::bfloat16>::lowest();
ov::bfloat16 max_tmp = std::numeric_limits<ov::bfloat16>::max();

double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
double max = max_tmp.to_bits();

double tmp_range = max - lowest;
if (tmp_range < kMaxRange) {
inData.start_from = lowest;
inData.range = (uint32_t)round(tmp_range);
} else {
inData.start_from = lowest > min_start ? lowest : min_start;
inData.range = kMaxRange - 1;
}

break;
}
case ov::element::Type_t::f16: {
ov::float16 lowest_tmp = std::numeric_limits<ov::float16>::lowest();
ov::float16 max_tmp = std::numeric_limits<ov::float16>::max();

double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
double max = max_tmp.to_bits();

double tmp_range = max - lowest;
if (tmp_range < kMaxRange) {
inData.start_from = lowest;
inData.range = (uint32_t)round(tmp_range);
} else {
inData.start_from = lowest > min_start ? lowest : min_start;
inData.range = kMaxRange - 1;
}

break;
}
case ov::element::Type_t::f8e4m3: {
ov::float8_e4m3 lowest_tmp = std::numeric_limits<ov::float8_e4m3>::lowest();
ov::float8_e4m3 max_tmp = std::numeric_limits<ov::float8_e4m3>::max();

double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
double max = max_tmp.to_bits();

double tmp_range = max - lowest;
if (tmp_range < kMaxRange) {
inData.start_from = lowest;
inData.range = (uint32_t)round(tmp_range);
} else {
inData.start_from = lowest > min_start ? lowest : min_start;
inData.range = kMaxRange - 1;
}

break;
}
case ov::element::Type_t::f8e5m2: {
ov::float8_e5m2 lowest_tmp = std::numeric_limits<ov::float8_e5m2>::lowest();
ov::float8_e5m2 max_tmp = std::numeric_limits<ov::float8_e5m2>::max();

double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
double max = max_tmp.to_bits();

double tmp_range = max - lowest;
if (tmp_range < kMaxRange) {
inData.start_from = lowest;
inData.range = (uint32_t)round(tmp_range);
} else {
inData.start_from = lowest > min_start ? lowest : min_start;
inData.range = kMaxRange - 1;
}

break;
}
CASE(ov::element::Type_t::f32)
CASE(ov::element::Type_t::f64)
CASE(ov::element::Type_t::i4)
CASE(ov::element::Type_t::i8)
CASE(ov::element::Type_t::i16)
CASE(ov::element::Type_t::i32)
CASE(ov::element::Type_t::i64)
CASE(ov::element::Type_t::u1)
CASE(ov::element::Type_t::u4)
CASE(ov::element::Type_t::u8)
CASE(ov::element::Type_t::u16)
CASE(ov::element::Type_t::u32)
CASE(ov::element::Type_t::u64)
break;
ov::test::utils::InputGenerateData inData;
if (temp_type.is_real()) {
inData.start_from = 0;
inData.range = 8;
inData.resolution = 32;
}

// ov::test::utils::InputGenerateData inData(min_start, max_range);
// #define CASE(X) \
// case X: { \
// auto lowest = std::numeric_limits<element_type_traits<X>::value_type>::lowest(); \
// auto max = std::numeric_limits<element_type_traits<X>::value_type>::max(); \
// double tmp_range = static_cast<double>(max) - static_cast<double>(lowest); \
// if (tmp_range < kMaxRange) { \
// inData.start_from = lowest; \
// inData.range = (uint32_t)round(tmp_range); \
// } else { \
// inData.range = kMaxRange - 1; \
// inData.start_from = lowest > min_start ? static_cast<double>(lowest) : min_start; \
// } \
// break; \
// } \
// switch (temp_type) {
// case(ov::element::Type_t::undefined): {
// inData.start_from = min_start;
// inData.range = max_range;
// break;
// }
// case(ov::element::Type_t::boolean): {
// inData.start_from = 0;
// inData.range = 1;
// break;
// }
// case(ov::element::Type_t::bf16): {
// ov::bfloat16 lowest_tmp = std::numeric_limits<ov::bfloat16>::lowest();
// ov::bfloat16 max_tmp = std::numeric_limits<ov::bfloat16>::max();

// double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
// double max = max_tmp.to_bits();

// double tmp_range = max - lowest;
// if (tmp_range < kMaxRange) {
// inData.start_from = lowest;
// inData.range = (uint32_t)round(tmp_range);
// } else {
// inData.start_from = lowest > min_start ? lowest : min_start;
// inData.range = kMaxRange - 1;
// }

// break;
// }
// case ov::element::Type_t::f16: {
// ov::float16 lowest_tmp = std::numeric_limits<ov::float16>::lowest();
// ov::float16 max_tmp = std::numeric_limits<ov::float16>::max();

// double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
// double max = max_tmp.to_bits();

// double tmp_range = max - lowest;
// if (tmp_range < kMaxRange) {
// inData.start_from = lowest;
// inData.range = (uint32_t)round(tmp_range);
// } else {
// inData.start_from = lowest > min_start ? lowest : min_start;
// inData.range = kMaxRange - 1;
// }

// break;
// }
// case ov::element::Type_t::f8e4m3: {
// ov::float8_e4m3 lowest_tmp = std::numeric_limits<ov::float8_e4m3>::lowest();
// ov::float8_e4m3 max_tmp = std::numeric_limits<ov::float8_e4m3>::max();

// double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
// double max = max_tmp.to_bits();

// double tmp_range = max - lowest;
// if (tmp_range < kMaxRange) {
// inData.start_from = lowest;
// inData.range = (uint32_t)round(tmp_range);
// } else {
// inData.start_from = lowest > min_start ? lowest : min_start;
// inData.range = kMaxRange - 1;
// }

// break;
// }
// case ov::element::Type_t::f8e5m2: {
// ov::float8_e5m2 lowest_tmp = std::numeric_limits<ov::float8_e5m2>::lowest();
// ov::float8_e5m2 max_tmp = std::numeric_limits<ov::float8_e5m2>::max();

// double lowest = 0 - static_cast<double>(lowest_tmp.to_bits());
// double max = max_tmp.to_bits();

// double tmp_range = max - lowest;
// if (tmp_range < kMaxRange) {
// inData.start_from = lowest;
// inData.range = (uint32_t)round(tmp_range);
// } else {
// inData.start_from = lowest > min_start ? lowest : min_start;
// inData.range = kMaxRange - 1;
// }

// break;
// }
// CASE(ov::element::Type_t::f32)
// CASE(ov::element::Type_t::f64)
// CASE(ov::element::Type_t::i4)
// CASE(ov::element::Type_t::i8)
// CASE(ov::element::Type_t::i16)
// CASE(ov::element::Type_t::i32)
// CASE(ov::element::Type_t::i64)
// CASE(ov::element::Type_t::u1)
// CASE(ov::element::Type_t::u4)
// CASE(ov::element::Type_t::u8)
// CASE(ov::element::Type_t::u16)
// CASE(ov::element::Type_t::u32)
// CASE(ov::element::Type_t::u64)
// break;
// }

return inData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,41 +229,41 @@ void inline fill_data_random(T* pointer,
return;
}

if (k != 1) {
testing::internal::Random random(seed);
const uint32_t k_range = k * range; // range with respect to k
random.Generate(k_range);

if (start_from < 0 && !std::numeric_limits<T>::is_signed) {
start_from = 0;
}
for (std::size_t i = 0; i < size; i++) {
pointer[i] = static_cast<T>(start_from + (random.Generate(k_range) / k));
}
} else {
if (std::numeric_limits<T>::is_integer) {
std::mt19937 gen(seed);
std::uniform_int_distribution<int64_t> dist(0, range);
// if (k != 1) {
testing::internal::Random random(seed);
const uint32_t k_range = k * range; // range with respect to k
random.Generate(k_range);

for (std::size_t i = 0; i < size; i++) {
pointer[i] = static_cast<T>(start_from + dist(gen));
}
} else {
std::mt19937 gen(seed);
std::uniform_real_distribution<double> dist(0, range);

for (std::size_t i = 0; i < size; i++) {
auto value = dist(gen);
if (std::is_same<ov::float16, T>::value) {
pointer[i] = static_cast<T>(ov::float16(start_from + value));
} else if (std::is_same<ov::bfloat16, T>::value) {
pointer[i] = static_cast<T>(ov::bfloat16(start_from + value));
} else {
pointer[i] = static_cast<T>(start_from + value);
}
}
}
if (start_from < 0 && !std::numeric_limits<T>::is_signed) {
start_from = 0;
}
for (std::size_t i = 0; i < size; i++) {
pointer[i] = static_cast<T>(start_from + (random.Generate(k_range) / k));
}
// } else {
// if (std::numeric_limits<T>::is_integer) {
// std::mt19937 gen(seed);
// std::uniform_int_distribution<int64_t> dist(0, range);

// for (std::size_t i = 0; i < size; i++) {
// pointer[i] = static_cast<T>(start_from + dist(gen));
// }
// } else {
// std::mt19937 gen(seed);
// std::uniform_real_distribution<double> dist(0, range);

// for (std::size_t i = 0; i < size; i++) {
// auto value = dist(gen);
// if (std::is_same<ov::float16, T>::value) {
// pointer[i] = static_cast<T>(ov::float16(start_from + value));
// } else if (std::is_same<ov::bfloat16, T>::value) {
// pointer[i] = static_cast<T>(ov::bfloat16(start_from + value));
// } else {
// pointer[i] = static_cast<T>(start_from + value);
// }
// }
// }
// }
}

template <class T>
Expand Down

0 comments on commit dd4ffec

Please sign in to comment.