protected override void TransformCore(ref TInput input, FixedSizeQueue <TInput> windowedBuffer, long iteration, ref VBuffer <TInput> output)
            {
                int size   = _parentSliding.WindowSize - _parentSliding._lag + 1;
                var result = output.Values;

                if (Utils.Size(result) < size)
                {
                    result = new TInput[size];
                }

                if (_parentSliding._lag == 0)
                {
                    for (int i = 0; i < _parentSliding.WindowSize; ++i)
                    {
                        result[i] = windowedBuffer[i];
                    }
                    result[_parentSliding.WindowSize] = input;
                }
                else
                {
                    for (int i = 0; i < size; ++i)
                    {
                        result[i] = windowedBuffer[i];
                    }
                }
                output = new VBuffer <TInput>(size, result, output.Indices);
            }
            private protected override void SetNaOutput(ref VBuffer <TInput> output)
            {
                int size   = _parentSliding.WindowSize - _parentSliding._lag + 1;
                var result = VBufferEditor.Create(ref output, size);

                TInput value = _parentSliding._nanValue;

                switch (_parentSliding._begin)
                {
                case BeginOptions.NaNValues:
                    value = _parentSliding._nanValue;
                    break;

                case BeginOptions.FirstValue:
                    // REVIEW: will complete the implementation
                    // if the design looks good
                    throw new NotImplementedException();
                }

                for (int i = 0; i < size; ++i)
                {
                    result.Values[i] = value;
                }
                output = result.Commit();
            }
Esempio n. 3
0
 public QueueItem(TKey key, TInput input, QueueTransformAsync queueTransformAsync)
 {
     Key   = key;
     Input = input;
     QueueTransformAsync  = queueTransformAsync;
     TaskCompletionSource = new TaskCompletionSource <TOutput>();
 }
Esempio n. 4
0
            //---------------------------------------------------------------------------------------
            // Just walks the entire data source upon its first invocation, performing the per-
            // element action for each element.
            //

            internal override bool MoveNext([MaybeNullWhen(false), AllowNull] ref TInput currentElement, ref int currentKey)
            {
                Debug.Assert(_elementAction != null, "expected a compiled operator");

                // We just scroll through the enumerator and execute the action. Because we execute
                // "in place", we actually never even produce a single value.

                // Cancellation testing must be performed here as full enumeration occurs within this method.
                // We only need to throw a simple exception here.. marshalling logic handled via QueryTaskGroupState.QueryEnd (called by ForAllSpoolingTask)
                TInput?element   = default(TInput);
                TKey?  keyUnused = default(TKey);
                int    i         = 0;

                while (_source.MoveNext(ref element, ref keyUnused))
                {
                    if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();
                    }
                    ;
                    _elementAction(element);
                }

                return(false);
            }
            protected override void SetNaOutput(ref VBuffer <TInput> output)
            {
                int size   = _parentSliding.WindowSize - _parentSliding._lag + 1;
                var result = output.Values;

                if (Utils.Size(result) < size)
                {
                    result = new TInput[size];
                }

                TInput value = _parentSliding._nanValue;

                switch (_parentSliding._begin)
                {
                case BeginOptions.NaNValues:
                    value = _parentSliding._nanValue;
                    break;

                case BeginOptions.FirstValue:
                    // REVIEW: will complete the implementation
                    // if the design looks good
                    throw new NotImplementedException();
                }

                for (int i = 0; i < size; ++i)
                {
                    result[i] = value;
                }
                output = new VBuffer <TInput>(size, result, output.Indices);
            }
            public async Task <TOutput> ConvertAsync(TInput input)
            {
                var actionType = new TBaseType();
                var action     = actionType as IUpdatable <TBaseInterfaceType>;

                action.UpdateFrom((TBaseInterfaceType)input);
                return(await Task.FromResult(actionType));
            }
            public TOutput Convert(TInput input)
            {
                var actionType = new TBaseType();
                var action     = actionType as IUpdatable <TBaseInterfaceType>;

                action.UpdateFrom((TBaseInterfaceType)input);
                return(actionType);
            }
