{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "57a2b335-a7f3-4ace-a2d8-52219c4febc5", "metadata": {}, "outputs": [], "source": [ "include(\"thinQR.jl\")\n", "using .thinQR" ] }, { "cell_type": "code", "execution_count": 2, "id": "8b3d71f8-2f4f-44f0-8c97-dd9d78706163", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x = [-1.5012955407352218e-16, 0.5000000000000001]\n" ] }, { "data": { "text/plain": [ "3-element Vector{Float64}:\n", " 0.9999999999999991\n", " 1.9999999999999996\n", " 2.9999999999999996" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = [1. 2; 3. 4.; 5. 6.]\n", "A = qrhous!(A)\n", "b = [1., 2, 3]\n", "x = A \\ b\n", "@show x\n", "A * x" ] }, { "cell_type": "code", "execution_count": 3, "id": "afd34800-7b9a-4006-9849-071fa197d962", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x = [5.810770900369532e-16, 0.4999999999999994]\n" ] }, { "data": { "text/plain": [ "3-element Vector{Float64}:\n", " 0.9999999999999993\n", " 1.9999999999999993\n", " 2.999999999999999" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using LinearAlgebra: \\, qr\n", "A = [1. 2.; 3. 4.; 5. 6.]\n", "(Q, R) = qr(A)\n", "x = A \\ [1., 2, 3]\n", "@show x\n", "A * x" ] }, { "cell_type": "code", "execution_count": 1, "id": "d7d24c53-5485-4f8a-bea3-3fe4ec1f456b", "metadata": {}, "outputs": [], "source": [ "using BenchmarkTools\n", "A=randn(100, 10_000)\n", "a=deepcopy(A)\n", "y=randn(100);" ] }, { "cell_type": "code", "execution_count": 5, "id": "652fe3c4-6b44-45e1-9bdc-5d7d41b55c6a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "BenchmarkTools.Trial: 20 samples with 1 evaluation.\n", " Range \u001b[90m(\u001b[39m\u001b[36m\u001b[1mmin\u001b[22m\u001b[39m … \u001b[35mmax\u001b[39m\u001b[90m): \u001b[39m\u001b[36m\u001b[1m246.781 ms\u001b[22m\u001b[39m … \u001b[35m278.597 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmin … max\u001b[90m): \u001b[39m18.71% … 22.05%\n", " Time \u001b[90m(\u001b[39m\u001b[34m\u001b[1mmedian\u001b[22m\u001b[39m\u001b[90m): \u001b[39m\u001b[34m\u001b[1m250.615 ms \u001b[22m\u001b[39m\u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmedian\u001b[90m): \u001b[39m19.94%\n", " Time \u001b[90m(\u001b[39m\u001b[32m\u001b[1mmean\u001b[22m\u001b[39m ± \u001b[32mσ\u001b[39m\u001b[90m): \u001b[39m\u001b[32m\u001b[1m252.757 ms\u001b[22m\u001b[39m ± \u001b[32m 7.079 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmean ± σ\u001b[90m): \u001b[39m20.18% ± 0.96%\n", "\n", " \u001b[39m \u001b[39m \u001b[39m \u001b[39m▄\u001b[39m▁\u001b[39m█\u001b[34m \u001b[39m\u001b[39m \u001b[39m \u001b[39m▁\u001b[39m▁\u001b[32m \u001b[39m\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \n", " \u001b[39m▆\u001b[39m▁\u001b[39m▁\u001b[39m█\u001b[39m█\u001b[39m█\u001b[34m▁\u001b[39m\u001b[39m▁\u001b[39m▆\u001b[39m█\u001b[39m█\u001b[32m▁\u001b[39m\u001b[39m▁\u001b[39m▁\u001b[39m▆\u001b[39m▆\u001b[39m▆\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▆\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▆\u001b[39m \u001b[39m▁\n", " 247 ms\u001b[90m Histogram: frequency by time\u001b[39m 279 ms \u001b[0m\u001b[1m<\u001b[22m\n", "\n", " Memory estimate\u001b[90m: \u001b[39m\u001b[33m1.54 GiB\u001b[39m, allocs estimate\u001b[90m: \u001b[39m\u001b[33m4804\u001b[39m." ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = deepcopy(a)\n", "@benchmark begin x = qrhous!($A) \\ $y; end" ] }, { "cell_type": "code", "execution_count": 6, "id": "c8e93f5c-b32c-4334-bd97-9779360d5d81", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "BenchmarkTools.Trial: 85 samples with 1 evaluation.\n", " Range \u001b[90m(\u001b[39m\u001b[36m\u001b[1mmin\u001b[22m\u001b[39m … \u001b[35mmax\u001b[39m\u001b[90m): \u001b[39m\u001b[36m\u001b[1m48.265 ms\u001b[22m\u001b[39m … \u001b[35m75.642 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmin … max\u001b[90m): \u001b[39m0.00% … 6.42%\n", " Time \u001b[90m(\u001b[39m\u001b[34m\u001b[1mmedian\u001b[22m\u001b[39m\u001b[90m): \u001b[39m\u001b[34m\u001b[1m60.888 ms \u001b[22m\u001b[39m\u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmedian\u001b[90m): \u001b[39m0.00%\n", " Time \u001b[90m(\u001b[39m\u001b[32m\u001b[1mmean\u001b[22m\u001b[39m ± \u001b[32mσ\u001b[39m\u001b[90m): \u001b[39m\u001b[32m\u001b[1m59.241 ms\u001b[22m\u001b[39m ± \u001b[32m 7.561 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmean ± σ\u001b[90m): \u001b[39m0.76% ± 1.71%\n", "\n", " \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m▂\u001b[39m█\u001b[39m█\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[32m \u001b[39m\u001b[39m \u001b[39m \u001b[39m \u001b[34m▂\u001b[39m\u001b[39m▅\u001b[39m▂\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \n", " \u001b[39m▅\u001b[39m▄\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m▄\u001b[39m▁\u001b[39m▅\u001b[39m▁\u001b[39m▅\u001b[39m▁\u001b[39m▁\u001b[39m▄\u001b[39m▄\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▄\u001b[39m▅\u001b[39m▁\u001b[32m▁\u001b[39m\u001b[39m▁\u001b[39m▄\u001b[39m▄\u001b[34m█\u001b[39m\u001b[39m█\u001b[39m█\u001b[39m▅\u001b[39m▄\u001b[39m▄\u001b[39m▁\u001b[39m▅\u001b[39m▅\u001b[39m▅\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▄\u001b[39m▅\u001b[39m▁\u001b[39m▄\u001b[39m▅\u001b[39m▄\u001b[39m▁\u001b[39m▄\u001b[39m▄\u001b[39m▅\u001b[39m▅\u001b[39m▁\u001b[39m▄\u001b[39m▄\u001b[39m▄\u001b[39m \u001b[39m▁\n", " 48.3 ms\u001b[90m Histogram: frequency by time\u001b[39m 73.7 ms \u001b[0m\u001b[1m<\u001b[22m\n", "\n", " Memory estimate\u001b[90m: \u001b[39m\u001b[33m7.92 MiB\u001b[39m, allocs estimate\u001b[90m: \u001b[39m\u001b[33m624\u001b[39m." ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using LinearAlgebra\n", "\n", "@benchmark begin x = $a \\ $y; end" ] }, { "cell_type": "code", "execution_count": 6, "id": "43d521a7-6bf4-45c6-abb6-0a07a666570d", "metadata": {}, "outputs": [], "source": [ "using Profile, ProfileSVG" ] }, { "cell_type": "code", "execution_count": 8, "id": "9443e1c4-03dd-46cb-a8ea-652c6862dbcf", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "ProfileSVG.FGConfig(Node(FlameGraphs.NodeData(ip:0x0, 0x01, 1:212)), Dict{Symbol, Any}(), FlameGraphs.FlameColors(ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(0.882,0.698,1.0), RGB{N0f8}(0.435,0.863,0.569), RGB{N0f8}(0.0,0.71,0.545), RGB{N0f8}(0.173,0.639,1.0)], RGB{N0f8}(1.0,1.0,1.0), RGB{N0f8}(0.0,0.0,0.0), ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(0.953,0.0,0.302), RGB{N0f8}(0.894,0.0,0.255), RGB{N0f8}(0.831,0.129,0.216), RGB{N0f8}(0.773,0.192,0.184)], ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(1.0,0.627,0.0), RGB{N0f8}(1.0,0.643,0.0), RGB{N0f8}(0.965,0.651,0.039), RGB{N0f8}(0.894,0.655,0.11)]), :fcolor, :fcolor, 1.0, false, 50, 2000, 960.0, 0.0, 2.0, \"inherit\", 12.0, false, :none, 0.001)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = a\n", "@profview qrhous!(A) \\ y" ] }, { "cell_type": "code", "execution_count": 2, "id": "fb2484bd-fd33-4b42-bc14-1006c4d9811d", "metadata": {}, "outputs": [], "source": [ "include(\"housQR.jl\")\n", "using .housQR" ] }, { "cell_type": "code", "execution_count": 2, "id": "eb827167-7fa3-4106-9bac-71a3c237ad5b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x = [1.3333333333333313, -0.3333333333333316]\n" ] }, { "data": { "text/plain": [ "3-element Vector{Float64}:\n", " 0.6666666666666674\n", " 2.6666666666666674\n", " 4.666666666666667" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "AAA = [1. 2; 3 4; 5 6]\n", "q_r = qrfact(AAA)\n", "\n", "b = [1., 2, 5]\n", "x = q_r \\ b\n", "@show x\n", "q_r.Q * q_r.R * x" ] }, { "cell_type": "code", "execution_count": 3, "id": "41d9dca0-6880-4133-8dc3-c35d5c0c9a49", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "size(v) = (100,)\n", "size(x) = (10000,)\n", "size(A.A) = (100, 10000)\n", "size(A.d) = (10000,)\n", "m = 10000\n" ] }, { "ename": "LoadError", "evalue": "BoundsError: attempt to access 100-element Vector{Float64} at index [10000]", "output_type": "error", "traceback": [ "BoundsError: attempt to access 100-element Vector{Float64} at index [10000]", "", "Stacktrace:", " [1] getindex", " @ ./essentials.jl:13 [inlined]", " [2] maybeview(A::Vector{Float64}, args::Int64)", " @ Base ./views.jl:149", " [3] \\(A::QRhous{Float64}, b::Vector{Float64})", " @ Main.housQR ~/Documents/University/Corsi/Computational Mathematics for Learning and Data Analysis/CMLDA/project/housQR.jl:125", " [4] top-level scope", " @ ./timing.jl:273 [inlined]", " [5] top-level scope", " @ ./In[3]:0" ] } ], "source": [ "asd = qrfact(A);\n", "\n", "@time asd \\ y;" ] }, { "cell_type": "code", "execution_count": 9, "id": "ee126d8a-ef8e-4cd9-b63c-6fb8696e9766", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.005245 seconds (2.92 k allocations: 22.947 MiB, 46.95% gc time)\n" ] } ], "source": [ "asd = qrfact(A);\n", "\n", "@time asd \\ y;" ] }, { "cell_type": "code", "execution_count": 7, "id": "13fd94ac-339b-4a9b-8532-10b4b05860bb", "metadata": { "scrolled": true }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "ProfileSVG.FGConfig(Node(FlameGraphs.NodeData(ip:0x0, 0x01, 1:122)), Dict{Symbol, Any}(), FlameGraphs.FlameColors(ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(0.882,0.698,1.0), RGB{N0f8}(0.435,0.863,0.569), RGB{N0f8}(0.0,0.71,0.545), RGB{N0f8}(0.173,0.639,1.0)], RGB{N0f8}(1.0,1.0,1.0), RGB{N0f8}(0.0,0.0,0.0), ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(0.953,0.0,0.302), RGB{N0f8}(0.894,0.0,0.255), RGB{N0f8}(0.831,0.129,0.216), RGB{N0f8}(0.773,0.192,0.184)], ColorTypes.RGB{FixedPointNumbers.N0f8}[RGB{N0f8}(1.0,0.627,0.0), RGB{N0f8}(1.0,0.643,0.0), RGB{N0f8}(0.965,0.651,0.039), RGB{N0f8}(0.894,0.655,0.11)]), :fcolor, :fcolor, 1.0, false, 50, 2000, 960.0, 0.0, 2.0, \"inherit\", 12.0, false, :none, 0.001)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@profview qrfact(A) \\ y" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.9.4", "language": "julia", "name": "julia-1.9" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.9.4" } }, "nbformat": 4, "nbformat_minor": 5 }