{"action":"created","issue":{"url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/124","repository_url":"https://api.github.com/repos/AtheMathmo/rulinalg","labels_url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/124/labels{/name}","comments_url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/124/comments","events_url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/124/events","html_url":"https://github.com/AtheMathmo/rulinalg/issues/124","id":197662737,"number":124,"title":"Conversion functions between element index and dimensional index","user":{"login":"bright-star","id":5308179,"avatar_url":"https://avatars.githubusercontent.com/u/5308179?v=3","gravatar_id":"","url":"https://api.github.com/users/bright-star","html_url":"https://github.com/bright-star","followers_url":"https://api.github.com/users/bright-star/followers","following_url":"https://api.github.com/users/bright-star/following{/other_user}","gists_url":"https://api.github.com/users/bright-star/gists{/gist_id}","starred_url":"https://api.github.com/users/bright-star/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bright-star/subscriptions","organizations_url":"https://api.github.com/users/bright-star/orgs","repos_url":"https://api.github.com/users/bright-star/repos","events_url":"https://api.github.com/users/bright-star/events{/privacy}","received_events_url":"https://api.github.com/users/bright-star/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-27T07:52:14Z","updated_at":"2016-12-28T10:51:02Z","closed_at":null,"body":"I didn't spot a function like this in the docs, but is this right?\r\n\r\n```rust\r\n// Gets the pair index from a matrix. Assumes row-major (but works with either).\r\nfn indices_from_pos(row_stride: usize, ind: usize) -> [usize; 2] {\r\n  let col_ind = ind % row_stride;\r\n  let row_ind = ind / row_stride;\r\n  [row_ind, col_ind]\r\n}\r\n```\r\n\r\nAlso, would a pair of methods like this be helpful to have implemented on `Matrix`?"},"comment":{"url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/comments/269460573","html_url":"https://github.com/AtheMathmo/rulinalg/issues/124#issuecomment-269460573","issue_url":"https://api.github.com/repos/AtheMathmo/rulinalg/issues/124","id":269460573,"user":{"login":"Andlon","id":578309,"avatar_url":"https://avatars.githubusercontent.com/u/578309?v=3","gravatar_id":"","url":"https://api.github.com/users/Andlon","html_url":"https://github.com/Andlon","followers_url":"https://api.github.com/users/Andlon/followers","following_url":"https://api.github.com/users/Andlon/following{/other_user}","gists_url":"https://api.github.com/users/Andlon/gists{/gist_id}","starred_url":"https://api.github.com/users/Andlon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andlon/subscriptions","organizations_url":"https://api.github.com/users/Andlon/orgs","repos_url":"https://api.github.com/users/Andlon/repos","events_url":"https://api.github.com/users/Andlon/events{/privacy}","received_events_url":"https://api.github.com/users/Andlon/received_events","type":"User","site_admin":false},"created_at":"2016-12-28T10:51:02Z","updated_at":"2016-12-28T10:51:02Z","body":"I can see that this might be convenient in that context, @bright-star.\r\n\r\nThat said, I think this is conflating two very similar but different problems:\r\n\r\n- Indexing into the internal data structure of a matrix (which \"coincidentally\" happens to be laid out flat in the way you want to do)\r\n- Mapping indices between two related, but different vector spaces\r\n\r\nDue to separation of concerns, it's usually a good idea to not mix these two concepts. In practice, choosing the vector spaces so that it aligns with the row/col alignment of the data structure *might* give better performance in some cases, but this is probably rarely the bottleneck of your program, and it could perhaps be considered a case of premature optimization. And if it is actually a bottleneck, a function to map indices can still be written outside of the library.\r\n\r\nBy the way, I really like your write-ups on electrostatics. I haven't read them in detail, and it's certainly not within my area of expertise, but it looks like a useful resource!"}}
{"actor":{"display_login":"Andlon"}}