コード例 #1
0
        public void EvalManagedConstantNetworkTest()
        {
            string modelDefinition = @"precision = ""float""
                traceLevel = 1
                run=NDLNetworkBuilder
                NDLNetworkBuilder=[
                v1 = Constant(1)
                v2 = Constant(2, tag=""output"")
                ol = Plus(v1, v2, tag=""output"")
                FeatureNodes = (v1)
                ]";

            using (var model = new ModelEvaluationExtendedF())
            {
                model.CreateNetwork(modelDefinition);

                VariableSchema outputSchema = model.GetOutputSchema();

                model.StartForwardEvaluation(outputSchema.Select(s => s.Name).ToList<string>());

                var outputBuffer = outputSchema.CreateBuffers<float>();
                var inputBuffer = new ValueBuffer<float>[0];

                // We can call the evaluate method and get back the results...
                model.ForwardPass(inputBuffer, outputBuffer);

                float[][] expected = { new float[] { 2 }, new float[] {3} };

                Assert.AreEqual(expected.Length, outputBuffer.Length);
                for (int idx = 0; idx < expected.Length; idx++)
                {
                    CollectionAssert.AreEqual(expected[idx], outputBuffer[idx].Buffer);
                }
            }
        }
コード例 #2
0
 public override EntityKey Create(IReadOnlyList <IProperty> properties, ValueBuffer valueBuffer)
 => Create(properties, p => valueBuffer[p.Index]);
コード例 #3
0
ファイル: QueryContext.cs プロジェクト: stevendarby/efcore
 public virtual InternalEntityEntry StartTracking(
     IEntityType entityType,
     object entity,
     ValueBuffer valueBuffer)
 // InitializeStateManager will populate the field before calling here
 => _stateManager !.StartTrackingFromQuery(entityType, entity, valueBuffer);
コード例 #4
0
            public TArray Build(MemoryAllocator allocator = default)
            {
                ValueOffsets.Append(Offset);

                var data = new ArrayData(DataType, ValueOffsets.Length - 1, 0, 0,
                                         new[] { ArrowBuffer.Empty, ValueOffsets.Build(allocator), ValueBuffer.Build(allocator) });

                return(Build(data));
            }
コード例 #5
0
 public TBuilder Resize(int length)
 {
     ValueOffsets.Resize(length + 1);
     ValueBuffer.Resize(length);
     return(Instance);
 }
コード例 #6
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual object?CreateFromBuffer(ValueBuffer valueBuffer)
 => _propertyAccessors.ValueBufferGetter !(valueBuffer);
コード例 #7
0
 public override InternalEntityEntry StartTrackingFromQuery(IEntityType baseEntityType, object entity, ValueBuffer valueBuffer, ISet <IForeignKey> handledForeignKeys)
 {
     if (entity is IEntity)
     {
         var context = _CurrentDatabase.Context.GetDynamicContext(baseEntityType.ClrType);
         ((IEntity)entity).EntityContext = context;
         return(null);
     }
     return(base.StartTrackingFromQuery(baseEntityType, entity, valueBuffer, handledForeignKeys));
 }
コード例 #8
0
        public void EvalManagedValuesBufferTest()
        {
            int bufferSize = 2;
            int colIndicesSize = 5;
            var vb = new ValueBuffer<float>(bufferSize);
            Assert.AreEqual(bufferSize, vb.Buffer.Length);
            Assert.IsNull(vb.Indices);
            Assert.IsNull(vb.ColIndices);

            vb = new ValueBuffer<float>(bufferSize, colIndicesSize);
            Assert.AreEqual(bufferSize, vb.Buffer.Length);
            Assert.AreEqual(bufferSize, vb.Indices.Length);
            Assert.AreEqual(colIndicesSize, vb.ColIndices.Length);
        }
コード例 #9
0
 public ValueBuffer Shape(ValueBuffer buffer)
 {
     return(ConvertBsonValuesToClrTypes(ReorderFields(buffer)));
 }
コード例 #10
0
 public virtual InternalEntityEntry StartTracking(
     IEntityType entityType,
     object entity,
     ValueBuffer valueBuffer)
 => StateManager.StartTrackingFromQuery(entityType, entity, valueBuffer);
