instance Elt (Complex a) in accelerate-1.2

8 views
Skip to first unread message

Henning Thielemann

unread,
Apr 17, 2018, 2:13:36 AM4/17/18
to Accelerate Project

I try to update accelerate-utility to accelerate-1.2. It seems that the
former universal instance on Complex:

instance A.Elt a => A.Elt (Complex a)
-- Defined in ‘Data.Array.Accelerate.Data.Complex’

was turned into a flexible instance:

instance Data.Array.Accelerate.Array.Sugar.Elt (Complex.Complex Float)
-- Defined in ‘Data.Array.Accelerate.Data.Complex’
instance Data.Array.Accelerate.Array.Sugar.Elt (Complex.Complex Double)
-- Defined in ‘Data.Array.Accelerate.Data.Complex’

This is actually less flexible and breaks my instance Unlift (Complex a)
in Data.Array.Accelerate.Utility.Lift.Exp. Wouldn't it be better to define
the Complex instance using a helper class for the elements of Complex
numbers? It seems that accelerate-fft defines its own class 'Numeric' for
that purpose.

Trevor McDonell

unread,
Apr 17, 2018, 2:28:36 AM4/17/18
to accelerat...@googlegroups.com

Hi Henning,

This change was necessary because complex numbers are now stored in the C-style array-of-struct representation. Thus, we only support certain types, not the universal instance we had previously.

Having an intermediate class might be an option, but I think you can achieve the same thing with an Elt (Complex a) constraint. And, we would still need Numeric in accelerate-fft, as it is still more restrictive than all complex number representation supported by accelerate (in particular, no FP16), and is used for other purposes besides.

Cheers,
-Trev


--
You received this message because you are subscribed to the Google Groups "Accelerate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelerate-hask...@googlegroups.com.
Visit this group at https://groups.google.com/group/accelerate-haskell.
For more options, visit https://groups.google.com/d/optout.

Henning Thielemann

unread,
Apr 17, 2018, 8:06:13 AM4/17/18
to Accelerate Project

On Tue, 17 Apr 2018, Trevor McDonell wrote:

> Having an intermediate class might be an option, but I think you can
> achieve the same thing with an Elt (Complex a) constraint.

What about extending the RealFloat class accordingly? So far I could
define:

cis :: (A.RealFloat a) => Exp a -> Exp (Complex a)
cis w = A.lift $ cos w :+ sin w

In accelerate-1.2 I have to add (A.Elt (Complex a)) to every computation
involving Complex numbers. If (A.Elt (Complex a)) would be an additional
constraint of "class A.RealFloat a" then this constraint would not be
necessary in Complex functions.
Reply all
Reply to author
Forward
0 new messages