NDArray的shapeInfo信息

在对涉及到使用NDArray类型的信息的Debug中,总是会对debug信息里面出现的shapeInfo的长度刚到疑惑。
经过阅读源码发现:

/**
     * Creates the shape information buffer
     * given the shape,stride
     * @param shape the shape for the buffer
     * @param stride the stride for the buffer
     * @param offset the offset for the buffer
     * @param elementWiseStride the element wise stride for the buffer
     * @param order the order for the buffer
     * @return the shape information buffer given the parameters
     */
    public static DataBuffer createShapeInformation(int[] shape, int[] stride, long offset, int elementWiseStride,
                    char order) {
        if (shape.length != stride.length)
            throw new IllegalStateException("Shape and stride must be the same length");

        int rank = shape.length;
        int shapeBuffer[] = new int[rank * 2 + 4];
        shapeBuffer[0] = rank;
        int count = 1;
        for (int e = 0; e < shape.length; e++)
            shapeBuffer[count++] = shape[e];

        for (int e = 0; e < stride.length; e++)
            shapeBuffer[count++] = stride[e];

        shapeBuffer[count++] = (int) offset;
        shapeBuffer[count++] = elementWiseStride;
        shapeBuffer[count] = (int) order;

        DataBuffer ret = Nd4j.createBufferDetached(shapeBuffer);
        ret.setConstant(true);

        return ret;
    }

shapeInfo的信息如此构成:

  1. 长度为 rank * 2 + 4
  2. 第一位为 rank, 后面紧跟的数据为 数组的shape,后面为stride,再紧接着依次为 offset, elementWiseStride和order
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值