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

Moved basic C error checking to Elixir #20

Merged
merged 2 commits into from
Jul 13, 2018
Merged

Moved basic C error checking to Elixir #20

merged 2 commits into from
Jul 13, 2018

Conversation

anshuman23
Copy link
Owner

I have moved the basic error checking capability to Elixir code because now we can actually obtain the arguments before passing them to the NIFs. I believe I have covered all the scenarios. However, for some functions I haven't explicitly raised errors, and that is because pattern matching will fail and take care of any problem. That is, you can't pass a graph instead of a tensor or a matrix, because the structs are different.

Do you have anything else in mind @josevalim?

raise ArgumentError, message: "Rows/Columns cannot be less than 1"
end
if(empty_list? datalist) do
raise ArgumentError, message: "Data provided cannot be an empty list"
Copy link
Contributor

Choose a reason for hiding this comment

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

Error messages in Elixir start in lower case. You also don't need the message key. So you should do this:

raise ArgumentError, "data provided cannot be an empty list"

Copy link
Owner Author

Choose a reason for hiding this comment

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

I apologize for such careless mistakes. Made the required changes in this commit

@@ -1,8 +1,21 @@
defmodule Tensorflex do

alias Tensorflex.{NIFs, Graph, Tensor, Matrix}

defp empty_list?([[]]), do: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to check if it is a list with an empty list OR if any entries in the list is an empty list?

Copy link
Owner Author

@anshuman23 anshuman23 Jul 13, 2018

Choose a reason for hiding this comment

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

I need to specifically check if it is an empty list within another list, that is, [[]]
For all other cases it is fine. For example a user could specify: Tensorflex.create_matrix(1,1,[[5]]) and that would be okay.

@@ -12,11 +25,21 @@ defmodule Tensorflex do
end

def create_matrix(nrows, ncols, datalist) do
if(nrows < 1 or ncols < 1) do
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also do this as guards:

def create_matrix(nrows, ncols, datalist) when nrows > 0 and ncols > 0 do

Copy link
Contributor

Choose a reason for hiding this comment

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

This way you don't need to explicitly raise argument error.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was thinking of doing that initially, but I thought that it might make it more cryptic for users to understand where they went wrong since they would have to figure out from the condition which fails, what went wrong.

But I think for some of the more obvious cases, like having a float argument for a float tensor, number of rows and columns to be greater than 0 for creating a matrix, we should have guards. I have made these changes in the latest commit.

@anshuman23 anshuman23 merged commit 639f11f into master Jul 13, 2018
@josevalim
Copy link
Contributor

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants