Пример #1
0
        public static unsafe object MakeTensorInfo(CudaContext context, Tensor tensor, bool index32, int flattenDim = -1)
        {
            if (index32)
            {
                TensorInfoIndex32 ti = new TensorInfoIndex32
                {
                    data = CudaHelpers.GetBufferStart(tensor),
                    dims = tensor.DimensionCount
                };
                for (int i = 0; i < tensor.DimensionCount; ++i)
                {
                    ti.sizes[i]   = (uint)tensor.Sizes[i];
                    ti.strides[i] = (uint)tensor.Strides[i];
                }

                if (flattenDim != -1)
                {
                    ti.sizes[flattenDim] = 1;
                }

                return(ti);
            }
            else
            {
                TensorInfoIndex64 ti = new TensorInfoIndex64
                {
                    data = CudaHelpers.GetBufferStart(tensor),
                    dims = tensor.DimensionCount
                };
                for (int i = 0; i < tensor.DimensionCount; ++i)
                {
                    ti.sizes[i]   = (ulong)tensor.Sizes[i];
                    ti.strides[i] = (ulong)tensor.Strides[i];
                }

                if (flattenDim != -1)
                {
                    ti.sizes[flattenDim] = 1;
                }

                return(ti);
            }
        }
Пример #2
0
        /// <summary>
        /// Makes the tensor information.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tensor">The tensor.</param>
        /// <param name="index32">if set to <c>true</c> [index32].</param>
        /// <param name="flattenDim">The flatten dim.</param>
        /// <returns>System.Object.</returns>
        unsafe public static object MakeTensorInfo(CudaContext context, NDArray tensor, bool index32, int flattenDim = -1)
        {
            if (index32)
            {
                var ti = new TensorInfoIndex32();
                ti.data = CudaHelpers.GetBufferStart(tensor);
                ti.dims = tensor.DimensionCount;
                for (int i = 0; i < tensor.DimensionCount; ++i)
                {
                    ti.sizes[i]   = (uint)tensor.Shape[i];
                    ti.strides[i] = (uint)tensor.Strides[i];
                }

                if (flattenDim != -1)
                {
                    ti.sizes[flattenDim] = 1;
                }

                return(ti);
            }
            else
            {
                var ti = new TensorInfoIndex64();
                ti.data = CudaHelpers.GetBufferStart(tensor);
                ti.dims = tensor.DimensionCount;
                for (int i = 0; i < tensor.DimensionCount; ++i)
                {
                    ti.sizes[i]   = (ulong)tensor.Shape[i];
                    ti.strides[i] = (ulong)tensor.Strides[i];
                }

                if (flattenDim != -1)
                {
                    ti.sizes[flattenDim] = 1;
                }

                return(ti);
            }
        }