andersbll / cudarray

CUDA-based NumPy
MIT License
233 stars 61 forks source link

transpose #9

Closed ghost closed 9 years ago

ghost commented 9 years ago

I'm not sure if I've done something incorrectly but I notice the following issue:

a = ca.random.uniform(size=(5,3)) a a.T

The transpose is 3x5 but it seems to be reading sequentially from top left to bottom right rather than transposing. I noticed in base.transpose you set a transposed flag so I assumed this flag would be used in other operators rather than explicitly transposing the matrix but I'm not sure anymore what's happening. In my code using a.T doesn't work unless it's a 1xN or Nx1.

Thanks.

vzhong commented 9 years ago

@helshowk I'm not sure what the issue is here:

In [37]: a = ca.array([[1,2],[3,4],[5,6]])

In [38]: a
Out[38]: 
array([[1, 2],
       [3, 4],
       [5, 6]])

In [39]: a.T
Out[39]: 
array([[1, 3, 5],
       [2, 4, 6]])

What is it that you expect the above output to be?

andersbll commented 9 years ago

@helshowk: Proper transpose support is on my TODO list. Currently, transpose works only in conjunction with operations that support it, that is, cudarray.dot()! I hope to implement this in the not too distant future.

@vzhong: I think your example works because NumPy performs the transpose when structure is printed to screen. On str(), CUDArrray copies the array to a NumPy array which is then printed. :)

ghost commented 9 years ago

@andersbll Thanks for letting me know and thanks for cudarray! For now I'm using numpy.transpose() and copying back to cudarray which isn't efficient but I'm going to refactor a few things to keep it all in a .dot(). If you have any starting pointers on how to help fix transpose I'd be happy to help if I can.

andersbll commented 9 years ago

@helshowk: Good to hear you can work around it for now. I have also found it practical on several occasions to quickly switch to NumPy. To support transpose properly, we need to implement somthing similar to numpy.ascontiguousarray(). This function should be called by all CUDArray operations that do not support transposed views. I imagine that calling ascontiguousarray() on a transposed view of an array should create a new array and the transposed view should point to the newly created array (and no longer be a view). I think this lazy tranpose scheme is NumPy compliant. You are of course most welcome to look into this - but be prepared to get your hands dirty as you have to understand underlying array representation.

ghost commented 9 years ago

@andersbll ok I'll have a look and see if I can get anything done...to be honest for now it works so it's not top priority and as you said it'll take a while to get into. Thanks again, closing the issue.