-
-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide diagonal_matrix as a method of matrix spaces #28882
Comments
comment:1
Ticket retargeted after milestone closed |
comment:3
I added a So, I tried to think of reasons why we would be using Are there practical reasons, so that I can write better code for this file now/ in the future? Also would like a review on this patch. New commits:
|
Commit: |
comment:5
It would be better to model this on the |
comment:6
Yes, this needs to be fixed for non-square matrices and requires doc-tests. However, ensuring the length of |
comment:10
Please review. Currently, this doesn't work: sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') sage: type(M1.diagonal_matrix([1, 2]))
sage: type(M2.diagonal_matrix([1, 2]))
Both the types are currently: <class 'sage.matrix.matrix_integer_sparse.Matrix_integer_sparse'> New commits:
|
comment:11
Matrix spaces can be created using the keyword diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py
index b4cb724e3b..3712806364 100644
--- a/src/sage/matrix/matrix_space.py
+++ b/src/sage/matrix/matrix_space.py
@@ -1600,7 +1600,7 @@ class MatrixSpace(UniqueRepresentation, Parent):
"""
if self.__nrows != self.__ncols:
raise TypeError("diagonal matrix must be square")
- A = sage.matrix.special.diagonal_matrix(self.base_ring(), self.dims()[0], entries)
+ A = sage.matrix.special.diagonal_matrix(self.base_ring(), self.dims()[0], entries, sparse=self.is_sparse())
A.set_immutable()
return A
Why make it immutable by default? |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:13
Replying to @jhpalmieri:
The above discussion thread suggested to model diagonal_matrix on the identity_matrix function. Since that was immutable by default, I made it so in diagonal_matrix as well. I'll remove it if required. I've now made a change that keeps the implementation method the same in the diagonal matrix. Please review. |
comment:14
The
This is not an issue with |
comment:15
Ok. Thank you for the clarification. I'm new to this library. I'll remove the immutability part and send the PR again. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:17
Replying to @sagetrac-git:
Please review |
Reviewer: John Palmieri |
comment:19
I made a few changes:
If you are happy with these changes, feel free to set to positive review. Make sure to add your real name to the "Authors" field. New commits:
|
comment:20
Thank you for the corrections u/jhpalmieri. Setting status to 'positive review'. |
Author: Sagnik Dey |
comment:21
|
comment:22
Replying to @vbraun:
Hey @vbraun, thanks for the pointer. I'm new to contributing to sage and this makes me realise I should run all the doctests before sending PRs. Just a clarification, should I also run the "long" tests? Also, regarding this change, clearly, the error is because I added a new function so the number of expected functions should increase by one. I can make the change in the test file and send it if that's what is required. However, I tried rebasing with current develop branch and then running the doc test and this gives expected and got values different:
Should I change the doctest before or after rebase? |
comment:23
I would propose this change: diff --git a/src/doc/en/thematic_tutorials/coercion_and_categories.rst b/src/doc/en/thematic_tutorials/coercion_and_categories.rst
index bd76813e9c..b58c9c59de 100644
--- a/src/doc/en/thematic_tutorials/coercion_and_categories.rst
+++ b/src/doc/en/thematic_tutorials/coercion_and_categories.rst
@@ -447,10 +447,10 @@ Sage's category framework can differentiate the two cases::
And indeed, ``MS2`` has *more* methods than ``MS1``::
sage: import inspect
- sage: len([s for s in dir(MS1) if inspect.ismethod(getattr(MS1,s,None))])
- 81
- sage: len([s for s in dir(MS2) if inspect.ismethod(getattr(MS2,s,None))])
- 121
+ sage: L1 = len([s for s in dir(MS1) if inspect.ismethod(getattr(MS1,s,None))])
+ sage: L2 = len([s for s in dir(MS2) if inspect.ismethod(getattr(MS2,s,None))])
+ sage: L1 < L2
+ True
This is because the class of ``MS2`` also inherits from the parent
class for algebras:: The doctest in question is supposed to demonstrate that there are more methods for square matrices than non-square matrices, but I don't see why the actual numbers should be important. And as we see here, the actual numbers are sensitive to changes in the Sage library; testing |
comment:24
Replying to @jhpalmieri:
Ok thank you, I'll make this change. Also, you recently changed the status of #27636 from positive_review to needs work. Can you please make a note there as to what change is required? |
comment:25
That was vbraun, not me. |
comment:27
Replying to @jhpalmieri:
I'm so sorry I got mixed up... New commits:
|
comment:28
First, the current branch fails to merge. Second, it is always best if you run all doctests ( |
comment:30
Here's a branch including that change. New commits:
|
comment:31
Replying to @jhpalmieri:
Oh sorry about that. Thank you for correcting it. I'll pull and rebase with current develop on my other branches as well.
Thank you! |
Changed branch from u/jhpalmieri/provide_diagonal_matrix_as_a_method_of_matrix_spaces to |
Sage provides two functions
identity_matrix
and
diagonal_matrix
in the global namespace.By contrast, matrix spaces have an
identity_matrix
method but no
diagonal_matrix
method.Global namespace functions:
Matrix space methods:
Before this ticket:
After this ticket:
Component: linear algebra
Keywords: diagonal matrix
Author: Sagnik Dey
Branch/Commit:
f2d8ea9
Reviewer: John Palmieri
Issue created by migration from https://trac.sagemath.org/ticket/28882
The text was updated successfully, but these errors were encountered: