!45888 support int input for Unique op
Merge pull request !45888 from xupan/unique_int
This commit is contained in:
commit
ca872c6bd2
|
@ -40,3 +40,28 @@ void Unique(const float *input, int input_len, float *output0, int *output0_len,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int FindInt(const int *array, int len, int target) {
|
||||
if (array == NULL) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (array[i] == target) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UniqueInt(const int *input, int input_len, int *output0, int *output0_len, int *output1) {
|
||||
*output0_len = 0;
|
||||
for (int i = 0; i < input_len; i++) {
|
||||
int idx = FindInt(output0, *output0_len, input[i]);
|
||||
if (idx != -1) {
|
||||
*output1++ = idx;
|
||||
} else {
|
||||
output0[(*output0_len)++] = input[i];
|
||||
*output1++ = *output0_len - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct UniqueParameter {
|
|||
extern "C" {
|
||||
#endif
|
||||
void Unique(const float *input, int input_len, float *output0, int *output0_len, int *output1);
|
||||
void UniqueInt(const int *input, int input_len, int *output0, int *output0_len, int *output1);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -53,6 +53,9 @@ int UniqueCPUKernel::Run() {
|
|||
UniqueFp16(static_cast<float16_t *>(input), in_tensors_[0]->ElementsNum(), static_cast<float16_t *>(output0),
|
||||
&output0_len, output1);
|
||||
#endif
|
||||
} else if (in_tensors_[0]->data_type() == kNumberTypeInt32) {
|
||||
UniqueInt(static_cast<int *>(input), in_tensors_[0]->ElementsNum(), static_cast<int *>(output0), &output0_len,
|
||||
output1);
|
||||
} else {
|
||||
Unique(static_cast<float *>(input), in_tensors_[0]->ElementsNum(), static_cast<float *>(output0), &output0_len,
|
||||
output1);
|
||||
|
|
Loading…
Reference in New Issue