HMatrix Matrix Double - 双乘积

HMatrix Matrix Double - Double product

f1 :: Mesh -> Matrix Double
f1 me = knx where
  hx :: Double
  (hx , _) = h me
  a, knx :: Matrix Double
  a = fromLists [[1,2], [3,4]] 
  knx = hx * a 
  -- knx = 2 * a

我不明白为什么在上面的函数中,乘以 2 有效,而乘以 hx = 0.5 无效。 OTOH,将 Matrix DoubleDouble 相乘 函数正常工作。

Couldn't match expected type ‘Matrix Double’
            with actual type ‘Double’
In the first argument of ‘(*)’, namely ‘hx’
In the expression: hx * a
Failed, modules loaded: none.

我很疑惑。欢迎任何指点!

HMatrix 中,scale :: Container c e => e -> c e -> c e 按照标签上的说明进行操作(将 c e 中的 e 乘以第一个 e)。这里有一些用法示例:https://hackage.haskell.org/package/hmatrix-0.16.1.4/docs/src/Data-Packed-Internal-Numeric.html

需要注意的是,scale x通过fromList.

将x视为单例列表来构造一个Container类型

如果至少重载常见的算术运算,那将非常方便,这样公式就可以类似于它们的数学对应物。我不确定定义函数同义词(例如 (.*) = scale )是个好主意还是只会增加一层复杂性。有什么想法吗?