Skip to content

BUG: tighten alignment for complex types. - #5365

Closed
cournape wants to merge 1 commit into
numpy:masterfrom
cournape:tighten_alilgnment_complex
Closed

cournape wants to merge 1 commit into
numpy:masterfrom
cournape:tighten_alilgnment_complex

Conversation

@cournape

Copy link
Copy Markdown
Member

Complex types memory representations in C for a given type are guaranteed to be equivalent to type[2]. As such, the alignment of complex<type> should be the same as type.

I tested scipy 0.14.x (at scipy/scipy@d6c3206, containing the f2py workaround) in the following setups:

numpy 1.9.1, w/ this patch
  • one genuine error (all platforms). Unlikely to be related to numpy.
[192.168.33.13] out: ======================================================================
[192.168.33.13] out: ERROR: test_antiderivative_of_constant (test_interpolate.TestPPoly)
[192.168.33.13] out: ----------------------------------------------------------------------
[192.168.33.13] out: Traceback (most recent call last):
[192.168.33.13] out:   File "/home/vagrant/src/master-env/lib/python2.7/site-packages/scipy/interpolate/tests/test_interpolate.py", line 659, in test_antiderivative_of_constant
[192.168.33.13] out:     assert_equal(p.antiderivative().c, PPoly([[1], [0]], [0, 1]).c)
[192.168.33.13] out:   File "/home/vagrant/src/master-env/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 821, in antiderivative
[192.168.33.13] out:     self.x, nu)
[192.168.33.13] out:   File "_ppoly.pyx", line 142, in scipy.interpolate._ppoly.fix_continuity (scipy/interpolate/_ppoly.c:5462)
[192.168.33.13] out: ValueError: order too large
  • a few minor precision issues that have been here for a while otherwise.
