View Issue Details

IDProjectCategoryView StatusLast Update
0002193Slicer4Core: Scripting (Wrapping, Python)public2014-03-06 04:52
Reporterm2j Assigned Tojcfr  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Product VersionSlicer 4.1.0 
Target VersionSlicer 4.2.0Fixed in VersionSlicer 4.2.0 
Summary0002193: Python NumPy crash
Description

Numpy crashes when I try to find the inverse of a square matrix. On the other hand, when I try to solve a linear least-squares problem, it does not obtain the correct answer.

1) Go to the Python interactor.
2) Enter the following commands:
import numpy
B = numpy.array([[1,2],[3,4]])
numpy.linalg.inv(B)

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/Documents/Mis_Programas/Slicer-4.1.0-linux-amd64/lib/Python/lib/python2.6/site-packages/numpy/linalg/linalg.py", line 423, in inv
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
File "/home/user/Documents/Mis_Programas/Slicer-4.1.0-linux-amd64/lib/Python/lib/python2.6/site-packages/numpy/linalg/linalg.py", line 310, in solve
return wrap(b.transpose().astype(result_t))
ValueError: On entry to DGESV parameter number 4 had an illegal value


I tried the same in the system installed python, and the answer is this one:

array([[-2. , 1. ],
[ 1.5, -0.5]])

Solving a linear least-squares problem:

Once again, in the Python Interactor:

1) Import the numpy package (in case you haven't imported it yet)
import numpy
2) Enter the following commands:
x = numpy.array([0, 1, 2, 3])
y = numpy.array([-1, 0.2, 0.9, 2.1])
A = numpy.vstack([x, numpy.ones(len(x))]).T
numpy.linalg.lstsq(A, y)
(array([-1. , 0.2]), array([], dtype=float64), 0, array([ 0., 0.]))

This is not the correct answer!!

I tried the same in the system installed python, and the correct answer is obtained:

(array([ 1. , -0.95]), array([ 0.05]), 2, array([ 4.10003045, 1.09075677]))

Additional Information

I am using Slicer 4.1.0 , 64 bits linux version.
I have tried both pre-compiled versions:
stable release and nightly build, with the same result.

TagsNo tags attached.

Relationships

has duplicate 0002249 closedjcfr numpy.linalg.det does not work 

Activities

jcfr

jcfr

2012-06-30 23:37

administrator   ~0005020

Last edited: 2012-06-30 23:38

The topic referenced in this note should resolve the problem: http://www.na-mic.org/Bug/view.php?id=2249#c5017

m2j> Could you try on your side and let me know if it also solves the issue you reported ?

Using the topic reported above, the test now passes (Ubuntu 10.04 / Gcc 4.4.3)

Python 2.6.6 (r266:84292, May 15 2012, 11:26:17)
[GCC 4.4.3] on linux2

import numpy
B = numpy.array([[1,2],[3,4]])
numpy.linalg.inv(B)
array([[-2. , 1. ],
[ 1.5, -0.5]])
x = numpy.array([0, 1, 2, 3])
y = numpy.array([-1, 0.2, 0.9, 2.1])
A = numpy.vstack([x, numpy.ones(len(x))]).T
numpy.linalg.lstsq(A, y)
(array([ 1. , -0.95]), array([ 0.05]), 2, array([ 4.10003045, 1.09075677]))

fedorov

fedorov

2012-07-01 14:05

developer   ~0005023

Tested with gcc 4.2.1 on Mac Snow leopard, the issue appears to be resolved.

B=np.array([[1,2],[3,4]])
np.linalg.inv(B)
array([[-2. , 1. ],
[ 1.5, -0.5]])
x = numpy.array([0, 1, 2, 3])
y = numpy.array([-1, 0.2, 0.9, 2.1])
A = numpy.vstack([x, numpy.ones(len(x))]).T
numpy.linalg.lstsq(A, y)
(array([ 1. , -0.95]), array([ 0.05]), 2, array([ 4.10003045, 1.09075677]))

jcfr

jcfr

2012-07-01 14:35

administrator   ~0005026

Excellent !

jcfr

jcfr

2012-07-01 18:29

administrator   ~0005030

Fixed in r20539
See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=20539

jcfr

jcfr

2012-07-27 15:40

administrator   ~0005397

Dear issue reporter,

Good news :) Slicer developers SOLVED the problem you reported - YOU now need to VERIFY and CLOSE this issue.

jcfr

jcfr

2014-03-06 04:50

administrator   ~0010695

Closing resolved issues that have not been updated in more than 3 months

Issue History

Date Modified Username Field Change
2012-06-13 12:12 m2j New Issue
2012-06-13 12:12 m2j Status new => assigned
2012-06-13 12:12 m2j Assigned To => jcfr
2012-06-30 23:37 jcfr Note Added: 0005020
2012-06-30 23:37 jcfr Status assigned => feedback
2012-06-30 23:38 jcfr Note Edited: 0005020
2012-06-30 23:39 jcfr Relationship added has duplicate 0002249
2012-07-01 14:05 fedorov Note Added: 0005023
2012-07-01 14:35 jcfr Note Added: 0005026
2012-07-01 18:29 jcfr Note Added: 0005030
2012-07-01 18:29 jcfr Status feedback => resolved
2012-07-01 18:29 jcfr Fixed in Version => Slicer 4.2.0 - Sept 1st 2012
2012-07-01 18:29 jcfr Resolution open => fixed
2012-07-01 18:30 jcfr Target Version => Slicer 4.2.0 - Sept 1st 2012
2012-07-27 15:40 jcfr Note Added: 0005397
2014-03-06 04:50 jcfr Note Added: 0010695
2014-03-06 04:52 jcfr Status resolved => closed