{"action":"opened","issue":{"url":"https://api.github.com/repos/bluss/ndarray/issues/489","repository_url":"https://api.github.com/repos/bluss/ndarray","labels_url":"https://api.github.com/repos/bluss/ndarray/issues/489/labels{/name}","comments_url":"https://api.github.com/repos/bluss/ndarray/issues/489/comments","events_url":"https://api.github.com/repos/bluss/ndarray/issues/489/events","html_url":"https://github.com/bluss/ndarray/issues/489","id":362256602,"node_id":"MDU6SXNzdWUzNjIyNTY2MDI=","number":489,"title":"Better error message when accidentally use an array instead of tuple for into_shape?","user":{"login":"drewm1980","id":190617,"node_id":"MDQ6VXNlcjE5MDYxNw==","avatar_url":"https://avatars1.githubusercontent.com/u/190617?v=4","gravatar_id":"","url":"https://api.github.com/users/drewm1980","html_url":"https://github.com/drewm1980","followers_url":"https://api.github.com/users/drewm1980/followers","following_url":"https://api.github.com/users/drewm1980/following{/other_user}","gists_url":"https://api.github.com/users/drewm1980/gists{/gist_id}","starred_url":"https://api.github.com/users/drewm1980/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewm1980/subscriptions","organizations_url":"https://api.github.com/users/drewm1980/orgs","repos_url":"https://api.github.com/users/drewm1980/repos","events_url":"https://api.github.com/users/drewm1980/events{/privacy}","received_events_url":"https://api.github.com/users/drewm1980/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-20T16:01:39Z","updated_at":"2018-09-20T16:01:39Z","closed_at":null,"author_association":"NONE","body":"I just lost an hour to the following incorrect code:\r\n\r\n```\r\n    #[test]\r\n    fn test_ndarray_eq()\r\n    {\r\n        let a = ndarray::arr3(&[[[true]]]);\r\n        let a2 = a.into_shape([1,1]).unwrap();\r\n        let a3 = a2.into_shape([1,1,1]).unwrap();\r\n        assert!(a == a3,\"Arrays are not equal!\");\r\n    }\r\n```\r\n\r\n>    error[E0308]: mismatched types                                                                                               \r\n>    --> src/lib.rs:156:20                                                                                                     \r\n>     |                                                                                                                        \r\n> 156 |         assert!(a==a2, \"Arrays do not match!\");                                                                        \r\n>     |                    ^^ expected array of 3 elements, found struct `ndarray::IxDynImpl`                                  \r\n>     |                                                                                                                        \r\n>     = note: expected type `ndarray::ArrayBase<_, ndarray::Dim<[usize; 3]>>`                                                  \r\n>                found type `ndarray::ArrayBase<ndarray::OwnedRepr<bool>, ndarray::Dim<ndarray::IxDynImpl>>`          \r\n\r\nThe source of the problem has nothing to do with \"==\", nothing to do with IxDynImpl, and isn't even on the line the error is thrown. If you print all of the arrays using println!, they all look like they have the correct shape, stride, and contained values.\r\n\r\nThis happened in my original code because I passed the output of .shape() into into_shape. It happened n the above minimized example because I passed the dimensions as arrays \"[...]\" instead of as tuples \"(...)\".\r\n\r\nIf there's anything that can be done to smooth out this sharp edge in the API, consider this a feature request. Failing that, maybe throw big warnings about this footgun in the into_shape() documentation (which says nothing about the type of the input since it's generic over E), and also in the section of the \"ndarray for numpy users\" section where you at least mention the ugly existence of three different representations of the shape of an array, with different methods to get them.\r\n\r\nBy the way, thanks for writing ndarray; I would not have even considered Rust without it."}}
{"actor":{"display_login":"drewm1980"}}