More matrix features to MathObject matrices#1076
Conversation
da3b3bf to
3df446c
Compare
|
I was looking at the POD since a lot of that is in the diff here, and I left some comments. But I'm going to pause because I think if you proofread the actual POD output you will see a lot of the same things that I'm seeing. I'll move on to testing the new tools now. |
| $A->subMatrix([3,1,2],[1,4,2]); # returns Matrix([9,12,10],[1,4,2],[5,8,6]); | ||
| =cut | ||
|
|
||
| sub subMatrix { |
There was a problem hiding this comment.
This has some issues as well. If I try it on a 1D matrix, I get an error:
$A = Matrix([ 1, 2, 3, 4 ]);
$B = $A->subMatrix([3]);
And if I try it on a 3D matrix, it is not returning what I would expect it to:
$A = Matrix([ [[1,2],[3,4]], [[5,6], [7,8]]]);
$B = $A->subMatrix([1], [1,2], [2]);
# $B seems to be what I would expect from subMatrix([1], [1,2], [1,2]);
There was a problem hiding this comment.
(It did seem to work when I tested with 2D matrices though.)
There was a problem hiding this comment.
I thought of subMatrix only on 2D matrices, so will rework for other dimensions.
There was a problem hiding this comment.
Rewrote this now. Should be working on non-2D matrices.
| my $el = $self->{data}[ $ind->[0] - 1 ]; | ||
| for my $i (1 .. scalar(@$ind) - 1) { $el = $el->{data}[ $ind->[$i] - 1 ]; } | ||
|
|
||
| # update the value of $el | ||
| $el = Value::makeValue($value); |
There was a problem hiding this comment.
This needs to be
| my $el = $self->{data}[ $ind->[0] - 1 ]; | |
| for my $i (1 .. scalar(@$ind) - 1) { $el = $el->{data}[ $ind->[$i] - 1 ]; } | |
| # update the value of $el | |
| $el = Value::makeValue($value); | |
| my $el = \($self->{data}[ $ind->[0] - 1 ]); | |
| for my $i (1 .. scalar(@$ind) - 1) { $el = \($$el->{data}[ $ind->[$i] - 1 ]); } | |
| # update the value of $el | |
| $$el = Value::makeValue($value); |
my $el = \($self->{data}[ $ind->[0] - 1 ]);
for my $i (1 .. scalar(@$ind) - 1) { $el = \($$el->{data}[ $ind->[$i] - 1 ]); }
# update the value of $el
$$el = Value::makeValue($value);in order to actually mutate the matrix.
There was a problem hiding this comment.
Changed this, but odd that the test works for the previous version of the code as well as this one, however, I think the test needs some help.
34fd8ed to
9ba941c
Compare
Also fix some documentation typos and clarifications. u
9ba941c to
c365efe
Compare
| these need to be added: | ||
| row : MathObjectMatrix | ||
| column : MathObjectMatrix | ||
| element : Real or Complex value |
There was a problem hiding this comment.
See my other comment about column. Currently for a 1D matrix, $matrix->column(1) is a Real. I do think it should be changed to be a MathObject Matrix though.
With the element method, it is more complicated than this. If you have an nD matrix and you pass n whole numbers to element, then yes you get a Real (or Complex, I assume). But if you pass fewer than n whole numbers, you get a Matrix. (And if you pass more than n, you get null.)
|
See my recent comments just now. I feel like we need to work on this file in a more methodical manner, especially since there are things to fix that precede the new things here. I propose:
When I look at the diff for this PR, it's just too overwhelming to sort out what is just POD moving around and what is new content. |
|
Would it make sense if we split this in two pieces?
|
|
This is being rewritten using different PRs. The first one is #1197 which cleans up the POD and a second one will take some of the functionality in this PR. Once both are merged, we will close this one. |
|
We should catalog what is still here that needs to be added.
Did I miss anything? We should be careful to add them so that they work for a Matrix object of any degree. We should agree on what things like "removeRow" and "removeColumn" mean for degrees other than 2. |
|
I think the methods in |
|
I've opened PRs that recover
and @somiaj also mentioned some methods from
Good thing about this convention:
"Bad" thing about this convention:
So an alternative would be to still make these methods illegal on degree 1 Matrices, yet still apply to degrees above 2. |
@somiaj Where is |
|
It was my dyslexia, sorry about that, it is |
|
OK, I found Most things in there are now implemented in But even then, what about when your matrix has floating point values in the first place? Well, if you think they all come from fractions, you could apply Fraction() to them first, again using the Fraction context. But even then, what if floating point entries came from irrational numbers? So I see too many floating point issues with doing a row reduction algorithm in We could put something like |
|
I haven't ran into enough floating point issues on smaller 3x3 or 4x4 matrices for the method in It would be nice to not have to use that older macro for this, and I think since these are math objects, equality isn't exact so floating point issues have never gotten bad enough to not mark answers correct. |
|
When you have used this, have you been also using Fraction context? Based on your second paragraph, I'm not sure the issue is clear. It's not an issue about one value being slightly different from another value. In a row reduction algorithm, scaling and subtraction happens in a way that is engineered to make one element of a row become zero, while other elements in the row get the same treatment and may or may not come out as zero. When one of those other elements in that row should become zero, but actually comes out nonzero because of machine rounding, it throws a big wrench in the algorithm. The algorithm reaches a cell that mathematically should have come to zero, and the algorithm should have moved to look at a cell to the right. But since it reaches a nonzero cell (owing to the rounding error), it normalizes the entire row so that cell has value 1. So what should not have been a pivot position comes out as a pivot position. Try this MWE: That matrix should row reduce to have only one pivot position, but I'm getting it to come out as the identity matrix. And it's just the classic machine rounding issue with an rref algorithm. |
|
I haven't tested the fraction context, and yea my matrices are nice in that they won't create something that the issues can cause problems. I can keep loading this older macro, but it also means it is harder to deprecate. To me I think it would be better to have the rref algorithm available with maybe a warning, and let authors decide if it is useful or not. If there are ways to improve it, that is good to. I also have algorithms that I use to put matrices in echelon form with no division to avoid such issues, but these are for writing solutions not graders. |
This builds on #1012 and includes