Je cours dans ces cas étranges de scalaires et de matrices se comportant bizarrement dans hmatrix. Si je ne tape pas annotate, l'opération fonctionne automatiquement ala matlab/python. Mais si je tape annoter le scalaire avec le "R" ou le type ou "Double", j'obtiens une erreur de type.Haskell hmatrix: type erreurs avec interactions vectorielles/scalaires?
Pourquoi est-ce?
λ> 4 + ([1,2,3] :: Vector R)
[5.0,6.0,7.0]
λ> (4 :: R) + ([1,2,3] :: Vector R)
<interactive>:155:14:
Couldn't match type ‘Vector R’ with ‘Double’
Expected type: R
Actual type: Vector R
In the second argument of ‘(+)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: R) + ([1, 2, 3] :: Vector R)
In an equation for ‘it’: it = (4 :: R) + ([1, 2, 3] :: Vector R)
λ> (4 :: Double) + ([1,2,3] :: Vector R)
<interactive>:156:19:
Couldn't match expected type ‘Double’ with actual type ‘Vector R’
In the second argument of ‘(+)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: Double) + ([1, 2, 3] :: Vector R)
In an equation for ‘it’:
it = (4 :: Double) + ([1, 2, 3] :: Vector R)
λ> (4 :: R) * ([1,2,3] :: Vector R)
<interactive>:157:14:
Couldn't match type ‘Vector R’ with ‘Double’
Expected type: R
Actual type: Vector R
In the second argument of ‘(*)’, namely ‘([1, 2, 3] :: Vector R)’
In the expression: (4 :: R) * ([1, 2, 3] :: Vector R)
In an equation for ‘it’: it = (4 :: R) * ([1, 2, 3] :: Vector R)
λ> 4 * ([1,2,3] :: Vector R)
[4.0,8.0,12.0]
λ>
Je vois. donc si quelqu'un se demande comment le réparer, remplacer les constantes d'un seul élément par (scalar myValue) fera vérifier les choses – daj