-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Matrix logarithm function (issue #5840) #12217
Conversation
@@ -278,9 +278,42 @@ function rcswap!{T<:Number}(i::Integer, j::Integer, X::StridedMatrix{T}) | |||
end | |||
end | |||
|
|||
function logm{T}(A::StridedMatrix{T}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type parameter T
isn't used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it isn't, should I remove it from the signature of the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you're using it 1) in the function body, or 2) to filter the types for which this method applies, then yeah, it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by @joehuchette, the T
parameter should be removed here.
Ref #5840 - GitHub does not link issue numbers from titles |
Thanks for contributing this. It appears that (at least some of) the code is a translation of http://eprints.ma.man.ac.uk/1687/02/logm.zip. According to http://www.mathworks.com/matlabcentral/fileexchange/33393 it should be BSD licensed so there is no problem in using it, but I think you should link to the source in the initial comment. |
# Use Schur decomposition | ||
n = chksquare(A) | ||
S,Q,d = schur(complex(A)) | ||
R = full(logm(UpperTriangular(S))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think full
is needed here.
Note that there's the awful "Mathworks products only" clause in the File Exchange terms of use, see 2.a.iii. at http://www.mathworks.com/matlabcentral/termsofuse.html#content. So despite the BSD license on the code, unless it's available through a different medium or directly from the author (edit: with a clear license or permission to redistribute), having looked at any code hosted on File Exchange means we can't distribute a translation of it in Julia. |
The first link above is to one of the authors' homepage so hopefully Mathworks can't claim this, but I cannot find any license statement in that source. |
A = sqrtm(A) | ||
end | ||
|
||
AmI = A - UpperTriangular(eye(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this more efficiently with A - I
. I
is a special constant of type UniformScaling
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it doesn't work if A
is UpperTriangular
, but
UpperTriangular(full(A) - I)
is even slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Now I understand. This is supposed to work so I'll fix this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It looks like scale(A,x)
has the same issue when A is UpperTriangular
.
Perhaps we can write to the author and get clear documentation for the license. |
end | ||
|
||
AmI = A - UpperTriangular(eye(n)) | ||
d2 = norm(AmI^2, 1)^(1/2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqrt
and cbrt
are much faster
I received the matlab code form the author, I think I can ask him for the permission to redistribute. Anyway, thank you for all your useful comments. |
84090ed
to
d6add4a
Compare
The code is released under the terms of the BSD license. The author has just uploaded a new version of the .zip file containing the licence statement (http://eprints.ma.man.ac.uk/1851/02/logm.zip). |
A = sqrtm(A) | ||
end | ||
|
||
AmI = UpperTriangular(full(A) - I) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed now so you should be able to do AmI = A - I
Great that the license question was resolved so fast. I've added a few comments, but I think it should be ready soon. |
…ecking to ensure the precision to be double
@mfasi Do you think this pr is ready now? The AppVeyor failure is unrelated. |
@andreasnoack All that I wanted to change is there and I'd be happy if you merged this pull request. Thank you for your feedback and support. |
RFC: Matrix logarithm function (issue #5840)
@mfasi Thank you for the contribution |
We do actually need to reproduce the original license statement in full here, for derived code. |
We can put it in License.md with a reference to which code falls under the license and just a note of |
There's a list of exceptions under |
This is also resulting in warnings which should be suppressed
|
@tkelman Sure, I can ask the author to relicense under Julia's MIT license. Is it enough if he just tells me that I can or should he add something to the original code? I don't know how to suppress the warnings, nor I could find it anywhere. What should I do? The warnings are an expected behaviour in that case. |
If you get written permission, we can add a comment indicating "Julia version relicensed with permission from original author" and I think it should be fine (though IANAL). Do the warnings occur every time, or only some of the time depending on randomness in the input matrices? There are other cases in the tests that do |
I'll contact the author and let you know. There is no randomness involved, the warnings are produced every time you run the tests. Thus, I think that |
@mfasi Thanks for patiently following the process and getting Cc: @alanedelman |
Just a hypothetical: how many tenured math, cs, and stats faculty around the world do you think we (+scipy, R, and octave communities) could get to co-sign a letter to the MathWorks complaining that the "may only be used with MathWorks products" clause is toxic (and hidden from users who otherwise think they're releasing code with a normal open source license) and asking them to drop it? |
Good idea. Do you have a link to the toxic clause in the MathWorks license? |
@ViralBShah You're very welcome. I'll add a link to this pull request in #5840. |
I added the matrix logarithm function, with test cases. Although I tried to stick to the guidelines, it's my first contribution, please forgive any silly errors I might have committed.