-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add an integer power function for second order tensors #53
Conversation
If we allowed for |
Yes, I know but I thought you don't want to allow to use |
I think this is fine. I don't expect large powers to be used much and we can fix it then if someone complains. |
src/basic_operations.jl
Outdated
return one(S) | ||
elseif p == -1 | ||
return inv(S) | ||
elseif p < 0 |
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.
Why throw domain error here? Can't you do inv(S)^(-p)
?
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.
Oh, I would fix it. But might be inv(S)^p
?
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.
No, sorry.
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.
BTW, how could I avoid errors in julia v0.6?
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.
What's the problem on 0.6?
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.
Oh, actually Travis would fail in "constructors" section, not in "simple math".
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 errors are following:
constructors: Test Failed
Expression: eltype(tens_arr1) == (Tensors.Tensor){1, 1, Float64, N}
Evaluated: Tensors.Tensor{1,1,T,M} where M where T<:Real == Tensors.Tensor{1,1,Float64,1}
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 would add more error message just in case.
Stacktrace:
[1] macro expansion at /home/travis/.julia/v0.6/Tensors/test/test_misc.jl:42 [inlined]
[2] macro expansion at ./test.jl:853 [inlined]
[3] macro expansion at /home/travis/.julia/v0.6/Tensors/test/runtests.jl:9 [inlined]
[4] macro expansion at /home/travis/.julia/v0.6/TimerOutputs/src/TimerOutput.jl:128 [inlined]
[5] macro expansion at /home/travis/.julia/v0.6/Tensors/test/runtests.jl:8 [inlined]
[6] anonymous at ./:?
@test t^1 ≈ t | ||
@test t^2 ≈ t ⋅ t | ||
@test t^3 ≈ t ⋅ t ⋅ t | ||
@test t^-1 ≈ inv(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.
Could you add a test for t^-2
as well
I think we should do this with |
Some change in Base made tests fail.. |
Its this: julia> zeros(Tensor{2, 3}, 3)
3-element Array{Tensors.Tensor{2,3,T,M} where M where T<:Real,1}:
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0] before |
julia> @code_warntype zeros(Tensor{2, 3}, 3)
julia> wut? julia> @which zeros(Tensor{2, 3}, 3)
ERROR: no method found for the specified argument types
Stacktrace:
[1] which(::Any, ::Any) at ./reflection.jl:824
julia> zeros(Tensor{2, 3}, 3)
3-element Array{Tensors.Tensor{2,3,T,M} where M where T<:Real,1}:
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0]
[0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0] wutwut? |
Also julia> methods(zeros, (Type{Tensor{2,3}}, Int))
# 0 methods for generic function "zeros": |
Bisected to JuliaLang/julia#21183 |
This would be useful in some cases.