コード例 #11
0
            public TArray Build(MemoryAllocator allocator = default)
            {
                ValueOffsets.Append(Offset);

                var validityBuffer = NullCount > 0
                                        ? ValidityBuffer.Build(allocator).ValueBuffer
                                        : ArrowBuffer.Empty;

                var data = new ArrayData(DataType, ValueOffsets.Length - 1, NullCount, 0,
                                         new[] { validityBuffer, ValueOffsets.Build(allocator), ValueBuffer.Build(allocator) });

                return(Build(data));
            }
コード例 #12
0
 public override TEntity Shape(QueryContext queryContext, ValueBuffer valueBuffer)
 => base.Shape(queryContext, valueBuffer.WithOffset(ValueBufferOffset));
コード例 #13
0
 public virtual EntityKey CreateEntityKey(ValueBuffer valueBuffer)
 {
     return(EntityKeyFactory.Create(EntityType, EntityKeyProperties, valueBuffer));
 }
コード例 #14
0
        public virtual IIncludeKeyComparer CreateIncludeKeyComparer(INavigation navigation, ValueBuffer valueBuffer)
        {
            if (navigation.IsDependentToPrincipal())
            {
                TKey keyValue;
                return(navigation.ForeignKey.GetDependentKeyValueFactory <TKey>().TryCreateFromBuffer(valueBuffer, out keyValue)
                    ? (IIncludeKeyComparer) new DependentToPrincipalIncludeComparer <TKey>(keyValue, PrincipalKeyValueFactory)
                    : new NullIncludeComparer());
            }

            return(new PrincipalToDependentIncludeComparer <TKey>(
                       (TKey)PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer),
                       navigation.ForeignKey.GetDependentKeyValueFactory <TKey>(),
                       PrincipalKeyValueFactory));
        }
