Unstack
=================



沿指定轴将输入张量拆分为多个子张量，输出子张量按内存顺序排列。

.. math::

    output_i = input[\text{index along axis}]
    \quad \text{for each slice along } axis

输入：
    - **input** - 输入张量地址。
    - **shape** - 输入张量各维度大小数组。
    - **ndim** - 输入张量维度。
    - **axis** - 拆分的维度索引。
    - **data_size** - 单个元素字节大小。

输出：
    - **output** - 输出张量地址数组，长度等于 ``shape[axis]``。

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

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

**共享存储版本:**

.. c:function:: void unstack_s(void* input, void* output, int* shape, int ndim, int axis, Uint32 data_size, int core_mask)

**C调用示例：**

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

    //FT78NE示例
    #include <stdio.h>
    #include <unstack.h>

    int main(int argc, char* argv[]) {
        float *input = (float *)0xA0000000;

        float *out0 = (float *)0xC0000000;
        float *out1 = (float *)0xC0100000;
        float *outputs[2] = {out0, out1};

        int shape[2] = {2, 128};
        int ndim = 2;
        int axis = 0;
        int core_mask = 0xff;

        unstack_s(input, outputs, shape, ndim, axis, sizeof(float), core_mask);
        return 0;
    }


**私有存储版本:**

.. c:function:: void unstack_p(void* input, void* output, int* shape, int ndim, int axis, Uint32 data_size)

**C调用示例：**

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

    //MT7004示例
    #include <stdio.h>
    #include <unstack.h>

    int main(int argc, char* argv[]) {
        half *input = (half *)0x10800000;
        half *out0 = (half *)0x10810000;
        half *out1 = (half *)0x10820000;
        half *outputs[2] = {out0, out1};

        int shape[3] = {1, 2, 64};
        int ndim = 3;
        int axis = 1;

        unstack_p(input, outputs, shape, ndim, axis, sizeof(half));
        return 0;
    }
    
