本文整理汇总了C#中System.Function类的典型用法代码示例。如果您正苦于以下问题:C# Function类的具体用法?C# Function怎么用?C# Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于System命名空间,在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JakobiMatrix
public static Matrix JakobiMatrix(Vector x, Function[] f, double precision)
{
if ((f.Length > 0) && (x.Length > 0) && (precision > 0))
{
Matrix J = new Matrix(f.Length, x.Length);
Vector temp = x.Clone() as Vector;
for (int counter1 = 0; counter1 < J.Height; counter1++)
{
for (int counter2 = 0; counter2 < J.Width; counter2++)
{
temp[counter2] += precision;
J[counter1][counter2] = (f[counter1](temp) - f[counter1](x)) / precision;
temp[counter2] -= precision;
}
}
return J;
}
else
{
throw new IncorrectIncomingDataException("Dimensions of delegates or vectors or precision are incorrect.");
}
}
示例2: VerificationException
/// <summary>
/// Creates a new verification exception
/// </summary>
/// <param name="message">The message</param>
/// <param name="function">The function being verified</param>
/// <param name="instruction">The instruction being verified</param>
/// <param name="index">The index of the instruction</param>
public VerificationException(string message, Function function, Instruction instruction, int index)
: base($"{index}: {message}")
{
this.Function = function;
this.Instruction = instruction;
this.InstructionIndex = index;
}
示例3: BuildDeclarations
private static void BuildDeclarations(Namespace @namespace, IEnumerable<Declarations.Declaration> declarations)
{
foreach(var declaration in declarations)
declaration.Match()
.With<NamespaceDeclaration>(ns =>
{
var childNamespace = new Namespace(ns.Syntax, @namespace, ns.Name);
@namespace.Add(childNamespace);
BuildDeclarations(childNamespace, ns.Members);
})
.With<ClassDeclaration>(@classDecl =>
{
var syntax = @classDecl.Syntax.Single(); // TODO handle partial classes
var @class = new Class(syntax, @namespace, syntax.Accessibility, @classDecl.Name);
@namespace.Add(@class);
})
.With<FunctionDeclaration>(@functionDeclaration =>
{
var syntax = @functionDeclaration.Syntax.Single(); // TODO handle overloads
var function = new Function(syntax, @namespace, syntax.Accessibility, @functionDeclaration.Name);
@namespace.Add(function);
})
// TODO handle ambigouous declarations
.Exhaustive();
}
示例4: FixGetterSetter
public static void FixGetterSetter(this Type type)
{
var methods = type.GetInstanceMethodNames();
foreach(string methname in methods)
{
if(methname.StartsWith("get_"))
{
string propname = methname.Substring(4);
bool has_setter = methods.Contains("set_"+propname);
Function fget = new Function("",string.Format("return this.get_{0}();",propname));
Function fset = new Function("value",string.Format("this.set_{0}(value);",propname));
if(has_setter)
{
defineprop(type, propname,fget,fset);
}
else
{
definepropreadonly(type, propname, fget);
}
}
}
}
示例5: FunctionInliner
public FunctionInliner(Function root)
{
_root = root;
_funStack.Push(root);
_sim = new ScopedIdentifierManager(true);
_locals = new CacheDictionary<Tuple<Function, IStorableLiteral>, IStorableLiteral>(CreateLocal);
}
示例6: Call
private Ref Call(Function function)
{
try
{
foreach(var statement in function.Body)
{
var returnValue = Execute(statement);
if(returnValue != null)
// TODO check that the reference ownership and mutablilty match the return type
// TODO constrain value to return type
// TODO constrain integer values to bits of return type
return returnValue;
}
// Reached end without return
if(function.ReturnType.Type is VoidType)
return voidReference.Borrow();
throw new InterpreterPanicException("Reached end of function without returning value");
}
catch(InterpreterPanicException ex)
{
ex.AddCallStack(function.QualifiedName());
throw;
}
}
示例7: TestInvalidMain
public void TestInvalidMain()
{
using (var container = new Win64Container())
{
var intType = container.VirtualMachine.TypeProvider.GetPrimitiveType(PrimitiveTypes.Int);
var mainFunc = new Function(
new FunctionDefinition("main", new List<VMType>() { intType }, intType),
new List<Instruction>()
{
new Instruction(OpCodes.LoadInt, 0),
new Instruction(OpCodes.Ret)
},
new List<VMType>());
try
{
container.LoadAssembly(Assembly.SingleFunction(mainFunc));
Assert.Fail("Expected invalid main to not pass.");
}
catch (Exception e)
{
Assert.AreEqual("Expected the main function to have the signature: 'main() Int'.", e.Message);
}
}
}
示例8: Window
///
/// <summary> * Create a window function for a given sample size. This preallocates
/// * resources appropriate to that block size.
/// * </summary>
/// * <param name="size"> The number of samples in a block that we will
/// * be asked to transform. </param>
/// * <param name="function"> The window function to use. Function.RECTANGULAR
/// * effectively means no transformation. </param>
///
public Window(int size, Function function)
{
blockSize = size;
// Create the window function as an array, so we do the
// calculations once only. For RECTANGULAR, leave the kernel as
// null, signalling no transformation.
kernel = function == Function.RECTANGULAR ? null : new double[size];
switch (function)
{
case Function.RECTANGULAR:
// Nothing to do.
break;
case Function.BLACKMAN_HARRIS:
makeBlackmanHarris(kernel, size);
break;
case Function.GAUSS:
makeGauss(kernel, size);
break;
case Function.WEEDON_GAUSS:
makeWeedonGauss(kernel, size);
break;
}
}
示例9: CreateFunctionImportMappingCommand
internal CreateFunctionImportMappingCommand(EntityContainerMapping em, Function function, string createFuncImpCmdId)
: base(PrereqId)
{
ContainerMapping = em;
Function = function;
_createFuncImpCmdId = createFuncImpCmdId;
}
示例10: CreateSimpleFunction
//TODO: get this near functiontest. This is not a general function.
public static IFunction CreateSimpleFunction(IFunctionStore store)
{
var function = new Function("test");
store.Functions.Add(function);
// initialize schema
IVariable x = new Variable<double>("x", 3);
IVariable y = new Variable<double>("y", 2);
IVariable f1 = new Variable<double>("f1");
function.Arguments.Add(x);
function.Arguments.Add(y);
function.Components.Add(f1);
// write some data
var xValues = new double[] {0, 1, 2};
var yValues = new double[] {0, 1};
var fValues = new double[] {100, 101, 102, 103, 104, 105};
function.SetValues(fValues,
new VariableValueFilter<double>(x, xValues),
new VariableValueFilter<double>(y, yValues),
new ComponentFilter(f1));
return function;
}
示例11: EventBubbleCorerctlyForFunctionWithReducedArgument
[Category(TestCategory.Jira)] //TOOLS-4934
public void EventBubbleCorerctlyForFunctionWithReducedArgument()
{
IFunction function = new Function
{
Arguments = {new Variable<int>("x1"), new Variable<int>("x2")},
Components = {new Variable<int>("f")}
};
function[0, 1] = new[] {1};
function[0, 2] = new[] {2};
function[1, 1] = new[] {3};
function[1, 2] = new[] {4};
var arg1 = function.Arguments[0];
var filteredFunction = function.Filter(new VariableValueFilter<int>(arg1, 0), new VariableReduceFilter(arg1));
int called = 0;
filteredFunction.ValuesChanged += (s, e) => called++;
function[0, 2] = 3; //set value
Assert.AreEqual(1, called);
}
示例12: ClassifyOperator
public static CXXOperatorArity ClassifyOperator(Function function)
{
if (function.Parameters.Count == 1)
return CXXOperatorArity.Unary;
return CXXOperatorArity.Binary;
}
示例13: CheckDefaultParametersForAmbiguity
private static bool CheckDefaultParametersForAmbiguity(Function function, Function overload)
{
var commonParameters = Math.Min(function.Parameters.Count, overload.Parameters.Count);
var i = 0;
for (; i < commonParameters; ++i)
{
var funcParam = function.Parameters[i];
var overloadParam = overload.Parameters[i];
if (!funcParam.QualifiedType.Equals(overloadParam.QualifiedType))
return false;
}
for (; i < function.Parameters.Count; ++i)
{
var funcParam = function.Parameters[i];
if (!funcParam.HasDefaultValue)
return false;
}
for (; i < overload.Parameters.Count; ++i)
{
var overloadParam = overload.Parameters[i];
if (!overloadParam.HasDefaultValue)
return false;
}
if (function.Parameters.Count > overload.Parameters.Count)
overload.ExplicitlyIgnore();
else
function.ExplicitlyIgnore();
return true;
}
示例14: WriteFunctionTitle
protected void WriteFunctionTitle( StreamWriter stream, Function function )
{
stream.Write( "//-----------------------------------------------------------------------------" );
stream.WriteLine( "// Function Name: " + function.Name );
stream.WriteLine( "//Function Desc: " + function.Description );
stream.WriteLine( "//-----------------------------------------------------------------------------" );
}
示例15: invokeInternal
/**
* Formats nicer error messages for the junit output
*/
private static double invokeInternal(Function target, ValueEval[] args, int srcCellRow, int srcCellCol)
{
ValueEval EvalResult = null;
try
{
EvalResult = target.Evaluate(args, srcCellRow, (short)srcCellCol);
}
catch (NotImplementedException e)
{
throw new NumericEvalEx("Not implemented:" + e.Message);
}
if (EvalResult == null)
{
throw new NumericEvalEx("Result object was null");
}
if (EvalResult is ErrorEval)
{
ErrorEval ee = (ErrorEval)EvalResult;
throw new NumericEvalEx(formatErrorMessage(ee));
}
if (!(EvalResult is NumericValueEval))
{
throw new NumericEvalEx("Result object type (" + EvalResult.GetType().Name
+ ") is invalid. Expected implementor of ("
+ typeof(NumericValueEval).Name + ")");
}
NumericValueEval result = (NumericValueEval)EvalResult;
return result.NumberValue;
}