public void SaveAndLoad_BasicDoc()
        {
            var doc = new BinaryVectorDocument();

            doc.Version = 1;
            doc.Properties["title"] = "abc";
            doc.Properties["value1"] = "12";
            //doc.Properties["null"] = null;

            doc.Vectors.Add(ColumnVector1D.Create(1.2, 7.4));
            doc.Vectors.Add(ColumnVector1D.Create(0.2, 3.9));
            doc.Vectors.Add(ColumnVector1D.Create(4.6, 5.1, 8.1));

            Console.WriteLine(doc.Checksum);

            using (var store = new InMemoryBlobStore())
            {
                store.Store("a", doc);

                var doc2 = store.Restore("a", new BinaryVectorDocument());

                Assert.That(doc2.Properties.Count, Is.EqualTo(2));
                Assert.That(doc2.Properties["title"], Is.EqualTo("abc"));
                Assert.That(doc2.Properties["value1"], Is.EqualTo("12"));
                //Assert.That(doc2.Properties["null"], Is.EqualTo(""));

                Assert.That(doc.Vectors[1][1], Is.EqualTo(3.9));
            }
        }
        public void SaveAndLoad_DocWithChildren()
        {
            var doc = new BinaryVectorDocument();

            doc.Version = 2;

            doc.Vectors.Add(ColumnVector1D.Create(1.2, 7.4));

            var doc1 = new BinaryVectorDocument();

            doc1.Vectors.Add(ColumnVector1D.Create(8.2432, 89.4));
            doc1.Vectors.Add(ColumnVector1D.Create(20, 0.14));

            doc.Children.Add(doc1);

            using (var store = new InMemoryBlobStore())
            {
                store.Store("a", doc);

                var doc2 = store.Restore("a", new BinaryVectorDocument());

                Assert.That(doc.Vectors[0][1], Is.EqualTo(7.4));
                Assert.That(doc.Children[0].Vectors[0][0], Is.EqualTo(8.2432));
                Assert.That(doc.Children[0].Vectors[1][1], Is.EqualTo(0.14));
            }
        }
Example #3
0
        public Task Send(IEnumerable<ColumnVector1D> data)
        {
            var doc = new BinaryVectorDocument();

            foreach (var d in data) doc.Vectors.Add(d);

            return SendBatch(doc, false);
        }
Example #4
0
        public async Task<Stream> Receive(object parameters = null)
        {
            var doc = new BinaryVectorDocument();

            foreach (var kv in ParamsToDict(parameters))
            {
                doc.Properties[kv.Key] = kv.Value;
            }

            var results = await SendBatch(doc, false, true);

            return results;
        }
        public void Checksum_ChangesWhenDataChanges()
        {
            var doc = new BinaryVectorDocument();

            doc.Version = 1;
            doc.Properties["title"] = "abc";

            var checksum1 = doc.Checksum;

            doc.Version = 2;

            var checksum2 = doc.Checksum;

            doc.Properties["title"] = "cba";

            var checksum3 = doc.Checksum;

            Assert.That(checksum1, Is.Not.EqualTo(checksum2));
            Assert.That(checksum2, Is.Not.EqualTo(checksum3));
        }
        private void WriteSummaryResponse(IRawClassifierTrainingContext<NetworkParameters> ctx, Stream response)
        {
            var summary = new BinaryVectorDocument();

            summary.Properties["RateOfErrorChange"] = ctx.RateOfErrorChange.GetValueOrDefault(1).ToString();
            summary.Properties["AverageError"] = ctx.AverageError.ToString();

            summary.Save(response);
        }
        private void Write(Stream response, Action<BinaryVectorDocument> writer)
        {
            var doc = new BinaryVectorDocument();

            writer(doc);

            doc.Save(response);
        }
        public void SetNullPropertyValue_ThrowsError()
        {
            var doc = new BinaryVectorDocument();

            Assert.Throws<ArgumentException>(() => doc.Properties["x"] = null);
        }
Example #9
0
 public Task Send(BinaryVectorDocument doc)
 {
     return SendBatch(doc, false);
 }
Example #10
0
        private async Task<Stream> SendBatch(BinaryVectorDocument doc, bool isLast, bool sendResponse = false)
        {
            {
                var transferDoc = new DataBatch();

                foreach (var prop in doc.Properties)
                {
                    transferDoc.Properties[prop.Key] = prop.Value;
                }

                foreach (var vec in doc.Vectors)
                {
                    transferDoc.Vectors.Add(vec);
                }

                foreach (var child in doc.Children)
                {
                    transferDoc.Children.Add(child);
                }

                transferDoc.Id = Id;
                transferDoc.ClientId = ClientId;
                transferDoc.BatchNum = (_batchIndex++);
                transferDoc.KeepAlive = !isLast;
                transferDoc.SendResponse = sendResponse;
                transferDoc.Path = Path;
                transferDoc.Verb = Verb;

                DebugOutput.Log("Sending batch {0}/{1}", Id, transferDoc.BatchNum);

                await Send(this, transferDoc, _compression);
            }

            return await ReceiveData(this, _compression);
        }