-
Notifications
You must be signed in to change notification settings - Fork 5
Show instance transposed? #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, so there is an option to transpose right before printing, which is disabled by default. instance Show (Array a) where
show = arrayString
arrayString
:: Array a
-- ^ Input 'Array'
-> String
-- ^ 'String' representation of 'Array'
arrayString a = arrayToString "ArrayFire Array" a 4 False -- <-- here
arrayToString expr (Array fptr) (fromIntegral -> prec) (fromIntegral . fromEnum -> transpose) =
unsafePerformIO . mask_ . withForeignPtr fptr $ \aptr ->
withCString expr $ \expCstr ->
alloca $ \ocstr -> do
throwAFError =<< af_array_to_string ocstr expCstr aptr prec transpose
peekCString =<< peek ocstr
--- determines whether or not to transpose the array before storing it in the string |
Interestingly, it looks like the same is true in the arrayfire Anyway, it looks like this just needs to have the view pattern changed to |
Ah, it appears ArrayFire assumes data is in column major order. I think the Haskell wrapper might need to transpose the data first, before sending the C array to arrayfire. Since the smart constructors we expose seem to give the impression that data is in row major order. matrix :: AFType a => (Int,Int) -> [[a]] -> Array a
matrix (x,y)
= mkArray [x,y]
. concat
. take x
. fmap (take y) |
@gilgamec also, one thing to note, transpose is the default for main :: IO ()
main = do
print newArray -- af_array_to_string
printArray newArray -- af_print
where
newArray = matrix @Double (2,2) [ [1..], [1..] ] * matrix @Double (2,2) [ [2..], [2..] ]
The second is transposed, the first is not. |
So, going off
It looks like the printer outputs dimension 0 values to a single line, with each successive dimension adding a newline after. If the values are stored column-major (i.e. dimension 0 is the columns), you would indeed need to transpose so that dimension 0 is the rows and each row is printed to a single line. |
Alright, let's do it. |
It looks like your
Show
instance forArray
is transposed:Another example: exceptions thrown by
matmul
suggest that the dimensions are (rows,columns):but the
Show
instance suggests the opposite:The text was updated successfully, but these errors were encountered: