/// <summary> /// Specifies that the arranged member will return consecutive values from the given array. /// If the arranged member is called after it has returned the last value, the behavior depends on the behavior parameter. /// </summary> /// <typeparam name="TReturn">Type of return value</typeparam> /// <param name="func">The arranged member</param> /// <param name="values">The list of values that will be returned by the arranged member. The list may be modified after the arrangement is made.</param> /// <param name="behavior">The behavior after the last value has been returned.</param> /// <returns>Reference to <see cref="IAssertable"/> interface.</returns> public static IAssertable ReturnsMany <TReturn>(this IFunc <TReturn> func, IList <TReturn> values, AfterLastValue behavior) { return(ProfilerInterceptor.GuardInternal(() => { if (values == null || values.Count == 0) { throw new ArgumentException("Expected at least one value to return", "values"); } Action <ReturnsManyImpl <TReturn> > afterEndAction = null; switch (behavior) { case AfterLastValue.ThrowAssertionFailed: afterEndAction = impl => MockingContext.Fail("List of arranged return values exhausted."); break; case AfterLastValue.KeepReturningLastValue: afterEndAction = impl => impl.CurrentIndex = values.Count - 1; break; case AfterLastValue.StartFromBeginning: afterEndAction = impl => impl.CurrentIndex = 0; break; default: throw new ArgumentException("behavior"); } return func.Returns(new ReturnsManyImpl <TReturn>(values, afterEndAction).GetNext); })); }
public void Load() { funcTypes.Clear(); Type[] types = DllHelper.GetMonoTypes(); foreach (var type in types) { object[] attrs = type.GetCustomAttributes(typeof(FuncHallAttribute), false); if (attrs.Length == 0) { continue; } FuncHallAttribute attribute = attrs[0] as FuncHallAttribute; if (funcTypes.ContainsKey(attribute.funcType)) { Log.Debug(string.Format("已经存在同类 IFunc : {0}", attribute.funcType)); throw new Exception(string.Format("已经存在同类IFunc : {0}", attribute.funcType)); } object o = Activator.CreateInstance(type); IFunc factory = o as IFunc; if (factory == null) { Log.Debug(string.Format("{0} 没有继承 ", o.GetType().FullName)); continue; } this.funcTypes.Add(attribute.funcType, factory); } ///默认显示Risk功能栏 CreateFunc(FuncType.Risk); }
public static void Invoke( IFunc <object, int> a, IFunc <object, double> b, IFunc <int, double> c) { __XEnumerable_GenericMethod.Sum(a); __XEnumerable_GenericMethod.Sum(b); __XEnumerable_GenericMethod.Sum(c); }
/// <summary> /// Construct a timeout cache, optionally with a cache timeout. /// </summary> public WeakCache(IFunc <T> getItem, int cacheTime = -1) { CacheTime = cacheTime; if (cacheTime == -1) { _updateTime = long.MaxValue; } _reference = new WeakReferencer <T>(getItem); }
/// <summary> /// Construct a new element link. /// </summary> public ElementLink(IFunc <Element> getElement, IAction <Element> onBuild = null, int cacheTime = -1) { _getElement = getElement; _cacheTime = cacheTime; _nextUpdate = Time.Milliseconds + _cacheTime; _onBuild = onBuild; _callbacks = new ArrayRig <IAction <Element> >(); _lock = new Lock(); _processing = false; }
/// <summary> /// Add or set an element to be retrieved using the specified method. The cache time is a number of /// milliseconds that the result of the 'retrieve' func can be cached for. /// </summary> public void Set(string key, IFunc <Element> retrieve, int cacheTime = -1, bool buildNow = true) { _lock.Take(); var link = _elements[key] = new ElementLink(retrieve, null, cacheTime); _lock.Release(); if (buildNow) { link.Build(); } }
public void CreateFunc(FuncType type) { if (curFuncType != type) { if (m_CurFunc != null) { m_CurFunc.RemoveFunc(); } m_CurFunc = funcTypes[type].CreateFunc(); m_CurFuncType = type; } }
public static double IterationSolve(IFunc func, double from, double to, int eps) { double x, prev; prev = x = from; do { prev = x; x = func.Xequals(prev); } while (Math.Round(x, eps) != Math.Round(prev, eps)); return(x); }
public static double NewtonSolve(IFunc func, double from, double to, int eps) { double x, prev; prev = x = from; do { prev = x; x = prev - func.Func(prev) / func.Deriv(prev); }while (Math.Round(x, eps) != Math.Round(prev, eps)); return(x); }
public IFunc <MyEnumerable <T>, MyEnumerable <U> > FMap <U>(IFunc <T, U> func) { return(new Function <MyEnumerable <T>, MyEnumerable <U> >(_t => { List <U> u = new List <U>(); foreach (T t in _t) { u.Add(func.Evaluate(t)); } return new MyEnumerable <U>(u); })); }
public IFunc <MyNullable <T>, MyNullable <U> > FMap <U>(IFunc <T, U> func) { return(new Function <MyNullable <T>, MyNullable <U> >(t => { if (t.HasValue) { return new MyNullable <U>(func.Evaluate(t.Value)); } else { return new MyNullable <U>(); } })); }
public DenseMatrix Cumulate(bool storeDerivative = false) { var inps = weightFuncOutputs.Select(kvPair => kvPair.Value); inputFuncOutput = IFunc.Apply(inps); if (storeDerivative) { foreach (var kvPair in weightFuncOutputs) { inputFuncDerivative[kvPair.Key] = IFunc.Differentiate(inputFuncOutput, kvPair.Value); } } return(inputFuncOutput); }
public Perceptron(double lerningRate, int inputAmount, IFunc fun, bool bias) { this.bias = bias; this.fun = fun; input = new double[inputAmount]; weight = new double[inputAmount + 1]; previousWeight = new double[inputAmount + 1]; this.inputAmount = inputAmount; for (int i = 0; i < inputAmount + 1; i++) { weight[i] = GRandom(-1, 1); } this.lerningRate = lerningRate; }
/// <summary> /// Add a child to the element builder to replace an existing id. /// </summary> public ElementBuilder ReplaceChild(string id, IFunc <Element> getElement, IAction <Element> onElement = null) { ElementBuilder builder; if (!SingleChildren.TryGetValue(id, out builder)) { _singleChildren.Add(id, builder = new ElementBuilder()); } builder.Action = BuilderAction.Replace; builder.GetElement = getElement; if (onElement != null) { builder._onBuilt = onElement; } return(builder); }
/// <summary> /// Add a child to the current element builder. /// </summary> public ElementBuilder AddChild(string id, IFunc <Element> getElement, IAction <Element> onElement = null) { ArrayRig <ElementBuilder> builders; if (!MultiChildren.TryGetValue(id, out builders)) { _multiChildren.Add(id, builders = new ArrayRig <ElementBuilder>()); } var builder = new ElementBuilder(); builders.Add(builder); builder.Action = BuilderAction.Add; builder.GetElement = getElement; if (onElement != null) { builder._onBuilt = onElement; } return(builder); }
public static EventHandler <TFrom> ToEventHandler <TFrom>(this IFunc <TFrom, Void> func) { return((obj, from) => func.Invoke(from)); }
/// <summary> /// Specifies that the arranged member will return consecutive values from the given array. /// If the arranged member is called after it has returned the last value, an exception is thrown. /// </summary> /// <typeparam name="TReturn">Type of the return value.</typeparam> /// <param name="func">The arranged member.</param> /// <param name="values">The array of values that will be returned by the arranged member.</param> /// <returns>Reference to <see cref="IAssertable"/> interface.</returns> public static IAssertable ReturnsMany <TReturn>(this IFunc <TReturn> func, params TReturn[] values) { return(ProfilerInterceptor.GuardInternal(() => ReturnsMany(func, values, AfterLastValue.KeepReturningLastValue))); }
public static void Func2(IFunc f) { Console.Write("ClasseA Func2 = "); f.Func1(); }
static public InfoSum Invoke(this IEnumerable <InfoFile> seqThe, IFunc <IEnumerable <InfoFile>, InfoSum> func) { return(func.Func(seqThe)); }
public void RegisterFunc(IFunc func) => Functions.Add(func.Name, func);
public ControlCompanion(T control, IFunc <T, string> readValue) { Control = control; this.readValue = readValue; }
public CopyPerc(double lerningRate, int inputAmount, IFunc fun, bool bias) : base(lerningRate, inputAmount, fun, bias) { }
public ControlCompanion(Control control, IFunc <Control, string> fetcher) { Control = control; this.fetcher = fetcher; }
/// <summary> /// Construct a new WeakReferencer with an initial item. /// </summary> public WeakReferencer(IFunc <T> getItem, T item) { GetItem = getItem; _item = new WeakReference <T>(item); _set = true; }
public ApplicativeA(IFunc <Number, Number> value) : base(value) { }
public static Action <TFrom> ToDelegate <TFrom>(this IFunc <TFrom, Void> func) { return(from => func.Invoke(from)); }
//-------------------------------------------// /// <summary> /// Construct a weak referencer with the function to refresh an item reference. /// </summary> public WeakReferencer(IFunc <T> getItem = null) { GetItem = getItem; _set = false; }
public static Predicate <TFrom> ToPredicate <TFrom>(this IFunc <TFrom, bool> func) { return(func.Invoke); }
/// <summary> /// Convenience function for more compact constructor. /// </summary> public WeakReferencer(Func <T> getItem) { GetItem = new FuncSet <T>(getItem); _set = false; }
public static Func <TTo> ToDelegate <TTo>(this IFunc <Void, TTo> func) { return(() => func.Invoke(Void.Instance)); }