Skip to content

Instantly share code, notes, and snippets.

@goropikari
Created September 16, 2018 07:13
Show Gist options
  • Select an option

  • Save goropikari/abae89a6a662355837f00eb3dba1e12b to your computer and use it in GitHub Desktop.

Select an option

Save goropikari/abae89a6a662355837f00eb3dba1e12b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:45:28.328000+09:00",
"start_time": "2018-09-16T06:45:24.925Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Julia Version 1.0.0\n",
"Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)\n",
"Platform Info:\n",
" OS: Linux (x86_64-pc-linux-gnu)\n",
" CPU: Intel(R) Core(TM) i5-4460T CPU @ 1.90GHz\n",
" WORD_SIZE: 64\n",
" LIBM: libopenlibm\n",
" LLVM: libLLVM-6.0.0 (ORCJIT, haswell)\n",
"Environment:\n",
" JULIA_SHELL = /usr/bin/zsh\n",
" JULIA_EDITOR = nvim\n"
]
}
],
"source": [
"versioninfo()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:45:28.757000+09:00",
"start_time": "2018-09-16T06:45:24.927Z"
}
},
"outputs": [],
"source": [
"using BenchmarkTools, Random\n",
"Random.seed!(0);"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:45:28.789000+09:00",
"start_time": "2018-09-16T06:45:24.930Z"
}
},
"outputs": [],
"source": [
"n = 1000\n",
"x = rand(n,n);\n",
"y = rand(n,n);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:45:42.867000+09:00",
"start_time": "2018-09-16T06:45:24.932Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 7.63 MiB\n",
" allocs estimate: 3\n",
" --------------\n",
" minimum time: 16.401 ms (0.00% GC)\n",
" median time: 18.724 ms (0.00% GC)\n",
" mean time: 21.585 ms (5.92% GC)\n",
" maximum time: 123.273 ms (71.90% GC)\n",
" --------------\n",
" samples: 232\n",
" evals/sample: 1"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark transpose(x) * x"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:45:54.855000+09:00",
"start_time": "2018-09-16T06:45:24.934Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 15.26 MiB\n",
" allocs estimate: 4\n",
" --------------\n",
" minimum time: 28.590 ms (0.00% GC)\n",
" median time: 32.745 ms (1.84% GC)\n",
" mean time: 35.063 ms (6.62% GC)\n",
" maximum time: 133.421 ms (64.85% GC)\n",
" --------------\n",
" samples: 143\n",
" evals/sample: 1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark permutedims(x) * x"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:06.454000+09:00",
"start_time": "2018-09-16T06:45:24.940Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 7.63 MiB\n",
" allocs estimate: 3\n",
" --------------\n",
" minimum time: 22.784 ms (0.00% GC)\n",
" median time: 24.591 ms (0.00% GC)\n",
" mean time: 28.024 ms (4.66% GC)\n",
" maximum time: 107.587 ms (76.81% GC)\n",
" --------------\n",
" samples: 179\n",
" evals/sample: 1"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark transpose(y) * x"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:18.189000+09:00",
"start_time": "2018-09-16T06:45:24.942Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 15.26 MiB\n",
" allocs estimate: 4\n",
" --------------\n",
" minimum time: 28.155 ms (0.00% GC)\n",
" median time: 35.017 ms (1.74% GC)\n",
" mean time: 47.152 ms (6.28% GC)\n",
" maximum time: 186.246 ms (74.01% GC)\n",
" --------------\n",
" samples: 106\n",
" evals/sample: 1"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark permutedims(y) * x"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:18.206000+09:00",
"start_time": "2018-09-16T06:45:24.948Z"
}
},
"outputs": [],
"source": [
"n = 1000\n",
"a = rand(n,n)\n",
"b = transpose(a)\n",
"c = permutedims(a);"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:30.100000+09:00",
"start_time": "2018-09-16T06:45:24.953Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 7.63 MiB\n",
" allocs estimate: 2\n",
" --------------\n",
" minimum time: 16.196 ms (0.00% GC)\n",
" median time: 19.268 ms (0.00% GC)\n",
" mean time: 24.740 ms (4.64% GC)\n",
" maximum time: 103.267 ms (82.21% GC)\n",
" --------------\n",
" samples: 202\n",
" evals/sample: 1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark b * a"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:41.812000+09:00",
"start_time": "2018-09-16T06:45:24.955Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: \n",
" memory estimate: 7.63 MiB\n",
" allocs estimate: 2\n",
" --------------\n",
" minimum time: 22.560 ms (0.00% GC)\n",
" median time: 23.881 ms (0.00% GC)\n",
" mean time: 27.300 ms (5.13% GC)\n",
" maximum time: 182.655 ms (66.64% GC)\n",
" --------------\n",
" samples: 183\n",
" evals/sample: 1"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"@benchmark c * a"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:42.229000+09:00",
"start_time": "2018-09-16T06:45:24.958Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a === b.parent"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:42.616000+09:00",
"start_time": "2018-09-16T06:45:24.960Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Ptr{Nothing} @0x00007ff953041550"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pointer_from_objref(a)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:42.652000+09:00",
"start_time": "2018-09-16T06:45:24.964Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Ptr{Nothing} @0x00007ff953041550"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pointer_from_objref(b.parent)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2018-09-16T15:46:42.654000+09:00",
"start_time": "2018-09-16T06:45:24.966Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Ptr{Nothing} @0x00007ff9526c11e0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pointer_from_objref(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×2 Array{Complex{Float64},2}:\n",
" 0.181477+1.74092im -1.16489+1.11049im\n",
" 0.405319+0.822867im 0.148019-1.51647im"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = randn(Complex{Float64}, 2, 2)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×2 LinearAlgebra.Adjoint{Complex{Float64},Array{Complex{Float64},2}}:\n",
" 0.181477-1.74092im 0.405319-0.822867im\n",
" -1.16489-1.11049im 0.148019+1.51647im "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B = A'"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×2 Array{Complex{Float64},2}:\n",
" 0.181477+1.74092im -1.16489+1.11049im\n",
" 0.405319+0.822867im 0.148019-1.51647im"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B.parent"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.0.0",
"language": "julia",
"name": "julia-1.0"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.0.0"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"toc_cell": false,
"toc_position": {},
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment