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 vectorization to 4 functions #317

Closed
wants to merge 10 commits into from

Conversation

michaelaye
Copy link
Contributor

Transferring the previously adapted style of vectorization from other functions
@AndrewAnnex
Copy link
Owner

AndrewAnnex commented Nov 2, 2019 via email

Copy link
Owner

@AndrewAnnex AndrewAnnex left a comment

Choose a reason for hiding this comment

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

okay I have posted me review comments:

  1. test are failing because you need to use the new if stypes.isiterable function for the 4 function instead of if hasattr
  2. docstrings need to be updated to indication functions can return a collection
  3. each function needs a separate unit test that just tests the vectorization independently
  4. there are a lot of unnecessary white space diffs in the PR, those changes need to be removed.

spiceypy/spiceypy.py Show resolved Hide resolved
spiceypy/spiceypy.py Show resolved Hide resolved
spiceypy/spiceypy.py Show resolved Hide resolved
spiceypy/spiceypy.py Show resolved Hide resolved
spiceypy/spiceypy.py Show resolved Hide resolved
@@ -5701,6 +5703,8 @@ def test_scencd():
sclkdp = spice.scencd(-32, sclkch)
npt.assert_almost_equal(sclkdp, 985327950.0)
assert sclkch == "2/20538:39:768"
mylist = 3 * [sclkch]
npt.assert_almost_equal(spice.scencd(-32, mylist), 3*[985327950.0])
Copy link
Owner

Choose a reason for hiding this comment

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

for these and other new unit tests, they should be independent test functions that include vectorized in the function name ie test_scencd_vectorized. see rest of test_wrapper.py for examples.

@@ -10985,8 +10993,16 @@ def scencd(sc, sclkch, MXPART=None):
sc = ctypes.c_int(sc)
sclkch = stypes.stringToCharP(sclkch)
sclkdp = ctypes.c_double()
libspice.scencd_c(sc, sclkch, ctypes.byref(sclkdp))
return sclkdp.value
if hasattr(sclkch, "__iter__"):
Copy link
Owner

Choose a reason for hiding this comment

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

for this function and for the other 4, change to use new iterable test function to fix failed builds

if stypes.isiterable(sclkch):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what about the other 14 uses of if hasattr?

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 can fix all of them if you want, IF you let me remove those un-holy white-spaces at the end of lines and in empty lines as well? Deal? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, i also found functions where you accept both scalar and iterable, but return type in the docstring does not mention it, e.g. srfxpt . Do those docstrings also need fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

another btw: as we want SpiceyPy to become PEP8 compliant in the future, right, we need to work on some stuff anyway. My editor removes them by default, that's why the white space was gone.

Quote from PEP8:

Avoid trailing whitespace anywhere. Because it's usually invisible, it can be confusing: e.g. a backslash followed by a space and a newline does not count as a line continuation marker. Some editors don't preserve it and many projects (like CPython itself) have pre-commit hooks that reject it.

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 have updated all if hasattr to stypes.isiterable if they fit the pattern of looping over a potential iterable, otherwise do skalar type return. There were some cases with cells where that pattern didn't match, so i didn't touch those.

@AndrewAnnex
Copy link
Owner

@michaelaye do you have time to update this PR? If not could you enable edits from maintainers so I could wrap it up?

@michaelaye
Copy link
Contributor Author

later today, yes. just finishing an MDAP proposal right now.

michaelaye and others added 8 commits November 21, 2019 01:06
* Update spiceypy.py to use equality instead of is for small integer comparisons, not really a bug for cpython, but could be for other implementations
* removes old 3.X versions that are no longer supported in CI builds
* updated docs section to include a link to the lessons
* updated top warning to also say the naif writes tutorials that use spiceypy (the lessons), fixes AndrewAnnex#314
* start of numpy string support
* added pandas test
* noticed a missed error check in a loop, may need to fix in other places
* added ev2lin, lightsail2 based unit test from @djcinsb

* add coveralls to windows
not wrapped inside scalar version of test.
@michaelaye
Copy link
Contributor Author

Seems like tests are still failing, ctypes wants a float not an iterable, it seems? How did you make it work for the other iterables?

>       et = ctypes.c_double(et)
456E       TypeError: a float is required

@@ -32,7 +32,7 @@ SPICE is an essential tool for scientists and engineers alike in the planetary
science field for Solar System Geometry. Please visit the NAIF website for more details about SPICE.

*IMPORTANT*: I have no current affiliation with NASA, NAIF, or JPL. The
code is provided "as is", use at your own risk.
code is provided "as is", use at your own risk. However, the NAIF now distributes python "lessons" that use SpiceyPy as the python to spice interface.
Copy link
Owner

