本文整理汇总了C#中SparseArray.CreateSquareTwinArray方法的典型用法代码示例。如果您正苦于以下问题:C# SparseArray.CreateSquareTwinArray方法的具体用法?C# SparseArray.CreateSquareTwinArray怎么用?C# SparseArray.CreateSquareTwinArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseArray
的用法示例。
在下文中一共展示了SparseArray.CreateSquareTwinArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: IterationStarting
public void IterationStarting(int iteration)
{
ZoneSystem = Root.ZoneSystem.ZoneArray;
if(Data == null)
{
Data = ZoneSystem.CreateSquareTwinArray<float>().GetFlatData();
}
else
{
for(int i = 0; i < Data.Length; i++)
{
Array.Clear(Data[i], 0, Data[i].Length);
}
}
Activities = ActivitiesToCapture.Select(a => a.Activity).ToArray();
}
示例3: ProcessFlow
public SparseTwinIndex<float> ProcessFlow(float[] Friction, SparseArray<float> O, SparseArray<float> D)
{
float[] o = O.GetFlatData();
float[] d = D.GetFlatData();
var oLength = o.Length;
var dLength = d.Length;
var squareSize = oLength * dLength;
Stopwatch watch = new Stopwatch();
watch.Start();
gravityModelShader.NumberOfXThreads = length;
gravityModelShader.NumberOfYThreads = 1;
gravityModelShader.ThreadGroupSizeX = 64;
gravityModelShader.ThreadGroupSizeY = 1;
float[] balanced = new float[] { 0, this.Epsilon };
int iterations = 0;
var step1 = new int[] { oLength, 0, this.MaxIterations };
var step2 = new int[] { oLength, 1, this.MaxIterations };
if ( flows == null || flows.Length != o.Length * d.Length )
{
flows = new float[squareSize];
}
SparseTwinIndex<float> ret = null;
Task createReturn = new Task( delegate()
{
ret = O.CreateSquareTwinArray<float>();
} );
createReturn.Start();
FillAndLoadBuffers( o, d, Friction, balanced );
iterations = Balance( gpu, gravityModelShader, balancedBuffer, parameters, balanced, iterations, step1, step2 );
gpu.Read( flowsBuffer, flows );
gravityModelShader.RemoveAllBuffers();
createReturn.Wait();
BuildDistribution( ret, O, D, oLength, flows );
watch.Stop();
using ( StreamWriter writer = new StreamWriter( "GPUPerf.txt", true ) )
{
writer.Write( "Iterations:" );
writer.WriteLine( iterations );
writer.Write( "Time(ms):" );
writer.WriteLine( watch.ElapsedMilliseconds );
}
return ret;
}
示例4: 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;
}
示例5: ComputeDistances
private void ComputeDistances(SparseArray<IZone> zoneSparseArray)
{
var distances = zoneSparseArray.CreateSquareTwinArray<float>();
var flatDistnaces = distances.GetFlatData();
var zones = zoneSparseArray.GetFlatData();
var length = zones.Length;
// build all of the distances in parallel
Parallel.For( 0, length, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, delegate(int i)
{
for ( int j = 0; j < length; j++ )
{
flatDistnaces[i][j] = ( i == j ) ? zones[i].InternalDistance
: CalcDistance( zones[i], zones[j] );
}
} );
Distances = distances;
}