# Where — MindSpore Signal+ 使用手册 alpha 文档

# Where

逐元素根据条件选择两个输入中的元素

\[\begin{split}output_i = \begin{cases} input0_i, & \text{if } condition_i \text{ is True} \\ input1_i, & \text{if } condition_i \text{ is False} \end{cases}\end{split}\]

输入：

  - input0 - 第一个输入数据地址。

  - input1 - 第二个输入数据地址。

  - condition - 条件数据地址。

  - length - 计算长度。

  - core_mask - 核掩码（仅共享存储版本需要）。

输出：

  - output - 计算结果地址。

支持平台：

  `FT78NE` `MT7004`

备注

- FT78NE 支持int8, int16, int32, fp16, fp32, fp64, cplx64, cplx128

- MT7004 支持fp16, fp32, int16, int32, cplx64

共享存储版本:

void i8_where_s(int8_t *input0, int8_t *input1, bool *condition, int8_t *output, int length, int core_mask)

void i16_where_s(int16_t *input0, int16_t *input1, bool *condition, int16_t *output, int length, int core_mask)

void i32_where_s(int32_t *input0, int32_t *input1, bool *condition, int32_t *output, int length, int core_mask)

void hp_where_s(half *input0, half *input1, bool *condition, half *output, int length, int core_mask)

void fp_where_s(float *input0, float *input1, bool *condition, float *output, int length, int core_mask)

void dp_where_s(double *input0, double *input1, bool *condition, double *output, int length, int core_mask)

void c64_where_s(float *input0, float *input1, bool *condition, float *output, int length, int core_mask)

void c128_where_s(double *input0, double *input1, bool *condition, double *output, int length, int core_mask)

C调用示例：

     1//FT78NE示例
     2#include <stdio.h>
     3#include <where.h>
     4int main(int argc, char* argv[]) {
     5    float *input0 = (float *)0xA0000000;   //input0在DDR空间
     6    float *input1 = (float *)0xB0000000;   //input1在DDR空间
     7    bool *condition = (bool *)0xC0000000;  //condition在DDR空间
     8    float *output = (float *)0xD0000000;   //output在DDR空间
     9    int length = 1000;
    10    int core_mask = 0xff;
    11    fp_where_s(input0, input1, condition, output, length, core_mask);
    12    return 0;
    13}

私有存储版本:

void i8_where_p(int8_t *input0, int8_t *input1, bool *condition, int8_t *output, int length)

void i16_where_p(int16_t *input0, int16_t *input1, bool *condition, int16_t *output, int length)

void i32_where_p(int32_t *input0, int32_t *input1, bool *condition, int32_t *output, int length)

void hp_where_p(half *input0, half *input1, bool *condition, half *output, int length)

void fp_where_p(float *input0, float *input1, bool *condition, float *output, int length)

void dp_where_p(double *input0, double *input1, bool *condition, double *output, int length)

void c64_where_p(float *input0, float *input1, bool *condition, float *output, int length)

void c128_where_p(double *input0, double *input1, bool *condition, double *output, int length)

C调用示例：

     1//FT78NE示例
     2#include <stdio.h>
     3#include <where.h>
     4int main(int argc, char* argv[]) {
     5    float *input0 = (float *)0x10000000;   //input0在L2空间
     6    float *input1 = (float *)0x10001000;   //input1在L2空间
     7    bool *condition = (bool *)0x10002000;  //condition在L2空间
     8    float *output = (float *)0x10003000;   //output在L2空间
     9    int length = 1000;
    10    fp_where_p(input0, input1, condition, output, length);
    11    return 0;
    12}