-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
More matrix features to MathObject matrices #1076
base: develop
Are you sure you want to change the base?
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. |
sub row { | ||
my $self = (ref($_[0]) ? $_[0] : shift); | ||
my $M = $self->promote(shift); | ||
my $i = shift; | ||
return if $i == 0; | ||
$i-- if $i > 0; | ||
Value::Error("Row must be a positive integer") unless $i =~ m/^[1-9]\d*$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't recall where, but there is somewhere else like this where we support having an explicit plus sign in front of the integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But maybe this would be better if if actually accessed the dimensions of the matrix, and required an integer that is a valid row index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since $i
is usually a Perl real (not a string, for example), an initial plus sign will not be in its stringified version, so won't be part of the comparison in $i =~ m/.../
even if you used $M->row(+3)
. It would only be there if you passed the row number as a string, as in $M->row("+3")
, which I might consider to be an improper value to pass (it is not a positive integer, it is a string).
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It did seem to work when I tested with 2D matrices though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of subMatrix only on 2D matrices, so will rework for other dimensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote this now. Should be working on non-2D matrices.
lib/Value/Matrix.pm
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
This builds on #1012 and includes