From: ·················@gmail.com
Subject: Python-on-lisp cannot import numpy and so on with SBCL and CMUCL
Date: 
Message-ID: <18f9415d-07c1-45d1-85cf-a5b6ffac1ffe@w39g2000prb.googlegroups.com>
Python-on-lisp With SBCL and CMUCL, following simple code cause error.

(py::py ” import numpy”)

First I thought, that was bug of pythononlisp.
(then I write another interface
http://www2s.biglobe.ne.jp/~niitsuma/pyjsonrpcembd.html
)

However, more simple call PyRun_SimpleString(“import numpy”) using
CFFI also cause error. (But with clisp the following works.)
----------------------------
(asdf:operate 'asdf:load-op :cffi)
;(require :cffi)
(cffi:define-foreign-library python-library
  (:darwin (:framework "Python"))
  (:unix (:or "libpython2.5.so.1.0" "libpython2.4.so.1.0"
"libpython2.3.so.1.0"))
  (:windows (:or "python25.dll" "python24.dll" "python23.dll") )
  (t (:default "libpython")))

(cffi:defcfun ("Py_Initialize" Py_Initialize) :void)

(defun init-python (&optional (program-name "cmucl") (secure NIL))
  (cffi:use-foreign-library python-library)
  (Py_Initialize)
)

(init-python)

(cffi:defcfun ("PyRun_SimpleString" PyRun_SimpleString) :void
  (code :string))

( PyRun_SimpleString "print 'test'")
( PyRun_SimpleString "import numpy")


----------------------------

debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial
thread" {A84D7A9}>:
  Error during processing of --eval option (LOAD #P"directtest.lisp"):

  arithmetic error FLOATING-POINT-OVERFLOW signalled

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE] Ignore and continue with next --eval option.
  1: [ABORT   ] Skip rest of --eval options.
  2:            Skip to toplevel READ/EVAL/PRINT loop.
  3: [QUIT    ] Quit SBCL (calling #'QUIT, killing the process).

((LAMBDA (SB-IMPL::E)) #<FLOATING-POINT-OVERFLOW {AC9F6D9}>)

----------------------------

I also try import another python libray. It is seem to SBCL can use /
usr/lib/python2.5/site-packaged/foo.py
But cannot use /usr/lib/python2.5/site-packaged/foo/baa.py

From: Waldek Hebisch
Subject: Re: Python-on-lisp cannot import numpy and so on with SBCL and CMUCL
Date: 
Message-ID: <gmfhj4$ovf$1@z-news.wcss.wroc.pl>
·················@gmail.com wrote:
> Python-on-lisp With SBCL and CMUCL, following simple code cause error.
> 
> (py::py ? import numpy?)
> 
> First I thought, that was bug of pythononlisp.
> (then I write another interface
> http://www2s.biglobe.ne.jp/~niitsuma/pyjsonrpcembd.html
> )
> 
> However, more simple call PyRun_SimpleString(?import numpy?) using
> CFFI also cause error. (But with clisp the following works.)
> ----------------------------
> (asdf:operate 'asdf:load-op :cffi)
> ;(require :cffi)
> (cffi:define-foreign-library python-library
>   (:darwin (:framework "Python"))
>   (:unix (:or "libpython2.5.so.1.0" "libpython2.4.so.1.0"
> "libpython2.3.so.1.0"))
>   (:windows (:or "python25.dll" "python24.dll" "python23.dll") )
>   (t (:default "libpython")))
> 
> (cffi:defcfun ("Py_Initialize" Py_Initialize) :void)
> 
> (defun init-python (&optional (program-name "cmucl") (secure NIL))
>   (cffi:use-foreign-library python-library)
>   (Py_Initialize)
> )
> 
> (init-python)
> 
> (cffi:defcfun ("PyRun_SimpleString" PyRun_SimpleString) :void
>   (code :string))
> 
> ( PyRun_SimpleString "print 'test'")
> ( PyRun_SimpleString "import numpy")
> 
> 
> ----------------------------
> 
> debugger invoked on a SIMPLE-ERROR in thread #<THREAD "initial
> thread" {A84D7A9}>:
>   Error during processing of --eval option (LOAD #P"directtest.lisp"):
> 
>   arithmetic error FLOATING-POINT-OVERFLOW signalled
> 
> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
> 
> restarts (invokable by number or by possibly-abbreviated name):
>   0: [CONTINUE] Ignore and continue with next --eval option.
>   1: [ABORT   ] Skip rest of --eval options.
>   2:            Skip to toplevel READ/EVAL/PRINT loop.
>   3: [QUIT    ] Quit SBCL (calling #'QUIT, killing the process).
> 
> ((LAMBDA (SB-IMPL::E)) #<FLOATING-POINT-OVERFLOW {AC9F6D9}>)
> 
> ----------------------------
> 
> I also try import another python libray. It is seem to SBCL can use /
> usr/lib/python2.5/site-packaged/foo.py
> But cannot use /usr/lib/python2.5/site-packaged/foo/baa.py
> 
> 
>

First guess would be that numpy and Lisp want different setting
of floating point unit.  For Lisp it is natural to trap on any
floating point error, but some code assumes that computation
will go on producing thing like Infinity or NotANumber.  It
seems that sbcl allows you to swith FPU to non-trapping mode,
try this.

-- 
                              Waldek Hebisch
·······@math.uni.wroc.pl 
From: ·················@gmail.com
Subject: Re: Python-on-lisp cannot import numpy and so on with SBCL and CMUCL
Date: 
Message-ID: <685710e7-cc14-4e85-b2a0-510f6000adca@w1g2000prk.googlegroups.com>
Thank you for the advice.
It works with (sb-int:set-floating-point-modes :traps '()) in SBCL
------------
(sb-int:set-floating-point-modes :traps '())
(require :pythononlisp)
(py::py "import numpy")
-----------