complex number performance enhancement...

2010-12-26 Thread Sunil S Nandihalli
Hello everybody,
 I have a numerically intensive code. after getting it to work I started
profiling the code .. and zeroed down that my complex number operations are
the most called functions and probably among the slowest due to my naive
implementation. The code I am using is in the following post.
https://gist.github.com/755484

I had earlier asked a similar question with out doing any profiling .. But
Stuart sierra had suggested that I look at one of his pastes .. which is

http://paste.lisp.org/display/93387

It uses protocols and deftype I noticed that it was an old post .. I could
not get it to compile to try it out.. I was complaining about likes of
trying to convert a name-space-qualified to a type name .. w.r.t ::Complex .
I tried a couple of things to get it working with out success..

Any suggestions to improve my code or to get stuart's code compiled so that
I can try it would be very help full.
Thanks,
Sunil.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: complex number performance enhancement...

2010-12-26 Thread Alex Osborne
Sunil S Nandihalli sunil.nandiha...@gmail.com writes:

 http://paste.lisp.org/display/93387

 It uses protocols and deftype I noticed that it was an old post .. I
 could not get it to compile to try it out.. I was complaining about
 likes of trying to convert a name-space-qualified to a type name
 .. w.r.t ::Complex . I tried a  couple of things to get it working
 with out success..

 Any suggestions to improve my code or to get stuart's code compiled so
 that I can try it would be very help full.

Here's how to get Stuart's working.

1. Replace ::Complex with Complex everywhere.  

2. Change (deftype Complex [r i]) to (defrecord Complex [r i]). 

3. Put a . after the Complex constructors so they look like this:

(extend-double add Complex Complex
   (fn [c1 c2] (Complex. (+ (:r c1) (:r c2))
 (+ (:i c1) (:i c2)

You should end up with something vaguely like this:

https://gist.github.com/755758

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: complex number performance enhancement...

2010-12-26 Thread Sunil S Nandihalli
thanks Alex for your response . I tried it ... It compiled fine .. but the
double dispatch does not seem to work correctly ..

 It some how reverses the arguments and then dispatches to the correct
function for the reversed arguments and the function works properly ..
i.e.
 when I do (- (Complex. 1 3) 3)  .. I would expect (Complex. -2 3) but I get
(Complex. 2 -3)
which is what I would expect to get when I do (- 3 (Complex. 1 3)) .

I am trying to make it work right .. but I thought some of you may better
able to fix it.

Thanks,
Sunil


 I am trying to debug it .. but would like some

 I am still trying to understand the code and figure it out.. But I just
thought I

On Mon, Dec 27, 2010 at 6:03 AM, Alex Osborne a...@meshy.org wrote:

 Sunil S Nandihalli sunil.nandiha...@gmail.com writes:

  http://paste.lisp.org/display/93387
 
  It uses protocols and deftype I noticed that it was an old post .. I
  could not get it to compile to try it out.. I was complaining about
  likes of trying to convert a name-space-qualified to a type name
  .. w.r.t ::Complex . I tried a  couple of things to get it working
  with out success..

  Any suggestions to improve my code or to get stuart's code compiled so
  that I can try it would be very help full.

 Here's how to get Stuart's working.

 1. Replace ::Complex with Complex everywhere.

 2. Change (deftype Complex [r i]) to (defrecord Complex [r i]).

 3. Put a . after the Complex constructors so they look like this:

(extend-double add Complex Complex
   (fn [c1 c2] (Complex. (+ (:r c1) (:r c2))
 (+ (:i c1) (:i c2)

 You should end up with something vaguely like this:

https://gist.github.com/755758

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: complex number performance enhancement...

2010-12-26 Thread Alex Osborne
Sunil S Nandihalli sunil.nandiha...@gmail.com writes:

 thanks Alex for your response . I tried it ... It compiled fine .. but the 
 double dispatch does not seem to work correctly ..

 It some how reverses the arguments and then dispatches to the correct
 function for the reversed arguments and the function works properly
 .. 
 i.e.
 when I do (- (Complex. 1 3) 3) .. I would expect (Complex. -2 3) but I get 
 (Complex. 2 -3)
 which is what I would expect to get when I do (- 3 (Complex. 1 3)) .

 I am trying to make it work right .. but I thought some of you may better 
 able to fix it.

Oh right.  Just swap type1 and type2 in extend-double.  Looks like the
implementation of (subtract Number Complex) had a bug too, it didn't
negate the imaginary component.

Updated the gist:

https://gist.github.com/755758

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en