Choose a reason for hiding this comment

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

I have already added this to the master branch, but I am not sure why this diff is still being shown by github.

@@ -97,7 +100,7 @@ as newer versions are released.

- OS: OS X, Linux, Windows
- CPU: 64bit only!
- Python 2.7, 3.3, 3.4, 3.5, 3.6, 3.7
- Python 2.7, 3.5, 3.6, 3.7
Copy link
Owner

Choose a reason for hiding this comment

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

okay something strange is happening

@AndrewAnnex
Copy link
Owner

okay, so there a few things going on here. In the future please try to seperate these comments into different posts so I can reply to each individually.

  1. I do not follow PEP8, or I mostly do? Either way, this PR must remain focused on getting these 4 functions working and up to spec with the rest of the codebase and should do nothing else. This policy is to keep the review process short and clear.

  2. using hasattr is fine if the collection is a 1d list or array of numerical/boolean datatypes. stypes.isiterable should only be used for functions in which a list of strings are given at the moment I have not tested it for other use cases. If that function needs to be updated to be used uniformly across spiceypy let me worry about that in a later commit.

  3. et2utc is failing because you are passing a collection of floats into ctypes.c_double, please look at the other vectorized functions that use hasattr to follow the existing pattern in the codebase.

  4. Something is very wrong with sct2e now given the unit test errors I am seeing in the travis CI logs

  5. utc2et is failing because you didn't delete the first call to stringToCharP

  6. There is something really odd with the git history of this branch now, you pulled in a lot of diffs that I committed into master creating a very complicated diff that is hard to parse through. I think you can fix this by squashing your changes and rebasing onto the master branch then force pushing to overwrite this branch on your fork.

  7. All white space diffs have to be reverted before I merge. I like to keep commits simple and although there might be good arguments to use black or pep8 in spiceypy, this PR is not the time for them.

  8. Unit tests I suggested need to be added to test the vectorization of these 4 functions.

Copy link
Owner

@AndrewAnnex AndrewAnnex left a comment

Choose a reason for hiding this comment

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

unit test are failing, all white space diffs need to be removed, branch needs to be squashed then rebased onto the master branch to fix the git history and to clear up all of the bad diffs in one go

see below for long comment addressing these and other issues

okay, so there a few things going on here. In the future please try to separate these comments into different posts so I can reply to each individually.

1. I do not follow PEP8, or I mostly do? Either way, this PR must remain focused on getting these 4 functions working and up to spec with the rest of the codebase and should do nothing else. This policy is to keep the review process short and clear.

2. using hasattr is fine if the collection is a 1d list or array of numerical/boolean datatypes. `stypes.isiterable` should only be used for functions in which a list of strings are given at the moment I have not tested it for other use cases. If that function needs to be updated to be used uniformly across spiceypy let me worry about that in a later commit.

3. et2utc is failing because you are passing a collection of floats into ctypes.c_double, please look at the other vectorized functions that use hasattr to follow the existing pattern in the codebase.

4. Something is very wrong with sct2e now given the unit test errors I am seeing in the travis CI logs

5. utc2et is failing because you didn't delete the first call to stringToCharP

6. There is something really odd with the git history of this branch now, you pulled in a lot of diffs that I committed into master creating a very complicated diff that is hard to parse through. I think you can fix this by squashing your changes and rebasing onto the master branch then force pushing to overwrite this branch on your fork.

7. All white space diffs have to be reverted before I merge. I like to keep commits simple and although there might be good arguments to use black or pep8 in spiceypy, this PR is not the time for them.

8. Unit tests I suggested need to be added to test the vectorization of these 4 functions.

:return: Output epoch, ephemeris seconds past J2000.
:rtype: float
:rtype: Union[float,Iterable[float]]
"""
utcstr = stypes.stringToCharP(utcstr)
Copy link
Owner

Choose a reason for hiding this comment

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

delete this to fix the unit test

@@ -5704,6 +5810,16 @@ def test_scencd():
spice.kclear()


def test_scencd_vectorized():
spice.kclear()
spice.furnsh(CoreKernel.testMetaKernel)
Copy link
Owner

Choose a reason for hiding this comment

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

CoreKernels

spice.furnsh(ExtraKernels.voyagerSclk)
et = spice.sct2e(-32, 985327965.0)
mylist = 3 * [985327965.0]
assert spice.sct2e(mylist) == 3*[et]
Copy link
Owner

Choose a reason for hiding this comment

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

you are forgetting to pass in -32

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.

vectorize sct2e, scencd, and et2utc
2 participants