相关疑难解决方法(0)

将 F# 测量单位与 System.Numerics.Vector<T> 结合使用

我很难将 F# 测量单位与System.Numerics.Vector<'T>类型结合使用。让我们看一个玩具问题:假设我们有一个类型xs的数组float<m>[],并且由于某种原因我们想要对其所有组件进行平方,从而得到一个类型的数组float<m^2>[]。这与标量代码完美配合:

xs |> Array.map (fun x -> x * x) // float<m^2>[]
Run Code Online (Sandbox Code Playgroud)

现在假设我们想要通过使用 SIMD 在 - 大小的块中执行乘法来向量化此操作System.Numerics.Vector<float>.Count,例如如下所示:

open System.Numerics
let simdWidth = Vector<float>.Count
// fill with dummy data
let xs = Array.init (simdWidth * 10) (fun i -> float i * 1.0<m>)
// array to store the results
let rs: float<m^2> array = Array.zeroCreate (xs |> Array.length)
// number of SIMD operations required
let chunks = (xs |> …
Run Code Online (Sandbox Code Playgroud)

.net f# simd vectorization units-of-measurement

5
推荐指数
1
解决办法
442
查看次数

如何一般性地删除F#度量单位

我有一些数据操作代码,最后吐出csv.

我开始升级它以在任何地方添加度量单位,但我现在遇到了我的csv函数问题:

val WriteCSV : string -> 'a list array -> 'b list -> string -> unit
Run Code Online (Sandbox Code Playgroud)

(参数是fileName,列数组,列标题,分隔符)

我之前发送[| s; x; y |]到WriteCSV的地方,我现在有一个问题,因为我无法发送[| skm; XMM; 青运|].

我尝试编写一个通常删除度量单位的函数,但它不起作用.

let removeUnit (n:float<_>) = n/1.0<_>
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  • 为什么不起作用?
  • 可以使它工作吗?
  • 有没有其他方法可以解决这个特殊问题?

f# units-of-measurement

3
推荐指数
1
解决办法
797
查看次数

标签 统计

f# ×2

units-of-measurement ×2

.net ×1

simd ×1

vectorization ×1