parent
77cc155e39
commit
238b67199f
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "nnacl/fp32/sparse_to_dense.h"
|
||||
|
||||
void SparseToDense(int **sparse_indices, int *output_shape,
|
||||
float *sparse_values, float default_value, float *output,
|
||||
bool isScalar, int index_start, int index_end, int out_width) {
|
||||
for (int i = index_start; i < index_end; i++) {
|
||||
for (int j = 0; j < out_width; j++) {
|
||||
output[i * out_width + j] = default_value;
|
||||
}
|
||||
}
|
||||
|
||||
int d1 = output_shape[1] * output_shape[2] * output_shape[3];
|
||||
int d2 = output_shape[2] * output_shape[3];
|
||||
int d3 = output_shape[3];
|
||||
|
||||
int index;
|
||||
if (isScalar == true) {
|
||||
for (int i = index_start; i < index_end; i++) {
|
||||
index = d1 * sparse_indices[i][0] + d2 * sparse_indices[i][1] +
|
||||
d3 * sparse_indices[i][2] + sparse_indices[i][3];
|
||||
output[index] = sparse_values[0];
|
||||
}
|
||||
} else {
|
||||
for (int i = index_start; i < index_end; i++) {
|
||||
index = d1 * sparse_indices[i][0] + d2 * sparse_indices[i][1] +
|
||||
d3 * sparse_indices[i][2] + sparse_indices[i][3];
|
||||
output[index] = sparse_values[i];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MINDSPORE_LITE_NNACL_FP32_SPARSETODENSE_H_
|
||||
#define MINDSPORE_LITE_NNACL_FP32_SPARSETODENSE_H_
|
||||
|
||||
#include "nnacl/sparse_to_dense_parameter.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void SparseToDense(int **sparse_indices_vect, int *output_shape,
|
||||
float *sparse_values, float default_value, float *output,
|
||||
bool isScalar, int index_start, int index_end, int out_width);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MINDSPORE_LITE_NNACL_FP32_SPARSETODENSE_H_
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "nnacl/sparse_to_dense.h"
|
||||
|
||||
void SparseToDense(int *input, int *output_shape_, float *snum, float *dnum, int sp_num, float *output,
|
||||
SparseToDenseParameter *s2d_param_, int task_id) {
|
||||
int m;
|
||||
for (int i = task_id; i < output_shape_[0]; i += s2d_param_->op_parameter_.thread_num_) {
|
||||
for (int j = 0; j < output_shape_[1]; j++) {
|
||||
m = i * output_shape_[1] + j;
|
||||
output[m] = dnum[0];
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < sp_num; j++) {
|
||||
int temp = j * 2;
|
||||
int temp1 = j * 2 + 1;
|
||||
int tempout1 = input[temp] * output_shape_[1] + input[temp1];
|
||||
output[tempout1] = snum[j];
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue