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

Refactor reduce to take an optional module and only a function name. #1386

Merged
merged 1 commit into from
Jun 19, 2019

Conversation

ttung
Copy link
Collaborator

@ttung ttung commented May 31, 2019

Module defaults to np (== numpy). Class no longer accepts a callable. Alias list is a dict that relatively easy to extend.

Test plan: travis

@codecov-io
Copy link

codecov-io commented May 31, 2019

Codecov Report

Merging #1386 into master will decrease coverage by 0.01%.
The diff coverage is 86.2%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1386      +/-   ##
==========================================
- Coverage   89.42%   89.41%   -0.02%     
==========================================
  Files         152      152              
  Lines        5531     5553      +22     
==========================================
+ Hits         4946     4965      +19     
- Misses        585      588       +3
Impacted Files Coverage Δ
starfish/core/image/_filter/reduce.py 91.8% <86.2%> (-3.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f0ae37...cfcbd63. Read the comment docs.

@ambrosejcarr
Copy link
Member

A couple high-level comments:

  1. Is there any reason we don't accept *args and **kwargs and pass those to the function? I could imagine it being important, for example...
  2. Can we have a couple examples in the class documentation? One simple one that uses "mean", and a complex one that uses scipy.linalg.norm selecting the 2 norm?
module=scipy.linalg
function="norm"
kwargs={"ord": 2}

@kevinyamauchi
Copy link
Collaborator

This looks good to be. I agree with @ambrosejcarr that some examples in the documentation would be really helpful.

@ttung ttung force-pushed the tonytung-reduce branch 2 times, most recently from 162b3a5 to 714a795 Compare June 3, 2019 18:43
@ttung ttung requested a review from shanaxel42 June 3, 2019 18:43
@ttung
Copy link
Collaborator Author

ttung commented Jun 3, 2019

I added a couple of tests, a couple of examples, and beefed up the docs.

@ttung ttung force-pushed the tonytung-reduce branch 2 times, most recently from 023cb4d to fd66303 Compare June 3, 2019 19:50
@ttung ttung force-pushed the tonytung-reduce branch from fd66303 to d9bfa9d Compare June 6, 2019 22:47
@ttung ttung added this to the 0.2.0 milestone Jun 10, 2019
@@ -17,53 +22,141 @@

class Reduce(FilterAlgorithmBase):
"""
Reduces the dimensions of the ImageStack by applying a function
along one or more axes.
Reduces the dimensions of the ImageStack by applying a function along one or more axes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

does 'Reduces the size of the dimensionsmake more sense? Reduces the dimensions made me think we were reducing the number of dimensions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reworded this. It now says, "Reduces the cardinality of one or more axes to 1 by applying a function across those axes."

def __init__(
self, dims: Iterable[Union[Axes, str]], func: Union[str, Callable] = 'max',
clip_method: Clip = Clip.CLIP
self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused about what is this the init method for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the init for the Reduce class. There is an init method for the FunctionSource class starting at L103.

Make a test ImageStack

'''
"""Make a test ImageStack."""

# Make the test image
test = np.ones((2, 4, 1, 2, 2), dtype='float32') * 0.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we use imagestack_factory() here instead? Or maybe add a imagestack_from_numpy method to factories/all_purpose.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could we use imagestack_factory() here instead?

Plausibly, though the inputs and outputs are very precise and not very numerous. Not sure if it makes sense to.

imagestack_from_numpy

ImageStack.from_numpy is basically that, isn't it?

@ttung ttung force-pushed the tonytung-reduce branch 2 times, most recently from 0347021 to b44147e Compare June 19, 2019 07:40
@ttung ttung force-pushed the tonytung-reduce branch from b44147e to 9e7557d Compare June 19, 2019 07:44
Module defaults to np (== numpy).  Class no longer accepts a callable.  Alias list is a dict that relatively easy to extend.

Test plan: travis
@ttung ttung force-pushed the tonytung-reduce branch from 9e7557d to cfcbd63 Compare June 19, 2019 07:50
@ttung ttung merged commit fcded6d into master Jun 19, 2019
ttung pushed a commit that referenced this pull request Jun 19, 2019
ttung pushed a commit that referenced this pull request Jun 19, 2019
@ttung ttung deleted the tonytung-reduce branch June 19, 2019 19:18
@@ -17,53 +22,141 @@

class Reduce(FilterAlgorithmBase):
Copy link
Member

Choose a reason for hiding this comment

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

@ttung given how codebases typically mirror map & reduce, I wonder if apply should be exposed in a similar fashion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I agree. I thought there was already an issue for that, but maybe I'm wrong.

It's also possible that Reduce might work for this already.

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.

5 participants