Esempio n. 8
0
 public LegacyInput()
 {
     m_mousePositionProp        = TInput.GetProperty("mousePosition");
     m_mouseDeltaProp           = TInput.GetProperty("mouseScrollDelta");
     m_getKeyMethod             = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
     m_getKeyDownMethod         = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
     m_getMouseButtonMethod     = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
     m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
 }
 public Operation(BackgroundProcessor <TInput, TOutput> processor, Task <TOutput> operation, TInput input, CancellationTokenSource tokenSource)
 {
     Processor            = processor;
     Task                 = operation;
     Input                = input;
     this.tokenSource     = tokenSource;
     ownerCount           = 1;
     primaryOwnerCanceled = 0;
 }
Esempio n. 10
0
 public void UpdateState(ref TInput input, long rowPosition, bool buffer = true)
 {
     if (rowPosition > PreviousPosition)
     {
         PreviousPosition = rowPosition;
         UpdateStateCore(ref input, buffer);
         Consume(input);
     }
 }
 internal ContainsSearchOperatorEnumerator(QueryOperatorEnumerator <TInput, TKey> source, TInput searchValue, IEqualityComparer <TInput> comparer, int partitionIndex, Shared <bool> resultFoundFlag, CancellationToken cancellationToken)
 {
     this.m_source            = source;
     this.m_searchValue       = searchValue;
     this.m_comparer          = comparer;
     this.m_partitionIndex    = partitionIndex;
     this.m_resultFoundFlag   = resultFoundFlag;
     this.m_cancellationToken = cancellationToken;
 }
Esempio n. 12
0
        public LegacyInput()
        {
            ExplorerCore.Log("Initializing Legacy Input support...");

            m_mousePositionProp        = TInput.GetProperty("mousePosition");
            m_getKeyMethod             = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
            m_getKeyDownMethod         = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
            m_getMouseButtonMethod     = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
            m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
        }
Esempio n. 13
0
            public override Terminator <TReduction> Invoke(TReduction reduction, TInput value)
            {
                var result = Next.Invoke(reduction, value);

                if (result.IsTerminated)
                {
                    return(result);
                }

                return(Loop.Invoke(reduction, value));
            }
Esempio n. 14
0
            internal override bool MoveNext(ref TOutput currentElement, ref TKey currentKey)
            {
                TInput local = default(TInput);

                if (this.m_source.MoveNext(ref local, ref currentKey))
                {
                    currentElement = this.m_selector(local);
                    return(true);
                }
                return(false);
            }
Esempio n. 15
0
        internal void ParallelCollectionItem_SetInputTest()
        {
            var item = Substitute.ForPartsOf <ParallelCollectionItem <TInput> >();

            var exptected = new TInput {
                Value = "correct value"
            };

            item.Input = exptected;

            Assert.True(((ICollectionItemInput)item).Input == Utils.SerializeToJSON(exptected));
        }
Esempio n. 16
0
        internal void ParallelActivityCollectionBase_SetInputTest()
        {
            var workflow = Substitute.ForPartsOf <ParallelWorkflowCollectionBase <TInput, TOutput> >(_domain, _workflowName, _version, _tasklistName, _amazonSwf);

            var exptected = new TInput {
                Value = "correct value"
            };

            workflow.Input = exptected;

            Assert.True(((IWorkflow)workflow).Input == Utils.SerializeToJSON(exptected));
        }
            public sealed override void TransformCore(ref TInput input, FixedSizeQueue <TInput> windowedBuffer, long iteration, ref VBuffer <double> dst)
            {
                var outputLength = Parent.OutputLength;

                var result = VBufferEditor.Create(ref dst, outputLength);

                result.Values.Fill(Double.NaN);

                SpectralResidual(input, windowedBuffer, ref result);

                dst = result.Commit();
            }
Esempio n. 18
0
        internal void ParallelActivityCollectionBase_SetInputTest()
        {
            var activity = Substitute.ForPartsOf <ParallelActivityCollectionBase <TInput, string, string, string> >("ActivityName", "TaskList");

            var exptected = new TInput {
                Value = "correct value"
            };

            activity.Input = exptected;

            Assert.True(((IActivity)activity).Input == Utils.SerializeToJSON(exptected));
        }
            private Action <long> MakePinger(DataViewRow input, AnomalyDetectionStateBase state)
            {
                _host.AssertValue(input);
                var           srcGetter = input.GetGetter <TInput>(input.Schema[_inputColumnIndex]);
                Action <long> pinger    = (long rowPosition) =>
                {
                    TInput src = default;
                    srcGetter(ref src);
                    state.UpdateState(ref src, rowPosition, _parent.WindowSize > 0);
                };

                return(pinger);
            }
