{"action":"created","issue":{"url":"https://api.github.com/repos/odlgroup/odl/issues/84","labels_url":"https://api.github.com/repos/odlgroup/odl/issues/84/labels{/name}","comments_url":"https://api.github.com/repos/odlgroup/odl/issues/84/comments","events_url":"https://api.github.com/repos/odlgroup/odl/issues/84/events","html_url":"https://github.com/odlgroup/odl/issues/84","id":118847163,"number":84,"title":"Vector creation utility","user":{"login":"adler-j","id":2202312,"avatar_url":"https://avatars.githubusercontent.com/u/2202312?v=3","gravatar_id":"","url":"https://api.github.com/users/adler-j","html_url":"https://github.com/adler-j","followers_url":"https://api.github.com/users/adler-j/followers","following_url":"https://api.github.com/users/adler-j/following{/other_user}","gists_url":"https://api.github.com/users/adler-j/gists{/gist_id}","starred_url":"https://api.github.com/users/adler-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adler-j/subscriptions","organizations_url":"https://api.github.com/users/adler-j/orgs","repos_url":"https://api.github.com/users/adler-j/repos","events_url":"https://api.github.com/users/adler-j/events{/privacy}","received_events_url":"https://api.github.com/users/adler-j/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/odlgroup/odl/labels/new%20feature","name":"new feature","color":"bfe5bf"},{"url":"https://api.github.com/repos/odlgroup/odl/labels/odl%20core","name":"odl core","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-25T14:27:35Z","updated_at":"2015-11-25T14:58:51Z","closed_at":null,"body":"As discussed in #82, we should maybe add a utility to create vectors (with all default options). In pseudocode the suggestion is to add\r\n\r\n```python\r\ndef vector(inp, dtype=None, impl=None):\r\n    if impl == 'numpy':\r\n         return Rn(len(inp), dtype=dtype).element(inp)\r\n    elif impl == 'cuda':\r\n         return CudaRn(len(inp), dtype=dtype).element(inp)\r\n```\r\n\r\nto some part of `odl/space`. Discussed options are `__init__.py` and a new file."},"comment":{"url":"https://api.github.com/repos/odlgroup/odl/issues/comments/159632776","html_url":"https://github.com/odlgroup/odl/issues/84#issuecomment-159632776","issue_url":"https://api.github.com/repos/odlgroup/odl/issues/84","id":159632776,"user":{"login":"adler-j","id":2202312,"avatar_url":"https://avatars.githubusercontent.com/u/2202312?v=3","gravatar_id":"","url":"https://api.github.com/users/adler-j","html_url":"https://github.com/adler-j","followers_url":"https://api.github.com/users/adler-j/followers","following_url":"https://api.github.com/users/adler-j/following{/other_user}","gists_url":"https://api.github.com/users/adler-j/gists{/gist_id}","starred_url":"https://api.github.com/users/adler-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adler-j/subscriptions","organizations_url":"https://api.github.com/users/adler-j/orgs","repos_url":"https://api.github.com/users/adler-j/repos","events_url":"https://api.github.com/users/adler-j/events{/privacy}","received_events_url":"https://api.github.com/users/adler-j/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T14:58:51Z","updated_at":"2015-11-25T14:58:51Z","body":"> I admit that __init__.py is far from optimal. Probably better to have an own file, space_util.py sounded okay.\r\n\r\nAgree\r\n\r\n> This version is obviously only for real data types, an analogon for complex would make sense, too. And then, names like real_vector and complex_vector would be good.\r\n\r\nI think that is making it to complicated (it should be doable with the `dtype` parameter). How about:\r\n\r\n```python\r\ndef vector(inp, dtype=None, impl=None):\r\n    array = np.asarray(inp, dtype=dtype)\r\n    if impl == 'numpy':\r\n         return Fn(len(inp), dtype=array.dtype).element(array)\r\n    elif impl == 'cuda':\r\n         return CudaFn(len(inp), dtype=array.dtype).element(array)\r\n```\r\n\r\nwith this, the vector will be complex if the input is complex\r\n\r\n```python\r\n>>> vector([1, 2])\r\nRn(2).element([1, 2])\r\n>>> vector([1, 1+2i])\r\nCn(2).element([1, 1+2i])\r\n```"}}