Last active
May 25, 2021 23:00
-
-
Save genkuroki/42ce04d1c0799c30b055c43d4c0aca32 to your computer and use it in GitHub Desktop.
Abstract eltype vs. Union eltype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "VERSION", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 1, | |
"data": { | |
"text/plain": "v\"1.7.0-DEV.1129\"" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "module A\n\nexport AbstractFoo, getval, UnionFoo, FooVector, generate_testdata, sum_elems, sum_index, runtest\n\nusing InteractiveUtils, BenchmarkTools\n\nabstract type AbstractFoo end\n\nuniontype(x, y) = Union{x, y}\nUnionFoo() = reduce(uniontype, subtypes(AbstractFoo))\n\nfor i in 1:5\n T = Symbol(:Foo, i)\n @eval export $T\n @eval struct $T <: AbstractFoo val::Float64 end\n @eval getval(x::$T) = x.val\nend\n\nstruct FooVector{T<:AbstractFoo} v::Vector{T} end\n\nfunction generate_testdata(n)\n Ts = subtypes(AbstractFoo)\n v = [rand(Ts)(rand()) for _ in 1:n]\n v_union = Vector{UnionFoo()}(v)\n data_naive = FooVector(v)\n data_union = FooVector(v_union)\n (; data_naive, data_union)\nend\n\nfunction sum_elems(data)\n s = 0.0\n for x in data.v\n s += getval(x)\n end\n s\nend\n\nfunction sum_index(data)\n s = 0.0\n for i in eachindex(data.v)\n @inbounds s += getval(data.v[i])\n end\n s\nend\n\nfunction runtest(n)\n data_naive, data_union = generate_testdata(n)\n \n @show sum_elems(data_naive)\n @show sum_elems(data_union)\n @show sum_index(data_naive)\n @show sum_index(data_union)\n println()\n \n print(\"sum_elems(data_naive):\")\n @btime A.sum_elems($data_naive)\n print(\"sum_elems(data_union):\")\n @btime A.sum_elems($data_union)\n print(\"sum_index(data_naive):\")\n @btime A.sum_index($data_naive)\n print(\"sum_index(data_union):\")\n @btime A.sum_index($data_union)\n \n nothing\nend\n\nend\n\nusing .A\n\nruntest(10^3)", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "sum_elems(data_naive) = 500.7159716608692\nsum_elems(data_union) = 500.7159716608692\nsum_index(data_naive) = 500.7159716608692\nsum_index(data_union) = 500.7159716608692\n\nsum_elems(data_naive): 55.400 μs (2000 allocations: 31.25 KiB)\nsum_elems(data_union): 160.200 μs (5980 allocations: 109.06 KiB)\nsum_index(data_naive): 55.200 μs (2000 allocations: 31.25 KiB)\nsum_index(data_union): 820.202 ns (0 allocations: 0 bytes)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "subtypes(AbstractFoo)", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 3, | |
"data": { | |
"text/plain": "5-element Vector{Any}:\n Foo1\n Foo2\n Foo3\n Foo4\n Foo5" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "UnionFoo()", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 4, | |
"data": { | |
"text/plain": "Union{Foo1, Foo2, Foo3, Foo4, Foo5}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "methods(getval)", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": "# 5 methods for generic function \"getval\":\n[1] getval(x::Foo1) in Main.A at In[2]:16\n[2] getval(x::Foo2) in Main.A at In[2]:16\n[3] getval(x::Foo3) in Main.A at In[2]:16\n[4] getval(x::Foo4) in Main.A at In[2]:16\n[5] getval(x::Foo5) in Main.A at In[2]:16", | |
"text/html": "# 5 methods for generic function <b>getval</b>:<ul><li> getval(x::<b>Foo1</b>) in Main.A at In[2]:16</li> <li> getval(x::<b>Foo2</b>) in Main.A at In[2]:16</li> <li> getval(x::<b>Foo3</b>) in Main.A at In[2]:16</li> <li> getval(x::<b>Foo4</b>) in Main.A at In[2]:16</li> <li> getval(x::<b>Foo5</b>) in Main.A at In[2]:16</li> </ul>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "n = 100\ndata_naive, data_union = generate_testdata(n)\n@show typeof(data_naive)\n@show typeof(data_union);", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "typeof(data_naive) = FooVector{AbstractFoo}\ntypeof(data_union) = FooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@show eltype(data_naive.v)\n@show eltype(data_union.v);", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "eltype(data_naive.v) = AbstractFoo\neltype(data_union.v) = Union{Foo1, Foo2, Foo3, Foo4, Foo5}\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@code_warntype sum_elems(data_naive)", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "MethodInstance for Main.A.sum_elems(::\u001b[0mFooVector{AbstractFoo})\n from sum_elems(data) in Main.A at In[2]:30\nArguments\n #self#\u001b[36m::Core.Const(Main.A.sum_elems)\u001b[39m\n data\u001b[36m::FooVector{AbstractFoo}\u001b[39m\nLocals\n @_3\u001b[33m\u001b[1m::Union{Nothing, Tuple{AbstractFoo, Int64}}\u001b[22m\u001b[39m\n s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n x\u001b[91m\u001b[1m::AbstractFoo\u001b[22m\u001b[39m\nBody\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m1 ─\u001b[39m (s = 0.0)\n\u001b[90m│ \u001b[39m %2 = Base.getproperty(data, :v)\u001b[36m::Vector{AbstractFoo}\u001b[39m\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%2))\n\u001b[90m│ \u001b[39m %4 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %5 = Base.not_int(%4)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %5\n\u001b[90m2 ┄\u001b[39m %7 = @_3\u001b[91m\u001b[1m::Tuple{AbstractFoo, Int64}\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m (x = Core.getfield(%7, 1))\n\u001b[90m│ \u001b[39m %9 = Core.getfield(%7, 2)\u001b[36m::Int64\u001b[39m\n\u001b[90m│ \u001b[39m %10 = s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %11 = Main.A.getval(x)\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m (s = %10 + %11)\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%2, %9))\n\u001b[90m│ \u001b[39m %14 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %15 = Base.not_int(%14)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %15\n\u001b[90m3 ─\u001b[39m goto #2\n\u001b[90m4 ┄\u001b[39m return s\n\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@code_warntype sum_elems(data_union)", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "MethodInstance for Main.A.sum_elems(::\u001b[0mFooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}})\n from sum_elems(data) in Main.A at In[2]:30\nArguments\n #self#\u001b[36m::Core.Const(Main.A.sum_elems)\u001b[39m\n data\u001b[36m::FooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\u001b[39m\nLocals\n @_3\u001b[33m\u001b[1m::Union{Nothing, Tuple{Any, Any}}\u001b[22m\u001b[39m\n s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n x\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\nBody\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m1 ─\u001b[39m (s = 0.0)\n\u001b[90m│ \u001b[39m %2 = Base.getproperty(data, :v)\u001b[36m::Vector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\u001b[39m\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%2))\n\u001b[90m│ \u001b[39m %4 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %5 = Base.not_int(%4)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %5\n\u001b[90m2 ┄\u001b[39m %7 = @_3\u001b[91m\u001b[1m::Tuple{Any, Any}\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m (x = Core.getfield(%7, 1))\n\u001b[90m│ \u001b[39m %9 = Core.getfield(%7, 2)\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %10 = s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %11 = Main.A.getval(x)\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m (s = %10 + %11)\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%2, %9))\n\u001b[90m│ \u001b[39m %14 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %15 = Base.not_int(%14)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %15\n\u001b[90m3 ─\u001b[39m goto #2\n\u001b[90m4 ┄\u001b[39m return s\n\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@code_warntype sum_index(data_naive)", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "MethodInstance for Main.A.sum_index(::\u001b[0mFooVector{AbstractFoo})\n from sum_index(data) in Main.A at In[2]:38\nArguments\n #self#\u001b[36m::Core.Const(Main.A.sum_index)\u001b[39m\n data\u001b[36m::FooVector{AbstractFoo}\u001b[39m\nLocals\n @_3\u001b[33m\u001b[1m::Union{Nothing, Tuple{Int64, Int64}}\u001b[22m\u001b[39m\n s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n val\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n i\u001b[36m::Int64\u001b[39m\nBody\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m1 ─\u001b[39m (s = 0.0)\n\u001b[90m│ \u001b[39m %2 = Base.getproperty(data, :v)\u001b[36m::Vector{AbstractFoo}\u001b[39m\n\u001b[90m│ \u001b[39m %3 = Main.A.eachindex(%2)\u001b[36m::Base.OneTo{Int64}\u001b[39m\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%3))\n\u001b[90m│ \u001b[39m %5 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %6 = Base.not_int(%5)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %6\n\u001b[90m2 ┄\u001b[39m %8 = @_3\u001b[36m::Tuple{Int64, Int64}\u001b[39m\n\u001b[90m│ \u001b[39m (i = Core.getfield(%8, 1))\n\u001b[90m│ \u001b[39m %10 = Core.getfield(%8, 2)\u001b[36m::Int64\u001b[39m\n\u001b[90m│ \u001b[39m $(Expr(:inbounds, true))\n\u001b[90m│ \u001b[39m %12 = s\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %13 = Base.getproperty(data, :v)\u001b[36m::Vector{AbstractFoo}\u001b[39m\n\u001b[90m│ \u001b[39m %14 = Base.getindex(%13, i)\u001b[91m\u001b[1m::AbstractFoo\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %15 = Main.A.getval(%14)\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %16 = (%12 + %15)\u001b[91m\u001b[1m::Any\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m (s = %16)\n\u001b[90m│ \u001b[39m (val = %16)\n\u001b[90m│ \u001b[39m $(Expr(:inbounds, :pop))\n\u001b[90m│ \u001b[39m val\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%3, %10))\n\u001b[90m│ \u001b[39m %22 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %23 = Base.not_int(%22)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %23\n\u001b[90m3 ─\u001b[39m goto #2\n\u001b[90m4 ┄\u001b[39m return s\n\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@code_warntype sum_index(data_union)", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "MethodInstance for Main.A.sum_index(::\u001b[0mFooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}})\n from sum_index(data) in Main.A at In[2]:38\nArguments\n #self#\u001b[36m::Core.Const(Main.A.sum_index)\u001b[39m\n data\u001b[36m::FooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\u001b[39m\nLocals\n @_3\u001b[33m\u001b[1m::Union{Nothing, Tuple{Int64, Int64}}\u001b[22m\u001b[39m\n s\u001b[36m::Float64\u001b[39m\n val\u001b[36m::Float64\u001b[39m\n i\u001b[36m::Int64\u001b[39m\nBody\u001b[36m::Float64\u001b[39m\n\u001b[90m1 ─\u001b[39m (s = 0.0)\n\u001b[90m│ \u001b[39m %2 = Base.getproperty(data, :v)\u001b[36m::Vector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\u001b[39m\n\u001b[90m│ \u001b[39m %3 = Main.A.eachindex(%2)\u001b[36m::Base.OneTo{Int64}\u001b[39m\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%3))\n\u001b[90m│ \u001b[39m %5 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %6 = Base.not_int(%5)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %6\n\u001b[90m2 ┄\u001b[39m %8 = @_3\u001b[36m::Tuple{Int64, Int64}\u001b[39m\n\u001b[90m│ \u001b[39m (i = Core.getfield(%8, 1))\n\u001b[90m│ \u001b[39m %10 = Core.getfield(%8, 2)\u001b[36m::Int64\u001b[39m\n\u001b[90m│ \u001b[39m $(Expr(:inbounds, true))\n\u001b[90m│ \u001b[39m %12 = s\u001b[36m::Float64\u001b[39m\n\u001b[90m│ \u001b[39m %13 = Base.getproperty(data, :v)\u001b[36m::Vector{Union{Foo1, Foo2, Foo3, Foo4, Foo5}}\u001b[39m\n\u001b[90m│ \u001b[39m %14 = Base.getindex(%13, i)\u001b[91m\u001b[1m::Union{Foo1, Foo2, Foo3, Foo4, Foo5}\u001b[22m\u001b[39m\n\u001b[90m│ \u001b[39m %15 = Main.A.getval(%14)\u001b[36m::Float64\u001b[39m\n\u001b[90m│ \u001b[39m %16 = (%12 + %15)\u001b[36m::Float64\u001b[39m\n\u001b[90m│ \u001b[39m (s = %16)\n\u001b[90m│ \u001b[39m (val = %16)\n\u001b[90m│ \u001b[39m $(Expr(:inbounds, :pop))\n\u001b[90m│ \u001b[39m val\n\u001b[90m│ \u001b[39m (@_3 = Base.iterate(%3, %10))\n\u001b[90m│ \u001b[39m %22 = (@_3 === nothing)\u001b[36m::Bool\u001b[39m\n\u001b[90m│ \u001b[39m %23 = Base.not_int(%22)\u001b[36m::Bool\u001b[39m\n\u001b[90m└──\u001b[39m goto #4 if not %23\n\u001b[90m3 ─\u001b[39m goto #2\n\u001b[90m4 ┄\u001b[39m return s\n\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "module B\n\nusing ..A\n\nfor i in 1:45\n T = Symbol(:Bar, i)\n @eval export $T\n @eval struct $T <: AbstractFoo val::Float64 end\n @eval A.getval(x::$T) = x.val\nend\n\nend\n\nusing .B\n\nruntest(10^3)", | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "sum_elems(data_naive) = 495.78388759142234\nsum_elems(data_union) = 495.78388759142234\nsum_index(data_naive) = 495.78388759142234\nsum_index(data_union) = 495.78388759142234\n\nsum_elems(data_naive): 104.100 μs (2000 allocations: 31.25 KiB)\nsum_elems(data_union): 226.500 μs (5980 allocations: 109.06 KiB)\nsum_index(data_naive): 105.300 μs (2000 allocations: 31.25 KiB)\nsum_index(data_union): 823.611 ns (0 allocations: 0 bytes)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "UnionFoo()", | |
"execution_count": 13, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 13, | |
"data": { | |
"text/plain": "Union{Foo1, Foo2, Foo3, Foo4, Foo5, Bar1, Bar10, Bar11, Bar12, Bar13, Bar14, Bar15, Bar16, Bar17, Bar18, Bar19, Bar2, Bar20, Bar21, Bar22, Bar23, Bar24, Bar25, Bar26, Bar27, Bar28, Bar29, Bar3, Bar30, Bar31, Bar32, Bar33, Bar34, Bar35, Bar36, Bar37, Bar38, Bar39, Bar4, Bar40, Bar41, Bar42, Bar43, Bar44, Bar45, Bar5, Bar6, Bar7, Bar8, Bar9}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "data_naive, data_union = generate_testdata(25)\ndata_naive.v", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 14, | |
"data": { | |
"text/plain": "25-element Vector{AbstractFoo}:\n Bar32(0.41813405556395544)\n Bar2(0.47980688586997045)\n Foo1(0.1335758874260604)\n Bar30(0.11058000714421956)\n Foo3(0.15965648219129425)\n Bar6(0.10295724516249605)\n Bar24(0.8971956613344436)\n Bar16(0.3441699015446429)\n Bar9(0.40344590911583267)\n Foo5(0.6285110840044839)\n Bar27(0.3819618601708723)\n Bar16(0.7404267783935812)\n Bar17(0.7563399026702167)\n Bar7(0.32724605641299)\n Bar22(0.5547432114438597)\n Bar33(0.4809547169382058)\n Bar3(0.027028444401783203)\n Foo5(0.9103694521696006)\n Bar31(0.9181792516214908)\n Bar45(0.464060416954047)\n Bar18(0.7959263385365192)\n Foo3(0.11610399231682678)\n Bar27(0.5861345523581152)\n Bar15(0.033288516236685384)\n Bar20(0.6783510585633865)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@show typeof(data_naive)\n@show typeof(data_union);", | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "typeof(data_naive) = FooVector{AbstractFoo}\ntypeof(data_union) = FooVector{Union{Foo1, Foo2, Foo3, Foo4, Foo5, Bar1, Bar10, Bar11, Bar12, Bar13, Bar14, Bar15, Bar16, Bar17, Bar18, Bar19, Bar2, Bar20, Bar21, Bar22, Bar23, Bar24, Bar25, Bar26, Bar27, Bar28, Bar29, Bar3, Bar30, Bar31, Bar32, Bar33, Bar34, Bar35, Bar36, Bar37, Bar38, Bar39, Bar4, Bar40, Bar41, Bar42, Bar43, Bar44, Bar45, Bar5, Bar6, Bar7, Bar8, Bar9}}\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "@show eltype(data_naive.v)\n@show eltype(data_union.v);", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "eltype(data_naive.v) = AbstractFoo\neltype(data_union.v) = Union{Foo1, Foo2, Foo3, Foo4, Foo5, Bar1, Bar10, Bar11, Bar12, Bar13, Bar14, Bar15, Bar16, Bar17, Bar18, Bar19, Bar2, Bar20, Bar21, Bar22, Bar23, Bar24, Bar25, Bar26, Bar27, Bar28, Bar29, Bar3, Bar30, Bar31, Bar32, Bar33, Bar34, Bar35, Bar36, Bar37, Bar38, Bar39, Bar4, Bar40, Bar41, Bar42, Bar43, Bar44, Bar45, Bar5, Bar6, Bar7, Bar8, Bar9}\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"@webio": { | |
"lastKernelId": null, | |
"lastCommId": null | |
}, | |
"kernelspec": { | |
"name": "julia-1.7-depwarn-o3", | |
"display_name": "Julia 1.7.0-DEV depwarn -O3", | |
"language": "julia" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"name": "julia", | |
"mimetype": "application/julia", | |
"version": "1.7.0" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"gist": { | |
"id": "42ce04d1c0799c30b055c43d4c0aca32", | |
"data": { | |
"description": "Abstract eltype vs. Union eltype", | |
"public": true | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/42ce04d1c0799c30b055c43d4c0aca32" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment