Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sparse*diagonal, diagonal*sparse methods and tests. Fixes #14416. #14461

Merged
merged 1 commit into from
Dec 23, 2015

Conversation

kshyatt
Copy link
Contributor

@kshyatt kshyatt commented Dec 22, 2015

No description provided.

@kshyatt kshyatt added linear algebra Linear algebra sparse Sparse arrays labels Dec 22, 2015
@inbounds for k=1:length(nzval)
Ynzval[k] = X[rowval[k],rowval[k]] * nzval[k]
end
SparseMatrixCSC(A.m, A.n, A.colptr, A.rowval, Ynzval)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy the colptr and rowval otherwise these alias

rowval = A.rowval
nzval = A.nzval
@inbounds for col = 1:A.n, k=A.colptr[col]:(A.colptr[col+1]-1)
Ynzval[k] += X[col, col] * nzval[k]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't need to be += since colptr is nondecreasing. Also would be better to use Array rather than zeros to initialize the nonzeros since you can make sparse matrices with element types that don't have zero defined.

rowval = A.rowval
nzval = A.nzval
@inbounds for k=1:length(nzval)
Ynzval[k] = X.diag[rowval[k]] * nzval[k]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .diag field access may be worth hoisting

@andreasnoack
Copy link
Member

@kshyatt Thanks for providing these. I think it would make sense to define them as methods for scale! and then define * as copy+scale!.

@kshyatt
Copy link
Contributor Author

kshyatt commented Dec 22, 2015

@andreasnoack that seems much better, actually, because we will minimize code duplication. Will update.

@kshyatt
Copy link
Contributor Author

kshyatt commented Dec 22, 2015

Good to go?

tkelman added a commit that referenced this pull request Dec 23, 2015
Added sparse*diagonal, diagonal*sparse methods and tests. Fixes #14416.
@tkelman tkelman merged commit 3642c96 into master Dec 23, 2015
@tkelman tkelman deleted the ksh/sparsediag branch December 23, 2015 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants