logger.debug("constructing sparse document matrix")
// construct the sparse matrix as lil_matrix first, convert to csc later
// lil_matrix can quickly update rows, so initialize it transposed (documents=rows)
mat = scipy.sparse.lil_matrix((1, 1), dtype = dtype)
mat.rows, mat.data = [], []
for i, doc in enumerate(corpus):
doc = sorted(doc)
mat.rows.append([fid for fid, _ in doc])
mat.data.append([val for _, val in doc])
docs = i + 1
mat._shape = (docs, m)
mat = mat.tocsr().transpose() // transpose back to documents=columns