Skip to content

Instantly share code, notes, and snippets.

@genkuroki
Created July 4, 2017 12:42
Show Gist options
  • Save genkuroki/0d150b1cec81359afeaff8564d64599a to your computer and use it in GitHub Desktop.
Save genkuroki/0d150b1cec81359afeaff8564d64599a to your computer and use it in GitHub Desktop.
Julia/Cubature and Yeppp.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Cubature and Yeppp\n\nhttps://github.com/stevengj/Cubature.jl\n数値積分\n\nhttps://github.com/JuliaMath/Yeppp.jl\nベクトルの高速数値計算"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Cubature\n\n# integrate(1/(1+x^2), (x, 0, ∞)) = pi/2\n# x = t/(1-t^2)\n# dx = (1+t^2)/(1-t^2)^2\n# x = 0~∞ ⇔ t = 0~1\n\na = pi/2\n@time b = hquadrature(x->1/(1+x^2),0,10^22)\n@time c = hquadrature(t->1/(1+(t/(1-t^2))^2)*(1+t^2)/(1-t^2)^2,0,1)\n@time d = hquadrature(t->(1+t^2)/(1-t^2+t^4),0,1)\n\ndisplay(a)\ndisplay(b)\ndisplay(c)\ndisplay(d)",
"execution_count": 6,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "1.5707963267948966"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": "(1.5707963267948966, 6.138518647513451e-12)"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": "(1.5707963267948966, 7.650730483975984e-10)"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": "(1.5707963267948966, 7.650730442049322e-10)"
},
"metadata": {}
},
{
"output_type": "stream",
"text": " 0.061307 seconds (12.19 k allocations: 688.093 KiB)\n 0.050534 seconds (13.24 k allocations: 748.005 KiB)\n 0.040982 seconds (12.77 k allocations: 718.796 KiB)\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Yeppp.log! の方が log. より3倍以上速い\n\nusing Yeppp\n\nx = rand(10^8)\n@time ty = @elapsed Yeppp.log!(similar(x), x)\n@time t = @elapsed log.(x)\nt/ty",
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"text": " 0.458827 seconds (10 allocations: 762.940 MiB, 24.33% gc time)\n 1.607678 seconds (33 allocations: 762.941 MiB, 3.58% gc time)\n",
"name": "stdout"
},
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "3.5039294453769205"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "julia-0.6",
"display_name": "Julia 0.6.0",
"language": "julia"
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "0.6.0"
},
"gist": {
"id": "",
"data": {
"description": "Julia/Cubature and Yeppp.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment