当前位置: 首页>>代码示例>>C#>>正文


C# ILArray.Serialize方法代码示例

本文整理汇总了C#中ILArray.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.Serialize方法的具体用法?C# ILArray.Serialize怎么用?C# ILArray.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILArray的用法示例。


在下文中一共展示了ILArray.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Serialize

        public void Test_Serialize() {
            int errorCode = 0;
            try {
                double[] data = new double[1000 * 1000 * 10];
                String filename = "ILDoubleArray_SerializeTest1.ils";
                for (int i = 0; i < data.Length; i++)
                    data[i] = (double)i;
                ILArray<double> A = new ILArray<double>(data, 1000,1000,10);

                FileStream fs = new FileStream(filename, FileMode.Create);
                Info("Serializing to file: (please wait...)");
                A.Serialize(fs); 
                fs.Close();
                FileInfo fi = new FileInfo(filename);
                Info("Serialized to file: [1000 x 1000 x 10] => " + ((int)(fi.Length/1024)) + "kB");
                
                // create reference storage from smaler range -> should Detach()  
                errorCode = 1;
                filename = "ILDoubleArray_SerializeTest2.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR1 = (ILArray<double>)A[0,"0:600;30:400;0:end"];
                AR1.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [600 x 360 x 10] => " + ((int)(fi.Length / 1024)) + "kB");

                // if reference storage saved effective memory - keep it as reference
                errorCode = 2;
                filename = "ILDoubleArray_SerializeTest3.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR2 = (ILArray<double>)A[0,"0:end,0:end;0:end,0:end;0:end"];
                AR2.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [2000 x 2000 x 20] => " + ((int)(fi.Length / 1024)) + "kB");


                // test if small reference would NOT store full data array
                errorCode = 4;
                filename = "ILDoubleArray_SerializeTest4.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR3 = (ILArray<double>)A["3;3;1"];
                AR3.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [1 x 1] => " + ((int)(fi.Length / 1024)) + "kB");
                if (fi.Length > 1024 * 2)
                    throw new Exception("Small reference storages should get detached before serializing!");
                errorCode = 5;

                Success("Test_serialize successfull");
            } catch (SerializationException e) {
                Error("Test_serialize failed on ErrorCode: "+ errorCode +"due: " + e.Message);
            } catch (Exception e) {
                Error("Test_serialize failed on ErrorCode: " + errorCode + "due: " + e.Message);
            }
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:57,代码来源:TESTILNumericArray.cs


注:本文中的ILArray.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。