コード例 #15
0
 private ValueBuffer ReorderFields(ValueBuffer buffer)
 {
     return(buffer);
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: CaffeineForCode/CNTK
        /// <summary>
        /// Evaluates an extended network (without a model and without input) and obtains a single layer output
        /// </summary>
        private static void EvaluateExtendedNetworkSingleLayerNoInput()
        {
            const string modelDefinition = @"precision = ""float"" 
                                     traceLevel = 1
                                     run=NDLNetworkBuilder
                                     NDLNetworkBuilder=[
                                     v1 = Constant(1)
                                     v2 = Constant(2, tag=""output"")
                                     ol = Plus(v1, v2, tag=""output"")
                                     FeatureNodes = (v1)
                                     ]";

            try
            {
                // The examples assume the executable is running from the data folder
                // We switch the current directory to the data folder (assuming the executable is in the <CNTK>/x64/Debug|Release folder
                string workingDirectory = Path.Combine(initialDirectory, @"..\..\Examples\Other\Simple2d\Config");
                Environment.CurrentDirectory = initialDirectory;

                using (var model = new ModelEvaluationExtendedF())
                {
                    // Create the network
                    // This network (AddOperatorConstantNoInput.cntk) is a simple network consisting of a single binary operator (Plus)
                    // operating over a two constants, therefore no input is necessary.
                    model.CreateNetwork(modelDefinition);

                    VariableSchema outputSchema = model.GetOutputSchema();

                    var outputNodeNames = outputSchema.Select(s => s.Name).ToList<string>();
                    model.StartForwardEvaluation(outputNodeNames);

                    var outputBuffer = outputSchema.CreateBuffers<float>();
                    var inputBuffer = new ValueBuffer<float>[0];

                    // We can call the evaluate method and get back the results...
                    model.ForwardPass(inputBuffer, outputBuffer);

                    // We expect two outputs: the v2 constant, and the ol Plus result
                    var expected = new float[][] { new float[] { 2 }, new float[] { 3 } };

                    Console.WriteLine("Expected values: {0}", string.Join(" - ", expected.Select(b => string.Join(", ", b)).ToList<string>()));
                    Console.WriteLine("Actual Values  : {0}", string.Join(" - ", outputBuffer.Select(b => string.Join(", ", b.Buffer)).ToList<string>()));
                }
            }
            catch (CNTKException ex)
            {
                Console.WriteLine("Error: {0}\nNative CallStack: {1}\n Inner Exception: {2}", ex.Message, ex.NativeCallStack, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}\nCallStack: {1}\n Inner Exception: {2}", ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }
        }
コード例 #17
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual IProperty FindNullPropertyInValueBuffer(ValueBuffer valueBuffer)
 => _property;
コード例 #18
0
 public virtual bool ShouldInclude(ValueBuffer valueBuffer)
 => _equalityComparer.Equals(
     (TKey)_principalKeyValueFactory.CreateFromBuffer(valueBuffer),
     _dependentKeyValue);
コード例 #19
0
 public Builder Clear()
 {
     ValueBuffer.Clear();
     Length = 0;
     return(this);
 }
コード例 #20
0
 public TResult Shape(QueryContext queryContext, ValueBuffer valueBuffer)
 => _materializer(
     _outerShaper.Shape(queryContext, valueBuffer),
     _innerShaper.Shape(queryContext, valueBuffer));
コード例 #21
0
 public abstract EntityKey Create(
     [NotNull] IEntityType entityType,
     [NotNull] IReadOnlyList <IProperty> properties,
     ValueBuffer valueBuffer);
コード例 #22
0
 public TBuilder Reserve(int capacity)
 {
     ValueOffsets.Reserve(capacity + 1);
     ValueBuffer.Reserve(capacity);
     return(Instance);
 }
コード例 #23
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual InternalEntityEntry TryGetEntry(IKey key, ValueBuffer valueBuffer, bool throwOnNullKey)
 => GetOrCreateIdentityMap(key).TryGetEntry(valueBuffer, throwOnNullKey);
コード例 #24
0
 public TBuilder Clear()
 {
     ValueOffsets.Clear();
     ValueBuffer.Clear();
     return(Instance);
 }
コード例 #25
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual object CreateFromBuffer(ValueBuffer valueBuffer)
 => TryCreateFromBuffer(valueBuffer, out var values) ? values : null;
コード例 #26
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual bool TryCreateFromBuffer(ValueBuffer valueBuffer, out TKey key)
 {
     key = (TKey)_propertyAccessors.ValueBufferGetter(valueBuffer);
     return(key != null);
 }
コード例 #27
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual IProperty FindNullPropertyInValueBuffer(ValueBuffer valueBuffer)
 => Properties.FirstOrDefault(p => valueBuffer[p.GetIndex()] == null);
コード例 #28
0
ファイル: EntityFinder.cs プロジェクト: takuya1981/efcore
        private static Expression <Func <object, bool> > BuildObjectLambda(IReadOnlyList <IProperty> keyProperties, ValueBuffer keyValues)
        {
            var entityParameter = Expression.Parameter(typeof(object), "e");

            return(Expression.Lambda <Func <object, bool> >(
                       BuildPredicate(keyProperties, keyValues, entityParameter), entityParameter));
        }
コード例 #29
0
 public virtual bool ShouldInclude(ValueBuffer valueBuffer) => false;
コード例 #30
0
 public virtual void Add(ValueBuffer valueBuffer, object entity)
 => _identityMap[(TKey)PrincipalKeyValueFactory.CreateFromBuffer(valueBuffer)] = new WeakReference <object>(entity);
コード例 #31
0
        public AbstraXProviderInternalEntityEntry(object entity, IStateManager stateManager, IEntityType entityType, ValueBuffer valueBuffer = default(ValueBuffer)) : base(stateManager, entityType)
        {
            this.Entity      = entity;
            this.ValueBuffer = valueBuffer;

            EnsureOriginalValues();
        }
コード例 #32
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public virtual bool ShouldInclude(ValueBuffer valueBuffer)
 => _dependentKeyValueFactory.TryCreateFromBuffer(valueBuffer, out var key) &&
 _equalityComparer.Equals(key, _principalKeyValue);
コード例 #33
0
 public virtual InternalEntityEntry Create(IStateManager stateManager, IEntityType entityType, object entity, ValueBuffer valueBuffer)
 => NewInternalEntityEntry(stateManager, entityType, entity, valueBuffer);
コード例 #34
0
ファイル: Program.cs プロジェクト: Microsoft/CNTK
        /// <summary>
        /// Evaluates an extended network (without a model and without input) and obtains a single layer output
        /// </summary>
        private static void EvaluateExtendedNetworkSingleLayerNoInput()
        {
            const string modelDefinition = @"precision = ""float""
                                     traceLevel = 1
                                     run=NDLNetworkBuilder
                                     NDLNetworkBuilder=[
                                     v1 = Constant(1)
                                     v2 = Constant(2, tag=""output"")
                                     ol = Plus(v1, v2, tag=""output"")
                                     FeatureNodes = (v1)
                                     ]";

            try
            {
                using (var model = new ModelEvaluationExtendedF())
                {
                    // Create the network
                    model.CreateNetwork(modelDefinition);

                    VariableSchema outputSchema = model.GetOutputSchema();

                    var outputNodeNames = outputSchema.Select(s => s.Name).ToList<string>();
                    model.StartForwardEvaluation(outputNodeNames);

                    var outputBuffer = outputSchema.CreateBuffers<float>();
                    var inputBuffer = new ValueBuffer<float>[0];

                    // We can call the evaluate method and get back the results...
                    model.ForwardPass(inputBuffer, outputBuffer);

                    // We expect two outputs: the v2 constant, and the ol Plus result
                    var expected = new float[][] { new float[] { 2 }, new float[] { 3 } };

                    Console.WriteLine("Expected values: {0}", string.Join(" - ", expected.Select(b => string.Join(", ", b)).ToList<string>()));
                    Console.WriteLine("Actual Values  : {0}", string.Join(" - ", outputBuffer.Select(b => string.Join(", ", b.Buffer)).ToList<string>()));
                }
            }
            catch (CNTKException ex)
            {
                OnCNTKException(ex);
            }
            catch (Exception ex)
            {
                OnGeneralException(ex);
            }
        }
コード例 #35
0
ファイル: ArduinoListener.cs プロジェクト: StarGate01/SAS2
 public ArduinoListener(string portName, int baud)
 {
     LastState = new ValueBuffer()
     {
         DigitalPins = new bool[14],
         AnalogPins = new decimal[6]
     };
     CommandQueue = new Queue<ArduinoCommand>();
     ListeningThreadCancelToken = new CancellationTokenSource();
     SPort = new SerialPort(portName);
     SPort.BaudRate = baud;
     SPort.DataReceived += SPort_DataReceived;
     SPort.Open();
     ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object cToken)
     {
         CancellationToken token = (CancellationToken)cToken;
         while (!token.IsCancellationRequested)
         {
             lock (WriteMonitor)
             {
                 WaitsForACK = true;
                 SPort.Write(new byte[] { 0x42 }, 0, 1);
                 waitACKHandle.WaitOne();
                 if (!token.IsCancellationRequested)
                 {
                     WaitsForACK = false;
                     byte[] binaryCommand;
                     if (CommandQueue.Count > 0)
                     {
                         binaryCommand = new byte[3];
                         WaitsForPollData = false;
                         ArduinoCommand command = CommandQueue.Dequeue();
                         switch (command.Command)
                         {
                             case "setup":
                                 binaryCommand[0] = 0x01;
                                 break;
                             case "change_d":
                                 binaryCommand[0] = 0x02;
                                 break;
                             case "change_a":
                                 binaryCommand[0] = 0x03;
                                 break;
                             case "reset_all":
                                 binaryCommand[0] = 0x04;
                                 break;
                         }
                         binaryCommand[1] = command.PinNumber;
                         binaryCommand[2] = command.Parameter;
                     }
                     else
                     {
                         binaryCommand = new byte[] { 0x00, 0x00, 0x00 };
                         WaitsForPollData = true;
                         LastPollData = new byte[14];
                         LastPollDataPosition = 0;
                     }
                     SPort.Write(binaryCommand, 0, binaryCommand.Length);
                     waitOKHandle.WaitOne();
                     if (!token.IsCancellationRequested)
                     {
                         if (WaitsForPollData)
                         {
                             for (var i = 0; i < 8; i++) LastState.DigitalPins[i] = (LastPollData[0] & (1 << i - 1)) != 0;
                             for (var i = 0; i < 6; i++) LastState.DigitalPins[i + 8] = (LastPollData[1] & (1 << i - 1)) != 0;
                             for (var i = 0; i < 6; i++)
                             {
                                 int value = 256 * LastPollData[2 + (i * 2)] + LastPollData[3 + (i * 2)];
                                 LastState.AnalogPins[i] = value * 100m / 1023m;
                             }
                         }
                     }
                 }
             }
         }
     }), ListeningThreadCancelToken.Token);
 }