Esempio n. 20
0
            private Action <long> MakePinger(Row input, TState state)
            {
                _host.AssertValue(input);
                var           srcGetter = input.GetGetter <TInput>(_inputColumnIndex);
                Action <long> pinger    = (long rowPosition) =>
                {
                    TInput src = default;
                    srcGetter(ref src);
                    state.UpdateState(ref src, rowPosition, _parent.WindowSize > 0);
                };

                return(pinger);
            }
Esempio n. 21
0
        public LegacyInput()
        {
            Implementation.Log("Initializing Legacy Input support...");

            m_mousePositionProp        = TInput.GetProperty("mousePosition");
            m_mouseScrollDeltaProp     = TInput.GetProperty("mouseScrollDelta");
            m_getKeyMethod             = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
            m_getKeyDownMethod         = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
            m_getKeyUpMethod           = TInput.GetMethod("GetKeyUp", new Type[] { typeof(KeyCode) });
            m_getMouseButtonMethod     = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
            m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
            m_getMouseButtonUpMethod   = TInput.GetMethod("GetMouseButtonUp", new Type[] { typeof(int) });
        }
Esempio n. 22
0
 public override Terminator <TReduction> Invoke(TReduction reduction, TInput value)
 {
     try
     {
         return(success.Invoke(reduction, value));
     }
     catch (TException exception)
     {
         return(exceptional.Invoke(
                    reduction,
                    new ExceptionalInput <TInput, TException>(value, exception)));
     }
 }
Esempio n. 23
0
        private static string BuildQuerySchema <TInput>()
        {
            TInput fieldWillBeReplacedSoDoNotUseIt_0A0A310123624BADA4F5CE81D5CAD0A446305CCCE73C2DD11E8CE1C45CB4DC26 = default(TInput);

            var gqlQuery     = new { fieldWillBeReplacedSoDoNotUseIt_0A0A310123624BADA4F5CE81D5CAD0A446305CCCE73C2DD11E8CE1C45CB4DC26 };
            var propertyInfo = gqlQuery.GetType().GetProperty("fieldWillBeReplacedSoDoNotUseIt_0A0A310123624BADA4F5CE81D5CAD0A446305CCCE73C2DD11E8CE1C45CB4DC26");

            var query = QueryBuilder(propertyInfo);

            query = query.Replace("fieldWillBeReplacedSoDoNotUseIt_0A0A310123624BADA4F5CE81D5CAD0A446305CCCE73C2DD11E8CE1C45CB4DC26", "");

            return(query);
        }
Esempio n. 24
0
            //---------------------------------------------------------------------------------------
            // This enumerates the entire input source to perform the search. If another peer
            // partition finds an answer before us, we will voluntarily return (propagating the
            // peer's result).
            //

            internal override bool MoveNext(ref bool currentElement, ref int currentKey)
            {
                Debug.Assert(_comparer != null);

                // Avoid enumerating if we've already found an answer.
                if (_resultFoundFlag.Value)
                {
                    return(false);
                }

                // We just scroll through the enumerator and accumulate the result.
                TInput element   = default(TInput) !;
                TKey   keyUnused = default(TKey) !;

                if (_source.MoveNext(ref element !, ref keyUnused))
                {
                    currentElement = false;
                    currentKey     = _partitionIndex;

                    // Continue walking the data so long as we haven't found an item that satisfies
                    // the condition we are searching for.
                    int i = 0;
                    do
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            _cancellationToken.ThrowIfCancellationRequested();
                        }
                        ;

                        if (_resultFoundFlag.Value)
                        {
                            // If cancellation occurred, it's because a successful answer was found.
                            return(false);
                        }

                        if (_comparer.Equals(element, _searchValue))
                        {
                            // We have found an item that satisfies the search. Cancel other
                            // workers that are concurrently searching, and return.
                            _resultFoundFlag.Value = true;
                            currentElement         = true;
                            break;
                        }
                    }while (_source.MoveNext(ref element !, ref keyUnused));

                    return(true);
                }

                return(false);
            }
