Skip to content

Make type check utilities#95

Merged
delta2323 merged 40 commits into
masterfrom
type-check
Jul 3, 2015
Merged

Make type check utilities#95
delta2323 merged 40 commits into
masterfrom
type-check

Conversation

@unnonouno
Copy link
Copy Markdown
Member

  • Make an expression tree to validate types and show errors
  • Add a function to check types to Function. The function is called with expression trees
  • Make examples of type check

fixes #1

For example, when 4th dimension of 1st argument of an input is expected to be 2, you can write like this:

def ceck_type_forward(self, in_types):
    in_types[0].shape[3].should_be(2)

And, actually it is 1, a user can get a error message like this:

Expect: in_types[0].shape[3] == 2
Actual: 1 != 2

Comment thread chainer/utils/type_check.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If get_type is not called only from get_types, I think get_type should be in get_types to narrow its scope.

@unnonouno unnonouno changed the title [WIP] Make type check utilities Make type check utilities Jun 30, 2015
@unnonouno
Copy link
Copy Markdown
Member Author

In offline discussion, we decided to use this style:

def ceck_type_forward(self, in_types):
    type_check.expect(
        in_types[0].shape[3] == 2,
        in_types[0].shape[2] == 1,
    )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can I write in_types[0].ndim.eval > self.axis instead? I think it is better because value of the left hand side is used afterwards as ndim.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By offline discussion, I found that it is necessary to wrap self.axis in order to print variable name axis when this expectation failed.

Comment thread chainer/utils/type_check.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bool is misunderstanding with bool (True or False)

@delta2323
Copy link
Copy Markdown
Member

LGTM 👍

delta2323 added a commit that referenced this pull request Jul 3, 2015
Make type check utilities
@delta2323 delta2323 merged commit ab8f07a into master Jul 3, 2015
@delta2323 delta2323 deleted the type-check branch July 3, 2015 02:40
niboshi pushed a commit to niboshi/chainer that referenced this pull request Jun 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature Implementation that introduces new interfaces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check function signature

3 participants