public TapeElement Visit(ConstPower intPower) { return(Compile(intPower, () => { var baseElement = intPower.Base.Accept(this); var element = new Compiled.ConstPower { Exponent = intPower.Exponent, Inputs = MakeInputEdges(() => { edges.Add(new InputEdge { Element = baseElement }); }), }; return element; })); }
public int Visit(ConstPower intPower) { return(Compile(intPower, () => { var baseIndex = intPower.Base.Accept(this); var element = new Compiled.ConstPower { Base = baseIndex, Exponent = intPower.Exponent, Inputs = new Compiled.InputEdge[] { new Compiled.InputEdge { Index = baseIndex }, }, }; return element; })); }
/// <summary> /// Initializes a new instance of the <see cref="CompiledDifferentiator"/> class. /// </summary> /// <param name="function">The function.</param> /// <param name="variables">The variables.</param> public CompiledDifferentiator(Term function, T variables) { Contract.Requires(function != null); Contract.Requires(variables != null); Contract.Requires(Contract.ForAll(variables, variable => variable != null)); Contract.Ensures(Dimension == variables.Count); if (function is Variable) { function = new ConstPower(function, 1); } var tapeList = new List <Compiled.TapeElement>(); new Compiler(variables, tapeList).Compile(function); tape = tapeList.ToArray(); Dimension = variables.Count; Variables = new ReadOnlyCollection <Variable>(variables); }
/// <summary> /// Initializes a new instance of the <see cref="CompiledDifferentiator"/> class. /// </summary> /// <param name="function">The function.</param> /// <param name="variables">The variables.</param> public CompiledDifferentiator(Term function, Variable[] variables) { /* * Contract.Requires(function != null); * Contract.Requires(variables != null); * Contract.Requires(Contract.ForAll(variables, variable => variable != null)); * Contract.Ensures(Dimension == variables.Length); */ if (function is Variable) { function = new ConstPower(function, 1); } var tapeList = new List <Compiled.TapeElement>(); new Compiler(variables, tapeList).Compile(function); tape = tapeList.ToArray(); Dimension = variables.Length; Variables = Array.AsReadOnly(variables); }