{"action":"created","issue":{"url":"https://api.github.com/repos/arrayfire/arrayfire/issues/1405","repository_url":"https://api.github.com/repos/arrayfire/arrayfire","labels_url":"https://api.github.com/repos/arrayfire/arrayfire/issues/1405/labels{/name}","comments_url":"https://api.github.com/repos/arrayfire/arrayfire/issues/1405/comments","events_url":"https://api.github.com/repos/arrayfire/arrayfire/issues/1405/events","html_url":"https://github.com/arrayfire/arrayfire/issues/1405","id":151973315,"number":1405,"title":"Create array from an existing memory buffer without copying in CPU backend","user":{"login":"drufat","id":1400254,"avatar_url":"https://avatars.githubusercontent.com/u/1400254?v=3","gravatar_id":"","url":"https://api.github.com/users/drufat","html_url":"https://github.com/drufat","followers_url":"https://api.github.com/users/drufat/followers","following_url":"https://api.github.com/users/drufat/following{/other_user}","gists_url":"https://api.github.com/users/drufat/gists{/gist_id}","starred_url":"https://api.github.com/users/drufat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drufat/subscriptions","organizations_url":"https://api.github.com/users/drufat/orgs","repos_url":"https://api.github.com/users/drufat/repos","events_url":"https://api.github.com/users/drufat/events{/privacy}","received_events_url":"https://api.github.com/users/drufat/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/arrayfire/arrayfire/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-29T21:33:27Z","updated_at":"2016-04-29T21:43:27Z","closed_at":"2016-04-29T21:38:20Z","body":"I would like to use arrayfire with the CPU backend, and I am unsure about how to avoid data copying. Is it possible for arrayfire to use an existing memory buffer without copying its content? Essentially, I am looking to create a \"view\" over existing preallocated data that will allow me to use the functionality that arrayfire provides without having to copy back and forth between my own representation, and the one that arrayfire adopts.\r\n\r\nAt the moment, when doing arrayfire computations, I am using something that looks like the code below\r\n```\r\n// read data\r\nauto X = array(dim0, dim1, input_buffer);\r\n\r\n// arrayfire computations\r\nauto Y = X + 1;\r\n\r\n// write data\r\nY.host(output_buffer);\r\n```\r\n\r\nThe above code copies the data both at the input stage, and the output stage, which is a wasted effort, when what I am looking to achieve is something like below: \r\n\r\n```\r\n// create views\r\nauto X = array_view(dim0, dim1, input_buffer);\r\nauto Y = array_view(dim0, dim1, output_buffer);\r\n\r\n// arrayfire computations\r\nY(span, span) = X(span, span) + 1;\r\n```\r\nEigen already provides this functionality with the [Map Class](https://eigen.tuxfamily.org/dox/classEigen_1_1Map.html). "},"comment":{"url":"https://api.github.com/repos/arrayfire/arrayfire/issues/comments/215889482","html_url":"https://github.com/arrayfire/arrayfire/issues/1405#issuecomment-215889482","issue_url":"https://api.github.com/repos/arrayfire/arrayfire/issues/1405","id":215889482,"user":{"login":"pavanky","id":364829,"avatar_url":"https://avatars.githubusercontent.com/u/364829?v=3","gravatar_id":"","url":"https://api.github.com/users/pavanky","html_url":"https://github.com/pavanky","followers_url":"https://api.github.com/users/pavanky/followers","following_url":"https://api.github.com/users/pavanky/following{/other_user}","gists_url":"https://api.github.com/users/pavanky/gists{/gist_id}","starred_url":"https://api.github.com/users/pavanky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavanky/subscriptions","organizations_url":"https://api.github.com/users/pavanky/orgs","repos_url":"https://api.github.com/users/pavanky/repos","events_url":"https://api.github.com/users/pavanky/events{/privacy}","received_events_url":"https://api.github.com/users/pavanky/received_events","type":"User","site_admin":false},"created_at":"2016-04-29T21:43:27Z","updated_at":"2016-04-29T21:43:27Z","body":"As for creating view, it may be more complicated than that. We have an open issue to tackle that issue: https://github.com/arrayfire/arrayfire/issues/482"}}