Пример #1
0
        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);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads the function parameters in from a stream
        /// </summary>
        /// <param name="sr">Stream reader</param>
        public override void Read(StreamReader sr)
        {
            string typeName = this.GetType().Name;
            string start    = "<" + typeName + ">";
            string end      = "</" + typeName + ">";


            KernelFactory kfact = KernelFactory.Instance;

            initialise();

            string str;

            str = sr.ReadLine();
            if (str != start)
            {
                throw new IOException("Unexpected section start");
            }

            // Version
            str = sr.ReadLine();
            int vers = int.Parse(str);

            // kernel count
            str = sr.ReadLine();
            int kcnt = int.Parse(str);

            // Cosntruct the kernels
            for (int i = 0; i < kcnt; i++)
            {
                str = sr.ReadLine();
                IKernelFunctionWithParams kf = kfact.CreateKernelFunction(str);
                kf.Read(sr);
                kernels.Add(kf);
            }
            // Build the maps
            buildMaps();

            // Read in the end marker
            str = sr.ReadLine();
            if (str != end)
            {
                throw new IOException("Unexpected section end");
            }
        }