Giter VIP home page Giter VIP logo

Comments (1)

goretkin avatar goretkin commented on August 30, 2024

with ] add FixArgs#nested (see Manifest.toml for full details)

using LazySets: LazySets, Interval, VPolytope
using LazySets: intersection, cartesian_product
using LazySets: concretize
using LazySets: CartesianProduct, Intersection, CartesianProductArray, AbstractPolyhedron

using FixArgs: FixArgs, @fix, Fix, @FixT
using Polyhedra: Polyhedra # LazySets: package 'Polyhedra' not loaded (it is required for executing `default_polyhedra_backend`)

a = Interval(0.1, 0.9)
b = Interval(0.2, 0.8)
c = VPolytope([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])

cap_now = Intersection(CartesianProductArray([a, b]), c)
cap_fix = @fix intersection((@fix reduce(cartesian_product, [a, b])), c)

# Note, this definition is not needed to create `cap_fix` above!
function LazySets.cartesian_product(a::Interval, b::Interval)
    cartesian_product(
        convert(VPolytope, a),
        convert(VPolytope, b)
    )
end

cap_now_concrete = concretize(cap_now)
cap_fix_concrete = cap_fix(())

println("\nconcretization evalautes to the same value:")
@show cap_now_concrete == cap_fix_concrete

println("\n")
@show typeof(cap_now)

println("\n")
@show typeof(cap_fix)

# type annotation on `cap` argument:
# https://github.com/JuliaReach/LazySets.jl/blob/53f21cb9c26355e7f218578e5b4036c3ff0091fe/src/Approximations/overapproximate.jl#L1202
T_now{N} = Intersection{
    N, 
    <:CartesianProductArray,
    <:AbstractPolyhedron
}

println("\nvalue type and annotation type now:")
@show typeof(cap_now) <: T_now

CartesianProductArray_fix{T} = FixArgs.@FixT reduce(::typeof(cartesian_product), ::Vector{T})
# @FixT wraps with `Some` unless `nothing`, and @fix leaves `Fix` unwrapped.
# TODO allow the following to work
# Intersection_fix{#=N, =#A, B} = FixArgs.@FixT intersection(::A, ::B)

# TODO allow extra type parameters in `Fix` type (maybe in a `Tuple`)
Intersection_fix{#=N, =#A, B} = Fix{typeof(intersection),Tuple{A, B}, NamedTuple{(), Tuple{}}} where B where A
T_fix#={N}=# = Intersection_fix{#=N, =#CartesianProductArray_fix{T}, Some{B}} where {T, B <: AbstractPolyhedron}

println("\nvalue type and annotation type using FixArgs.jl:")
@show typeof(cap_fix) <: T_fix
/Users/goretkin/projects/LazySetsFixArgs/Manifest.toml


println("\npieces of the types:")
@show typeof(cap_fix.args[1]) <: CartesianProductArray_fix
@show typeof(something(cap_fix.args[2])) <: AbstractPolyhedron

output

concretization evalautes to the same value:
cap_now_concrete == cap_fix_concrete = true


typeof(cap_now) = Intersection{Float64,CartesianProductArray{Float64,Interval{Float64,IntervalArithmetic.Interval{Float64}}},VPolytope{Float64,Array{Float64,1}}}


typeof(cap_fix) = Fix{typeof(intersection),Tuple{Fix{typeof(reduce),Tuple{Some{typeof(cartesian_product)},Some{Array{Interval{Float64,IntervalArithmetic.Interval{Float64}},1}}},NamedTuple{(),Tuple{}}},Some{VPolytope{Float64,Array{Float64,1}}}},NamedTuple{(),Tuple{}}}

value type and annotation type now:
typeof(cap_now) <: T_now = true

value type and annotation type using FixArgs.jl:
typeof(cap_fix) <: T_fix = true

pieces of the types:
typeof(cap_fix.args[1]) <: CartesianProductArray_fix = true
typeof(something(cap_fix.args[2])) <: AbstractPolyhedron = true
true

from fixargs.jl.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.