コード例 #1
0
ファイル: PyTorch.gen.cs プロジェクト: Gao851021/Torch.NET
        public Tensor empty(NumSharp.Shape sizes, Tensor @out = null, dtype?dtype = null, layout?layout = null, device?device = null, bool?requires_grad = null, bool?pin_memory = null)
        {
            //auto-generated code, do not change
            var args = ToTuple(new object[]
            {
                sizes,
            });
            var kwargs = new PyDict();

            if (@out != null)
            {
                kwargs["out"] = ToPython(@out);
            }
            if (dtype != null)
            {
                kwargs["dtype"] = ToPython(dtype);
            }
            if (layout != null)
            {
                kwargs["layout"] = ToPython(layout);
            }
            if (device != null)
            {
                kwargs["device"] = ToPython(device);
            }
            if (requires_grad != null)
            {
                kwargs["requires_grad"] = ToPython(requires_grad);
            }
            if (pin_memory != null)
            {
                kwargs["pin_memory"] = ToPython(pin_memory);
            }
            dynamic py = self.InvokeMethod("empty", args, kwargs);

            return(ToCsharp <Tensor>(py));
        }
コード例 #2
0
ファイル: torch.gen.cs プロジェクト: Gao851021/Torch.NET
 public static Tensor empty(NumSharp.Shape sizes, Tensor @out = null, dtype?dtype = null, layout?layout = null, device?device = null, bool?requires_grad = null, bool?pin_memory = null)
 => PyTorch.Instance.empty(sizes, @out: @out, dtype: dtype, layout: layout, device: device, requires_grad: requires_grad, pin_memory: pin_memory);
コード例 #3
0
        protected void autoresetDefault_UInt16()
        {
            if (typeof(TOut) == typeof(UInt16))
            {
                autoresetDefault_NoCast();
                return;
            }

            var   localBlock = Block;
            Shape shape      = Shape;
            var   convert    = Converts.FindConverter <UInt16, TOut>();

            if (!Shape.IsContiguous || Shape.ModifiedStrides)
            {
                //Shape is sliced, auto-resetting
                switch (Type)
                {
                case IteratorType.Scalar:
                {
                    var offset = shape.TransformOffset(0);
                    if (offset != 0)
                    {
                        MoveNext          = () => convert(*((UInt16 *)localBlock.Address + offset));
                        MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    }
                    else
                    {
                        MoveNext          = () => convert(*((UInt16 *)localBlock.Address));
                        MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    }

                    Reset   = () => { };
                    HasNext = () => true;
                    break;
                }

                case IteratorType.Vector:
                {
                    var size = Shape.size;
                    MoveNext = () =>
                    {
                        var ret = convert(*((UInt16 *)localBlock.Address + shape.GetOffset(index++)));
                        if (index >= size)
                        {
                            index = 0;
                        }
                        return(ret);
                    };
                    MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");

                    Reset   = () => index = 0;
                    HasNext = () => true;
                    break;
                }

                case IteratorType.Matrix:
                case IteratorType.Tensor:
                {
                    var iterator = new NDCoordinatesIncrementor(ref shape, incr => incr.Reset());
                    var index    = iterator.Index;
                    Func <int[], int> getOffset = shape.GetOffset;
                    MoveNext = () =>
                    {
                        var ret = convert(*((UInt16 *)localBlock.Address + getOffset(index)));
                        iterator.Next();
                        return(ret);
                    };
                    MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    Reset             = () => iterator.Reset();
                    HasNext           = () => true;
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                //Shape is not sliced, auto-resetting
                switch (Type)
                {
                case IteratorType.Scalar:
                    MoveNext          = () => convert(*(UInt16 *)localBlock.Address);
                    MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    Reset             = () => { };
                    HasNext           = () => true;
                    break;

                case IteratorType.Vector:
                    var size = Shape.size;
                    MoveNext = () =>
                    {
                        var ret = convert(*((UInt16 *)localBlock.Address + index++));
                        if (index >= size)
                        {
                            index = 0;
                        }
                        return(ret);
                    };
                    MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    Reset             = () => index = 0;
                    HasNext           = () => true;
                    break;

                case IteratorType.Matrix:
                case IteratorType.Tensor:
                    var iterator = new NDOffsetIncrementorAutoresetting(Shape);     //we do not copy the dimensions because there is not risk for the iterator's shape to change.
                    MoveNext          = () => convert(*((UInt16 *)localBlock.Address + iterator.Next()));
                    MoveNextReference = () => throw new NotSupportedException("Unable to return references during iteration when casting is involved.");
                    HasNext           = () => true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }