If it gives the correct answer then it is correct,
but yes, apparently there is not yet any special
code for sparsevec +/ .* densevec .



----- Original Message -----
From: Jan Jacobs <[email protected]>
Date: Sunday, February 21, 2010 12:13
Subject: [Jgeneral] dot product of sparse vector with non-sparse vector
To: General forum <[email protected]>

> ls,
> the script below does suggest that dot product of sparse (spv) 
> with dense
> vector (nsv) is not optimised. Is this correct?
> If so, is     
> +/(5&$.spv)*nsv{~4&$.spv      the best 
> possible alternative?
> Thanks in advance,
> Jan.
> 
> mksv=:3 : 0
>  NB. non sparse
>  ?y.$0
> :
>  NB. sparse
>  0.9(i.x.)}1$.y.
> )
> mul=:3 : 0
> ] spv=:100 mksv y.    NB. less sparse
> ] nsv=:mksv y.
>  ts1=.ts'+/nsv*nsv'
>  ts2=.ts'+/nsv*spv'
>  ts3=.ts'+/spv*spv'
>  {."1 ts1,ts2,:ts3
> )
> pd'new'
> pd'key  +/nsv*nsv +/nsv*spv +/spv*spv'
> pd |: mul"0 (1000*>:i.100)
> pd'show'
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to