Created
August 14, 2017 09:09
-
-
Save saschatimme/bc9f953bcce0303faea39274d0dff0b4 to your computer and use it in GitHub Desktop.
This file contains 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": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"WARNING: Compat.AsyncCondition is deprecated, use Base.AsyncCondition instead.\n", | |
" likely near /Users/sascha/.julia/v0.6/IJulia/src/kernel.jl:31\n", | |
"WARNING: Compat.AsyncCondition is deprecated, use Base.AsyncCondition instead.\n", | |
" likely near /Users/sascha/.julia/v0.6/IJulia/src/kernel.jl:31\n" | |
] | |
} | |
], | |
"source": [ | |
"import TypedPolynomials\n", | |
"import DynamicPolynomials\n", | |
"import MultivariatePolynomials\n", | |
"using StaticArrays" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"WARNING: Compat.AsyncCondition is deprecated, use Base.AsyncCondition instead.\n", | |
" likely near /Users/sascha/.julia/v0.6/IJulia/src/kernel.jl:31\n", | |
"WARNING: Compat.AsyncCondition is deprecated, use Base.AsyncCondition instead.\n", | |
" likely near /Users/sascha/.julia/v0.6/IJulia/src/kernel.jl:31\n" | |
] | |
} | |
], | |
"source": [ | |
"using BenchmarkTools" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 49, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3-element MVector{3,Complex{Float64}}:\n", | |
" 0.337939+0.625128im\n", | |
" 0.921418+0.218451im\n", | |
" 0.478515+0.968963im" | |
] | |
}, | |
"execution_count": 49, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"v = @MVector rand(Complex128, 2)\n", | |
"u = @MVector rand(Complex128, 3)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 46, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"a = 5\n", | |
"b = 4\n", | |
"c = 3;\n", | |
"\n", | |
"#create the variables\n", | |
"@TypedPolynomials.polyvar sθ cθ x0\n", | |
"f1 = cθ^2 + sθ^2 - (1.0 + 0im)\n", | |
"f2 = (a*cθ - b)^2 + (1.0 + 0im) * (a*sθ)^2 - c^2;\n", | |
"h1 = cθ^2 + sθ^2 - (1.0 + 0im)*x0^2\n", | |
"h2 = (a*cθ - b)^2 + (1.0 + 0im) * (a*sθ)^2 - c^2*x0^2;" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 47, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"eval2 (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 47, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"eval2(p1, p2, x) = p1(MultivariatePolynomials.variables(p1)=>x) .+ p2(MultivariatePolynomials.variables(p2)=>x)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 50, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"BenchmarkTools.Trial: \n", | |
" memory estimate: 64 bytes\n", | |
" allocs estimate: 4\n", | |
" --------------\n", | |
" minimum time: 157.665 ns (0.00% GC)\n", | |
" median time: 161.373 ns (0.00% GC)\n", | |
" mean time: 180.488 ns (2.56% GC)\n", | |
" maximum time: 2.834 μs (84.59% GC)\n", | |
" --------------\n", | |
" samples: 10000\n", | |
" evals/sample: 796" | |
] | |
}, | |
"execution_count": 50, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"@benchmark eval2($f1, $f2, $v)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 51, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"BenchmarkTools.Trial: \n", | |
" memory estimate: 2.44 KiB\n", | |
" allocs estimate: 116\n", | |
" --------------\n", | |
" minimum time: 7.794 μs (0.00% GC)\n", | |
" median time: 8.053 μs (0.00% GC)\n", | |
" mean time: 9.156 μs (3.65% GC)\n", | |
" maximum time: 923.998 μs (96.95% GC)\n", | |
" --------------\n", | |
" samples: 10000\n", | |
" evals/sample: 4" | |
] | |
}, | |
"execution_count": 51, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"@benchmark eval2($h1, $h2, $u)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 53, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"#create the variables\n", | |
"@DynamicPolynomials.polyvar sθ cθ x0\n", | |
"# now construct the system\n", | |
"# In the future we will be able to avoid to explicitly write complex coefficients\n", | |
"f3 = cθ^2 + sθ^2 - (1.0 + 0im)\n", | |
"f4 = (a*cθ - b)^2 + (1.0 + 0im) * (a*sθ)^2 - c^2;\n", | |
"h3 = cθ^2 + sθ^2 - (1.0 + 0im)*x0^2\n", | |
"h4 = (a*cθ - b)^2 + (1.0 + 0im) * (a*sθ)^2 - c^2*x0^2;" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 54, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"BenchmarkTools.Trial: \n", | |
" memory estimate: 640 bytes\n", | |
" allocs estimate: 16\n", | |
" --------------\n", | |
" minimum time: 383.030 ns (0.00% GC)\n", | |
" median time: 401.042 ns (0.00% GC)\n", | |
" mean time: 520.024 ns (17.16% GC)\n", | |
" maximum time: 19.084 μs (95.78% GC)\n", | |
" --------------\n", | |
" samples: 10000\n", | |
" evals/sample: 203" | |
] | |
}, | |
"execution_count": 54, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"@benchmark eval2($f3, $f4, $u)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 55, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"BenchmarkTools.Trial: \n", | |
" memory estimate: 800 bytes\n", | |
" allocs estimate: 20\n", | |
" --------------\n", | |
" minimum time: 464.838 ns (0.00% GC)\n", | |
" median time: 478.604 ns (0.00% GC)\n", | |
" mean time: 607.164 ns (15.62% GC)\n", | |
" maximum time: 27.392 μs (95.75% GC)\n", | |
" --------------\n", | |
" samples: 10000\n", | |
" evals/sample: 197" | |
] | |
}, | |
"execution_count": 55, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"@benchmark eval2($h3, $h4, $u)" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Julia 0.6.0", | |
"language": "julia", | |
"name": "julia-0.6" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment