GraphBLAS / graphblas-api-c

Other
7 stars 3 forks source link

GrB_Matrix_diag #35

Closed DrTimothyAldenDavis closed 3 years ago

DrTimothyAldenDavis commented 3 years ago

The new constructor in the v2.0 spec, GrB_Matrix_diag, is:

GrB_Matrix_diag (C, v) ;

which is the same as C = diag(v) in MATLAB notation. I suggest

GrB_Matrix_diag (C, v, k, desc)

which is the same as C = diag(v,k) in MATLAB. If k is nonzero, it creates a square matrix of dimension n + abs(k). If k > 0 then it populates C(i,i+k) = v(i) where v is the is the +k diagonal of C. If k < 0, it populates C(i-k,i) = v(i) below the main diagonal.

I have this 2nd function as GxB_Matrix_diag. I add the descriptor because all functions, even GrB_Matrix_nvals, should have a descriptor, in my opinion.

DrTimothyAldenDavis commented 3 years ago

Related to this, I have a

GxB_Vector_diag (v, A, k, desc)

which extracts the kth diagonal from the matrix A. This is like GrB_select (... DIAG ...) except it returns a vector, not a matrix. Currently the descriptor just controls the # of threads I can use.

mcmillan03 commented 3 years ago

Adding k parameter to Matrix_diag. Suggest submitting a separate issues requesting (1) GrB_Vector_diag, and (2) adding descriptors to all methods.

DrTimothyAldenDavis commented 3 years ago

I will add GrB_Vector_diag as another issue.

DrTimothyAldenDavis commented 3 years ago

See #48 for the descriptor issue.