Comments (9)
promote_op
uses type inference, and while type inference is a heuristic, it is required to be a conservative heuristic. Specifically, type inference is always allowed to return a non-concrete supertype of the correct result, but it would be a very serious bug if type inference ever returned an incorrect result.
from julia.
The reason is that that Symmetric
wrappers only look at one, say the upper, triangle, and as for elements of the lower triangle, we pick elements from the upper and transpose them. Similarly for Hermitian
. For Number
elements, that transpose/adjoint doesn't make a type difference, but for matrix elements, the obtained result is a Transpose/Adjoint
, which combined with the original matrices returns the AbstractMatrix
. The function to look at is
function symmetric_type(::Type{T}) where {S<:AbstractMatrix, T<:AbstractMatrix{S}}
return Symmetric{AbstractMatrix, T}
end
so it seems nobody had a better answer so far.
from julia.
Does the result improve if the eltype
is a Union
of three types? That's generally the best that this may be narrowed down to.
from julia.
I don't know, it depends on whether promote_op
gives a sensible answer when given this Union
.
The issue is that I need to allocate a matrix to store the result of the kronecker product, which I do with Matrix{promote_op(*, T, S)}
. Now if T,S == Matrix{Float64}
this gives me a Matrix{Matrix{Float64}}
, which is exactly what I need. But if T,S == AbstractMatrix
this gives me a Matrix{Any}
which ruins everything.
EDIT: I just tested, and it does work. Let T = Union{Symmetric{Float64, Matrix{Float64}}, Transpose{Float64, Matrix{Float64}}, Matrix{Float64}}
. Then promote_op(*, T, T) == Matrix{Float64}
and everything is fine. Ditto if we have Hermitian
and Adjoint
instead of Symmetric
and Transpose
.
from julia.
Thanks for the information. AbstractMatrix
still seems like a bad choice, as it erases information. Union{Matrix{T},Transpose{Matrix{T}},Symmetric{Matrix{T}}}
would still make it possible to allocate the necessary matrix.
from julia.
On a second thought, the easiest solution would be for promote_op(*,AbstractMatrix,AbstractMatrix)
to return AbstractMatrix
. Does anything depend on it returning Any
?
from julia.
On a second thought, the easiest solution would be for
promote_op(*,AbstractMatrix,AbstractMatrix)
to returnAbstractMatrix
.
Good question why that is not the case.
from julia.
not really, promote_op
of almost any abstract type will return Any
because the compiler can't prove that no one will introduce a new method.
from julia.
Do you mean that someone could define a new Prank
subtype of AbstractMatrix
, and define a method for *
that takes two Prank
s to a String
?
I suppose that's possible, but I don't see why promote_type
should indulge this behaviour. Isn't type inference supposed to be just a heuristic anyway?
from julia.
Related Issues (20)
- ERROR: LoadError: UndefVarError: `UUIDs` not defined. HOT 5
- Possible improvement in memory used in storage of a `Union` of immutable structs?
- Enable opt-in recursive constant propagation HOT 2
- Common code not included in optionally-generated function HOT 8
- Stack overflow during type inference HOT 8
- Regression 1.9 -> 1.10: `getproperty` 3x longer HOT 2
- [LinearAlgebra] Wrong positive definite check when performing Cholesky decomposition HOT 3
- Assertion failure inside rr causing test x86_64-linux-gnuassertrr to fail HOT 2
- Impossible values of allunique() and allequal() HOT 3
- `permute_dims` fails in edge case because of use if `1:length`
- Documentation example not behaving as displayed - behavior of "const" on immutable objects. HOT 1
- Make precise semantics of world-age increments in top-level thunks
- New precompilation crashes on Julia 1.11-rc1 HOT 68
- introduce a function to check whether a value can be represented as a type HOT 5
- Plots package doesn't work HOT 2
- suboptimal abstract return type inference involving `getindex(::Tuple)` HOT 1
- Improvements to `JULIA_CPU_TARGET` and its documentation
- [WONTFIX] `fill()` is a footgun HOT 2
- The relative precedence of `::` and `where` is strangely context dependent HOT 5
- Allow Adding Runtime Precompiles to Module Image HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.