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

Make type check utilities #95

Merged
merged 40 commits into from
Jul 3, 2015
Merged

Make type check utilities #95

merged 40 commits into from
Jul 3, 2015

Conversation

unnonouno
Copy link
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

return info


def get_type(name, index, array, accept_none):
Copy link
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
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,
    )

def check_type_forward(self, in_types):
type_check.expect(in_types.size() > 0)
type_check.expect(in_types[0].ndim >
type_check.IntVariable(self.axis, 'axis'))
Copy link
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
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.

BinaryOperator.__init__(self, priority, lhs, rhs, exp, func)


class Bool(object):
Copy link
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
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