Skip to content

Commit 6b8f649

Browse files
dmjioclaude
andauthored
blas: make dotAll polymorphic via AFResult (#72)
Changes dotAll from a hardcoded Complex Double return to Scalar a, consistent with sumAll, productAll, and the rest of the *All family. Real arrays now return a plain scalar rather than forcing callers to unwrap an imaginary component that is always zero. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 40b7496 commit 6b8f649

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎src/ArrayFire/BLAS.hs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
--------------------------------------------------------------------------------
22
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE TypeApplications #-}
34
{-# LANGUAGE ViewPatterns #-}
45
--------------------------------------------------------------------------------
56
-- |
@@ -113,9 +114,9 @@ dot arr1 arr2 prop1 prop2 =
113114
-- | Scalar dot product between two vectors. Also referred to as the inner product. Returns the result as a host scalar.
114115
--
115116
-- >>> dotAll (vector @Double 10 [1..]) (vector @Double 10 [1..]) None None
116-
-- 385.0 :+ 0.0
117+
-- 385.0
117118
dotAll
118-
:: AFType a
119+
:: forall a . AFResult a
119120
=> Array a
120121
-- ^ Left-hand side array
121122
-> Array a
@@ -124,13 +125,12 @@ dotAll
124125
-- ^ Options for left-hand side. Currently only AF_MAT_NONE and AF_MAT_CONJ are supported.
125126
-> MatProp
126127
-- ^ Options for right-hand side. Currently only AF_MAT_NONE and AF_MAT_CONJ are supported.
127-
-> Complex Double
128-
-- ^ Real and imaginary component result
129-
dotAll arr1 arr2 prop1 prop2 = do
130-
let (real,imag) =
131-
infoFromArray22 arr1 arr2 $ \a b c d ->
132-
af_dot_all a b c d (toMatProp prop1) (toMatProp prop2)
133-
real :+ imag
128+
-> Scalar a
129+
-- ^ Result as the array's element type
130+
dotAll arr1 arr2 prop1 prop2 =
131+
toAFResult @a $
132+
infoFromArray22 arr1 arr2 $ \a b c d ->
133+
af_dot_all a b c d (toMatProp prop1) (toMatProp prop2)
134134

135135
-- | Transposes a matrix.
136136
--

‎test/ArrayFire/BLASSpec.hs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ spec =
4040
it "Should dot product two vectors" $ do
4141
dot (vector @Double 2 (repeat 2)) (vector @Double 2 (repeat 2)) None None
4242
`shouldBe` scalar @Double 8
43-
it "Should produce scalar dot product between two vectors as a Complex number" $ do
43+
it "Should produce scalar dot product between two vectors" $ do
4444
dotAll (vector @Double 2 (repeat 2)) (vector @Double 2 (repeat 2)) None None
45-
`shouldBe` 8.0 :+ 0.0
45+
`shouldBe` (8.0 :: Double)
4646
it "Should take the transpose of a matrix" $ do
4747
transpose (matrix @Double (2,2) [[1,1],[2,2]]) False
4848
`shouldBe` matrix @Double (2,2) [[1,2],[1,2]]

0 commit comments

Comments
 (0)