提交 b7c7b0e6 编写于 作者: 赵奇可

change std::array to std::vector to fix compatibility with ndk17b

上级 9efc54d6
...@@ -58,21 +58,21 @@ inline int64_t Bound(int64_t val, int64_t limit) { ...@@ -58,21 +58,21 @@ inline int64_t Bound(int64_t val, int64_t limit) {
} }
inline void GetWeightsAndIndices(float scale, int64_t out_loc, int64_t limit, inline void GetWeightsAndIndices(float scale, int64_t out_loc, int64_t limit,
std::array<float, 4>* weights, std::vector<float>* weights,
std::array<int64_t, 4>* indices) { std::vector<int64_t>* indices) {
const int64_t in_loc = scale * out_loc; const int64_t in_loc = scale * out_loc;
const float delta = scale * out_loc - in_loc; const float delta = scale * out_loc - in_loc;
const int64_t offset = lrintf(delta * kTableSize); const int64_t offset = lrintf(delta * kTableSize);
const float* coeffs_tab = GetCoeffsTable(); const float* coeffs_tab = GetCoeffsTable();
*weights = {{coeffs_tab[offset * 2 + 1], coeffs_tab[offset * 2], *weights = {coeffs_tab[offset * 2 + 1], coeffs_tab[offset * 2],
coeffs_tab[(kTableSize - offset) * 2], coeffs_tab[(kTableSize - offset) * 2],
coeffs_tab[(kTableSize - offset) * 2 + 1]}}; coeffs_tab[(kTableSize - offset) * 2 + 1]};
*indices = {{Bound(in_loc - 1, limit), Bound(in_loc, limit), *indices = {Bound(in_loc - 1, limit), Bound(in_loc, limit),
Bound(in_loc + 1, limit), Bound(in_loc + 2, limit)}}; Bound(in_loc + 1, limit), Bound(in_loc + 2, limit)};
} }
inline float Interpolate1D(const std::array<float, 4>& weights, inline float Interpolate1D(const std::vector<float>& weights,
const std::array<float, 4>& values) { const std::vector<float>& values) {
return values[0] * weights[0] + values[1] * weights[1] + return values[0] * weights[0] + values[1] * weights[1] +
values[2] * weights[2] + values[3] * weights[3]; values[2] * weights[2] + values[3] * weights[3];
} }
...@@ -95,17 +95,17 @@ inline void ResizeImage(const float *images, ...@@ -95,17 +95,17 @@ inline void ResizeImage(const float *images,
const float height_scale, const float height_scale,
const float width_scale, const float width_scale,
float *output) { float *output) {
std::array<float, 4> coeff = {{0.0, 0.0, 0.0, 0.0}}; std::vector<float> coeff = {0.0, 0.0, 0.0, 0.0};
#pragma omp parallel for collapse(2) #pragma omp parallel for collapse(2)
for (index_t b = 0; b < batch_size; ++b) { for (index_t b = 0; b < batch_size; ++b) {
for (index_t y = 0; y < out_height; ++y) { for (index_t y = 0; y < out_height; ++y) {
std::array<float, 4> y_weights; std::vector<float> y_weights;
std::array<index_t, 4> y_indices; std::vector<index_t> y_indices;
GetWeightsAndIndices(height_scale, y, in_height, &y_weights, GetWeightsAndIndices(height_scale, y, in_height, &y_weights,
&y_indices); &y_indices);
for (index_t x = 0; x < out_width; ++x) { for (index_t x = 0; x < out_width; ++x) {
std::array<float, 4> x_weights; std::vector<float> x_weights;
std::array<index_t, 4> x_indices; std::vector<index_t> x_indices;
GetWeightsAndIndices(width_scale, x, in_width, &x_weights, GetWeightsAndIndices(width_scale, x, in_width, &x_weights,
&x_indices); &x_indices);
...@@ -117,15 +117,15 @@ inline void ResizeImage(const float *images, ...@@ -117,15 +117,15 @@ inline void ResizeImage(const float *images,
float *channel_output_ptr = float *channel_output_ptr =
output + (b * channels + c) * out_height * out_width; output + (b * channels + c) * out_height * out_width;
for (index_t i = 0; i < 4; ++i) { for (index_t i = 0; i < 4; ++i) {
const std::array<float, 4> values = { const std::vector<float> values = {
{static_cast<float>(channel_input_ptr static_cast<float>(channel_input_ptr
[y_indices[i] * in_width + x_indices[0]]), [y_indices[i] * in_width + x_indices[0]]),
static_cast<float>(channel_input_ptr static_cast<float>(channel_input_ptr
[y_indices[i] * in_width + x_indices[1]]), [y_indices[i] * in_width + x_indices[1]]),
static_cast<float>(channel_input_ptr static_cast<float>(channel_input_ptr
[y_indices[i] * in_width + x_indices[2]]), [y_indices[i] * in_width + x_indices[2]]),
static_cast<float>(channel_input_ptr static_cast<float>(channel_input_ptr
[y_indices[i] * in_width + x_indices[3]])}}; [y_indices[i] * in_width + x_indices[3]])};
coeff[i] = Interpolate1D(x_weights, values); coeff[i] = Interpolate1D(x_weights, values);
} }
channel_output_ptr[y * out_width + x] = channel_output_ptr[y * out_width + x] =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册