numpy 1.9.1, w/o this patch
  • Same results as above for rh5 and osx and windows 64 bits, but a dozen new errors for windows 32 bits:
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZaxpy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 85, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_almost_equal(real_y,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([  0.+0.j,  12.+0.j,  24.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_stride (test_fblas.TestZaxpy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 71, in test_x_stride
[172.17.5.102] err:     assert_array_almost_equal(real_y,y)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([  0.+0.j,   7.+0.j,  14.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZaxpy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 78, in test_y_stride
[172.17.5.102] err:     assert_array_almost_equal(real_y,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  3.+0.j,  6.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZcopy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 219, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_almost_equal(x[::4],y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  4.+0.j,  8.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZcopy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 213, in test_y_stride
[172.17.5.102] err:     assert_array_almost_equal(x,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_simple (test_fblas.TestZscal)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 145, in test_simple
[172.17.5.102] err:     assert_array_almost_equal(real_x,x)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  3.+0.j,  6.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_simple (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 288, in test_simple
[172.17.5.102] err:     assert_array_almost_equal(desired_x,x)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 315, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_almost_equal(desired_x,x[::4])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  4.+0.j,  8.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 297, in test_x_stride
[172.17.5.102] err:     assert_array_almost_equal(desired_x,x[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  2.+0.j,  4.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\lib\blas\tests\test_fblas.py", line 307, in test_y_stride
[172.17.5.102] err:     assert_array_almost_equal(desired_y,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 842, in assert_array_almost_equal
[172.17.5.102] err:     precision=decimal)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not almost equal to 6 decimals
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZaxpy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 87, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_equal(real_y,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([  0.+0.j,  12.+0.j,  24.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZaxpy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 80, in test_y_stride
[172.17.5.102] err:     assert_array_equal(real_y,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  3.+0.j,  6.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZcopy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 219, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_equal(x[::4],y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  4.+0.j,  8.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZcopy)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 213, in test_y_stride
[172.17.5.102] err:     assert_array_equal(x,y[::2])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_simple (test_fblas.TestZscal)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 146, in test_simple
[172.17.5.102] err:     assert_array_equal(real_x,x)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  3.+0.j,  6.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_simple (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 287, in test_simple
[172.17.5.102] err:     assert_array_equal(desired_x,x)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_and_y_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 314, in test_x_and_y_stride
[172.17.5.102] err:     assert_array_equal(desired_x,x[::4])
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  4.+0.j,  8.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_x_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 297, in test_x_stride
[172.17.5.102] err:     assert_array_equal(desired_y,y)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  2.+0.j,  4.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err: 
[172.17.5.102] err: ======================================================================
[172.17.5.102] err: FAIL: test_y_stride (test_fblas.TestZswap)
[172.17.5.102] err: ----------------------------------------------------------------------
[172.17.5.102] err: Traceback (most recent call last):
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\scipy\linalg\tests\test_fblas.py", line 305, in test_y_stride
[172.17.5.102] err:     assert_array_equal(desired_x,x)
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 739, in assert_array_equal
[172.17.5.102] err:     verbose=verbose, header='Arrays are not equal')
[172.17.5.102] err:   File "C:\Users\vagrant\src\master-env\lib\site-packages\numpy\testing\utils.py", line 665, in assert_array_compare
[172.17.5.102] err:     raise AssertionError(msg)
[172.17.5.102] err: AssertionError:
[172.17.5.102] err: Arrays are not equal
[172.17.5.102] err: 
[172.17.5.102] err: (mismatch 66.6666666667%)
[172.17.5.102] err:  x: array([ 0.+0.j,  0.+0.j,  0.+0.j])
[172.17.5.102] err:  y: array([ 0.+0.j,  1.+0.j,  2.+0.j])
[172.17.5.102] err: 

Complex types memory representations in C are guaranteed to be equivalent to
type[2]. As such, the alignment of complex<type> should be the same as type.
@juliantaylor

Copy link
Copy Markdown
Contributor

test failure is real, should be the same you see on sparc

@juliantaylor

Copy link
Copy Markdown
Contributor

confirmed the bus error on sparc with this patch,, see I told you I tried this :)
that said that this crashes even though the alignment should be sufficient is an issue in numpy, a fix for that would be great.

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

The real problem apparently is that the logic in the loop selection in
lowlevel_strided_loops.c.src:PyArray_GetStridedCopyFn is correct only
if the alignment is the same as for the integer type of the same itemsize.
.
In particular, complex64 on gcc/linux/x86_64 has alignment 4 and
itemsize 8. The loop selector sees the array is aligned and selects
itemsize-8 loop. However, the itemsize-8 loop itself assumes the data
is aligned according to uint64 -> boom. (On x86 this doesn't matter,
apart from the asserts.)

@juliantaylor

Copy link
Copy Markdown
Contributor

yes thats why I introduced the copy alignment variable to account for this, one could also add special complex code or only use copy alignment for copy operations.

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

Yes, the problem is that PyArray_ISALIGNED has nothing to do with the alignment that the copy loops want to know about. Nevertheless, PyArray_ISALIGNED is used to in ndarray_constr.c to decide this. I'll try to see if this it's easy to come up with a patch...

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

I won't finish it today (or tomorrow), but the suggested fix would be to restore descr->alignment to be the alignment given by the C compiler --- this is a public API in numpy, and this is how it used to be. Then, add an internal function PyArray_DescrGetCopyAlignment(desrc) that returns the appropriate alignment for the copy loops, and use that in all code paths that end up choosing copy loops. There are a number of them, and various variants of alignment checks are littered here and there, so there's some cleanup to do. (There are also some FIXMEs there along these lines :)

@juliantaylor

Copy link
Copy Markdown
Contributor

do we really care that a complex float32 from 8 byte unaligned memory is not flagged as 4 byte aligned?
if not my other pr is somewhat simpler

@charris

charris commented Dec 11, 2014

Copy link
Copy Markdown
Member

I haven't worked on this so my opinion might be totally irrelevant, but if I understand correctly, it makes sense to distinguish the types of alignment if one is specific to the needs of copying.

@njsmith

njsmith commented Dec 11, 2014

Copy link
Copy Markdown
Member

"do we really care that a complex float32 from unaligned memory is not
flagged as aligned?" -- maybe I'm just not the audience for this question,
but FWIW I have no idea what you're asking :-)

Do I have it right that basically what the strided copy loop code should be
doing is, if (ptr % itemsize) == (stride % itemsize) == 0 then we use the
aligned loop, and otherwise we use the unaligned one?
On 11 Dec 2014 21:22, "Julian Taylor" [email protected] wrote:

do we really care that a complex float32 from unaligned memory is not
flagged as aligned?
if not my other pr is somewhat simpler

—
Reply to this email directly or view it on GitHub
#5365 (comment).

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

The strided copy loop should be doing if (ptr % _ALIGN(@copytype@)) == 0 && (stride % _ALIGN(@copytype@)) == 0) where @copytype@ is uint8, uint16, uint32, uint64 and is chosen based on itemsize. Currently, it assumes this check is equivalent to checking the dtype alignment.

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

@cournape: did you also test with Numpy 1.8.x? What I don't understand right now is that the complex alignment was doubled already in Numpy 1.8 (c9bf9b0), so one would expect to see f2py issues also there?

@juliantaylor

Copy link
Copy Markdown
Contributor

1.8 didn't actually check the alignment, everything was aligned

@pv

pv commented Dec 11, 2014

Copy link
Copy Markdown
Member

@juliantaylor: do you mean flags.aligned == True on all newly allocated arrays? Or just the thing of adding alignment checks to the transfer loops?

@juliantaylor

Copy link
Copy Markdown
Contributor

the former, but also for arrays which where created by passing the constructor a pointer

@cournape

Copy link
Copy Markdown
Member Author

@pv for numpy 1.8.1 on win-32, I had np.dtype("D").alignment == 8 true.

@rgommers

Copy link
Copy Markdown
Member

@cournape test failure for Bento build

@charris

charris commented Jan 19, 2015

Copy link
Copy Markdown
Member

Closing this. For 1.9.2 will backport #5316, and for 1.10.0 another fix is pending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants