private static void TestReadWrite(IKernelFunctionWithParams kf) { string typeName = kf.GetType().Name; string fn = typeName + ".txt"; // Write out the kernel StreamWriter sw = new StreamWriter(fn); kf.Write(sw); sw.Close(); // Now read it back again StreamReader sr = new StreamReader(fn); KernelFactory kfact = KernelFactory.Instance; IKernelFunctionWithParams kf1 = kfact.CreateKernelFunction(typeName); kf1.Read(sr); sr.Close(); // Now test that they're the same Assert.Equal(kf.ThetaCount, kf1.ThetaCount); for (int i = 0; i < kf.ThetaCount; i++) { Assert.Equal(kf[i], kf1[i], 1e-6); } }
/// <summary> /// Registers a kernel function. The factory is primed with stock /// kernel functions. This function allows clients to add in custom /// kernel functions /// </summary> /// <param name="ikf">Type instance</param> public void RegisterKernelFunction(IKernelFunctionWithParams ikf) { Type kfType = ikf.GetType(); string typeName = kfType.Name; if (creators.ContainsKey(typeName)) creators[typeName] = kfType; else creators.Add(typeName, kfType); }
/// <summary> /// Registers a kernel function. The factory is primed with stock /// kernel functions. This function allows clients to add in custom /// kernel functions /// </summary> /// <param name="ikf">Type instance</param> public void RegisterKernelFunction(IKernelFunctionWithParams ikf) { Type kfType = ikf.GetType(); string typeName = kfType.Name; if (creators.ContainsKey(typeName)) { creators[typeName] = kfType; } else { creators.Add(typeName, kfType); } }