Skip to content

tf.reshape accepts Dimension objects for the shape parameter - #12127

Closed
facaiy wants to merge 7 commits into
tensorflow:masterfrom
facaiy:ENH/tf_reshape_support_dimension_obj
Closed

facaiy wants to merge 7 commits into
tensorflow:masterfrom
facaiy:ENH/tf_reshape_support_dimension_obj

Conversation

@facaiy

@facaiy facaiy commented Aug 9, 2017 •

Copy link
Copy Markdown
Member

The PR aims to fix #11974.

Because it's my first contribution, so the PR is opened early to get feedback from community.

What changes were proposed in this pull request?

Cast tf.Dimension to int for shape argument.

How was this patch tested?

  • add a doctest.

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@mention-bot

Copy link
Copy Markdown

@facaiy, thanks for your PR! By analyzing the history of the files in this pull request, we identified @keveman, @vrv and @tensorflower-gardener to be potential reviewers.

@yaroslavvb

Copy link
Copy Markdown
Contributor

Sorry I don't understand the motivation
compat.as_bytes(x.str()) instead of compat.as_bytes(x)

what does this improve?

@facaiy facaiy changed the title tf.reshape accepts Dimension objects for the shape parameter WIP: tf.reshape accepts Dimension objects for the shape parameter Aug 11, 2017
@facaiy
facaiy force-pushed the ENH/tf_reshape_support_dimension_obj branch from b48e565 to 69a8cdd Compare August 11, 2017 03:49
@facaiy facaiy changed the title WIP: tf.reshape accepts Dimension objects for the shape parameter tf.reshape accepts Dimension objects for the shape parameter Aug 11, 2017
@facaiy

facaiy commented Aug 11, 2017

Copy link
Copy Markdown
Member Author

@yaroslavvb , the PR is modified as suggested by @pmccarter . But I am not sure whether it is implemented correctly, could you give more feedback? Thanks.

@rmlarsen
rmlarsen requested a review from martinwicke August 11, 2017 18:22
@rmlarsen rmlarsen added the awaiting review Pull request awaiting review label Aug 11, 2017
@rmlarsen

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins test this please

@rmlarsen

Copy link
Copy Markdown
Contributor

@facaiy As you can see here: https://ci.tensorflow.org/job/tensorflow-pull-requests-cpu/6320/consoleFull
this breaks a large number of tests. I'll let @martinwicke give detailed comments.

@facaiy

facaiy commented Aug 11, 2017 •

Copy link
Copy Markdown
Member Author

@rmlarsen @martinwicke It'll be really useful for me if I can check test.log of CI. Because my laptop is left on office, hence I'll check it later. Thanks very much!

@facaiy

facaiy commented Aug 12, 2017

Copy link
Copy Markdown
Member Author

@tensorflow-jenkins test this please

@facaiy

facaiy commented Aug 12, 2017

Copy link
Copy Markdown
Member Author

Hi, @rmlarsen . I submit a fix, and could you help retest the PR? Thanks.

Returns:
A `Tensor`. Has the same type as `tensor`.
"""
if hasattr(shape, "__len__") and len(shape) <= 8:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should we raise an exception when len(shape) > 8?

@facaiy

facaiy commented Aug 12, 2017

Copy link
Copy Markdown
Member Author

By the way, since reshape is migrated from _gen_array_op to array_op, should we remove the duplicate document of _gen_array_op._reshape? If I understand correctly, the description is in the tensorflow/core/ops/ops.pbtxt

@yaroslavvb

Copy link
Copy Markdown
Contributor

@facaiy The docs are inside cc file which defines reshape op.

To think of it, this approach would trigger an API review. I wonder if there's a simple solution which would only touch a couple of lines of Python code, better chance of being accepted without a lot of work on maintaining team. BTW, the best way to test things is to run all relevant tests locally first, using "bazel test"

@facaiy

facaiy commented Aug 12, 2017 •

Copy link
Copy Markdown
Member Author

Thanks for your explanation, @yaroslavvb .

I agree that migrating reshape will introduce duplicate code and increase maintain cost, so I'd like to try to fix it in tensor_util.make_tensor_proto as well. If success, another PR will be opened, see #12513 .

Anyway, if you have any new idea / suggestion, please tell me. I'd like to take a try.

Running all test locally is time-consuming, hence only several unit tests are selected by me to be tested at first. By the way, could you tell me how to run doctest? Thanks.

@facaiy facaiy mentioned this pull request Aug 23, 2017
3 tasks done
@facaiy facaiy closed this Sep 3, 2017
@facaiy
facaiy deleted the ENH/tf_reshape_support_dimension_obj branch September 3, 2017 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Pull request awaiting review cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tf.reshape does not accept Dimension objects for the shape parameter

7 participants