Exemple #1
0
        private Tensor <T> LoadVarData <T>(string name)
            where T : unmanaged
        {
            var v      = GetVar(name);
            var reader = new SpanReader(File.ReadAllBytes(Path.Combine(_modelPath, name)));

            var version  = reader.Read <uint>();
            var lodLevel = reader.Read <ulong>();

            for (uint i = 0; i < lodLevel; i++)
            {
                var len = reader.Read <ulong>();
                reader.Skip((int)len);
            }

            version = reader.Read <uint>();
            if (version != 0)
            {
                throw new NotSupportedException();
            }
            {
                var descSize = reader.Read <int>();
                reader.Skip(descSize);
            }

            var rest = reader.ReadAsSpan();
            var data = MemoryMarshal.Cast <byte, T>(rest);

            return(new DenseTensor <T>(data.ToArray(), GetVarShape(name)));
        }