C#代码:
[GpuManaged, Test]
public static void ActionFactoryWithClosure2()
{
var MyGPU = Gpu.Get(0);
var arg1 = Enumerable.Range(0, Length).ToArray();
var arg2 = Enumerable.Range(0, Length).ToArray();
var result = new int[Length];
Func<int[], Action<int>> opFactory = res => i =>
{
res[i] = arg1[i] + arg2[i];
};
MyGPU.For(0, arg1.Length, opFactory(result));
}
VB.NET 代码:
<GpuManaged>
Public Shared Function GPU_TEST_VB_20170920()
Dim MyGPU As Alea.Gpu = Gpu.Default
Dim arg1 = Enumerable.Range(0, Length).ToArray()
Dim arg2 = Enumerable.Range(0, Length).ToArray()
Dim result = New Integer(Length - 1) {}
Dim expected = New Integer(Length - 1) {}
Dim opFactory As Func(Of Integer(), Action(Of Integer)) = Function(res) Function(i)
res(i) = arg1(i) + arg2(i)
End Function
Dim op As Action(Of Integer) = Function(i) InlineAssignHelper(result(i), arg1(i) + arg2(i))
Dim op2 As Action(Of Integer) = Sub(i)
result(i) = arg1(i) + arg2(i)
End Sub
MyGPU.[For](0, result.Length, Function(i) InlineAssignHelper(result(i), arg1(i) + arg2(i))) 'Error : The given key was not present in the dictionary.
MyGPU.For(0, arg1.Length, opFactory(result)) 'Error : The given key was not present in the dictionary.
MyGPU.For(0, arg1.Length, op) 'Error : The given key was not present in the dictionary.
MyGPU.For(0, arg1.Length, op2) 'Error : Cannot get field ""$VB$Local_result. Possible reasons: -> Static field Is Not supported."
End Sub
在 C# 的情况下,我可以运行示例代码,但在 VB 中,我收到错误消息(请参阅上面的代码行)我应该做什么
相同条件:VS 2017、Windows 10、AleaGPU 3.0.3