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
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: #7920Description 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: #7920setting to needs_review for the patchbot.
Still needs work to hook it into the constructor etc.
New commits:
d66b7bc | src/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' |
d33d173 | sage.matrix: Factor Matrix_double_dense through Matrix_numpy_dense, add Matrix_numpy_integer_dense |
Author: Matthias Koeppe
Branch pushed to git repo; I updated commit sha1. New commits:
98ced3c | src/sage/matrix/matrix_numpy_integer_dense.pyx: Fix doctest |
Branch pushed to git repo; I updated commit sha1. New commits:
5b288c3 | sage.modules.vector_numpy_integer_dense: New |
Stalled in needs_review or needs_info; likely won't make it into Sage 9.5.
Branch pushed to git repo; I updated commit sha1. New commits:
d07cf93 | Merge tag '9.5' into t/32465/refactor_matrix_double_dense_through_matrix_numpy_dense |
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.
Replying to @tscrim:
Do I understand this ticket correctly that it is basically refactoring out methods into base classes?
Yes
Replying to @tscrim:
Why isn't, e.g.,
_numpy_dtypeintset forMatrix_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
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)
TrueOnce done, you can set a positive review on my behalf.
Thank you!
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:
b0a1a04 | src/sage/{matrix/matrix,modules/vector}_numpy_integer_dense.pyx: Fix doctest output in 32bit |
Nice catch, fixed now
Changed branch from u/mkoeppe/refactor_matrix_double_dense_through_matrix_numpy_dense to b0a1a04