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
matrix() command should accept some Matlab-style inputs #11699
Comments
comment:1
see also http://www.mathworks.com/help/techdoc/math/f1-84864.html#f1-84906 |
comment:2
In particular, elements can be separated by either commas or spaces (or both), and rows are separated by semicolons. So we should be able to easily separate by splitting the string:
|
comment:3
Or probably even faster, do the ','->' ' translation once at the beginning to avoid lots of small strings being created:
This would just be inserted in the first time the elements of a matrix were accessed and would convert the string to a list of elements like it expects. |
comment:4
In fact, we should support multiple lines here too, like Matlab, so you could do:
To do that, do
At this point, it might be better to use regular expressions. It's certainly worth a timing test. Note the following matlab examples:
|
comment:5
Oops, that should |
comment:6
Slightly faster than the double replace, if
Then the double replace above becomes: |
comment:7
Okay, here's a new iteration, especially since I flipped logic above with the r.strip()
|
comment:8
Okay, try this. I think it still needs some optimization with the string handling stuff, and it could probably use some more doctests, but it's basically ready for review. |
Author: Dan Drake |
This comment has been minimized.
This comment has been minimized.
comment:9
Hrm, Robert Bradshaw just tossed some cold water on my simple string-handling: https://groups.google.com/d/msg/sage-devel/p-nrpKUBMm8/_4DL5li7NcQJ The quick version: what about |
comment:10
quick comment: you should probably use |
comment:11
Another problem: If we do put this in, I think the docstring should be explicit that using strings is limited, and only really works for number literals and similar things. Then later someone can write a full parser and figure out the evaluation context stuff. |
comment:13
Maybe on another ticket, but can I ask for one more enhancement on this? Can we make the following work:
(i.e., any "]" or "[" next to row delimiters are stripped). That would mean that I could cut and paste output from Sage back into Sage to make a matrix. |
comment:14
Replying to @jasongrout:
Sure, no problem. Although you'll still have the split-on-whitespace and context limitations. But plain numerical matrices are common enough so that I think it's worth it. |
apply to main repo |
comment:15
Attachment: trac_11699_matlab_input_to_matrix.patch.gz See #12354 for another take on this as preparser syntax. |
comment:17
This patch causes a doctest to fail in sageinspect.py (see patchbot logs) -- looks like somebody helpfully wrote a doctest which relies on the docstring of "matrix()" being exactly 34 lines long. (There is also another failure on the most recent run, but I suspect that is just a random glitch.) |
comment:18
argh, I was trying to use this today, thinking it was already in... |
Commit: |
Branch: u/ddrake/string-matrix-11699 |
Changed work issues from failing doctest to failing doc build |
comment:24
I've ported this over to 6.9.beta3. It builds, works, and passes doctests, but the documentation doesn't build -- I have doctests with New commits:
|
comment:25
Replying to @dandrake:
Use
instead of
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:27
Replying to @jdemeyer:
That's it! Thank you. |
Changed work issues from failing doc build to none |
comment:29
Failing doctest
|
Dependencies: #24742 |
comment:32
I don't plan to work on this, but if anybody does: it should be on top of #24742. |
In https://groups.google.com/d/msg/sage-devel/p-nrpKUBMm8/LUMAfoXsz-UJ Jason Grout mentioned that it would be convenient if Sage accepted the following Matlab syntax for creating matrices:
This should be an easy change to the
matrix()
command, and would be very convenient for users, even those with no Matlab background.Depends on #24742
CC: @kini @kcrisman @mforets
Component: linear algebra
Author: Dan Drake
Branch/Commit: u/ddrake/string-matrix-11699 @
5d006ef
Issue created by migration from https://trac.sagemath.org/ticket/11699
The text was updated successfully, but these errors were encountered: