Comments (6)
Yes, statically sized arrays work out of the box, it's trivial to check:
julia> using StaticArrays, JET
julia> x = SizedVector{3}(rand(3)); y = SizedMatrix{4, 3}(rand(4, 3));
julia> f(x, y) = x' * (y*x)
f (generic function with 1 method)
julia> @report_call f(x, y)
═════ 1 possible error found ═════
┌ @ REPL[9]:1 Main.*(Main.'(x), Main.*(y, x))
│┌ @ /home/mason/julia/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:308 LinearAlgebra.dot(Base.getproperty(u, :parent), v)
││┌ @ /home/mason/.julia/packages/StaticArrays/NTbHj/src/linalg.jl:189 StaticArrays.same_size(a, b)
│││┌ @ /home/mason/.julia/packages/StaticArrays/NTbHj/src/traits.jl:186 StaticArrays._throw_size_mismatch(as...)
││││┌ @ /home/mason/.julia/packages/StaticArrays/NTbHj/src/traits.jl:191 StaticArrays._throw_size_mismatch(::SizedVector{3, Float64, Vector{Float64}}, ::SizedVector{4, Float64, Vector{Float64}})
│││││ may throw: StaticArrays.throw(StaticArrays.DimensionMismatch(Base.string("Sizes ", StaticArrays.map(StaticArrays._size, Argument(2))::Any, " of input arrays do not match")::Any)::Any)
││││└────────────────────────────────────────────────────────────────────
Union{}
julia> @report_call f(x, x*x')
No errors !
Float64
from jet.jl.
Thanks for raising this interesting issue.
In Julia, most information about array shape doesn't appear in Julia's type lattice (i.e. compile time), which its type inference works on, but only appear in runtime.
Since JET.jl is internally powered by Julia's native type inference system (and so it inherits its limitations), JET.jl can reports type level errors like NoMethodError
but it can't report those involved with shape and such, like DimensionMismatch
.
julia> using JET
[ Info: Precompiling JET [c3a54625-cd67-489e-a8e7-0a5a0ff4e31b]
julia> @report_call [1,2,3]' * [1,2,3]'
═════ 1 possible error found ═════
┌ @ /Users/aviatesk/julia/julia/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:317 *(::LinearAlgebra.Adjoint{Int64, Vector{Int64}}, ::LinearAlgebra.Adjoint{Int64, Vector{Int64}})
│ may throw: LinearAlgebra.throw(LinearAlgebra.MethodError(LinearAlgebra.*, Core.tuple(Argument(2), Argument(3))::Tuple{LinearAlgebra.Adjoint{Int64, Vector{Int64}}, LinearAlgebra.Adjoint{Int64, Vector{Int64}}})::Any)
└─────────────────────────────────────────────────────────────────────────────────────────────
Union{}
julia> @report_call [1,2,3]' * [1,2,3,4]
No errors !
Int64
Static array shape checking will require lots of work, extending the type lattice and maybe huge modification of its abstract interpretation logic, as such I don't think I will working on it in near future (I'm focusing on improving the quality of type-level checks for now).
But, hopefully, once I've got satisfied with the type-level error check, I think a more advanced error check like array shape checking might be my next scope.
On the other hand, there are static analysis approaches like : https://github.com/google-research/swift-tfp
Well, JET.jl is actually supposed to check errors mostly statically, and so swift-tfp's approach (abstract interpretation) is in fact same as JET for array shape checking.
Anyway, thanks for telling me interesting sets of discussions and projects !
from jet.jl.
Glad to hear! What about packages like https://github.com/JuliaArrays/StaticArrays.jl which have array dims in type parameters? (If we can separate codegen from type logic and dispatch)
There are also abstract tracing type approaches : FluxML/Mjolnir.jl#1
Also can you elaborate on the "mostly statically" and the connection to tfp?
Thanks !
from jet.jl.
That's awesome. Now we just need to deal with the codegen issue right ?
from jet.jl.
What codegen issue?
from jet.jl.
Would make static arrays more versatile
from jet.jl.
Related Issues (20)
- MethodError: no method matching add_control_flow!(::BitVector, ::Core.Compiler.CFG, ::BitSet) HOT 2
- MethodError: no method matching ⊑(::Core.Compiler.JLTypeLattice, ::Core.Compiler.MustAlias, ::Type{Array}) HOT 2
- `AssertionError`: `get_binding_type` should resolve the already-defined variable type HOT 1
- UndefVarError not caught in if/else statement
- False-positive with code using `@ccallable`
- override_precompiled_cache concurrency violation on 1.11 HOT 1
- Tagbot isn't working HOT 3
- Suggestion: make `ignored_modules` a tuple of symbols, instead of a tuple of modules HOT 1
- JET misses failed inference (a reproducer)
- JET doesn't analyze expression given to `@btime` HOT 5
- false positive MethodErrorReport Base.@kwdef with non used parameter HOT 1
- Use depth-limited type printing, from Julia 1.10 HOT 1
- @test_opt without the printing HOT 2
- Ignore given function name in `JET.test_package`
- Incomplete types break JET on Julia 1.10 HOT 1
- More readable "no method was found" messages with !Matched indication HOT 1
- Stack overflow in inference HOT 1
- Include submodules in `target_modules`?
- UI feature request: better (or at least larger) callstack browser HOT 1
- JET error `invalid lookup expr` with new `public` keyword HOT 7
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 jet.jl.