{"action":"created","issue":{"url":"https://api.github.com/repos/bmcfee/pescador/issues/22","repository_url":"https://api.github.com/repos/bmcfee/pescador","labels_url":"https://api.github.com/repos/bmcfee/pescador/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/bmcfee/pescador/issues/22/comments","events_url":"https://api.github.com/repos/bmcfee/pescador/issues/22/events","html_url":"https://github.com/bmcfee/pescador/issues/22","id":136775040,"number":22,"title":"zmq_stream producing \"unaligned\" np.ndarrays","user":{"login":"cjacoby","id":929267,"avatar_url":"https://avatars.githubusercontent.com/u/929267?v=3","gravatar_id":"","url":"https://api.github.com/users/cjacoby","html_url":"https://github.com/cjacoby","followers_url":"https://api.github.com/users/cjacoby/followers","following_url":"https://api.github.com/users/cjacoby/following{/other_user}","gists_url":"https://api.github.com/users/cjacoby/gists{/gist_id}","starred_url":"https://api.github.com/users/cjacoby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjacoby/subscriptions","organizations_url":"https://api.github.com/users/cjacoby/orgs","repos_url":"https://api.github.com/users/cjacoby/repos","events_url":"https://api.github.com/users/cjacoby/events{/privacy}","received_events_url":"https://api.github.com/users/cjacoby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-02-26T18:24:46Z","updated_at":"2016-02-27T09:03:14Z","closed_at":null,"body":"A zmq_stream produces \"unaligned\" np.ndarrays, which theano doesn't know how to deal with. You can force a copy with np.array(), but that seems to defeat the purpose of the copy=False mode, no?\r\n\r\nTo Reproduce:\r\n```\r\nimport pescador\r\nimport numpy as np\r\nimport theano\r\nimport theano.tensor as T\r\n\r\n# A theano function that does something with two matrices\r\ndef theano_function():\r\n    x = T.matrix('x')\r\n    w = T.matrix('w')\r\n    return theano.function([x, w], T.mean(T.dot(x, w)))\r\n\r\n# A ZMQ Stream for testing\r\ndef data_gen():\r\n    while True:\r\n         yield {'X': np.random.random([8, 8])}\r\nstream = pescador.Streamer(data_gen)\r\nzmq_stream = pescador.zmq_stream(stream)\r\n\r\nW = np.random.random([8, 8])\r\nf = theano_function()\r\n\r\n# This proves that the result is unaligned:\r\nprint (next(zmq_stream)['X'].flags.aligned)  # >>> False\r\n\r\n# This call will fail.\r\nf(next(zmq_stream)['X'], W)\r\n\r\n# But this succeeds, because the copy forces the alignment\r\nf(np.array(next(zmq_stream)['X']), W)\r\n\r\nprint (np.array(next(zmq_stream)['X']).flags.aligned)  # >>> True\r\n```\r\n\r\n\r\nThis is the error I get:\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-6-17de2968d2f1> in <module>()\r\n----> 1 f(next(zmq_stream)['X'], W)\r\n\r\n/usr/local/museami-dev/Theano-0.7.0-py2.7.egg/theano/compile/function_module.pyc in __call__(self, *args, **kwargs)\r\n    511                     try:\r\n    512                         s.storage[0] = s.type.filter(arg, strict=s.strict,\r\n--> 513                                 allow_downcast=s.allow_downcast)\r\n    514 \r\n    515                     except Exception, e:\r\n\r\n/usr/local/museami-dev/Theano-0.7.0-py2.7.egg/theano/tensor/type.pyc in filter(self, data, strict, allow_downcast)\r\n    178                             \"object shape\", data.shape,\r\n    179                             \"object strides\", data.strides,\r\n--> 180                             \"object dtype\", data.dtype)\r\n    181 \r\n    182         i = 0\r\n\r\nTypeError: ('Bad input argument to theano function with name \"<ipython-input-2-96a0c586bb31>:5\"  at index 0(0-based)', 'The numpy.ndarray object is not aligned. Theano C code does not support that.', 'object buffer\\xb01\\x1fHR\\x90\\xae?\\x80446LG\\xbd?\\x04h \"\\x87\\xfb\\xce?\\\r\n.... [a bunch of crap here] ..... x1b\\xcc\\xed?', 'object shape', (8, 8), 'object strides', (64, 8), 'object dtype', dtype('float64'))\r\n```"},"comment":{"url":"https://api.github.com/repos/bmcfee/pescador/issues/comments/189608574","html_url":"https://github.com/bmcfee/pescador/issues/22#issuecomment-189608574","issue_url":"https://api.github.com/repos/bmcfee/pescador/issues/22","id":189608574,"user":{"login":"bmcfee","id":1190540,"avatar_url":"https://avatars.githubusercontent.com/u/1190540?v=3","gravatar_id":"","url":"https://api.github.com/users/bmcfee","html_url":"https://github.com/bmcfee","followers_url":"https://api.github.com/users/bmcfee/followers","following_url":"https://api.github.com/users/bmcfee/following{/other_user}","gists_url":"https://api.github.com/users/bmcfee/gists{/gist_id}","starred_url":"https://api.github.com/users/bmcfee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmcfee/subscriptions","organizations_url":"https://api.github.com/users/bmcfee/orgs","repos_url":"https://api.github.com/users/bmcfee/repos","events_url":"https://api.github.com/users/bmcfee/events{/privacy}","received_events_url":"https://api.github.com/users/bmcfee/received_events","type":"User","site_admin":false},"created_at":"2016-02-27T09:03:14Z","updated_at":"2016-02-27T09:03:14Z","body":"@cjacoby can you pull branch #23 and let me know if it fixes the problem for you?"}}