Skip to content
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

Add row/columnAddVector to NumericMatrix #462

Merged
merged 11 commits into from
Dec 31, 2022
Merged

Add row/columnAddVector to NumericMatrix #462

merged 11 commits into from
Dec 31, 2022

Conversation

Aweptimum
Copy link
Contributor

Adds the feature discussed in #459

There are two decisions I made that you might want to consider before merging

  1. At first, I decided to match the behavior of row/columnAdd where k is not allowed to be 0, so I added a condition to check if the given vector is a zero-vector by comparing its length to 0 (within the tolerance of the matrix). As I was writing this PR though, I realized it might best to break precedent since the user may not know the contents of the vector at run-time vs the explicit k passed into row/columnAdd. If you disagree, you can revert the last commit. However, I think there's little harm in letting it pass through, and it might be even better to keep the comparison and just return self to avoid adding imprecision and creating a new matrix.
  2. In the tests, I used MatrixFactory::createNumeric to make intellisense happy 🙃
    It's inconsistent with the rest of the tests, but I figured it may not matter

Let me know of any desired changes or formatting errors, I did my best to follow the guidelines.

@markrogoyski
Copy link
Owner

Hi @Aweptimum,

Thank you for your pull request!

Before I can run the CI tests, please either merge the latest develop branch into your branch and push the changes to the pull request, or rebase based on develop and push the changes. There are some updates in develop since your PR that will affect the success of the unit tests.

Thanks!
Mark

Similar to columnAdd's condition that k be non-zero,
but may not be necessary.
The # of elements in the vector should equal the # of rows

col element
Given a column index and a vector, adds the elements of the vector to the corresponding row.

Conditions are:
1. The column index must exist
2. The vector cannot be a zero-vector
3. The # of vector components must equal the # of matrix rows

For 2. the zero-length check uses the error of the matrix to compare the vector length to zero.
Make sure the count of the vector components equals the number of rows in the matrix
Given a vector and a row index, adds the elements of the vector to the corresponding row

Conditions are:
1. The row index must exist
2. The vector cannot be a zero-vector
3. The # of vector components must equal the # of matrix columns

For 2. the zero-vector check uses the error of the matrix to compare the vector magnitude to zero.
It might be worth breaking the precedent set by row/columnAdd since it's not guaranteed a user knows they're passing a zero vector into the method. In such a case, it seems best to allow the addition rather than break.
@Aweptimum
Copy link
Contributor Author

Done! I had noticed the same precision failures as in the other open PR, nice work :)

@coveralls
Copy link

Coverage Status

Coverage: 99.962% (+0.03%) from 99.934% when pulling 21b83d5 on Aweptimum:addVector-ops into 7275502 on markrogoyski:develop.

@Aweptimum
Copy link
Contributor Author

It seems one of my commits removed the newline in the MatrixColumnOperationsTest (probably a squash gone wrong), although putting it back locally hasn't made phpcs happy. It's failing every file in my local repo with the same error, that they all end with \r\n. I have VSCode set to use \n instead of \r\n and haven't touched any other files, so I'm not sure what's going on.

The RowOperations test seems to have no errors, so I can try adding the newline back to the columns test, squash it into the column length-mismatch test commit, and force push again to see if it passes the CI. You alright with that?

@markrogoyski
Copy link
Owner

Hi @Aweptimum,

Don't worry about the newlines. With Macs/Linux/Windows sometimes it is hard to get it all right. I'll take care of the newlines. The tests are passing, which are the important check.

Let me know if you have any other changes planned. Otherwise, I'll go ahead and merge it and take care of the PHPCS linting issue.

Thanks,
Mark

@Aweptimum
Copy link
Contributor Author

Cool, thanks Mark! I had no other changes planned for this branch.

@markrogoyski markrogoyski merged commit c97386d into markrogoyski:develop Dec 31, 2022
if ($mᵢ < 0 || $mᵢ >= $this->m) {
throw new Exception\MatrixException('Row to add does not exist');
}
if ($v->count() !== $this->m) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This should actually be n and not m. I've fixed this and added some unit tests around it.

@markrogoyski
Copy link
Owner

Thanks again for the PR. This functionality will go out in the next release, v2.8.0.

@Aweptimum
Copy link
Contributor Author

You're welcome, thanks for fiddling with it!

@Aweptimum
Copy link
Contributor Author

I realized the next day I forgot to add it to the docs 🤦‍♂️ should probably just make that a part of #461

@markrogoyski
Copy link
Owner

I added them to the README in the develop branch. No worries. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants