BIDData / BIDMat

A CPU and GPU-accelerated matrix library for data mining
BSD 3-Clause "New" or "Revised" License
265 stars 73 forks source link

GSMat contains no transpose method #27

Open DanielTakeshi opened 9 years ago

DanielTakeshi commented 9 years ago

The GSMat class contains no transpose method. Something like this might work:

override def t = {
  val out = GSMat.newOrCheckGSMat(ncols, nrows, nnz0, null, GUID, "t".##)
  CUMATD.transpose(this.data, nrows, out.data, ncols, nrows, ncols)
  cudaDeviceSynchronize()
  out
}

(Note the extra nnz0 term to include when checking the cache for GSMats).

However, I did a few tests and got some weird behavior when multiplying GSMats with other matrices (e.g., GSMat(a) * GMat(mkdiag(ones(3,1)))), so I just wanted to check in and see if GSMats were really supposed to have transposes. It seems like they should because SMats have transposes.

DanielTakeshi commented 9 years ago

The above won't quite work. A lame shortcut for now, since I'm not completely sure how to implement it in GSMats, is to use GSMat(SMat(a).t). For now, I'll leave this open in case we want to fix this later.

jcanny commented 9 years ago

Transposing sparse matrices into a valid representation (CSC +COO in BIDMat) is very expensive because it requires a resort of indices. On the other hand, transpose of dense matrices is fast. Its often possible to get the result you want without sparse transpose. e.g. for a sparse S and dense M,

M * S^T = M ^ S (^ is directly implemented) S^T * M = (M^T * S)^T (two dense transposes)

We should probably implement this some time, but we need to find a way to discourage people from using it.