예제 #1
0
        static void TestWrite(bool compressed, ref int result)
        {
            string filename = compressed ? "test_compressed.npz" : "test.npz";

            byte[] expected = File.ReadAllBytes(Test.AssetPath(filename));

            UInt8Tensor     color  = Test.Tensor <UInt8Tensor, byte, UInt8Buffer>(new Shape(new uint[] { 5, 5, 3 }));
            Float32Tensor   depth  = Test.Tensor <Float32Tensor, float, Float32Buffer>(new Shape(new uint[] { 5, 5 }));
            string          path   = Path.GetRandomFileName();
            NPZOutputStream stream = new NPZOutputStream(path, compressed ? CompressionMethod.DEFLATED : CompressionMethod.STORED);

            stream.Write("color.npy", color);
            stream.Write("depth.npy", depth);
            stream.Close();

            byte[] actual = File.ReadAllBytes(path);

            string tag = "c#_npz_write";

            if (compressed)
            {
                tag += "_compressed";
            }
            Test.AssertEqual <byte, byte[]>(expected, actual, ref result, tag);

            File.Delete(path);
        }
예제 #2
0
        static void TestRead <T, D, B>(ref int result, string tag)
            where B : IList <D>
            where T : Tensor <D, B>
        {
            Shape  shape    = new Shape(new uint[] { 5, 2, 5 });
            T      expected = Test.Tensor <T, D, B>(shape);
            string path     = Test.AssetPath(tag + ".npy");
            T      actual   = (T)Activator.CreateInstance(typeof(T), new object[] { path });

            Test.AssertEqual <D, B>(expected, actual, ref result, "c#_npy_read_" + tag);
        }
예제 #3
0
        static void TestWrite <T, D, B>(ref int result, string tag)
            where B : IList <D>
            where T : Tensor <D, B>
        {
            Shape  shape  = new Shape(new uint[] { 5, 2, 5 });
            T      tensor = Test.Tensor <T, D, B>(shape);
            string path   = Path.GetRandomFileName();

            tensor.Save(path);
            byte[] actual   = File.ReadAllBytes(path);
            byte[] expected = File.ReadAllBytes(Test.AssetPath(tag + ".npy"));
            Test.AssertEqual <byte, byte[]>(expected, actual, ref result, "c#_npy_write_" + tag);
            File.Delete(path);
        }
예제 #4
0
        static void TestRead(bool compressed, ref int result)
        {
            UInt8Tensor   expectedColor = Test.Tensor <UInt8Tensor, byte, UInt8Buffer>(new Shape(new uint[] { 5, 5, 3 }));
            Float32Tensor expectedDepth = Test.Tensor <Float32Tensor, float, Float32Buffer>(new Shape(new uint[] { 5, 5 }));

            string         filename = compressed ? "test_compressed.npz" : "test.npz";
            NPZInputStream stream   = new NPZInputStream(Test.AssetPath(filename));

            UInt8Tensor   actualColor = stream.ReadUInt8("color.npy");
            Float32Tensor actualDepth = stream.ReadFloat32("depth.npy");

            string tag = "c#_npz_read";

            if (compressed)
            {
                tag += "_compressed";
            }

            Test.AssertEqual <byte, UInt8Buffer>(expectedColor, actualColor, ref result, tag + " color");
            Test.AssertEqual <float, Float32Buffer>(expectedDepth, actualDepth, ref result, tag + " depth");
        }