Clip
=================



逐元素将输入张量 `src` 的值裁剪到指定的最小值 `min` 和最大值 `max` 范围内。

.. math::

    \text{dst}_i = \max(\min, \min(\text{src}_i, \max))

输入：
    - **src** - 输入张量的数据地址。
    - **length** - 输入张量的总元素数量。
    - **min** - 裁剪范围的最小值。
    - **max** - 裁剪范围的最大值。
    - **core_mask** - 核掩码。

输出：
    - **dst** - 输出张量的数据地址，其大小与`src`相同。

支持平台：
    ``FT78NE``
    ``MT7004``

.. note::
    - FT78NE 支持int8, int16, int32, fp32, fp64
    - MT7004 支持int16, int32, fp16, fp32

**共享存储版本:**

.. c:function:: void i8_clip_s(int8_t* src, int8_t* dst, int length, int8_t min, int8_t max, int core_mask)
.. c:function:: void i16_clip_s(int16_t* src, int16_t* dst, int length, int16_t min, int16_t max, int core_mask)
.. c:function:: void i32_clip_s(int32_t* src, int32_t* dst, int length, int32_t min, int32_t max, int core_mask)
.. c:function:: void fp_clip_s(float* src, float* dst, int length, float min, float max, int core_mask)
.. c:function:: void hp_clip_s(half* src, half* dst, int length, half min, half max, int core_mask)
.. c:function:: void dp_clip_s(double* src, double* dst, int length, double min, double max, int core_mask)

**C调用示例：**

.. code-block:: c
    :linenos:
    :emphasize-lines: 13

    //FT78NE示例
    #include <stdio.h>
    #include <clip.h>
    int main(int argc, char* argv[]) {
        float *src = (float *)0xA0000000;    // src 在DDR空间
        float *dst = (float *)0xB0000000;    // dst
        
        int length = 4096;
        float min = 0.0f;
        float max = 6.0f; //  例如ReLU6的裁剪范围
        int core_mask = 0xff;
        
        fp_clip_s(src, dst, length, min, max, core_mask);
        return 0;
    }


**私有存储版本:**

.. c:function:: void i8_clip_p(int8_t* src, int8_t* dst, int length, int8_t min, int8_t max)
.. c:function:: void i16_clip_p(int16_t* src, int16_t* dst, int length, int16_t min, int16_t max)
.. c:function:: void i32_clip_p(int32_t* src, int32_t* dst, int length, int32_t min, int32_t max)
.. c:function:: void fp_clip_p(float* src, float* dst, int length, float min, float max)
.. c:function:: void hp_clip_p(half* src, half* dst, int length, half min, half max)
.. c:function:: void dp_clip_p(double* src, double* dst, int length, double min, double max)

**C调用示例：**

.. code-block:: c
    :linenos:
    :emphasize-lines: 12

    //FT78NE示例
    #include <stdio.h>
    #include <clip.h>
    int main(int argc, char* argv[]) {
        float *src = (float *)0x10000000;    // src 在L2空间
        float *dst = (float *)0x11000000;    // dst
        
        int length = 1024;
        float min = -1.0f;
        float max = 1.0f;
        
        fp_clip_p(src, dst, length, min, max);
        return 0;
    }