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

Fix common_subexpression bug #1338

Merged
merged 12 commits into from
Dec 3, 2015
Merged

Fix common_subexpression bug #1338

merged 12 commits into from
Dec 3, 2015

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Dec 3, 2015

Fixes #1325

@cpcloud cpcloud self-assigned this Dec 3, 2015
@cpcloud cpcloud added this to the 0.9.0 milestone Dec 3, 2015
@cpcloud cpcloud added the bug label Dec 3, 2015
@cpcloud
Copy link
Member Author

cpcloud commented Dec 3, 2015

@llllllllll this could use your review when you get a chance

@llllllllll
Copy link
Member

I will look at this now

all_leaves = [expr._leaves() for expr in exprs]

# leaves common to all expressions
leaves = set.intersection(*map(set, all_leaves))
Copy link
Member

Choose a reason for hiding this comment

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

this fails if there are no exprs, one way to fix this is to define the function like:

def common_subexpression(expr, *exprs):
    exprs = (expr,) + exprs
    ...

This will make it raise the correct type error if the one required argument is not passed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll make this change


@property
def _args(self):
# XXX: is this a hack?
Copy link
Member

Choose a reason for hiding this comment

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

Why do you think this might be a hack?

Copy link
Member Author

Choose a reason for hiding this comment

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

because _args is supposed to be the values of __slots__ sans the _hash property and _full_expr isn't a slot

Copy link
Member

Choose a reason for hiding this comment

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

I thought _args was supposed to be all of the arguments passed to the constructor, is there a reason we need to put the args of _fullexpr in there?

Copy link
Member Author

Choose a reason for hiding this comment

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

we need because otherwise there's no path from a broadcast expression to the true leaf because for the following expression t.amount + 1, Broadcast's _args look like this _children=(t,), _scalars=(t,), _scalar_expr=t.amount + 1) and the path algorithm will traverse an expression until we've reached the end of the path and in this case we are traversing to a leaf which doesn't appear in Broadcast._traverse() because everything is scalar-ified

Copy link
Member

Choose a reason for hiding this comment

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

Ah, okay. Lets leave the comment for now then and maybe revisit the path algorithm some time in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

IOW, _children[0].isidentical(_scalars[0]) is False because _children datashapes have the dimension whereas _scalars don't

@llllllllll
Copy link
Member

Looks great!

cpcloud added a commit that referenced this pull request Dec 3, 2015
@cpcloud cpcloud merged commit 66757ed into blaze:master Dec 3, 2015
@cpcloud cpcloud deleted the transform-subexpr branch December 3, 2015 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants