[Functions] Add quantile function (#700)

* Add sort function

* Add isfinite function

* upgrade isinf isnan

* Add Scalar to FDTensor

* Add floor, ceil function

* add cast functions

* Update out_tmp

* Update quantile

* add gather scatter along axis

* finish quantile function

* Add quantile unittest

* refresh code style for test source code

* Add comments

* Add full function

* Add scalar to fd tensor

* Add full unittest

* Add functions headers

* move fdtensor operators to fastdeploy namespace
This commit is contained in:
Jack Zhou
2022-11-28 09:51:40 +08:00
committed by GitHub
parent 4e74ac06fb
commit 129dda7809
37 changed files with 1567 additions and 75 deletions

View File

@@ -13,9 +13,9 @@
// limitations under the License.
#pragma once
#include <vector>
#include <cmath>
#include "gtest/gtest.h"
#include <cmath>
#include <vector>
namespace fastdeploy {
@@ -33,8 +33,8 @@ struct CheckData {
template <typename T>
void operator()(const T* lhs_ptr, const T* rhs_ptr, int num, int atol = 0) {
for (int i = 0; i < num; ++i) {
// ASSERT_FLOAT_EQ(lhs_ptr[i], rhs_ptr[i]);
int abs_diff = abs(lhs_ptr[i] - rhs_ptr[i]);
// ASSERT_FLOAT_EQ(lhs_ptr[i], rhs_ptr[i]);
int abs_diff = std::abs(lhs_ptr[i] - rhs_ptr[i]);
if (abs_diff > atol) {
std::cout << "lhs_ptr: " << static_cast<int64_t>(lhs_ptr[i])
<< " rhs_ptr: " << static_cast<int64_t>(rhs_ptr[i])
@@ -44,16 +44,16 @@ struct CheckData {
ASSERT_EQ(1, 1);
}
}
void operator()(const float* lhs_ptr, const float* rhs_ptr,
int num, float atol = 1e-06, float rtol = 1e-06) {
void operator()(const float* lhs_ptr, const float* rhs_ptr, int num,
float atol = 1e-06, float rtol = 1e-06) {
for (int i = 0; i < num; ++i) {
float abs_diff = fabs(lhs_ptr[i] - rhs_ptr[i]);
float rel_diff = abs_diff / (std::max(fabs(lhs_ptr[i]),
fabs(rhs_ptr[i])) + 1e-06);
float rel_diff =
abs_diff / (std::max(fabs(lhs_ptr[i]), fabs(rhs_ptr[i])) + 1e-06);
if (abs_diff > atol && rel_diff > rtol) {
std::cout << "lhs_ptr: " << lhs_ptr[i] << " rhs_ptr: "
<< rhs_ptr[i] << " abs_diff: " << abs_diff
<< " rel_diff: " << rel_diff << std::endl;
std::cout << "lhs_ptr: " << lhs_ptr[i] << " rhs_ptr: " << rhs_ptr[i]
<< " abs_diff: " << abs_diff << " rel_diff: " << rel_diff
<< std::endl;
ASSERT_EQ(1, 0);
}
ASSERT_EQ(1, 1);