Avatar
ちなみにこちらで var grid = Array(repeating: R.zero, count: a.rows * b.cols) for l in (0 ..< a.rows * b.cols) { let (i, k) = (l / b.cols, l % b.cols) var x = R.zero for j in 0 ..< a.cols { x = x + a[i, j] * b[j, k] } grid[l] = x } var grid = Array(repeating: R.zero, count: a.rows * b.cols) for l in (0 ..< a.rows * b.cols) { let (i, k) = (l / b.cols, l % b.cols) grid[l] = (0 ..< a.cols).sum{ j in a[i, j] * b[j, k] } } を比較すると 1: 53.226 msec. 2: 348.296 msec. となって、for を使った方が全然速い感じです。