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

Implement svdx(Number, Number) #22195

Merged
merged 1 commit into from
Jun 4, 2017
Merged

Implement svdx(Number, Number) #22195

merged 1 commit into from
Jun 4, 2017

Conversation

andreasnoack
Copy link
Member

By popular demand. Also

Make svd(x::Number) return numbers

Implement hash, isequal, and == for Factorizations

cc @alanedelman

@@ -231,6 +232,10 @@ function svdfact(A::StridedMatrix{TA}, B::StridedMatrix{TB}) where {TA,TB}
S = promote_type(Float32, typeof(one(TA)/norm(one(TA))),TB)
return svdfact!(copy_oftype(A, S), copy_oftype(B, S))
end
# This method can be heavily optimized but it is probably not cirtical
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

@@ -30,6 +30,10 @@ end
convert(::Type{Factorization{T}}, F::Factorization{T}) where {T} = F
inv(F::Factorization{T}) where {T} = A_ldiv_B!(F, eye(T, size(F,1)))

Base.hash(F::Factorization, h::UInt) = mapreduce(f -> hash(getfield(F, f)), hash, h, fieldnames(F))
Base.:(==)( F::T, G::T) where {T<:Factorization} = all(f -> getfield(F, f) == getfield(G, f), fieldnames(F))
Copy link
Member

Choose a reason for hiding this comment

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

Guessing the extra spaces are for alignment? :)

# This method can be heavily optimized but it is probably not critical
# and might introduce bugs or inconsistencies relative to the 1x1 matrix
# version
svdfact(x::Number, y::Number) = svdfact(fill(x,1,1), fill(y,1,1))
Copy link
Member

Choose a reason for hiding this comment

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

Missing spaces between function arguments? (Spaces exist in the similar method definition below.)

@test svdfact(x,y) == svdfact(fill(x,1,1), fill(y,1,1))
@test svdvals(x,y) == first(svdvals(fill(x,1,1), fill(y,1,1)))
@test svd(x,y) == first.(svd(fill(x,1,1), fill(y,1,1)))
end
Copy link
Member

Choose a reason for hiding this comment

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

We should choose a convention for spaces separating function arguments and use it consistently :).

Make svd(x::Number) return numbers

Implement hash, isequal, and == for Factorizations
@andreasnoack andreasnoack merged commit 0cc329e into master Jun 4, 2017
@andreasnoack andreasnoack deleted the anj/svd branch June 4, 2017 00:32
@tkelman
Copy link
Contributor

tkelman commented Jun 4, 2017

How many of the other factorizations do we do this for?

@andreasnoack
Copy link
Member Author

andreasnoack commented Jun 4, 2017

In theory, we do all of them, see #1871, but some of them are broken, e.g. qr. I'm working on a PR to fix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants