sagemath/sage

Refactor {Matrix,Vector}_double_dense through ..._numpy_dense, add ..._numpy_integer_dense

Closed this issue · 30 comments

... in order to define matrix spaces backed by numpy arrays of various types
https://numpy.org/doc/stable/reference/arrays.scalars.html#signed-integer-types

For ZZ, this could for example provide a separate element implementation that is never used for arithmetic, but is good enough for creating matrices in methods such as vertex_adjacency_matrix (#32666)

Related earlier ticket: #7920

CC: @kliem @orlitzky

Component: linear algebra

Author: Matthias Koeppe

Branch/Commit: b0a1a04

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/32465

Description changed:

--- 
+++ 
@@ -2,3 +2,4 @@
 https://numpy.org/doc/stable/reference/arrays.scalars.html#signed-integer-types
 
 
+Related earlier ticket: #7920

Description changed:

--- 
+++ 
@@ -1,5 +1,7 @@
 ... in order to define matrix spaces backed by numpy arrays of various types
 https://numpy.org/doc/stable/reference/arrays.scalars.html#signed-integer-types
 
+For `ZZ`, this could for example provide a separate element implementation that is never used for arithmetic, but is good enough for creating matrices in methods such as `vertex_adjacency_matrix` (#32666)
+
 
 Related earlier ticket: #7920
comment:4

setting to needs_review for the patchbot.

Still needs work to hook it into the constructor etc.


New commits:

d66b7bcsrc/sage/matrix/matrix_double_dense.pyx: Update copyright according to 'git blame -w --date=format:%Y src/sage/matrix/matrix_double_dense.pyx | sort -k2'
d33d173sage.matrix: Factor Matrix_double_dense through Matrix_numpy_dense, add Matrix_numpy_integer_dense

Commit: d33d173

Author: Matthias Koeppe

Changed commit from d33d173 to 98ced3c

Branch pushed to git repo; I updated commit sha1. New commits:

98ced3csrc/sage/matrix/matrix_numpy_integer_dense.pyx: Fix doctest

Branch pushed to git repo; I updated commit sha1. New commits:

cde4e54src/sage/modules/vector_double_dense.pyx: Update copyright according to 'git blame -w --date=format:%Y src/sage/modules/vector_double_dense.pyx | sort -k2'
2ffb118Vector_double_dense: Factor through new class Vector_numpy_dense

Changed commit from 98ced3c to 2ffb118

Changed commit from 2ffb118 to 5b288c3

Branch pushed to git repo; I updated commit sha1. New commits:

5b288c3sage.modules.vector_numpy_integer_dense: New

Branch pushed to git repo; I updated commit sha1. New commits:

c8eec7eMerge tag '9.5.beta6' into t/32465/refactor_matrix_double_dense_through_matrix_numpy_dense
5323b25src/sage/matrix/matrix_numpy_dense.pyx: Returns -> Return

Changed commit from 5b288c3 to 5323b25

comment:10

Stalled in needs_review or needs_info; likely won't make it into Sage 9.5.

Changed commit from 5323b25 to d07cf93

Branch pushed to git repo; I updated commit sha1. New commits:

d07cf93Merge tag '9.5' into t/32465/refactor_matrix_double_dense_through_matrix_numpy_dense
comment:13

Do I understand this ticket correctly that it is basically refactoring out methods into base classes?

Why isn't, e.g., _numpy_dtypeint set for Matrix_double_dense? I would think this would cause problems when using this class with numpy.

comment:14

Replying to @tscrim:

Do I understand this ticket correctly that it is basically refactoring out methods into base classes?

Yes

comment:15

Replying to @tscrim:

Why isn't, e.g., _numpy_dtypeint set for Matrix_double_dense? I would think this would cause problems when using this class with numpy.

Matrix_double_dense is also abstract. _numpy_dtypeint is set in the subclasses, see src/sage/matrix/matrix_real_double_dense.pyx and src/sage/matrix/matrix_complex_double_dense.pyx

Reviewer: Travis Scrimshaw

comment:16

Ah, I see. Thank you. This is essentially a positive review. One little change I saw when reading it over (a while-we-are-at-it):

In matrix_numpy_dense is_symmetric():

-        The tolerance inequality is strict:
+        The tolerance inequality is strict::
+
             sage: m.is_symmetric(tol=0.1)
             False
             sage: m.is_symmetric(tol=0.11)
             True

Once done, you can set a positive review on my behalf.

Changed commit from d07cf93 to 21ed44a

Branch pushed to git repo; I updated commit sha1. New commits:

93f3925src/sage/matrix/matrix_numpy_dense.pyx: Fix doc markup, whitespace
21ed44aMerge tag '9.6.beta1' into t/32465/refactor_matrix_double_dense_through_matrix_numpy_dense
comment:18

Thank you!

comment:19

On 32-bit:

**********************************************************************
File "src/sage/matrix/matrix_numpy_integer_dense.pyx", line 15, in sage.matrix.matrix_numpy_integer_dense
Failed example:
    M.numpy()
Expected:
    array([[ 0,  0,  0],
           [ 0,  0, 47]])
Got:
    array([[ 0,  0,  0],
           [ 0,  0, 47]], dtype=int64)
**********************************************************************
1 item had failures:
   1 of   6 in sage.matrix.matrix_numpy_integer_dense
    [8 tests, 1 failure, 0.01 s]
**********************************************************************
File "src/sage/modules/vector_numpy_integer_dense.pyx", line 12, in sage.modules.vector_numpy_integer_dense
Failed example:
    v.numpy()
Expected:
    array([ 0, 42,  0])
Got:
    array([ 0, 42,  0], dtype=int64)
**********************************************************************
1 item had failures:
   1 of   6 in sage.modules.vector_numpy_integer_dense
    [5 tests, 1 failure, 0.01 s]

Branch pushed to git repo; I updated commit sha1. New commits:

b0a1a04src/sage/{matrix/matrix,modules/vector}_numpy_integer_dense.pyx: Fix doctest output in 32bit

Changed commit from 21ed44a to b0a1a04

comment:22

Nice catch, fixed now