Exemplo n.º 1
0
        public Tensor IndexSelect(Tensor result, Tensor src, Tensor indice)
        {
            int  ndim        = result.DimensionCount;
            long storageSize = TensorDimensionHelpers.GetStorageSize(result.Sizes, result.Strides);
            long cols        = result.Sizes[ndim - 1];

            if (storageSize % cols != 0)
            {
                throw new Exception($"Invalid tensor storage size = '{storageSize}', and cols = '{cols}'");
            }

            long rows = storageSize / cols;

            Tensor writeTarget = TensorResultBuilder.GetWriteTarget(result, src, false, new long[] { indice.Sizes[0], src.Sizes[1] });

            TensorApplyCPU.IndexSelect(writeTarget, src, indice, (int)rows, (int)cols);
            return(writeTarget);
        }