• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SparseArray类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SparseArray的典型用法代码示例。如果您正苦于以下问题:C# SparseArray类的具体用法?C# SparseArray怎么用?C# SparseArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SparseArray类属于命名空间,在下文中一共展示了SparseArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SparseArraySimpleTest

        public void SparseArraySimpleTest()
        {
            var stringArrayRef = new string[1000];
            var stringArray = new SparseArray<string>(1000);

            var randomGenerator = new RandomGenerator(66707770); // make this deterministic
            for (int idx = 0; idx < 1000; idx++)
            {
                if (randomGenerator.Generate(2.0) > 1)
                { // add data.
                    stringArrayRef[idx] = idx.ToString();
                    stringArray[idx] = idx.ToString();
                }
                else
                {
                    stringArrayRef[idx] = null;
                    stringArray[idx] = null;
                }
            }

            for (int idx = 0; idx < 1000; idx++)
            {
                Assert.AreEqual(stringArrayRef[idx], stringArray[idx]);
            }
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:25,代码来源:SparseArrayTests.cs


示例2: Generate

        public void Generate(SparseArray<float> production, SparseArray<float> attractions)
        {
            var ages = this.Root.Demographics.AgeRates;
            var studentRates = this.Root.Demographics.SchoolRates.GetFlatData();
            var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
            var prod = production.GetFlatData();

            for ( int i = 0; i < zones.Length; i++ )
            {
                // this is only null for externals
                var studentRatesForZone = studentRates[i];
                if ( studentRatesForZone == null )
                {
                    // if it is an external ignore
                    prod[i] = 0f;
                }
                else
                {
                    // otherwise compute the production
                    var pd = zones[i].PlanningDistrict;
                    prod[i] = zones[i].Population * ages[zones[i].ZoneNumber, this.Age] * studentRatesForZone[this.Age, 0] *
                        StudentDailyRates[pd, 0, this.Age] * StudentTimeOfDayRates[pd, 0, this.Age];
                }
            }

            SaveProductionToDisk( zones, prod );
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:SchoolGeneration.cs


示例3: Generate

        public override void Generate(SparseArray<float> production, SparseArray<float> attractions)
        {
            if(LoadData)
            {
                LoadExternalWorkerRates.LoadData();
                LoadWorkAtHomeRates.LoadData();
                LoadExternalJobsRates.LoadData();
                ExternalRates = LoadExternalWorkerRates.GiveData();
                WorkAtHomeRates = LoadWorkAtHomeRates.GiveData();
                ExternalRates = LoadExternalJobsRates.GiveData();
            }
            var flatProduction = production.GetFlatData();
            var flatWah = new float[flatProduction.Length];
            var totalProduction = ComputeProduction(flatProduction, flatWah);
            var totalAttraction = ComputeAttraction(attractions.GetFlatData());

            Normalize(production.GetFlatData(), attractions.GetFlatData(), totalProduction, totalAttraction);
            totalAttraction = RemoveWAHFromAttraction(attractions.GetFlatData(), flatWah);
            StoreProductionData(production);
            WriteGenerationFile(totalProduction, totalAttraction);
            WriteAttractionFile(attractions);
            if(LoadData)
            {
                LoadExternalWorkerRates.UnloadData();
                LoadWorkAtHomeRates.UnloadData();
                LoadExternalJobsRates.UnloadData();
                WorkAtHomeRates = null;
                ExternalRates = null;
                ExternalJobs = null;
            }
        }
开发者ID:dianatle,项目名称:XTMF,代码行数:31,代码来源:PoRPoWGeneration.cs


示例4: Generate

        public override void Generate(SparseArray<float> production, SparseArray<float> attractions)
        {
            if ( LoadData )
            {
                if ( DailyRates == null )
                {
                    this.LoadDailyRates.LoadData();
                    this.DailyRates = this.LoadDailyRates.GiveData();
                }
                if ( TimeOfDayRates == null )
                {
                    this.LoadTimeOfDayRates.LoadData();
                    this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData();
                }
            }
            var flatProduction = production.GetFlatData();
            var numberOfIndexes = flatProduction.Length;

            // Compute the Production
            ComputeProduction( flatProduction, numberOfIndexes );
            float totalProduction = flatProduction.Sum();
            WriteGenerationCSV( totalProduction );
            //The PoRPoS Model does NOT include having an attraction component.  The distribution will handle this case.
            if ( LoadData )
            {
                this.DailyRates = null;
                this.TimeOfDayRates = null;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:29,代码来源:PoRPoSGeneration.cs


示例5: Run

        public override void Run()
        {
            var numberOfCategories = this.Categories.Count;
            SparseArray<float>[] O = new SparseArray<float>[numberOfCategories];
            SparseArray<float>[] D = new SparseArray<float>[numberOfCategories];

            Generation = true;
            for ( int i = 0; i < numberOfCategories; i++ )
            {
                O[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
                D[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
                this.Categories[i].Generate( O[i], D[i] );
            }
            Generation = false;

            var modeSplit = this.ModeSplit.ModeSplit( this.Distribution.Distribute( O, D, this.Categories ), this.Categories.Count );
            if ( this.Transpose )
            {
                TransposeMatrix( modeSplit );
            }
            if ( this.SaveOutput )
            {
                if ( !Directory.Exists( this.PurposeName ) )
                {
                    Directory.CreateDirectory( this.PurposeName );
                }
                for ( int i = 0; i < modeSplit.Count; i++ )
                {
                    this.WriteModeSplit( modeSplit[i], this.Root.Modes[i], this.PurposeName );
                }
            }
            this.Flows = modeSplit;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:33,代码来源:DemographicPurpose.cs


示例6: Run

 public override void Run()
 {
     if ( !this.Execute ) return;
     // we actually don't write our mode choice
     var numberOfCategories = this.Categories.Count;
     SparseArray<float>[] O = new SparseArray<float>[numberOfCategories];
     SparseArray<float>[] D = new SparseArray<float>[numberOfCategories];
     for ( int i = 0; i < O.Length; i++ )
     {
         O[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
         D[i] = Root.ZoneSystem.ZoneArray.CreateSimilarArray<float>();
         this.Categories[i].Generate( O[i], D[i] );
     }
     // if we only need to run generation we are done
     if ( this.OnlyDoGeneration ) return;
     // we don't do mode choice
     foreach ( var distributionData in this.Distribution.Distribute( O, D, this.Categories ) )
     {
         var interative = this.ModeSplit as IInteractiveModeSplit;
         if ( interative != null )
         {
             interative.EndInterativeModeSplit();
         }
         if ( !String.IsNullOrWhiteSpace( this.SaveResultFileName ) )
         {
             SaveFriction( distributionData.GetFlatData() );
         }
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:29,代码来源:PoRPoWPurpose.cs


示例7: Generate

 public void Generate(SparseArray<float> production, SparseArray<float> attractions)
 {
     float totalProduction = 0;
     float totalAttraction = 0;
     foreach (var zone in production.ValidIndexies())
     {
         float prod, attr;
         production[zone] = (prod = this.PopulationFactor * production[zone]);
         attractions[zone] = (attr = this.EmploymentFactor * attractions[zone]);
         totalProduction += prod;
         totalAttraction += attr;
     }
     if (totalAttraction <= 0)
     {
         throw new XTMF.XTMFRuntimeException("There is no employment in the zone system!");
     }
     else if (totalProduction <= 0)
     {
         throw new XTMF.XTMFRuntimeException("There is no population in the zone system!");
     }
     // Normalize the attractions
     var inverseTotalAttraction = 1 / totalAttraction; // inverse totalAttraction to save on divisions
     foreach (var zone in Root.ZoneSystem.ZoneArray.ValidIndexies())
     {
         attractions[zone] = (attractions[zone] * inverseTotalAttraction) * totalProduction;
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:27,代码来源:SimpleGeneration.cs


示例8: Generate

        public override void Generate(SparseArray<float> production, SparseArray<float> attractions)
        {
            if ( LoadData )
            {
                if ( DailyRates == null )
                {
                    this.LoadDailyRates.LoadData();
                    this.DailyRates = this.LoadDailyRates.GiveData();
                }
                if ( TimeOfDayRates == null )
                {
                    this.LoadTimeOfDayRates.LoadData();
                    this.TimeOfDayRates = this.LoadTimeOfDayRates.GiveData();
                }
            }
            var flatProduction = production.GetFlatData();
            var flatAttraction = attractions.GetFlatData();

            var numberOfIndexes = flatAttraction.Length;

            // Compute the Production and Attractions
            ComputeProduction( flatProduction, flatAttraction, numberOfIndexes );

            //We do not normalize the attraction
            if ( LoadData )
            {
                this.LoadDailyRates.UnloadData();
                this.LoadTimeOfDayRates.UnloadData();
                DailyRates = null;
                TimeOfDayRates = null;
            }
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:32,代码来源:PowGeneration.cs


示例9: TestCSVODC

 public void TestCSVODC()
 {
     try
     {
         int[] zones = new int[] { 0, 1, 2, 3, 4, 5, 6 };
         SparseArray<int> referenceArray = new SparseArray<int>( new SparseIndexing()
         {
             Indexes = new SparseSet[]
         {
             new SparseSet() { Start = 0, Stop = 6 }
         }
         } );
         float[][][] allData = new float[1][][];
         var data = CreateData( zones.Length );
         CreateCSVFile( zones, data, "Test.csv" );
         allData[0] = data;
         var writer = new ODMatrixWriter<int>( referenceArray, 1, 1 );
         writer.LoadCSVTimes( "Test.csv", false, 0, 0 );
         writer.Save( "Test.odc", false );
         var odcFloatData = ConvertData( allData, zones.Length, 1, 1 );
         ValidateData( zones, odcFloatData, "Test.odc" );
     }
     finally
     {
         File.Delete( "Test.csv" );
         File.Delete( "Test.odc" );
     }
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:28,代码来源:ODCTesting.cs


示例10: EmmeMatrix

 public EmmeMatrix(SparseArray<IZone> zoneSystem, float[][] data)
 {
     var zones = zoneSystem.GetFlatData();
     MagicNumber = EmmeMagicNumber;
     Version = 1;
     Type = DataType.Float;
     Dimensions = 2;
     float[] temp = new float[zones.Length * zones.Length];
     Indexes = new int[2][];
     for(int i = 0; i < Indexes.Length; i++)
     {
         var row = Indexes[i] = new int[zones.Length];
         for(int j = 0; j < row.Length; j++)
         {
             row[j] = zones[j].ZoneNumber;
         }
     }
     for(int i = 0; i < data.Length; i++)
     {
         Array.Copy(data[i], 0, temp, i * zones.Length, zones.Length);
     }
     FloatData = temp;
     DoubleData = null;
     SignedIntData = null;
     UnsignedIntData = null;
 }
开发者ID:Cocotus,项目名称:XTMF,代码行数:26,代码来源:EmmeMatrix.cs


示例11: GetRenderers

        private SparseArray<DataRenderer> GetRenderers(IEntity entity) {
            SparseArray<DataRenderer> renderers;

            if (_renderers.TryGetValue(entity.UniqueId, out renderers) == false) {
                renderers = new SparseArray<DataRenderer>();
                _renderers[entity.UniqueId] = renderers;
            }

            return renderers;
        }
开发者ID:jyunfan2015,项目名称:forge-sample,代码行数:10,代码来源:EntityContainerEventMonitor.cs


示例12: SetOneHundredElements

        public void SetOneHundredElements()
        {
            SparseArray<int> array = new SparseArray<int>(10);

            for (int k = 0; k < 100; k++)
                array[(ulong)k] = k;

            for (int k = 0; k < 100; k++)
                Assert.AreEqual(k, array[(ulong)k]);
        }
开发者ID:ajlopez,项目名称:AjActivity,代码行数:10,代码来源:SparseArrayTests.cs


示例13: GettingNonExistingReturnsNull

        public void GettingNonExistingReturnsNull()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(10000));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:10,代码来源:Fixture.cs


示例14: GetNegativeShouldNotFail

        public void GetNegativeShouldNotFail()
        {
            var array = new SparseArray<string>();

            Assert.IsNull(array.GetValue(-10));

            // We shouldn't have allocated items.

            Assert.AreEqual("Values=20", array.ToString());
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:10,代码来源:Fixture.cs


示例15: ProcessFlow

        public SparseTwinIndex<float> ProcessFlow(SparseArray<float> O, SparseArray<float> D, int[] validIndexes, SparseArray<float> attractionStar = null)
        {
            int length = validIndexes.Length;
            Productions = O;
            Attractions = D;
            if(attractionStar == null)
            {
                AttractionsStar = D.CreateSimilarArray<float>();
            }
            else
            {
                AttractionsStar = attractionStar;
            }
            FlowMatrix = Productions.CreateSquareTwinArray<float>();
            if(Friction == null)
            {
                InitializeFriction(length);
            }
            var flatAttractionStar = AttractionsStar.GetFlatData();
            float[] oldTotal = new float[flatAttractionStar.Length];
            var flatAttractions = Attractions.GetFlatData();
            for(int i = 0; i < length; i++)
            {
                flatAttractionStar[i] = 1f;
                oldTotal[i] = flatAttractions[i];
            }
            int iteration = 0;
            float[] columnTotals = new float[length];
            var balanced = false;
            do
            {
                if(ProgressCallback != null)
                {
                    // this doesn't go to 100%, but that is alright since when we end, the progress
                    // of the calling model should assume we hit 100%
                    ProgressCallback(iteration / (float)MaxIterations);
                }
                Array.Clear(columnTotals, 0, columnTotals.Length);
                if(Vector.IsHardwareAccelerated)
                {
                    VectorProcessFlow(columnTotals, FlowMatrix.GetFlatData());
                }
                else
                {
                    ProcessFlow(columnTotals);
                }
                balanced = Balance(columnTotals, oldTotal);
            } while((++iteration) < MaxIterations && !balanced);

            if(ProgressCallback != null)
            {
                ProgressCallback(1f);
            }
            return FlowMatrix;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:55,代码来源:GravityModel.cs


示例16: TestSparseArraySimple

        public void TestSparseArraySimple()
        {
            // intialize.
            var array = new SparseArray<int>(10);

            // fill and resize in the process.
            for (int idx = 0; idx < 1000; idx++)
            {
                if (idx >= array.Length)
                {
                    array.Resize(idx + 100);
                }
                array[idx] = idx;
            }
            for (int idx = 5000; idx < 10000; idx++)
            {
                if (idx >= array.Length)
                {
                    array.Resize(idx + 100);
                }
                array[idx] = idx;
            }

            // test content.
            for (int idx = 0; idx < 1000; idx++)
            {
                Assert.AreEqual(idx, array[idx]);
            }
            for (int idx = 1001; idx < 5000; idx++)
            {
                Assert.AreEqual(0, array[idx]);
            }
            for (int idx = 5000; idx < 10000; idx++)
            {
                Assert.AreEqual(idx, array[idx]);
            }

            // test enumerator.
            var list = new List<int>(array);
            for (int idx = 0; idx < 1000; idx++)
            {
                Assert.AreEqual(idx, list[idx]);
            }
            for (int idx = 1001; idx < 5000; idx++)
            {
                Assert.AreEqual(0, list[idx]);
            }
            for (int idx = 5000; idx < 10000; idx++)
            {
                Assert.AreEqual(idx, list[idx]);
            }
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:52,代码来源:SparseArrayTests.cs


示例17: SetOneThousandSparseElements

        public void SetOneThousandSparseElements()
        {
            SparseArray<int> array = new SparseArray<int>(10);

            for (int k = 0; k < 1000; k++)
            {
                array[(ulong)(k*1000)] = k;
                Assert.AreEqual(k, array[(ulong)(k*1000)]);
            }

            for (int k = 0; k < 1000; k++)
                Assert.AreEqual(k, array[(ulong)(k*1000)]);
        }
开发者ID:ajlopez,项目名称:AjActivity,代码行数:13,代码来源:SparseArrayTests.cs


示例18: Process

        public static SparseTwinIndex<float> Process(SparseArray<float> production, float[] friction)
        {
            var ret = production.CreateSquareTwinArray<float>();
            var flatRet = ret.GetFlatData();
            var flatProduction = production.GetFlatData();
            var numberOfZones = flatProduction.Length;
            try
            {
                // Make all of the frictions to the power of E
                Parallel.For( 0, friction.Length, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
                    delegate(int i)
                    {
                        friction[i] = (float)Math.Exp( friction[i] );
                    } );

                Parallel.For( 0, numberOfZones, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
                    delegate(int i)
                    {
                        float sum = 0f;
                        var iIndex = i * numberOfZones;
                        // gather the sum of the friction
                        for ( int j = 0; j < numberOfZones; j++ )
                        {
                            sum += friction[iIndex + j];
                        }
                        if ( sum <= 0 )
                        {
                            return;
                        }
                        sum = 1f / sum;
                        for ( int j = 0; j < numberOfZones; j++ )
                        {
                            flatRet[i][j] = flatProduction[i] * ( friction[iIndex + j] * sum );
                        }
                    } );
            }
            catch ( AggregateException e )
            {
                if ( e.InnerException is XTMFRuntimeException )
                {
                    throw new XTMFRuntimeException( e.InnerException.Message );
                }
                else
                {
                    throw new XTMFRuntimeException( e.InnerException.Message + "\r\n" + e.InnerException.StackTrace );
                }
            }
            return ret;
        }
开发者ID:Cocotus,项目名称:XTMF,代码行数:49,代码来源:SinglyConstrainedGravityModel.cs


示例19: SetOneThousandElements

        public void SetOneThousandElements()
        {
            SparseArray<int> array = new SparseArray<int>(10);

            for (int k = 0; k < 1000; k++)
            {
                array[(ulong)k] = k;
                Assert.AreEqual(k, array[(ulong)k]);
                if (k>1)
                    Assert.AreEqual(1, array[1], string.Format("One lost at {0}", k));
            }

            for (int k = 0; k < 1000; k++)
                Assert.AreEqual(k, array[(ulong)k]);
        }
开发者ID:ajlopez,项目名称:AjActivity,代码行数:15,代码来源:SparseArrayTests.cs


示例20: ArrayObject

        public ArrayObject(Environment env, uint length)
            : base(env, env.Maps.Array, env.Prototypes.Array)
        {
            this.length = length;

            if (length > 0x20000)
            {
                this.sparse = new SparseArray();
                this.isDense = false;
            }
            else
            {
                this.dense = new Descriptor[length];
                this.isDense = true;
            }
        }
开发者ID:wesleywiser,项目名称:IronJS,代码行数:16,代码来源:ArrayObject.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SparseCompressedRowMatrixStorage类代码示例发布时间:2022-05-24
下一篇:
C# SparqlResultsFormat类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap