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

DM-12272: Fix bug in arrayFromVector #30

Merged
merged 6 commits into from Oct 21, 2017
Merged

DM-12272: Fix bug in arrayFromVector #30

merged 6 commits into from Oct 21, 2017

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Oct 19, 2017

No description provided.

Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

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

Looks good. Some style comments.

@@ -43,7 +43,7 @@ using Array2D = ndarray::Array<double, 2, 2>;
/**
2D array of const double; typically used for lists of const points
*/
using ConstArray2D = ndarray::Array<double const, 2, 2>;
using ConstArray2D = ndarray::Array<const double, 2, 2>;
Copy link
Member

Choose a reason for hiding this comment

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

The new way is inconsistent with LSST convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case one reads left to right; a similar issue comes up for shared_ptr, e.g. "shared_ptr" is a shared pointer to a const foo. I know we've adopted this convention in real life, but I don't know if it's in the standard.

Copy link
Member

Choose a reason for hiding this comment

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

Which standard do you mean? 😕

@@ -78,6 +78,11 @@ Reshape a vector as a 2-dimensional array that shares the same memory
@warning You must hold onto the original vector until you are done
with the returned array, else the array will be corrupted.
Copy link
Member

Choose a reason for hiding this comment

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

Per the style guide, notes should appear after the parameter/return/exception section.

@@ -67,14 +67,14 @@ ConstArray2D arrayFromVector(std::vector<double> const &vec, int nAxes) {
}

Array2D arrayFromVector(std::vector<double> &vec, int nAxes) {
if (vec.size() % nAxes != 0) {
int nPoints = vec.size() / nAxes;
if (nPoints * nAxes != vec.size()) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this change. What's wrong with the original test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt the test was more obvious the new way. I'd seen it done elsewhere in our stack and I preferred it.

def test_arrayFromVector(self):
nAxes = 3
nValues = 5
dataVec = np.random.rand(nAxes * nValues)
Copy link
Member

Choose a reason for hiding this comment

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

Does this use a fixed seed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. In this case I don't see how it can make any difference, but providing a seed is best practice.

dataVec = np.random.rand(nAxes * nValues)
desiredDataArr = dataVec.copy()
desiredDataArr.shape = (nAxes, nValues)
dataArr = ast.arrayFromVector(vec=dataVec, nAxes=nAxes)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't dataVec a numpy.ndarray? Would it be useful to test this with a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll test both ways.

the strides vector was incorrect in arrayFromVector.
Add a pybind11 wrapper and a unit test.
explaining how to use it for a vector of polynomial coefficients
and move the warning to after the parameter list as per our standard
I was only using the typedefs in a few locations (basically for
data, but not coefficient arrays). I think the intent is clearer
using the typedefs everwhere, especially given that the coefficient
array arguments should have had const elements, but did not.
@r-owen r-owen merged commit 4035ac0 into master Oct 21, 2017
@ktlim ktlim deleted the tickets/DM-12272 branch August 25, 2018 04:30
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.

None yet

2 participants