本文整理汇总了C#中MyMemoryBlock.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# MyMemoryBlock.Fill方法的具体用法?C# MyMemoryBlock.Fill怎么用?C# MyMemoryBlock.Fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMemoryBlock
的用法示例。
在下文中一共展示了MyMemoryBlock.Fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run(MatOperation operation, MyMemoryBlock<float> A, MyMemoryBlock<float> B, MyMemoryBlock<float> Result)
{
Result.Fill(.0f);
switch (operation)
{
case MatOperation.EuclidDist:
if (B.Count == A.ColumnHint)
{
A.SafeCopyToHost();
B.SafeCopyToHost();
for (int row = 0; row < A.Count / A.ColumnHint; row++)
{
Result.Host[row] = 0;
for (int Bindex = 0; Bindex < B.Count; Bindex++)
{
Result.Host[row] += (B.Host[Bindex] - A.Host[A.ColumnHint * row + Bindex]) * (B.Host[Bindex] - A.Host[A.ColumnHint * row + Bindex]);
}
Result.Host[row] = (float)Math.Sqrt( (double) Result.Host[row] );
//System.Console.Write(" " + Result.Host[row]);
}
Result.SafeCopyToDevice();
}
break;
default:
MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cpu mat ops. for undefined MatOperation");
break;
}
}
示例2: Run
public override void Run(MatOperation operation, MyMemoryBlock<float> A, float value, MyMemoryBlock<float> Result)
{
Result.Fill(.0f);
switch (operation)
{
case MatOperation.Multiplication:
MyCublasFactory.Instance.Axpy(value, A.GetDevice(callee), 1, Result.GetDevice(callee), 1);
break;
default:
MyLog.Writer.WriteLine(MyLogLevel.ERROR, "Trying to run cublas for undefined MatOperation");
break;
}
}
示例3: Run
public void Run(VectorOperation operation,
MyMemoryBlock<float> a,
MyMemoryBlock<float> b,
MyMemoryBlock<float> result)
{
if (!Validate(operation, a.Count, b.Count))
return;
switch (operation)
{
case VectorOperation.Rotate:
{
b.SafeCopyToHost();
float rads = DegreeToRadian(b.Host[0]);
float[] transform = { (float)Math.Cos(rads), -(float)Math.Sin(rads), (float)Math.Sin(rads), (float)Math.Cos(rads) };
Array.Copy(transform, m_temp.Host, transform.Length);
m_temp.SafeCopyToDevice();
m_matOperation.Run(MatOperation.Multiplication, m_temp, a, result);
}
break;
case VectorOperation.Angle:
{
m_matOperation.Run(MatOperation.DotProd, a, b, result);
result.SafeCopyToHost();
float dotProd = result.Host[0];
float angle = RadianToDegree((float)Math.Acos(dotProd));
result.Fill(0);
result.Host[0] = angle;
result.SafeCopyToDevice();
}
break;
case VectorOperation.DirectedAngle:
{
result.Host[0] = -90;
result.SafeCopyToDevice();
Run(VectorOperation.Rotate, a, result, result);
result.CopyToMemoryBlock(m_temp, 0, 0, result.Count);
m_matOperation.Run(MatOperation.DotProd, a, b, result);
result.SafeCopyToHost();
float dotProd = result.Host[0];
float angle;
if (Math.Abs(Math.Abs(dotProd) - 1) < 1E-4)
angle = 0;
else
angle = RadianToDegree((float)Math.Acos(dotProd));
m_matOperation.Run(MatOperation.DotProd, m_temp, b, result);
result.SafeCopyToHost();
float perpDotProd = result.Host[0];
if (perpDotProd > 0)
angle *= -1;
result.Fill(0);
result.Host[0] = angle;
result.SafeCopyToDevice();
}
break;
}
}