From: gnp
Subject: CMUCL Warning
Date: 
Message-ID: <1133646306.665222.28820@g49g2000cwa.googlegroups.com>
Hi all,

Can anyone explain to me the following warning
issued by the CMUCL compiler:
; In: DEFUN LU-DECOMPOSITION
;   (POSITION MAXVAL COL)
; --> DO BLOCK LET TAGBODY RETURN-FROM
; ==>
;   (PROGN
;     NIL)
; Warning: This is not a (VALUES &OPTIONAL NUMBER &REST T):
;   NIL
; ; [Last message occurs 2 times]
; Compilation unit finished.
;   2 warnings

My machine is x86 (slackware 10.2, cmucl 19c).
I don't get any warning when compiling the same code
with SBCL (0.9.5)

The part of the code where the warning occurs reads as follows:
	(let* ((col (map 'vector #'*
			 (subseq (acol scrambled j) j)
			 (subseq v j)))
	       (maxval (reduce #'max col))
	       (ipiv (+ j (position maxval col))))

where the function acol has been defined as:

(defun acol (arr-in j)
  "Returns a vector which is a column of a 2D array"
  (let* ((nrows (array-dimension arr-in 0))
	 (result (make-array nrows)))
    (dotimes (i nrows result)
      (setf (svref result i) (aref arr-in i j)))))


This is a part of a function to perform LU (lower-upper) decomposition
in matrices. In fact, I have translated it in lisp from fortran.
The fortran version comes from the "Numerical Recipes in Fortran"
book (online at www.nr.com). I could post the whole lisp function
if anyone wants, I just didn't want to disrupt  this newsgroup with
a too long newbie post :-)


thanks in advance
--gnp

From: Carl Shapiro
Subject: Re: CMUCL Warning
Date: 
Message-ID: <ouyek4ten0g.fsf@panix3.panix.com>
"gnp" <·······@gmail.com> writes:

> The part of the code where the warning occurs reads as follows:
> 	(let* ((col (map 'vector #'*
> 			 (subseq (acol scrambled j) j)
> 			 (subseq v j)))
> 	       (maxval (reduce #'max col))
> 	       (ipiv (+ j (position maxval col))))

I've tried compiling this expression wrapped in a simple top-level
definition but cannot reproduce your warnings.

...

> This is a part of a function to perform LU (lower-upper) decomposition
> in matrices. In fact, I have translated it in lisp from fortran.
> The fortran version comes from the "Numerical Recipes in Fortran"
> book (online at www.nr.com). I could post the whole lisp function
> if anyone wants, I just didn't want to disrupt  this newsgroup with
> a too long newbie post :-)

There may not be a need to hand translate the Fortran flavored NR code
as much (if not all) of it is readily machine translatable into Common
Lisp using a freely available Fortran to Lisp translator such as f2cl.
From: gnp
Subject: Re: CMUCL Warning
Date: 
Message-ID: <1133660894.934773.232760@g49g2000cwa.googlegroups.com>
Thanks for the response, I just found the solution: The warning
disappears when I replace
(position maxval col)
with
(position maxval col :test #'equal)

I am just trying to learn common lisp, and I wrote this as an exercise.
Anyway, the fortran to lisp translator sounds interesting, I will look
for it. Thank you very much,

gnp
From: Christophe Rhodes
Subject: Re: CMUCL Warning
Date: 
Message-ID: <sq64q5p93x.fsf@cam.ac.uk>
"gnp" <·······@gmail.com> writes:

> Thanks for the response, I just found the solution: The warning
> disappears when I replace
> (position maxval col)
> with
> (position maxval col :test #'equal)

This smells a little bit of a workaround.

The basic reason you are getting your warning is because you use the
return value from POSITION in a call to +.  
  (let (...
        (maxval (reduce #'max col))
	(ipiv (+ j (position maxval col))))
    ...)
Under certain optimization conditions, the compiler will attempt to
deduce more information about the return value of position, and will
maybe attempt to expand it into simpler code; I suspect that both of
these will happen in your case.

If, then, it expands into something like
  (do ((i 0 (1+ i)))
      ((= i end) nil)
    (when (funcall test (aref col i))
      (return i)))
[ as the warning text suggests:
  ;   (POSITION MAXVAL COL)
  ; --> DO BLOCK LET TAGBODY RETURN-FROM
        ^^ ]
then the compiler will see explicitly a possible NIL return value,
which it knows cannot be added to J, whatever J is.  (I should say 
that while I'm moderately sure the above analysis is right, I don't 
understand why you don't get the warning when you use :test #'equal).

The warning is arguably undesireable behaviour in this case, because
you know that the element you're searching for is, but sometimes it's
helpful in telling you that you should probably handle an extra case.

(You might want to rewrite the code anyway, so that you don't need to
go over the COL vector twice; then this problem will go away naturally
:-)

Christophe