Microsoft Accelerator V2 - toArray2D 问题

发布于 2024-08-17 07:54:40 字数 570 浏览 5 评论 0原文

我是 Microsoft.Accelerator 的新手。看一下下面的代码(它是 F#,但与 C# 类似):

type FPA = Microsoft.ParallelArrays.FloatParallelArray

let fi = List.init 9 (fun i -> new FPA(i, [|10;10|])) 
let process (fi: FPA list) : FPA list = fi // complicated function
let newfi = process fi
let target = new DX9Target()
for newf in newfi do printfn "%A" (target.toArray2D(newf))

基本上,我创建一个 FPA 列表,并以生成的 newfi 列表中的每个元素都依赖于 fi 列表中的所有元素的方式处理它。最后我想得到最终的 fi 列表。我的问题是:我应该为生成的 FPA 列表中的每个元素 (FPA) 调用 toArray2D 吗?在我看来,每次调用 toArray2D 时都会运行整个计算,这非常耗时。

感谢您的帮助。 奥尔德里奇

I am new to Microsoft.Accelerator. Take a look at the following code (it is F# but it is similar to C#):

type FPA = Microsoft.ParallelArrays.FloatParallelArray

let fi = List.init 9 (fun i -> new FPA(i, [|10;10|])) 
let process (fi: FPA list) : FPA list = fi // complicated function
let newfi = process fi
let target = new DX9Target()
for newf in newfi do printfn "%A" (target.toArray2D(newf))

Basicaly I create a list of FPAs and process it in a way that every element in the resulting newfi list is dependend on all elements in the fi list. Finaly I would like to get the resulting fi list. And my question is: Should I call toArray2D for every single element (FPA) in the resulting FPA list? It seems to me that the whole computation is run everytime I call toArray2D, which is very time consuming.

Thank you for your help.
Oldrich

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄人书 2024-08-24 07:54:40

FPA 表示要执行的计算。您有两个此类计算列表,finewfi。由于您定义事物的方式,newfi 的每个元素都是一个计算,需要独立运行才能获取其值;尽管它是根据 fi 的常见底层元素定义的,但无法利用这一事实仅计算一次底层 fi 值并重用他们。如果您希望这些 fi 计算仅执行一次,则需要执行以下操作之一:

  1. 获取 fi 计算的结果(例如,通过使用toArray2D),并根据这些计算值构建 newfi 列表。
  2. 创建一个计算,表示单个数组中的所有 newfi 值 - 您可能需要聪明一点才能编写这样的计算,但这可以让您一次计算所有值,而无需重新计算fi 值。

An FPA represents a computation to be performed. You have two lists of such computations, fi and newfi. Because of how you're defining things, each element of newfi is a computation which will need to be run independently to get its value; even though it is defined in terms of common underlying elements of fi, there is no way to take advantage of that fact to only compute the underlying fi values a single time and reuse them. If you want those fi computations to be performed only a single time, you'll need to do one of the following:

  1. Get the results of the fi computations (e.g. by using toArray2D), and build the newfi list based on these computed values.
  2. Create a single computation which represents all newfi values in a single array - you may need to be a bit clever to compose such a computation, but this could allow you to calculate all values at once without needing to recompute the fi values.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文