Exemplo n.º 1
0
        public IReadOnlyList <ExecutionResult> ExecuteSequential(IReadOnlyList <float[]> input)
        {
            _lap.PushLayer();
            var ret = new List <ExecutionResult>();

            _dataSource = new SequentialRowDataSource(input);
            var provider = new MiniBatchProvider(_dataSource, false);

            using (var executionContext = new ExecutionContext(_lap)) {
                executionContext.Add(provider.GetMiniBatches(1, mb => _Execute(executionContext, mb)));

                IGraphOperation operation;
                while ((operation = executionContext.GetNextOperation()) != null)
                {
                    _lap.PushLayer();
                    operation.Execute(executionContext);
                    ret.AddRange(_GetResults());
                    _ClearContextList();
                    _lap.PopLayer();
                }
            }
            _lap.PopLayer();
            _dataSource = null;
            return(ret);
        }
Exemplo n.º 2
0
        public ExecutionResult Execute(float[] input)
        {
            _lap.PushLayer();
            ExecutionResult ret = null;

            _dataSource = new SingleRowDataSource(input, false, MiniBatchSequenceType.Standard, 0);
            var provider = new MiniBatchProvider(_dataSource, false);

            using (var executionContext = new ExecutionContext(_lap)) {
                executionContext.Add(provider.GetMiniBatches(1, mb => _Execute(executionContext, mb)));

                IGraphOperation operation;
                while ((operation = executionContext.GetNextOperation()) != null)
                {
                    _lap.PushLayer();
                    operation.Execute(executionContext);
                    ret = _GetResults().Single();
                    _ClearContextList();
                    _lap.PopLayer();
                }
            }
            _lap.PopLayer();
            _dataSource = null;
            return(ret);
        }
Exemplo n.º 3
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new Exception($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }
        public static void TestVariableArithmetic()
        {
            var context = new ExecutionContext(new Python3Calculator());
            var foo = new Variable("foo", context);
            var bar = new Variable("bar", context);

            context.Assign(foo, new Literal(3));
            context.Assign(bar, new Literal(5.0f));

            AssertEquals(context.Add(foo, bar).AsValue(), 8.0f);
            AssertEquals(context.Add(bar, foo).AsValue(), 8.0f);

            AssertEquals(context.Subtract(foo, bar).AsValue(), -2.0f);
            AssertEquals(context.Subtract(bar, foo).AsValue(), 2.0f);

            AssertEquals(context.Multiply(foo, bar).AsValue(), 15.0f);
            AssertEquals(context.Multiply(bar, foo).AsValue(), 15.0f);

            AssertEquals(context.Divide(foo, bar).AsValue(), 3 / 5.0f);
            AssertEquals(context.Divide(bar, foo).AsValue(), 5.0f / 3);

            AssertEquals(context.Mod(foo, bar).AsValue(), 3.0f);
            AssertEquals(context.Mod(bar, foo).AsValue(), 2.0f);
        }