Optimization 在F#中,将内核应用于大型数组的最佳方法是什么?

Optimization 在F#中,将内核应用于大型数组的最佳方法是什么?,optimization,f#,Optimization,F#,我有以下代码: // reduce by 25x let smallOutput = Array2D.init (output.GetLength(0) / 5) (output.GetLength(1) / 5) (fun _ _ -> Int32.MinValue) let weights = array2D [| [| 1; 1; 1; 1; 1 |] [| 1; 3; 3; 3; 1 |] [| 1; 3; 5; 3; 1 |

我有以下代码:

// reduce by 25x
let smallOutput = Array2D.init (output.GetLength(0) / 5) (output.GetLength(1) / 5) (fun _ _ -> Int32.MinValue)
let weights =
    array2D [|
        [| 1; 1; 1; 1; 1 |]
        [| 1; 3; 3; 3; 1 |]
        [| 1; 3; 5; 3; 1 |]
        [| 1; 3; 3; 3; 1 |]
        [| 1; 1; 1; 1; 1 |]
    |]
let weightsSum = 45
for y in [0 .. smallOutput.GetLength(0) - 1] do
    for x in [0 .. smallOutput.GetLength(1) - 1] do
        let mutable v = 0
        for i in [0 .. 4] do
            for j in [0 .. 4] do
                v <- v + weights.[j, i] * output.[y * 5 + j, x * 5 + i]

        smallOutput.[y, x] <- v / weightsSum
//减少25倍
让smallOutput=Array2D.init(output.GetLength(0)/5)(output.GetLength(1)/5)(fun\uuu->Int32.MinValue)
让重量=
阵列2d[|
[| 1; 1; 1; 1; 1 |]
[| 1; 3; 3; 3; 1 |]
[| 1; 3; 5; 3; 1 |]
[| 1; 3; 3; 3; 1 |]
[| 1; 1; 1; 1; 1 |]
|]
设权重Ssum=45
对于[0..smallOutput.GetLength(0)-1]do中的y
对于[0..smallOutput.GetLength(1)-1]中的x
设可变v=0
因为我在[0..4]中是这样做的
对于[0..4]中的j,do

v我认为,除了在初始化
smallOutput
变量时已经进行求和之外,没有什么可以进一步优化它;i、 e

let smallOutput = Array2D.init (output.GetLength(0) / 5) (output.GetLength(1) / 5) (fun y x -> 
    let mutable v = 0
    for i in [0 .. 4] do
        for j in [0 .. 4] do
            v <- v + weights.[j, i] * output.[y * 5 + j, x * 5 + i]
    v / weightsSum)
let smallOutput=Array2D.init(output.GetLength(0)/5)(output.GetLength(1)/5)(fun y x->
设可变v=0
因为我在[0..4]中是这样做的
对于[0..4]中的j,do

v我认为除了在初始化
smallOutput
变量时已经进行求和之外,没有什么可以做的来进一步优化它

let smallOutput = Array2D.init (output.GetLength(0) / 5) (output.GetLength(1) / 5) (fun y x -> 
    let mutable v = 0
    for i in [0 .. 4] do
        for j in [0 .. 4] do
            v <- v + weights.[j, i] * output.[y * 5 + j, x * 5 + i]
    v / weightsSum)
let smallOutput=Array2D.init(output.GetLength(0)/5)(output.GetLength(1)/5)(fun y x->
设可变v=0
因为我在[0..4]中是这样做的
对于[0..4]中的j,do
v