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

Exception raising in Field APIs #2846

Open
victoriacity opened this issue Aug 30, 2021 · 3 comments
Open

Exception raising in Field APIs #2846

victoriacity opened this issue Aug 30, 2021 · 3 comments
Assignees
Labels
feature request Suggest an idea on this project good first issue A great chance for starters welcome contribution

Comments

@victoriacity
Copy link
Member

The current Field APIs, including ScalarField, MatrixField, and Structfield (after #2627) use assertions statements to check input validity, for example,

assert self.m == other.m and self.n == other.n, f"Dimension mismatch between shapes ({self.n}, {self.m}), ({other.n}, {other.m})"

In software engineering practice, assertion is used to verify whether the program itself is implemented correctly regardless of user inputs, while exceptions/errors are used to check validity of the inputs. Therefore quite a few occurrences of assert statements in field.py and matrix.py are supposed to raise errors.

Contributions are greatly welcomed!

@victoriacity victoriacity added feature request Suggest an idea on this project welcome contribution good first issue A great chance for starters labels Aug 30, 2021
@ntlm1686
Copy link
Contributor

ntlm1686 commented Sep 22, 2021

Could you please give an example of changing an assert statement to an exception?
Also, any resources that help write exceptions in Taichi are appreciated.

@gaocegege
Copy link
Collaborator

gaocegege commented Nov 3, 2021

Could you please give an example of changing an assert statement to an exception? Also, any resources that help write exceptions in Taichi are appreciated.

I refined the exception when converting from/to numpy array in the PR #3058. And there are many other asserts in the codebase. Welcome other contributions! You can have a look at the PR, as an example.

I am unassigning myself since it is an umbrella issue.

@ntlm1686
Copy link
Contributor

ntlm1686 commented Nov 4, 2021

Could you please give an example of changing an assert statement to an exception? Also, any resources that help write exceptions in Taichi are appreciated.

I refined the exception when converting from/to numpy array in the PR #3058. And there are many other asserts in the codebase. Welcome other contributions! You can have a look at the PR, as an example.

I am unassigning myself since it is an umbrella issue.

Thanks, gocegege! I have created a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project good first issue A great chance for starters welcome contribution
Projects
None yet
Development

No branches or pull requests

3 participants