>Date: Thu, 08 Nov 2007 11:15:05 -0800
>From: Roger Hui <[EMAIL PROTECTED]>
>Subject: Re: [Jprogramming] speed of matrix*vector
>operation. To: Programming forum
><[email protected]> Message-ID:
><[EMAIL PROTECTED]> Content-Type: text/plain;
>charset=us-ascii
>
>He means matrix multiply. * in MatLab is matrix multiply.
>
thanks everybody.
Here is the code and its timing results.
vector =: 256 [EMAIL PROTECTED] 0
matrix=: 256 312 [EMAIL PROTECTED] 0
1000 (6!:2) 'output =: vector +/ .* matrix'
0.000264996
Which means 1000 iterations ran in about 0.265 seconds which
is about half the time MatLab took.
Thanks again.
>You should exclude the time required for generating the
>random numbers. e.g.
>
> 6!:2 '(?256$0)+/ . *?256 312$0'
>0.00416422
> x=: 256 [EMAIL PROTECTED] 0
> y=: 256 312 [EMAIL PROTECTED] 0
> 6!:2 'x +/ .*y'
>0.000503416
>
>As well, use [EMAIL PROTECTED] rather than ?x$y . This makes a
>difference especially when y is 2. The idea for [EMAIL PROTECTED] is
>from k.
>
> ts=: 6!:2 , 7!:[EMAIL PROTECTED]
> ts '1e6 [EMAIL PROTECTED] 2'
>0.00208853 1.04934e6
> ts '?1e6$2'
>0.0127536 5.24352e6
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm