2using System.Collections.Generic;
6using System.Threading.Tasks;
30 using (MemoryStream ms =
new MemoryStream(rg))
31 using (BinaryReader br =
new BinaryReader(ms))
33 int nFmt = br.ReadInt32();
35 if (nFmt != (
int)DATA_FORMAT.LIST_DOUBLE &&
36 nFmt != (int)DATA_FORMAT.LIST_FLOAT)
37 return DATA_FORMAT.NONE;
39 return (DATA_FORMAT)nFmt;
49 public static byte[]
Pack(List<double> rg, out DATA_FORMAT fmt)
51 fmt = DATA_FORMAT.LIST_DOUBLE;
53 using (MemoryStream ms =
new MemoryStream())
54 using (BinaryWriter bw =
new BinaryWriter(ms))
59 for (
int i = 0; i < rg.Count; i++)
77 using (MemoryStream ms =
new MemoryStream(rg))
78 using (BinaryReader br =
new BinaryReader(ms))
80 DATA_FORMAT fmt1 = (DATA_FORMAT)br.ReadInt32();
82 if (fmtExpected != DATA_FORMAT.LIST_DOUBLE)
83 throw new Exception(
"The format expected should be DATA_FORMAT.LIST_DOUBLE, but instead it is '" + fmtExpected.ToString() +
"'.");
85 if (fmt1 != fmtExpected)
86 throw new Exception(
"Invalid data format, expected '" + fmtExpected.ToString() +
"' but found '" + fmt1.ToString() +
"'.");
88 int nCount = br.ReadInt32();
89 List<double> rgData =
new List<double>();
91 for (
int i = 0; i < nCount; i++)
93 rgData.Add(br.ReadDouble());
106 public static byte[]
Pack(List<float> rg, out DATA_FORMAT fmt)
108 fmt = DATA_FORMAT.LIST_FLOAT;
110 using (MemoryStream ms =
new MemoryStream())
111 using (BinaryWriter bw =
new BinaryWriter(ms))
116 for (
int i = 0; i < rg.Count; i++)
134 using (MemoryStream ms =
new MemoryStream(rg))
135 using (BinaryReader br =
new BinaryReader(ms))
137 DATA_FORMAT fmt1 = (DATA_FORMAT)br.ReadInt32();
139 if (fmtExpected != DATA_FORMAT.LIST_FLOAT)
140 throw new Exception(
"The format expected should be DATA_FORMAT.LIST_FLOAT, but instead it is '" + fmtExpected.ToString() +
"'.");
142 if (fmt1 != fmtExpected)
143 throw new Exception(
"Invalid data format, expected '" + fmtExpected.ToString() +
"' but found '" + fmt1.ToString() +
"'.");
145 int nCount = br.ReadInt32();
146 List<float> rgData =
new List<float>();
148 for (
int i = 0; i < nCount; i++)
150 rgData.Add(br.ReadSingle());
The BinaryData class is used to pack and unpack DataCriteria binary data, optionally stored within ea...
static List< double > UnPackDoubleList(byte[] rg, DATA_FORMAT fmtExpected)
Unpack the byte array into a list of double values.
static byte[] Pack(List< float > rg, out DATA_FORMAT fmt)
Pack a list of float into a byte array.
static DATA_FORMAT UnPackType(byte[] rg)
Unpack the type packed into the byte array (if any).
BinaryData()
The constructor.
static List< float > UnPackFloatList(byte[] rg, DATA_FORMAT fmtExpected)
Unpack the byte array into a list of float values.
static byte[] Pack(List< double > rg, out DATA_FORMAT fmt)
Pack a list of double into a byte array.
The SimpleDatum class holds a data input within host memory.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...