Esempio n. 25
0
            //---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext(ref TOutput currentElement, ref TKey currentKey)
            {
                // So long as the source has a next element, we have an element.
                TInput element = default(TInput);

                if (_source.MoveNext(ref element, ref currentKey))
                {
                    Debug.Assert(_selector != null, "expected a compiled operator");
                    currentElement = _selector(element);
                    return(true);
                }

                return(false);
            }
Esempio n. 26
0
        /// <summary>
        ///Switch 的测试
        ///</summary>
        public void SwitchTest1Helper <TInput, TCase, TOther>()

            where TCase : IEquatable <T>
        {
            TInput t = default(TInput);
            Func <TInput, TCase> selector = null;
            Action <TOther>      action   = null;

            SwithCaseExtension.SwithCase <TCase, TOther> expected = null;
            SwithCaseExtension.SwithCase <TCase, TOther> actual;
            actual = SwithCaseExtension.Switch <TInput, TCase, TOther>(t, selector, action);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Esempio n. 27
0
        internal void ParallelActivityCollectionBase_GetInputTest()
        {
            var workflow = Substitute.ForPartsOf <ParallelWorkflowCollectionBase <TInput, TOutput> >(_domain, _workflowName, _version, _tasklistName, _amazonSwf);

            var exptected = new TInput {
                Value = "correct value"
            };

            ((IWorkflow)workflow).Input = Utils.SerializeToJSON(exptected);

            var result = workflow.Input;

            AssertObjectEquals.PropertyValuesAreEqual(result, exptected);
        }
            //---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext(ref TOutput currentElement, ref int currentKey)
            {
                // So long as the source has a next element, we have an element.
                TInput element = default(TInput);

                if (m_source.MoveNext(ref element, ref currentKey))
                {
                    Contract.Assert(m_selector != null, "expected a compiled selection function");
                    currentElement = m_selector(element, currentKey);
                    return(true);
                }

                return(false);
            }
            //---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext([MaybeNullWhen(false), AllowNull] ref TOutput currentElement, ref int currentKey)
            {
                // So long as the source has a next element, we have an element.
                TInput element = default(TInput) !;

                if (_source.MoveNext(ref element !, ref currentKey))
                {
                    Debug.Assert(_selector != null, "expected a compiled selection function");
                    currentElement = _selector(element, currentKey);
                    return(true);
                }

                return(false);
            }
Esempio n. 30
0
            //---------------------------------------------------------------------------------------
            // This enumerates the entire input source to perform the search. If another peer
            // partition finds an answer before us, we will voluntarily return (propagating the
            // peer's result).
            //

            internal override bool MoveNext(ref bool currentElement, ref int currentKey)
            {
                Contract.Assert(m_predicate != null);

                // Avoid enumerating if we've already found an answer.
                if (m_resultFoundFlag.Value)
                {
                    return(false);
                }

                // We just scroll through the enumerator and accumulate the result.
                TInput element   = default(TInput);
                TKey   keyUnused = default(TKey);

                if (m_source.MoveNext(ref element, ref keyUnused))
                {
                    currentElement = !m_qualification;
                    currentKey     = m_partitionIndex;

                    int i = 0;
                    // Continue walking the data so long as we haven't found an item that satisfies
                    // the condition we are searching for.
                    do
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(m_cancellationToken);
                        }

                        if (m_resultFoundFlag.Value)
                        {
                            // If cancelation occurred, it's because a successful answer was found.
                            return(false);
                        }

                        if (m_predicate(element) == m_qualification)
                        {
                            // We have found an item that satisfies the search. Tell other
                            // workers that are concurrently searching, and return.
                            m_resultFoundFlag.Value = true;
                            currentElement          = m_qualification;
                            break;
                        }
                    }while (m_source.MoveNext(ref element, ref keyUnused));

                    return(true);
                }

                return(false);
            }