Ejemplo n.º 1
0
        public void TestReshapeFloat4DPointToTheSameStorage()
        {
            var x = new FloatTensor(10, 10, 10, 5);

            x.Fill(1);

            var y = x.NewWithStorage1d((UIntPtr)0, 5000, 1);

            y[567] = 0;

            int count = 0;

            for (int i = 0; i < x.Shape[0]; i++)
            {
                for (int j = 0; j < x.Shape[1]; j++)
                {
                    for (int k = 0; k < x.Shape[2]; k++)
                    {
                        for (int l = 0; l < x.Shape[3]; l++)
                        {
                            Assert.AreEqual(x[i, j, k, l], y[count++]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Tensor CreateVariable(float[] data, long[] shape, string name = "")
        {
            FloatTensor floatTensor = new FloatTensor(shape);
            var         ptr         = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
            var         tensor      = FloatTensor.NewWithStorage1d(new FloatTensor.FloatStorage(new FloatTensor.FloatStorage.HType(ptr, false)), UIntPtr.Zero, data.Length, 1);

            return(Reshape(Out(tensor), shape));
        }
Ejemplo n.º 3
0
        public void NewFloatTensorWithStorage1D()
        {
            var x1 = new FloatTensor(9);
            var x2 = x1.NewWithStorage1d((UIntPtr)0, 9, 1);

            for (int i = 0; i < x1.Shape[0]; i++)
            {
                Assert.AreEqual(x1[i], x2[i]);
            }
        }
Ejemplo n.º 4
0
        public void GetFloatTensorData()
        {
            const int size     = 10;
            var       storage0 = new AtenSharp.FloatTensor.FloatStorage(2 * size);

            var x1 = new FloatTensor(size);
            var x2 = FloatTensor.NewWithStorage1d(storage0, UIntPtr.Zero, size, 1);
            var x3 = x2.NewWithStorage1d((UIntPtr)size, size, 1);

            Assert.AreNotEqual(IntPtr.Zero, x1.Data);
            Assert.AreNotEqual(IntPtr.Zero, x2.Data);
            Assert.AreNotEqual(IntPtr.Zero, x3.Data);

            Assert.AreNotEqual(IntPtr.Zero, x1.Storage);
            Assert.AreNotEqual(IntPtr.Zero, x2.Storage);
            Assert.AreNotEqual(IntPtr.Zero, x3.Storage);
        }
Ejemplo n.º 5
0
        public void TestReshapeFloat1D()
        {
            var x = new FloatTensor(10);

            for (int i = 0; i < x.Shape[0]; i++)
            {
                x[i] = i;
            }

            var y = x.NewWithStorage1d((UIntPtr)0, 10, 1);

            for (int i = 0; i < x.Shape[0]; i++)
            {
                Assert.AreEqual(y[i], i);
                Assert.AreEqual(x[i], i);
            }
        }
Ejemplo n.º 6
0
        public void TestReshapeFloat1DPointToTheSameStorage()
        {
            var x = new FloatTensor(10);

            for (int i = 0; i < x.Shape[0]; i++)
            {
                x[i] = i;
            }

            var y = x.NewWithStorage1d((UIntPtr)0, 10, 1);

            y[5] = 0;

            for (int i = 0; i < x.Shape[0]; i++)
            {
                Assert.AreEqual(y[i], x[i]);
            }
        }