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

Conversation

Projects
None yet
3 participants
@unnonouno
Member

unnonouno commented Jun 27, 2015

  • 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

@unnonouno unnonouno changed the title from [WIP] Make type check utilities to Make type check utilities Jun 30, 2015

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 1, 2015

Member

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,
    )
Member

unnonouno commented Jul 1, 2015

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,
    )

unnonouno added some commits Jul 1, 2015

@beam2d beam2d added the feature label Jul 2, 2015

@beam2d beam2d added this to the v1.1.0 milestone Jul 2, 2015

@delta2323 delta2323 self-assigned this Jul 2, 2015

pass
def check_type_backward(self, in_types, grad_types):
"""Checks types of gradient data before back propagation.

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

Does this function check types of input data as well? In other words, if check_type_forward is passed. isn't it necessary to write a check which involves in_types only?

@delta2323

delta2323 Jul 2, 2015

Member

Does this function check types of input data as well? In other words, if check_type_forward is passed. isn't it necessary to write a check which involves in_types only?

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

We need comments somewhere that backward should be called after forward is called

@delta2323

delta2323 Jul 2, 2015

Member

We need comments somewhere that backward should be called after forward is called

This comment has been minimized.

@unnonouno

unnonouno Jul 2, 2015

Member

I added a comment to check_type_backward

@unnonouno

unnonouno Jul 2, 2015

Member

I added a comment to check_type_backward

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'))

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

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.

@delta2323

delta2323 Jul 2, 2015

Member

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.

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

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

@delta2323

delta2323 Jul 2, 2015

Member

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

continue
type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
def check_type_backward(self, in_types, out_types):

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

Do we need dtype check between in_types and out_types?

@delta2323

delta2323 Jul 2, 2015

Member

Do we need dtype check between in_types and out_types?

def check_type_backward(self, in_types, out_types):
type_check.expect(
in_types.size() == 2,

This comment has been minimized.

@delta2323

delta2323 Jul 2, 2015

Member

This is already checked by check_type_forward

@delta2323

delta2323 Jul 2, 2015

Member

This is already checked by check_type_forward

Kenta OONO
@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

typo: independent of

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

typo: independent of

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

input data -> input/gradient data

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

input data -> input/gradient data

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

typo: tuple

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

typo: tuple

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

typo: abstract

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

typo: abstract

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

are -> be

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

are -> be

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

First character of "Raise" should be lower-cased, or first character of when in the comments above should be upper-cased.

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

First character of "Raise" should be lower-cased, or first character of when in the comments above should be upper-cased.

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

typo: function (remove "s")

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

typo: function (remove "s")

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

typo: backward

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

typo: backward

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

I think 'When "some" expression is evaluated...' is appropriate because previous sentence does not indicate that the expression is in given expressions.

Member

delta2323 commented on chainer/utils/type_check.py in 0306a3a Jul 2, 2015

I think 'When "some" expression is evaluated...' is appropriate because previous sentence does not indicate that the expression is in given expressions.

@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 2, 2015

Member

I would like you to add two things

  • Both of x==y and z==w call __nonzero__, which by default return True unless they are None.
  • The reason why and returns evaluation result of second term is that both terms return True.
Member

delta2323 commented on chainer/utils/type_check.py in cfe009c Jul 2, 2015

I would like you to add two things

  • Both of x==y and z==w call __nonzero__, which by default return True unless they are None.
  • The reason why and returns evaluation result of second term is that both terms return True.
@delta2323

This comment has been minimized.

Show comment
Hide comment
@delta2323

delta2323 Jul 3, 2015

Member

LGTM 👍

Member

delta2323 commented Jul 3, 2015

LGTM 👍

delta2323 added a commit that referenced this pull request Jul 3, 2015

@delta2323 delta2323 merged commit ab8f07a into master Jul 3, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@delta2323 delta2323 deleted the type-check branch Jul 3, 2015

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