Re: m.*! not native?

Jefferson Provost <[email protected]>
Newsgroups gmane.lisp.matlisp.user
Message-ID <[email protected]>
Raymond Toy wrote:
>>>>>>"Jefferson" == Jefferson Provost <[email protected]> writes:
>>>>>
> 
>     Jefferson> I'm not sure.  The short answer is that I would love to have it better
>     Jefferson> optmized, but if it's not a priority for you guys, I understand.
> 
> If you can, please try the CVS version.  I've put in an optimized
> version that should run as fast as a Fortran version should (on
> CMUCL).
> 
> I'd be interested to know if it's fast enough for you.

Yes it's quite fast.  Multiplying two NxN matrices is still a little 
slower than the outer product of two N-length vectors (which should also 
be O(N^2) operations) -- but this is probably from going out of cache on 
the large matrices, while the smaller vectors will stay in cache.

As I mentioned before, I had changed my code so I didn't need to call 
M.* as often, but that was a sub-optimal solution.  But, I realized that 
my main use of M.* was to "mask" a matrix, i.e. set a bunch of elements 
to 0.0 using another matrix as a guide:  (m.*! mask x).  So I wrote a 
special function just to do that masking.  It's MUCH faster, since it 
does no multiplication at all...


(defmethod mmask! ((a real-matrix) (mask real-matrix))

   (let* ((nxm (number-of-elements a))
	 (aa (store a))
	 (bb (store mask)))
     (declare (type fixnum nxm)
	     (type (real-matrix-store-type (*)) aa bb)
	     (optimize (speed 3) (safety 0)))

     (dotimes (k nxm a)
       (declare (type fixnum k))
       (let ((b-val (aref bb k)) )
	(declare (type real-matrix-element-type b-val)
		 (:explain :calls :types :boxing))
	(when (zerop b-val)
	  (setf (aref aa k) 0.0d0))))))

J.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.