### A Pluto.jl notebook ###
# v0.17.0

using Markdown
using InteractiveUtils

# ╔═╡ 0fea38f6-2c9e-43c6-bfc1-267ff220a0cc
begin
	using IndividualDisplacements, DataFrames, MeshArrays, PlutoUI
	import CairoMakie as Mkie
	"done with loading packages"
end

# ╔═╡ 5c7e4e72-3f69-11ec-258b-6bcfdc7b1d65
md"""# Simple Three Dimensional Flow Field

Simulate the trajectory of an individual point, first in a perfectly circular flow (a.k.a. solid body rotation). Then add a convergent term to obtain a spiraling trajectory, and a constant vertical velocity for the third dimension. These simple flow configurations can be thought of as idealized models e.g. ocean meso-scale eddies.

For additional documentation e.g. see :
[1](https://JuliaClimate.github.io/IndividualDisplacements.jl/dev/),
[2](https://JuliaClimate.github.io/MeshArrays.jl/dev/),
[3](https://docs.juliadiffeq.org/latest/solvers/ode_solve.html),
[4](https://en.wikipedia.org/wiki/Displacement_(vector))

### Exercise examples:

- make the sinking velocity decrease with time (hint: it increases in the original notebook)
- change the number of times the particle goes around the origin
- flow field parameters (e.g. intensity and sign of the convergent term)
"""

# ╔═╡ aadd082a-3ed9-41b7-ba5e-7c5f77d59508
TableOfContents()

# ╔═╡ 011c89a7-f3d1-4cea-b71a-3d6f96a1801c
begin
function solid_body_rotation(np,nz)
    Γ=simple_periodic_domain(np)
    Γ = UnitGrid(Γ.XC.grid;option="full")
    γ=Γ.XC.grid;

    #Solid-body rotation around central location ...
    i=Int(np/2+1)
    u=-(Γ.YG.-Γ.YG[1][i,i])
    v=(Γ.XG.-Γ.XG[1][i,i])

    #... plus a convergent term to / from central location
    d=-0.01
    u=u+d*(Γ.XG.-Γ.XG[1][i,i])
    v=v+d*(Γ.YG.-Γ.YG[1][i,i])

    #Replicate u,v in vertical dimension
    uu=MeshArray(γ,γ.ioPrec,nz)
    [uu[k]=u[1] for k=1:nz]
    vv=MeshArray(γ,γ.ioPrec,nz)
    [vv[k]=v[1] for k=1:nz]

    #Vertical velocity component w
    w=fill(-0.01,MeshArray(γ,γ.ioPrec,nz+1))

    return write(uu),write(vv),write(w)
end

md"""## 1. Problem Configuration

### 1.1 Gridded Flow Fields

**solid\_body\_rotation(np,nz)**

Set up an idealized flow field which consists of
[rigid body rotation](https://en.wikipedia.org/wiki/Rigid_body),
plus a convergent term, plus a sinking term.
"""
end

# ╔═╡ 2200503c-605c-4dfd-878f-ffea2431f7ba
begin
	np,nz=16,4 #gridded domain size (horizontal and vertical)
	u,v,w=solid_body_rotation(np,nz) #staggered velocity arrays
	𝐹=FlowFields(u,u,v,v,0*w,1*w,[0,19.95*2*pi]); #FlowFields data structure
	"Done with defining the flow fields."
end

# ╔═╡ bde49eaf-3747-4edf-b712-3ee6f08ffe20
md"""### 1.2 Initialize Individuals

Here just one individual is initialized at [np*1/3,np*1/3,nz*1/3] in the three-dimensional space of the flow fields."""

# ╔═╡ c60a48e0-6f51-44b0-bd6e-332e04d2d332
begin
	(x,y,z)=(np*1/3,np*1/3,nz*1/3)
	𝐼=Individuals(𝐹,x,y,z)
end

# ╔═╡ 45762eb1-7404-4524-8d1d-788a70f8f5ef
md"""### 1.3 A Closer Look

The above `Individuals` constructor wraps up 𝐹, the initial position, and other needed components within 𝐼. **At this point, you can either jump to section 2 or read through the next code cell**
to learn more about how the details as needed e.g. if you wanted to overide default options
that were selected for you by the section 1.2 constructor.
"""

# ╔═╡ b70d76d1-09f3-462a-b550-8fa51cb90c2c
begin
	# Initial position is

	📌=[x,y,z]

	# and the data structure ([DataFrame](http://juliadata.github.io/DataFrames.jl/stable/))
	# to record properties along the individual's path accordingly.

	🔴 = DataFrame(ID=Int[], x=Float64[], y=Float64[], z=Float64[], t=Float64[])

	# It is the postprocessing function's responsibility to provide the record. It is thus
	# important that this intermediary (`postproc`) be consistent with the solver setup (`sol`)
	# and the expected record format (`🔴`).

	function postproc(sol,𝐹::FlowFields;id=missing,𝑇=missing)
	    df=postprocess_xy(sol,𝐹,id=id,𝑇=𝑇)
	    #add third coordinate
	    z=sol[3,:]
	    df.z=z[:]
	    return df
	end

	# The velocity function `🚄` relies only on flow fields obtained from
	# `𝐹` (which is defined above) to interpolate velocity at the specified
	# space-time position (e.g. those of individuals).

	🚄 = dxdt!

	# Now that every thing needed to carry out the computation is in place,
	# we wrap up the problem configuration in a struct (`Individuals`) which
	# links to the initial positions, flow fields, etc. all that will be
	# necessary to compute trajectories over time (`∫!(𝐼,𝑇)`).

	#assemble as a NamedTuple:
	I=(position=📌,record=🔴,velocity=🚄,
	postprocessing=postproc,parameters=𝐹)

	#construct Individuals from NamedTuple:
	𝐽=Individuals(I)
end

# ╔═╡ 8cc54cc2-5284-40b1-9a30-0ad6f725053f
md"""## 2 Trajectory Simulations

The `∫!` function call below returns the final positions & updates `𝐼.📌` accordingly. It also records properties observed along the trajectory in `𝐼.🔴`.
Simple methods to visualize the individual trajectory (plot or movie) are provided at the end.

### 2.1 Compute Trajectory
"""

# ╔═╡ 503c8702-df0b-4495-8245-4ba6608431e3
begin
	𝑇=(0.0,𝐼.𝑃.𝑇[2])
	∫!(𝐼,𝑇)
end

# ╔═╡ 32a8b0ee-e61d-495b-ba53-56a6c6126950
md"""### 2.2 Visualize Trajectory"""

# ╔═╡ dd62433c-2274-4c6f-9e27-34bc2c620df1
begin
	nt=length(𝐼.🔴.x)

	time = Mkie.Node(nt)
	xx=Mkie.@lift( [𝐼.🔴.x[1:$time];fill(NaN,nt-$time)] )
	yy=Mkie.@lift( [𝐼.🔴.y[1:$time];fill(NaN,nt-$time)] )
	zz=Mkie.@lift( [𝐼.🔴.z[1:$time];fill(NaN,nt-$time)] )

	Mkie.set_theme!(Mkie.theme_light())
	f=Mkie.Figure(resolution = (900, 600))
	a = Mkie.Axis3(f[1, 1],xlabel="x",ylabel="y",zlabel="z",
		title="Solid body rotation / Spiral example")
	Mkie.lines!(a,xx,yy,zz,linewidth=1.0,color=:black)
	Mkie.scatter!(a,[𝐼.🔴.x[1]],[𝐼.🔴.y[1]],[𝐼.🔴.z[1]],color=:red)
	Mkie.scatter!(a,[𝐼.🔴.x[nt]],[𝐼.🔴.y[nt]],[𝐼.🔴.z[nt]],color=:green)

	f
end

# ╔═╡ 250d011e-57db-4d80-b16e-dbc28fec9fba
begin
	#plt=myplot(nt)
	#scatter!(plt,[📌[1]],[📌[2]],[📌[3]])
	#scatter!(plt,[𝐼.🔴.x[end]],[𝐼.🔴.y[end]],[𝐼.🔴.z[end]])
	#scatter!(plt,[𝐼.🔴.x[1]],[𝐼.🔴.y[1]],[𝐼.🔴.z[1]])
end

# ╔═╡ a0bf6d10-5d42-481b-8720-dadd3f727e8b
md"""### 2.3 Animation example"""

# ╔═╡ 2b8ee43d-1225-4475-91c9-161cf612bfb2
begin
	if false
		p=Int(ceil(nt/50))
		tt=1:p:nt
		tt=tt.+(nt-maximum(tt))

		fil=joinpath(tempdir(),"solid_body_rotation.mp4")
		Mkie.record(f,fil, tt; framerate = 20) do t
			time[] = t
		end
		LocalResource(fil)
	else
		"""try code in this cell to generate animation"""
	end
end

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
IndividualDisplacements = "b92f0c32-5b7e-11e9-1d7b-238b2da8b0e6"
MeshArrays = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"

[compat]
CairoMakie = "~0.6.6"
DataFrames = "~1.2.2"
IndividualDisplacements = "~0.3.3"
MeshArrays = "~0.2.26"
PlutoUI = "~0.7.18"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

[[AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "485ee0867925449198280d4af84bdb46a2a404d0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.0.1"

[[AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "0ec322186e078db08ea3e7da5b8b2885c099b393"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.1.0"

[[AbstractTrees]]
git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.3.4"

[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.1"

[[Animations]]
deps = ["Colors"]
git-tree-sha1 = "e81c509d2c8e49592413bfb0bb3b08150056c79d"
uuid = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
version = "0.4.1"

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "f87e559f87a45bece9c9ed97458d3afe98b1ebb9"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.1.0"

[[ArrayInterface]]
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "e527b258413e0c6d4f66ade574744c94edef81f8"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "3.1.40"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Automa]]
deps = ["Printf", "ScanByte", "TranscodingStreams"]
git-tree-sha1 = "d50976f217489ce799e366d9561d56a98a30d7fe"
uuid = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
version = "0.8.2"

[[AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.0.1"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BitTwiddlingConvenienceFunctions]]
deps = ["Static"]
git-tree-sha1 = "bc1317f71de8dce26ea67fcdf7eccc0d0693b75b"
uuid = "62783981-4cbd-42fc-bca8-16325de8dc4b"
version = "0.1.1"

[[Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"

[[CEnum]]
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.1"

[[CFTime]]
deps = ["Dates", "Printf"]
git-tree-sha1 = "bca6cb6ee746e6485ca4535f6cc29cf3579a0f20"
uuid = "179af706-886a-5703-950a-314cd64e0468"
version = "0.1.1"

[[CPUSummary]]
deps = ["Hwloc", "IfElse", "Static"]
git-tree-sha1 = "87b0c9c6ee0124d6c1f4ce8cb035dcaf9f90b803"
uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
version = "0.1.6"

[[CSV]]
deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings"]
git-tree-sha1 = "74147e877531d7c172f70b492995bc2b5ca3a843"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.9.10"

[[Cairo]]
deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"]
git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b"
uuid = "159f3aea-2a34-519c-b102-8c37f9878175"
version = "1.0.5"

[[CairoMakie]]
deps = ["Base64", "Cairo", "Colors", "FFTW", "FileIO", "FreeType", "GeometryBasics", "LinearAlgebra", "Makie", "SHA", "StaticArrays"]
git-tree-sha1 = "774ff1cce3ae930af3948c120c15eeb96c886c33"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
version = "0.6.6"

[[Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "f2202b55d816427cd385a9a4f3ffb226bee80f99"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+0"

[[CatViews]]
deps = ["Random", "Test"]
git-tree-sha1 = "23d1f1e10d4e24374112fcf800ac981d14a54b24"
uuid = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
version = "1.0.0"

[[ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "f885e7e7c124f8c92650d61b9477b9ac2ee607dd"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.11.1"

[[ChangesOfVariables]]
deps = ["LinearAlgebra", "Test"]
git-tree-sha1 = "9a1d594397670492219635b35a3d830b04730d62"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.1"

[[CloseOpenIntervals]]
deps = ["ArrayInterface", "Static"]
git-tree-sha1 = "7b8f09d58294dc8aa13d91a8544b37c8a1dcbc06"
uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9"
version = "0.1.4"

[[CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.0"

[[ColorBrewer]]
deps = ["Colors", "JSON", "Test"]
git-tree-sha1 = "61c5334f33d91e570e1d0c3eb5465835242582c4"
uuid = "a2cac450-b92f-5266-8821-25eda20663c8"
version = "0.4.0"

[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random"]
git-tree-sha1 = "a851fec56cb73cfdf43762999ec72eff5b86882a"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.15.0"

[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.0"

[[ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"]
git-tree-sha1 = "45efb332df2e86f2cb2e992239b6267d97c9e0b6"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.9.7"

[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.8"

[[CommonSolve]]
git-tree-sha1 = "68a0743f578349ada8bc911a5cbd5a2ef6ed6d1f"
uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
version = "0.2.0"

[[CommonSubexpressions]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.0"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "dce3e3fea680869eaa0b774b2e8343e9ff442313"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.40.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"

[[ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f74e9d5388b8620b4cee35d4c5a618dd4dc547f4"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.3.0"

[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.7"

[[Crayons]]
git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.0.4"

[[CyclicArrays]]
git-tree-sha1 = "4ab3cb8563aceca605a543a19aacaf09c6781dd3"
uuid = "6023044f-b3ef-4c22-8399-3ec90a0c9b75"
version = "0.5.0"

[[DEDataArrays]]
deps = ["ArrayInterface", "DocStringExtensions", "LinearAlgebra", "RecursiveArrayTools", "SciMLBase", "StaticArrays"]
git-tree-sha1 = "31186e61936fbbccb41d809ad4338c9f7addf7ae"
uuid = "754358af-613d-5f8d-9788-280bf1605d4c"
version = "0.2.0"

[[DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"

[[DataFrames]]
deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "d785f42445b63fc86caa08bb9a9351008be9b765"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.2.2"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.10"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[DiffEqBase]]
deps = ["ArrayInterface", "ChainRulesCore", "DEDataArrays", "DataStructures", "Distributions", "DocStringExtensions", "FastBroadcast", "ForwardDiff", "FunctionWrappers", "IterativeSolvers", "LabelledArrays", "LinearAlgebra", "Logging", "MuladdMacro", "NonlinearSolve", "Parameters", "PreallocationTools", "Printf", "RecursiveArrayTools", "RecursiveFactorization", "Reexport", "Requires", "SciMLBase", "Setfield", "SparseArrays", "StaticArrays", "Statistics", "SuiteSparse", "ZygoteRules"]
git-tree-sha1 = "5c3d877ddfc2da61ce5cc1f5ce330ff97789c57c"
uuid = "2b5f629d-d688-5b77-993f-72d75c75574e"
version = "6.76.0"

[[DiffResults]]
deps = ["StaticArrays"]
git-tree-sha1 = "c18e98cba888c6c25d1c3b048e4b3380ca956805"
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
version = "1.0.3"

[[DiffRules]]
deps = ["LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
git-tree-sha1 = "3287dacf67c3652d3fed09f4c12c187ae4dbb89a"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "1.4.0"

[[DiskArrays]]
git-tree-sha1 = "6a50d800025a1664c99a8e819e0568c75e3ac0c7"
uuid = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
version = "0.2.12"

[[Distances]]
deps = ["LinearAlgebra", "Statistics", "StatsAPI"]
git-tree-sha1 = "837c83e5574582e07662bbbba733964ff7c26b9d"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.10.6"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[Distributions]]
deps = ["ChainRulesCore", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
git-tree-sha1 = "72dcda9e19f88d09bf21b5f9507a0bb430bce2aa"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
version = "0.25.24"

[[DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.6"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[EarCut_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3f3a2501fa7236e9b911e0f7a588c657e822bb6d"
uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
version = "2.2.3+0"

[[EllipsisNotation]]
deps = ["ArrayInterface"]
git-tree-sha1 = "9aad812fb7c4c038da7cab5a069f502e6e3ae030"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "1.1.1"

[[Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b3bfd02e98aedfa5cf885665493c5598c350cd2f"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.2.10+0"

[[ExponentialUtilities]]
deps = ["ArrayInterface", "LinearAlgebra", "Printf", "Requires", "SparseArrays"]
git-tree-sha1 = "cb39752c2a1f83bbe0fda393c51c480a296042ad"
uuid = "d4d017d3-3776-5f7e-afef-a10c40355c18"
version = "1.10.1"

[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"

[[FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "d8a578692e3077ac998b50c0217dfd67f21d1e5f"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.0+0"

[[FFTW]]
deps = ["AbstractFFTs", "FFTW_jll", "LinearAlgebra", "MKL_jll", "Preferences", "Reexport"]
git-tree-sha1 = "463cb335fa22c4ebacfd1faba5fde14edb80d96c"
uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
version = "1.4.5"

[[FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c6033cc3892d0ef5bb9cd29b7f2f0331ea5184ea"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.10+0"

[[FastBroadcast]]
deps = ["LinearAlgebra", "Polyester", "Static"]
git-tree-sha1 = "e32a81c505ab234c992ca978f31ed8b0dabbc327"
uuid = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
version = "0.1.11"

[[FastClosures]]
git-tree-sha1 = "acebe244d53ee1b461970f8910c235b259e772ef"
uuid = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
version = "0.3.2"

[[FileIO]]
deps = ["Pkg", "Requires", "UUIDs"]
git-tree-sha1 = "2db648b6712831ecb333eae76dbfd1c156ca13bb"
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
version = "1.11.2"

[[FilePathsBase]]
deps = ["Dates", "Mmap", "Printf", "Test", "UUIDs"]
git-tree-sha1 = "5440c1d26aa29ca9ea848559216e5ee5f16a8627"
uuid = "48062228-2e41-5def-b9a4-89aafe57970f"
version = "0.9.14"

[[FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"]
git-tree-sha1 = "8756f9935b7ccc9064c6eef0bff0ad643df733a3"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.12.7"

[[FiniteDiff]]
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
git-tree-sha1 = "8b3c09b56acaf3c0e581c66638b85c8650ee9dca"
uuid = "6a86dc24-6348-571c-b903-95158fe2bd41"
version = "2.8.1"

[[FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"

[[Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "21efd19106a55620a188615da6d3d06cd7f6ee03"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.93+0"

[[Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"

[[ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions", "StaticArrays"]
git-tree-sha1 = "ef3fec65f9db26fa2cf8f4133c697c5b7ce63c1d"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.22"

[[FreeType]]
deps = ["CEnum", "FreeType2_jll"]
git-tree-sha1 = "cabd77ab6a6fdff49bfd24af2ebe76e6e018a2b4"
uuid = "b38be410-82b0-50bf-ab77-7b57e271db43"
version = "4.0.0"

[[FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "87eb71354d8ec1a96d4a7636bd57a7347dde3ef9"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.4+0"

[[FreeTypeAbstraction]]
deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics", "StaticArrays"]
git-tree-sha1 = "19d0f1e234c13bbfd75258e55c52aa1d876115f5"
uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
version = "0.9.2"

[[FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.10+0"

[[FunctionWrappers]]
git-tree-sha1 = "241552bc2209f0fa068b6415b1942cc0aa486bcc"
uuid = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
version = "1.1.2"

[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[[GeometryBasics]]
deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "58bcdf5ebc057b085e58d95c138725628dd7453c"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.4.1"

[[Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"

[[Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "7bf67e9a481712b3dbe9cb3dac852dc4b1162e02"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.3+0"

[[Graphics]]
deps = ["Colors", "LinearAlgebra", "NaNMath"]
git-tree-sha1 = "1c5a84319923bea76fa145d49e93aa4394c73fc2"
uuid = "a2bd30eb-e257-5431-a919-1863eab51364"
version = "1.1.1"

[[Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "344bf40dcab1073aca04aa0df4fb092f920e4011"
uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472"
version = "1.3.14+0"

[[GridLayoutBase]]
deps = ["GeometryBasics", "InteractiveUtils", "Match", "Observables"]
git-tree-sha1 = "e2f606c87d09d5187bb6069dab8cee0af7c77bdb"
uuid = "3955a311-db13-416c-9275-1d80ed98e5e9"
version = "0.6.1"

[[Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"

[[HDF5_jll]]
deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "OpenSSL_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "fd83fa0bde42e01952757f01149dd968c06c4dba"
uuid = "0234f1f7-429e-5d53-9886-15a909be8d59"
version = "1.12.0+1"

[[HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
git-tree-sha1 = "8a954fed8ac097d5be04921d595f741115c1b2ad"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "2.8.1+0"

[[HostCPUFeatures]]
deps = ["BitTwiddlingConvenienceFunctions", "IfElse", "Libdl", "Static"]
git-tree-sha1 = "8f0dc80088981ab55702b04bba38097a44a1a3a9"
uuid = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0"
version = "0.1.5"

[[Hwloc]]
deps = ["Hwloc_jll"]
git-tree-sha1 = "92d99146066c5c6888d5a3abc871e6a214388b91"
uuid = "0e44f5e4-bd66-52a0-8798-143a42290a1d"
version = "2.0.0"

[[Hwloc_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "3395d4d4aeb3c9d31f5929d32760d8baeee88aaf"
uuid = "e33a78d0-f292-5ffc-b300-72abe9b543c8"
version = "2.5.0+0"

[[Hyperscript]]
deps = ["Test"]
git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9"
uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
version = "0.0.4"

[[HypertextLiteral]]
git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.3"

[[IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.2"

[[IfElse]]
git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
version = "0.1.1"

[[ImageCore]]
deps = ["AbstractFFTs", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Graphics", "MappedArrays", "MosaicViews", "OffsetArrays", "PaddedViews", "Reexport"]
git-tree-sha1 = "9a5c62f231e5bba35695a20988fc7cd6de7eeb5a"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.9.3"

[[ImageIO]]
deps = ["FileIO", "Netpbm", "OpenEXR", "PNGFiles", "TiffImages", "UUIDs"]
git-tree-sha1 = "a2951c93684551467265e0e32b577914f69532be"
uuid = "82e4d734-157c-48bb-816b-45c225c6df19"
version = "0.5.9"

[[Imath_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "87f7662e03a649cffa2e05bf19c303e168732d3e"
uuid = "905a6f67-0a94-5f89-b386-d35d92009cd1"
version = "3.1.2+0"

[[IndirectArrays]]
git-tree-sha1 = "012e604e1c7458645cb8b436f8fba789a51b257f"
uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959"
version = "1.0.0"

[[IndividualDisplacements]]
deps = ["CFTime", "CSV", "CyclicArrays", "DataFrames", "Dates", "MeshArrays", "NetCDF", "OrdinaryDiffEq", "Pkg", "Random", "UnPack"]
git-tree-sha1 = "3ebe0723d67f2c2a608542d6db654c2504426d1a"
uuid = "b92f0c32-5b7e-11e9-1d7b-238b2da8b0e6"
version = "0.3.3"

[[Inflate]]
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.2"

[[InlineStrings]]
deps = ["Parsers"]
git-tree-sha1 = "19cb49649f8c41de7fea32d089d37de917b553da"
uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48"
version = "1.0.1"

[[IntelOpenMP_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "d979e54b71da82f3a65b62553da4fc3d18c9004c"
uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"
version = "2018.0.3+2"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Interpolations]]
deps = ["AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]
git-tree-sha1 = "61aa005707ea2cebf47c8d780da8dc9bc4e0c512"
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
version = "0.13.4"

[[IntervalSets]]
deps = ["Dates", "EllipsisNotation", "Statistics"]
git-tree-sha1 = "3cc368af3f110a767ac786560045dceddfc16758"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.5.3"

[[InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.2"

[[InvertedIndices]]
git-tree-sha1 = "bee5f1ef5bf65df56bdd2e40447590b272a5471f"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.1.0"

[[IrrationalConstants]]
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.1.1"

[[Isoband]]
deps = ["isoband_jll"]
git-tree-sha1 = "f9b6d97355599074dc867318950adaa6f9946137"
uuid = "f1662d9f-8043-43de-a69a-05efc1cc6ff4"
version = "0.1.1"

[[IterTools]]
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
version = "1.3.0"

[[IterativeSolvers]]
deps = ["LinearAlgebra", "Printf", "Random", "RecipesBase", "SparseArrays"]
git-tree-sha1 = "1169632f425f79429f245113b775a0e3d121457c"
uuid = "42fd0dbc-a981-5370-80f2-aaf504508153"
version = "0.9.2"

[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"

[[JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.2"

[[KernelDensity]]
deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"]
git-tree-sha1 = "591e8dc09ad18386189610acafb970032c519707"
uuid = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
version = "0.6.3"

[[LAME_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
uuid = "dd4b983a-f0e5-5f8d-a1b7-129d4a5fb1ac"
version = "2.10.1+0"

[[LaTeXStrings]]
git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.3.0"

[[LabelledArrays]]
deps = ["ArrayInterface", "LinearAlgebra", "MacroTools", "StaticArrays"]
git-tree-sha1 = "8f5fd068dfee92655b79e0859ecad8b492dfe8b1"
uuid = "2ee39098-c373-598a-b85f-a56591580800"
version = "1.6.5"

[[LayoutPointers]]
deps = ["ArrayInterface", "LinearAlgebra", "ManualMemory", "SIMDTypes", "Static"]
git-tree-sha1 = "83b56449c39342a47f3fcdb3bc782bd6d66e1d97"
uuid = "10f19ff3-798f-405d-979b-55457f8fc047"
version = "0.1.4"

[[LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Libffi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "761a393aeccd6aa92ec3515e428c26bf99575b3b"
uuid = "e9f186c6-92d2-5b65-8a66-fee21dc1b490"
version = "3.2.2+0"

[[Libgcrypt_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgpg_error_jll", "Pkg"]
git-tree-sha1 = "64613c82a59c120435c067c2b809fc61cf5166ae"
uuid = "d4300ac3-e22c-5743-9152-c294e39db1e4"
version = "1.8.7+0"

[[Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "c333716e46366857753e273ce6a69ee0945a6db9"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.42.0+0"

[[Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.16.1+1"

[[Libmount_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9c30530bf0effd46e15e0fdcf2b8636e78cbbd73"
uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7f3efec06033682db852f8b3bc3c1d2b0a0ab066"
uuid = "38a345b3-de98-5d2b-a5d3-14cd9215e700"
version = "2.36.0+0"

[[LightGraphs]]
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
git-tree-sha1 = "432428df5f360964040ed60418dd5601ecd240b6"
uuid = "093fc24a-ae57-5d10-9952-331d41423f4d"
version = "1.3.5"

[[LineSearches]]
deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf"]
git-tree-sha1 = "f27132e551e959b3667d8c93eae90973225032dd"
uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
version = "7.1.1"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[LogExpFunctions]]
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "be9eef9f9d78cecb6f262f3c10da151a6c5ab827"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.5"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[LoopVectorization]]
deps = ["ArrayInterface", "CPUSummary", "CloseOpenIntervals", "DocStringExtensions", "HostCPUFeatures", "IfElse", "LayoutPointers", "LinearAlgebra", "OffsetArrays", "PolyesterWeave", "Requires", "SIMDDualNumbers", "SLEEFPirates", "Static", "ThreadingUtilities", "UnPack", "VectorizationBase"]
git-tree-sha1 = "caaa2d3518fe6312327819cdd485a4258e52ece0"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
version = "0.12.95"

[[MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "5455aef09b40e5020e1520f551fa3135040d4ed0"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2021.1.1+2"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.9"

[[Makie]]
deps = ["Animations", "Base64", "ColorBrewer", "ColorSchemes", "ColorTypes", "Colors", "Contour", "Distributions", "DocStringExtensions", "FFMPEG", "FileIO", "FixedPointNumbers", "Formatting", "FreeType", "FreeTypeAbstraction", "GeometryBasics", "GridLayoutBase", "ImageIO", "IntervalSets", "Isoband", "KernelDensity", "LaTeXStrings", "LinearAlgebra", "MakieCore", "Markdown", "Match", "MathTeXEngine", "Observables", "Packing", "PlotUtils", "PolygonOps", "Printf", "Random", "RelocatableFolders", "Serialization", "Showoff", "SignedDistanceFields", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "StatsFuns", "StructArrays", "UnicodeFun"]
git-tree-sha1 = "56b0b7772676c499430dc8eb15cfab120c05a150"
uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
version = "0.15.3"

[[MakieCore]]
deps = ["Observables"]
git-tree-sha1 = "7bcc8323fb37523a6a51ade2234eee27a11114c8"
uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
version = "0.1.3"

[[ManualMemory]]
git-tree-sha1 = "9cb207b18148b2199db259adfa923b45593fe08e"
uuid = "d125e4d3-2237-4719-b19c-fa641b8a4667"
version = "0.1.6"

[[MappedArrays]]
git-tree-sha1 = "e8b359ef06ec72e8c030463fe02efe5527ee5142"
uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
version = "0.4.1"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Match]]
git-tree-sha1 = "5cf525d97caf86d29307150fcba763a64eaa9cbe"
uuid = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
version = "1.1.0"

[[MathTeXEngine]]
deps = ["AbstractTrees", "Automa", "DataStructures", "FreeTypeAbstraction", "GeometryBasics", "LaTeXStrings", "REPL", "RelocatableFolders", "Test"]
git-tree-sha1 = "70e733037bbf02d691e78f95171a1fa08cdc6332"
uuid = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
version = "0.2.1"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[MeshArrays]]
deps = ["CatViews", "Dates", "LazyArtifacts", "NearestNeighbors", "Pkg", "Printf", "SparseArrays", "Statistics", "Unitful"]
git-tree-sha1 = "628c1e1ee3b69635027a76f208e2e76541cd1162"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
version = "0.2.26"

[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.2"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[MosaicViews]]
deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"]
git-tree-sha1 = "b34e3bc3ca7c94914418637cb10cc4d1d80d877d"
uuid = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389"
version = "0.3.3"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[MuladdMacro]]
git-tree-sha1 = "c6190f9a7fc5d9d5915ab29f2134421b12d24a68"
uuid = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
version = "0.2.2"

[[NLSolversBase]]
deps = ["DiffResults", "Distributed", "FiniteDiff", "ForwardDiff"]
git-tree-sha1 = "50310f934e55e5ca3912fb941dec199b49ca9b68"
uuid = "d41bc354-129a-5804-8e4c-c37616107c6c"
version = "7.8.2"

[[NLsolve]]
deps = ["Distances", "LineSearches", "LinearAlgebra", "NLSolversBase", "Printf", "Reexport"]
git-tree-sha1 = "019f12e9a1a7880459d0173c182e6a99365d7ac1"
uuid = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
version = "4.5.1"

[[NaNMath]]
git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.5"

[[NearestNeighbors]]
deps = ["Distances", "StaticArrays"]
git-tree-sha1 = "16baacfdc8758bc374882566c9187e785e85c2f0"
uuid = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
version = "0.4.9"

[[NetCDF]]
deps = ["DiskArrays", "Formatting", "NetCDF_jll"]
git-tree-sha1 = "23b0e32fde256a4e2e497e678abcf956ed26204b"
uuid = "30363a11-5582-574a-97bb-aa9a979735b9"
version = "0.11.3"

[[NetCDF_jll]]
deps = ["Artifacts", "HDF5_jll", "JLLWrappers", "LibCURL_jll", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Pkg", "Zlib_jll", "nghttp2_jll"]
git-tree-sha1 = "0cf4d1bf2ef45156aed85c9ac5f8c7e697d9288c"
uuid = "7243133f-43d8-5620-bbf4-c2c921802cf3"
version = "400.702.400+0"

[[Netpbm]]
deps = ["FileIO", "ImageCore"]
git-tree-sha1 = "18efc06f6ec36a8b801b23f076e3c6ac7c3bf153"
uuid = "f09324ee-3d7c-5217-9330-fc30815ba969"
version = "1.0.2"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[NonlinearSolve]]
deps = ["ArrayInterface", "FiniteDiff", "ForwardDiff", "IterativeSolvers", "LinearAlgebra", "RecursiveArrayTools", "RecursiveFactorization", "Reexport", "SciMLBase", "Setfield", "StaticArrays", "UnPack"]
git-tree-sha1 = "e9ffc92217b8709e0cf7b8808f6223a4a0936c95"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
version = "0.3.11"

[[Observables]]
git-tree-sha1 = "fe29afdef3d0c4a8286128d4e45cc50621b1e43d"
uuid = "510215fc-4207-5dde-b226-833fc4488ee2"
version = "0.4.0"

[[OffsetArrays]]
deps = ["Adapt"]
git-tree-sha1 = "043017e0bdeff61cfbb7afeb558ab29536bbb5ed"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.10.8"

[[Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7937eda4681660b4d6aeeecc2f7e1c81c8ee4e2f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+0"

[[OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
git-tree-sha1 = "327f53360fdb54df7ecd01e96ef1983536d1e633"
uuid = "52e1d378-f018-4a11-a4be-720524705ac7"
version = "0.3.2"

[[OpenEXR_jll]]
deps = ["Artifacts", "Imath_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "923319661e9a22712f24596ce81c54fc0366f304"
uuid = "18a262bb-aa17-5467-a713-aee519bc75cb"
version = "3.1.1+0"

[[OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"

[[OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "15003dcb7d8db3c6c857fda14891a539a8f2705a"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.10+0"

[[OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.5+0"

[[Opus_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "51a08fb14ec28da2ec7a927c4337e4332c2a4720"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.2+0"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[OrdinaryDiffEq]]
deps = ["Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "ExponentialUtilities", "FastClosures", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "Logging", "LoopVectorization", "MacroTools", "MuladdMacro", "NLsolve", "Polyester", "PreallocationTools", "RecursiveArrayTools", "Reexport", "SparseArrays", "SparseDiffTools", "StaticArrays", "UnPack"]
git-tree-sha1 = "6f76c887ddfd3f2a018ef1ee00a17b46bcf4886e"
uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
version = "5.67.0"

[[PCRE_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b2a7af664e098055a7529ad1a900ded962bca488"
uuid = "2f80f16e-611a-54ab-bc61-aa92de5b98fc"
version = "8.44.0+0"

[[PDMats]]
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "c8b8775b2f242c80ea85c83714c64ecfa3c53355"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.3"

[[PNGFiles]]
deps = ["Base64", "CEnum", "ImageCore", "IndirectArrays", "OffsetArrays", "libpng_jll"]
git-tree-sha1 = "6d105d40e30b635cfed9d52ec29cf456e27d38f8"
uuid = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
version = "0.3.12"

[[Packing]]
deps = ["GeometryBasics"]
git-tree-sha1 = "1155f6f937fa2b94104162f01fa400e192e4272f"
uuid = "19eb6ba3-879d-56ad-ad62-d5c202156566"
version = "0.4.2"

[[PaddedViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "646eed6f6a5d8df6708f15ea7e02a7a2c4fe4800"
uuid = "5432bcbf-9aad-5242-b902-cca2824c8663"
version = "0.5.10"

[[Pango_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "FriBidi_jll", "Glib_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9bc1871464b12ed19297fbc56c4fb4ba84988b0d"
uuid = "36c8627f-9965-5494-a995-c6b170f724f3"
version = "1.47.0+0"

[[Parameters]]
deps = ["OrderedCollections", "UnPack"]
git-tree-sha1 = "34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.12.3"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.1.2"

[[Pixman_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "b4f5d02549a10e20780a24fce72bea96b6329e29"
uuid = "30392449-352a-5448-841d-b1acce4e97dc"
version = "0.40.1+0"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PkgVersion]]
deps = ["Pkg"]
git-tree-sha1 = "a7a7e1a88853564e551e4eba8650f8c38df79b37"
uuid = "eebad327-c553-4316-9ea0-9fa01ccd7688"
version = "0.1.1"

[[PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "b084324b4af5a438cd63619fd006614b3b20b87b"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.0.15"

[[PlutoUI]]
deps = ["AbstractPlutoDingetjes", "Base64", "Dates", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "UUIDs"]
git-tree-sha1 = "57312c7ecad39566319ccf5aa717a20788eb8c1f"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.18"

[[Polyester]]
deps = ["ArrayInterface", "BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "ManualMemory", "PolyesterWeave", "Requires", "Static", "StrideArraysCore", "ThreadingUtilities"]
git-tree-sha1 = "892b8d9dd3c7987a4d0fd320f0a421dd90b5d09d"
uuid = "f517fe37-dbe3-4b94-8317-1923a5111588"
version = "0.5.4"

[[PolyesterWeave]]
deps = ["BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "Static", "ThreadingUtilities"]
git-tree-sha1 = "a3ff99bf561183ee20386aec98ab8f4a12dc724a"
uuid = "1d0040c9-8b98-4ee7-8388-3f51789ca0ad"
version = "0.1.2"

[[PolygonOps]]
git-tree-sha1 = "77b3d3605fc1cd0b42d95eba87dfcd2bf67d5ff6"
uuid = "647866c9-e3ac-4575-94e7-e3d426903924"
version = "0.1.2"

[[PooledArrays]]
deps = ["DataAPI", "Future"]
git-tree-sha1 = "a193d6ad9c45ada72c14b731a318bedd3c2f00cf"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "1.3.0"

[[PreallocationTools]]
deps = ["Adapt", "ArrayInterface", "ForwardDiff", "LabelledArrays"]
git-tree-sha1 = "ba819074442cd4c9bda1a3d905ec305f8acb37f2"
uuid = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
version = "0.2.0"

[[Preferences]]
deps = ["TOML"]
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.2.2"

[[PrettyTables]]
deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"]
git-tree-sha1 = "d940010be611ee9d67064fe559edbb305f8cc0eb"
uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
version = "1.2.3"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[ProgressMeter]]
deps = ["Distributed", "Printf"]
git-tree-sha1 = "afadeba63d90ff223a6a48d2009434ecee2ec9e8"
uuid = "92933f4c-e287-5a05-a399-4b506db050ca"
version = "1.7.1"

[[QuadGK]]
deps = ["DataStructures", "LinearAlgebra"]
git-tree-sha1 = "78aadffb3efd2155af139781b8a8df1ef279ea39"
uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
version = "2.4.2"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Ratios]]
deps = ["Requires"]
git-tree-sha1 = "01d341f502250e81f6fec0afe662aa861392a3aa"
uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
version = "0.4.2"

[[RecipesBase]]
git-tree-sha1 = "44a75aa7a527910ee3d1751d1f0e4148698add9e"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.1.2"

[[RecursiveArrayTools]]
deps = ["ArrayInterface", "ChainRulesCore", "DocStringExtensions", "FillArrays", "LinearAlgebra", "RecipesBase", "Requires", "StaticArrays", "Statistics", "ZygoteRules"]
git-tree-sha1 = "c944fa4adbb47be43376359811c0a14757bdc8a8"
uuid = "731186ca-8d62-57ce-b412-fbd966d074cd"
version = "2.20.0"

[[RecursiveFactorization]]
deps = ["LinearAlgebra", "LoopVectorization", "Polyester", "StrideArraysCore", "TriangularSolve"]
git-tree-sha1 = "b7edd69c796b30985ea6dfeda8504cdb7cf77e9f"
uuid = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
version = "0.2.5"

[[Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[RelocatableFolders]]
deps = ["SHA", "Scratch"]
git-tree-sha1 = "cdbd3b1338c72ce29d9584fdbe9e9b70eeb5adca"
uuid = "05181044-ff0b-4ac5-8273-598c1e38db00"
version = "0.1.3"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"

[[Rmath]]
deps = ["Random", "Rmath_jll"]
git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f"
uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa"
version = "0.7.0"

[[Rmath_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "68db32dff12bb6127bac73c209881191bf0efbb7"
uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f"
version = "0.3.0+0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[SIMD]]
git-tree-sha1 = "9ba33637b24341aba594a2783a502760aa0bff04"
uuid = "fdea26ae-647d-5447-a871-4b548cad5224"
version = "3.3.1"

[[SIMDDualNumbers]]
deps = ["ForwardDiff", "IfElse", "SLEEFPirates", "VectorizationBase"]
git-tree-sha1 = "62c2da6eb66de8bb88081d20528647140d4daa0e"
uuid = "3cdde19b-5bb0-4aaf-8931-af3e248e098b"
version = "0.1.0"

[[SIMDTypes]]
git-tree-sha1 = "330289636fb8107c5f32088d2741e9fd7a061a5c"
uuid = "94e857df-77ce-4151-89e5-788b33177be4"
version = "0.1.0"

[[SLEEFPirates]]
deps = ["IfElse", "Static", "VectorizationBase"]
git-tree-sha1 = "1410aad1c6b35862573c01b96cd1f6dbe3979994"
uuid = "476501e8-09a2-5ece-8869-fb82de89a1fa"
version = "0.6.28"

[[ScanByte]]
deps = ["Libdl", "SIMD"]
git-tree-sha1 = "9cc2955f2a254b18be655a4ee70bc4031b2b189e"
uuid = "7b38b023-a4d7-4c5e-8d43-3f3097f304eb"
version = "0.3.0"

[[SciMLBase]]
deps = ["ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "RecipesBase", "RecursiveArrayTools", "StaticArrays", "Statistics", "Tables", "TreeViews"]
git-tree-sha1 = "ad2c7f08e332cc3bb05d33026b71fa0ef66c009a"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
version = "1.19.4"

[[Scratch]]
deps = ["Dates"]
git-tree-sha1 = "0b4b7f1393cff97c33891da2a0bf69c6ed241fda"
uuid = "6c6a2e73-6563-6170-7368-637461726353"
version = "1.1.0"

[[SentinelArrays]]
deps = ["Dates", "Random"]
git-tree-sha1 = "f45b34656397a1f6e729901dc9ef679610bd12b5"
uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
version = "1.3.8"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Setfield]]
deps = ["ConstructionBase", "Future", "MacroTools", "Requires"]
git-tree-sha1 = "def0718ddbabeb5476e51e5a43609bee889f285d"
uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46"
version = "0.8.0"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Showoff]]
deps = ["Dates", "Grisu"]
git-tree-sha1 = "91eddf657aca81df9ae6ceb20b959ae5653ad1de"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "1.0.3"

[[SignedDistanceFields]]
deps = ["Random", "Statistics", "Test"]
git-tree-sha1 = "d263a08ec505853a5ff1c1ebde2070419e3f28e9"
uuid = "73760f76-fbc4-59ce-8f25-708e95d2df96"
version = "0.4.0"

[[SimpleTraits]]
deps = ["InteractiveUtils", "MacroTools"]
git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231"
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
version = "0.9.4"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.1"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[SparseDiffTools]]
deps = ["Adapt", "ArrayInterface", "Compat", "DataStructures", "FiniteDiff", "ForwardDiff", "LightGraphs", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays", "VertexSafeGraphs"]
git-tree-sha1 = "0b0bd4086536520cfc452ba51b177be8cf634d91"
uuid = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
version = "1.17.2"

[[SpecialFunctions]]
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "f0bccf98e16759818ffc5d97ac3ebf87eb950150"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "1.8.1"

[[StackViews]]
deps = ["OffsetArrays"]
git-tree-sha1 = "46e589465204cd0c08b4bd97385e4fa79a0c770c"
uuid = "cae243ae-269e-4f55-b966-ac2d0dc13c15"
version = "0.1.1"

[[Static]]
deps = ["IfElse"]
git-tree-sha1 = "e7bc80dc93f50857a5d1e3c8121495852f407e6a"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
version = "0.4.0"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "3c76dde64d03699e074ac02eb2e8ba8254d428da"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.2.13"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[StatsAPI]]
git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.0.0"

[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "eb35dcc66558b2dda84079b9a1be17557d32091a"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.12"

[[StatsFuns]]
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
git-tree-sha1 = "95072ef1a22b057b1e80f73c2a89ad238ae4cfff"
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
version = "0.9.12"

[[StrideArraysCore]]
deps = ["ArrayInterface", "CloseOpenIntervals", "IfElse", "LayoutPointers", "ManualMemory", "Requires", "SIMDTypes", "Static", "ThreadingUtilities"]
git-tree-sha1 = "f081c3c985849f4263fd0ed13e51feceed4ccc79"
uuid = "7792a7ef-975c-4747-a70f-980b88e8d1da"
version = "0.2.8"

[[StructArrays]]
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
git-tree-sha1 = "2ce41e0d042c60ecd131e9fb7154a3bfadbf50d3"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.6.3"

[[SuiteSparse]]
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.1"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.6.0"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[TensorCore]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6"
uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50"
version = "0.1.1"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[ThreadingUtilities]]
deps = ["ManualMemory"]
git-tree-sha1 = "03013c6ae7f1824131b2ae2fc1d49793b51e8394"
uuid = "8290d209-cae3-49c0-8002-c8c24d57dab5"
version = "0.4.6"

[[TiffImages]]
deps = ["ColorTypes", "DataStructures", "DocStringExtensions", "FileIO", "FixedPointNumbers", "IndirectArrays", "Inflate", "OffsetArrays", "PkgVersion", "ProgressMeter", "UUIDs"]
git-tree-sha1 = "c342ae2abf4902d65a0b0bf59b28506a6e17078a"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
version = "0.5.2"

[[TranscodingStreams]]
deps = ["Random", "Test"]
git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.9.6"

[[TreeViews]]
deps = ["Test"]
git-tree-sha1 = "8d0d7a3fe2f30d6a7f833a5f19f7c7a5b396eae6"
uuid = "a2a6695c-b41b-5b7d-aed9-dbfdeacea5d7"
version = "0.3.0"

[[TriangularSolve]]
deps = ["CloseOpenIntervals", "IfElse", "LayoutPointers", "LinearAlgebra", "LoopVectorization", "Polyester", "Static", "VectorizationBase"]
git-tree-sha1 = "ec9a310324dd2c546c07f33a599ded9c1d00a420"
uuid = "d5829a12-d9aa-46ab-831f-fb7c9ab06edf"
version = "0.1.8"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[UnPack]]
git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b"
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
version = "1.0.2"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[UnicodeFun]]
deps = ["REPL"]
git-tree-sha1 = "53915e50200959667e78a92a418594b428dffddf"
uuid = "1cfade01-22cf-5700-b092-accc4b62d6e1"
version = "0.4.1"

[[Unitful]]
deps = ["ConstructionBase", "Dates", "LinearAlgebra", "Random"]
git-tree-sha1 = "880f77d2cd4c6948e6bd55425b7b52f34dcd7f4b"
uuid = "1986cc42-f94f-5a68-af5c-568840ba703d"
version = "1.9.1"

[[VectorizationBase]]
deps = ["ArrayInterface", "CPUSummary", "HostCPUFeatures", "Hwloc", "IfElse", "LayoutPointers", "Libdl", "LinearAlgebra", "SIMDTypes", "Static"]
git-tree-sha1 = "5239606cf3552aff43d79ecc75b1af1ce4625109"
uuid = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
version = "0.21.21"

[[VertexSafeGraphs]]
deps = ["LightGraphs"]
git-tree-sha1 = "b9b450c99a3ca1cc1c6836f560d8d887bcbe356e"
uuid = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f"
version = "0.1.2"

[[WeakRefStrings]]
deps = ["DataAPI", "InlineStrings", "Parsers"]
git-tree-sha1 = "c69f9da3ff2f4f02e811c3323c22e5dfcb584cfa"
uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
version = "1.4.1"

[[WoodburyMatrices]]
deps = ["LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "de67fa59e33ad156a590055375a30b23c40299d3"
uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6"
version = "0.5.5"

[[XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "1acf5bdf07aa0907e0a37d3718bb88d4b687b74a"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.12+0"

[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"

[[Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "5be649d550f3f4b95308bf0183b82e2582876527"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.6.9+4"

[[Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4e490d5c960c314f33885790ed410ff3a94ce67e"
uuid = "0c0b7dd1-d40b-584c-a123-a41640f87eec"
version = "1.0.9+4"

[[Xorg_libXdmcp_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fe47bd2247248125c428978740e18a681372dd4"
uuid = "a3789734-cfe1-5b06-b2d0-1dd0d9d62d05"
version = "1.1.3+4"

[[Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "b7c0aa8c376b31e4852b360222848637f481f8c3"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.4+4"

[[Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Xorg_libX11_jll"]
git-tree-sha1 = "19560f30fd49f4d4efbe7002a1037f8c43d43b96"
uuid = "ea2f1a96-1ddc-540d-b46f-429655e07cfa"
version = "0.9.10+4"

[[Xorg_libpthread_stubs_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "6783737e45d3c59a4a4c4091f5f88cdcf0908cbb"
uuid = "14d82f49-176c-5ed1-bb49-ad3f5cbd8c74"
version = "0.1.0+3"

[[Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "daf17f441228e7a3833846cd048892861cff16d6"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.13.0+3"

[[Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "79c31e7844f6ecf779705fbc12146eb190b7d845"
uuid = "c5fb5394-a638-5e4d-96e5-b29de1b5cf10"
version = "1.4.0+3"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[ZygoteRules]]
deps = ["MacroTools"]
git-tree-sha1 = "8c1a8e4dfacb1fd631745552c8db35d0deb09ea0"
uuid = "700de1a5-db45-46bc-99cf-38207098b444"
version = "0.2.2"

[[isoband_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "a1ac99674715995a536bbce674b068ec1b7d893d"
uuid = "9a68df92-36a6-505f-a73e-abb412b6bfb4"
version = "0.2.2+0"

[[libass_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "HarfBuzz_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "5982a94fcba20f02f42ace44b9894ee2b140fe47"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.15.1+0"

[[libfdk_aac_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "daacc84a041563f965be61859a36e17c4e4fcd55"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "2.0.2+0"

[[libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "94d180a6d2b5e55e447e2d27a29ed04fe79eb30c"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.38+0"

[[libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "c45f4e40e7aafe9d086379e5578947ec8b95a8fb"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+0"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

[[x264_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4fea590b89e6ec504593146bf8b988b2c00922b2"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2021.5.5+0"

[[x265_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "ee567a171cce03570d77ad3a43e90218e38937a9"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.5.0+0"
"""

# ╔═╡ Cell order:
# ╟─5c7e4e72-3f69-11ec-258b-6bcfdc7b1d65
# ╟─0fea38f6-2c9e-43c6-bfc1-267ff220a0cc
# ╟─aadd082a-3ed9-41b7-ba5e-7c5f77d59508
# ╟─011c89a7-f3d1-4cea-b71a-3d6f96a1801c
# ╠═2200503c-605c-4dfd-878f-ffea2431f7ba
# ╟─bde49eaf-3747-4edf-b712-3ee6f08ffe20
# ╠═c60a48e0-6f51-44b0-bd6e-332e04d2d332
# ╟─45762eb1-7404-4524-8d1d-788a70f8f5ef
# ╟─b70d76d1-09f3-462a-b550-8fa51cb90c2c
# ╟─8cc54cc2-5284-40b1-9a30-0ad6f725053f
# ╠═503c8702-df0b-4495-8245-4ba6608431e3
# ╟─32a8b0ee-e61d-495b-ba53-56a6c6126950
# ╟─dd62433c-2274-4c6f-9e27-34bc2c620df1
# ╟─250d011e-57db-4d80-b16e-dbc28fec9fba
# ╟─a0bf6d10-5d42-481b-8720-dadd3f727e8b
# ╟─2b8ee43d-1225-4475-91c9-161cf612bfb2
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002


export cg

function cg(A::Union{SparseMatrixCSC{TF,Int},Matrix{TF}},b::Vector{TF}; kwargs...) where {TF<:Real}
	x = zeros(TF,size(A,2)) # pre-allocate
	return cg(v -> mul!(x, transpose(A), v, TF(1.0), TF(0.0)),b; kwargs...) # multiply with transpose of A for efficiency
end

cg(A,b::Vector;kwargs...)= cg(x -> A*x,b;kwargs...)

"""
This is a slightly modified version from the Julia Package KrylovMethods

x,flag,err,iter,resvec = cg(A,b,tol=1e-2,maxIter=100,M=1,x=[],out=0)

(Preconditioned) Conjugate Gradient applied to the linear system A*x = b, where A is assumed
to be symmetric positive semi definite.

Input:

  A       - matrix or function computing A*x
  b       - right hand side vector
  tol     - error tolerance
  maxIter - maximum number of iterations
  M       - preconditioner, a function that computes M\\x
  x       - starting guess
  out     - flag for output (-1: no output, 0: only errors, 1: final status, 2: residual norm at each iteration)

Output:

  x       - approximate solution
  flag    - exit flag ( 0 : desired tolerance achieved,
  					 -1 : maxIter reached without converging
  					 -2 : Matrix A is not positive definite
  					 -3 : cg stalled, i.e. two consecutive residuals have same norm
  					 -9 : right hand side was zero)
  err     - norm of relative residual, i.e., norm(A*x-b)/norm(b)
  iter    - number of iterations
  resvec  - norm of relative residual at each iteration
"""
# function cg(A::Function,b::Vector; tol::Real=1e-2,maxIter::Integer=100,M::Function=identity,x::Vector=[],out::Integer=0,
# 	storeInterm::Bool=false)
function cg(A::Function,b::Vector{TF}; tol::Real=1e-2,maxIter::Integer=100,M::Function=identity,x::Vector=[],out::Integer=0) where {TF <: Real}
	n = length(b)

	if norm(b)==0; return zeros(eltype(b),n), -9, 0f0, 0, [0f0]; end
	if isempty(x)
		x = zeros(TF,n)#x = zeros(eltype(b),n)
		r = copy(b)
	else
		r = b .- A(x)::Vector{TF}
	end
	z = M(r)::Vector{TF}
	p = copy(z)::Vector{TF}

    # if storeInterm
    #     X = zeros(n,maxIter)	# allocate space for intermediates
    # end

	nr0  = norm(b)

	if out==2
		println("=== cg ===")
		println(@sprintf("%4s\t%7s","iter","relres"))
	end

	resvec = zeros(TF,maxIter)
	iter   = 1 # makes iter available outside the loop
	flag   = -1

	if norm(r)/nr0<=tol
		flag = 0;
		return x,flag,resvec[iter],iter,resvec[1:iter]
	end

	#TF    = typeof(x[1])
 	alpha = TF(0)
	beta  = TF(0)
	lastIter = 0
	for iter=1:maxIter
		lastIter = iter

		Ap 	  = A(p)::Vector{TF}
		gamma = dot(r,z)
		#gamma = BLAS.dot(n, r,1,z,1)#
		alpha = gamma / dot(p,Ap)
		#alpha = gamma / BLAS.dot(n, p,1,Ap,1)#dot(p,Ap)

		if alpha==Inf || alpha<0
			flag = -2; break
		end

		BLAS.axpy!(n,alpha,p,1,x,1) # x = alpha*p+x
		#if storeInterm; X[:,iter] = x; end
		BLAS.axpy!(n,-alpha,Ap,1,r,1) # r -= alpha*Ap

		#resvec[iter] = BLAS.nrm2(n, r, 1) / nr0#
		resvec[iter]  = norm(r)/nr0
		if out==2
			println(iter,resvec[iter])
		end
		if resvec[iter] <= tol
			flag = 0; break
		end

		z    = M(r)::Vector{TF}
		#beta = BLAS.dot(n, z,1,r,1) / gamma
		beta  = dot(z,r) / gamma
		# the following two lines are equivalent to p = z + beta*p
		#p = BLAS.scal!(n,beta,p,1)::Vector{TF}
		#p = BLAS.axpy!(n,TF(1.0),z,1,p,1)::Vector{TF}
		p  = BLAS.axpby!(TF(1.0), z, beta, p)::Vector{TF} # Overwrite Y with X*a + Y*b, where a and b are scalars. Return Y
	end

	if out>=0
		if flag==-1
			println("cg iterated maxIter (=%d) times but reached only residual norm %1.2e instead of tol=%1.2e.",
																								maxIter,resvec[lastIter],tol)
		elseif flag==-2
			println("Matrix A in cg has to be positive definite.")
		elseif flag==0 && out>=1
			println("cg achieved desired tolerance at iteration %d. Residual norm is %1.2e.",lastIter,resvec[lastIter])
		end
	end
    return x,flag,resvec[lastIter],lastIter,resvec[1:lastIter]
end

#specifically for CDS/DIA storage matrices
# function cg(R::Matrix{TF},offset::Vector{TI},b::Vector{TF},tol::Real,maxIter::Integer,x::Vector{TF},out::Integer) where {TF <: Real, TI <: Integer}
# 	n  	   = length(b)
# 	ndiags = size(R,2)
# 	r  	   = zeros(TF,n)

# 	if norm(b)==0; return zeros(eltype(b),n),-9,0.0,0,[0.0]; end

# 	CDS_MVp_MT(n,ndiags,R,offset,x,r)
# 	r .= -r .+ b
# 		#r = b .- A(x)::Vector{TF}

# 	z = copy(r)

# 	p = copy(r)::Vector{TF}

# 	nr0  = norm(b)

# 	resvec = zeros(TF,maxIter)
# 	iter   = 1 # makes iter available outside the loop
# 	flag   = -1

# 	if norm(r)/nr0<=tol
# 		flag = 0;
# 		return x,flag,resvec[iter],iter,resvec[1:iter]
# 	end

#  	alpha  	 = TF(0)
# 	beta     = TF(0)
# 	lastIter = 0
# 	Ap  	 = zeros(TF,n)
# 	for iter=1:maxIter
# 		lastIter = iter

# 		#Ap 	  = A(p)::Vector{TF}
# 		fill!(Ap,TF(0))
# 		CDS_MVp_MT(n,ndiags,R,offset,p,Ap)
# 		gamma = dot(r,z)
# 		#gamma = BLAS.dot(n, r,1,z,1)#
# 		alpha = gamma / dot(p,Ap)
# 		#alpha = gamma / BLAS.dot(n, p,1,Ap,1)#dot(p,Ap)

# 		if alpha==Inf || alpha<0
# 			flag = -2; break
# 		end

# 		BLAS.axpy!(n,alpha,p,1,x,1) # x = alpha*p+x
# 		BLAS.axpy!(n,-alpha,Ap,1,r,1) # r -= alpha*Ap

# 		#resvec[iter] = BLAS.nrm2(n, r, 1) / nr0#
# 		resvec[iter]  = norm(r)/nr0
# 		if resvec[iter] <= tol
# 			flag = 0; break
# 		end

# 		#z    = M(r)::Vector{TF}
# 		z = copy(r)
# 		#beta = BLAS.dot(n, z,1,r,1) / gamma
# 		beta  = dot(z,r) / gamma
# 		# the following two lines are equivalent to p = z + beta*p
# 		#p = BLAS.scal!(n,beta,p,1)::Vector{TF}
# 		#p = BLAS.axpy!(n,TF(1.0),z,1,p,1)::Vector{TF}
# 		p  = BLAS.axpby!(TF(1.0), z, beta, p)::Vector{TF} # Overwrite Y with X*a + Y*b, where a and b are scalars. Return Y
# 	end
#
# 	if out>=0
# 		if flag==-1
# 			println("cg iterated maxIter (=%d) times but reached only residual norm %1.2e instead of tol=%1.2e.",
# 																								maxIter,resvec[lastIter],tol)
# 		elseif flag==-2
# 			println("Matrix A in cg has to be positive definite.")
# 		elseif flag==0 && out>=1
# 			println("cg achieved desired tolerance at iteration %d. Residual norm is %1.2e.",lastIter,resvec[lastIter])
# 		end
# 	end

#     return x,flag,resvec[lastIter],lastIter,resvec[1:lastIter]

# end


n = 10 # rand(1:10)
m = 9  # rand(1:10)
@test matrixdepot("kahan", n) == matrixdepot("kahan", n, 1.2, 25.)
@test matrixdepot("kahan", m ,n, 4, 5) == matrixdepot("kahan", Float64, m, n, 4, 5)

@test matrixdepot("kahan", n, 0.5*pi, 1) ≈ Matrix(1.0I, n,n)
println("'kahan' passed test...")


abstract type Smoother end
abstract type Sweep end
struct SymmetricSweep <: Sweep
end
struct ForwardSweep <: Sweep
end
struct BackwardSweep <: Sweep
end
struct GaussSeidel{S} <: Smoother
    sweep::S
    iter::Int
end
GaussSeidel(; iter = 1) = GaussSeidel(SymmetricSweep(), iter)
GaussSeidel(f::ForwardSweep) = GaussSeidel(f, 1)
GaussSeidel(b::BackwardSweep) = GaussSeidel(b, 1)
GaussSeidel(s::SymmetricSweep) = GaussSeidel(s, 1)

function (s::GaussSeidel{S})(A, x, b) where {S<:Sweep}
    for i in 1:s.iter
        if S === ForwardSweep || S === SymmetricSweep
            gs!(A, b, x, 1, 1, size(A, 1))
        end
        if S === BackwardSweep || S === SymmetricSweep
            gs!(A, b, x, size(A, 1), -1, 1)
        end
    end
end

function gs!(A, b, x, start, step, stop)
    n = size(A, 1)
    z = zero(eltype(A))
    @inbounds for col in 1:size(x, 2)
        for i in start:step:stop
            rsum = z
            d = z
            for j in nzrange(A, i)
                row = A.rowval[j]
                val = A.nzval[j]
                d = ifelse(i == row, val, d)
                rsum += ifelse(i == row, z, val * x[row, col])
            end
            x[i, col] = ifelse(d == 0, x[i, col], (b[i, col] - rsum) / d)
        end
    end
end

struct Jacobi{T,TX} <: Smoother
    ω::T
    temp::TX
    iter::Int
end
Jacobi(ω, x::TX; iter=1) where {T, TX<:AbstractArray{T}} = Jacobi{T,TX}(ω, similar(x), iter)
Jacobi(x::TX, ω=0.5; iter=1) where {T, TX<:AbstractArray{T}} = Jacobi{T,TX}(ω, similar(x), iter)

function (jacobi::Jacobi)(A, x, b)

    ω = jacobi.ω
    one = Base.one(eltype(A))
    temp = jacobi.temp
    z = zero(eltype(A))

    for i in 1:jacobi.iter
        @inbounds for col = 1:size(x, 2)
            for i = 1:size(A, 1)
                temp[i, col] = x[i, col]
            end

            for i = 1:size(A, 1)
                rsum = z
                diag = z

                for j in nzrange(A, i)
                    row = A.rowval[j]
                    val = A.nzval[j]

                    diag = ifelse(row == i, val, diag)
                    rsum += ifelse(row == i, z, val * temp[row, col])
                end

                xcand = (one - ω) * temp[i, col] + ω * ((b[i, col] - rsum) / diag)
                x[i, col] = ifelse(diag == 0, x[i, col], xcand)
            end
        end
    end
end

#=
using KissThreading: tmap!

struct ParallelJacobi{T,TX} <: Smoother
    ω::T
    temp::TX
end
ParallelJacobi(ω, x::TX) where {T, TX<:AbstractArray{T}} = ParallelJacobi{T,TX}(ω, similar(x))
ParallelJacobi(x::TX, ω = 0.5) where {T, TX<:AbstractArray{T}} = ParallelJacobi{T,TX}(ω, similar(x))

struct ParallelTemp{TX, TI}
    temp::TX
    col::TI
end
(ptemp::ParallelTemp)(i) = ptemp.temp[i, ptemp.col]

struct ParallelJacobiMapper{TA, TX, TB, TTemp, TF, TI}
    A::TA
    x::TX
    b::TB
    temp::TTemp
    ω::TF
    col::TI
end
function (pjacobmapper::ParallelJacobiMapper)(i)
    A = pjacobmapper.A
    x = pjacobmapper.x
    b = pjacobmapper.b
    temp = pjacobmapper.temp
    ω = pjacobmapper.ω
    col = pjacobmapper.col

    one = Base.one(eltype(A))
    z = zero(eltype(A))
    rsum = z
    diag = z

    for j in nzrange(A, i)
        row = A.rowval[j]
        val = A.nzval[j]

        diag = ifelse(row == i, val, diag)
        rsum += ifelse(row == i, z, val * temp[row, col])
    end
    xcand = (one - ω) * temp[i, col] + ω * ((b[i, col] - rsum) / diag)

    return ifelse(diag == 0, x[i, col], xcand)
end

function (jacobi::ParallelJacobi)(A, x, b)
    ω = jacobi.ω
    temp = jacobi.temp
    for col = 1:size(x, 2)
        @views tmap!(ParallelTemp(temp, col), x[1:size(A, 1), col], 1:size(A, 1))
        @views tmap!(ParallelJacobiMapper(A, x, b, temp, ω, col),
            x[1:size(A, 1), col], 1:size(A, 1))
    end
end
=#

struct JacobiProlongation{T}
    ω::T
end

struct DiagonalWeighting
end
struct LocalWeighting
end

function (j::JacobiProlongation)(A, T, S, B, degree = 1, weighting = LocalWeighting())
    D_inv_S = weight(weighting, A, j.ω)
    P = T
    for i = 1:degree
        P = P - (D_inv_S * P)
    end
    P
end

function weight(::DiagonalWeighting, S, ω)
    D_inv = 1 ./ diag(S)
    D_inv_S = scale_rows(S, D_inv)
    (eltype(S)(ω) / approximate_spectral_radius(D_inv_S)) * D_inv_S
    # (ω) * D_inv_S
end

function weight(::LocalWeighting, S, ω)
    #=D = abs.(S) * ones(eltype(S), size(S, 1))
    D_inv = 1 ./ D[find(D)]
    D_inv_S = scale_rows(S, D_inv)
    eltype(S)(ω) * D_inv_S=#
    D = zeros(eltype(S), size(S,1))
    for i = 1:size(S, 1)
        for j in nzrange(S, i)
            row = S.rowval[j]
            val = S.nzval[j]
            D[row] += abs(val)
        end
    end
    for i = 1:size(D, 1)
        if D[i] != 0
            D[i] = 1/D[i]
        end
    end
    D_inv_S = scale_rows(S, D)
    # eltype(S)(ω) * D_inv_S
    rmul!(D_inv_S, eltype(S)(ω))
end

#approximate_spectral_radius(A) =
#    eigs(A, maxiter = 15, tol = 0.01, ritzvec = false)[1][1] |> real

function scale_rows!(ret, S, v)
    n = size(S, 1)
    for i = 1:n
        for j in nzrange(S, i)
            row = S.rowval[j]
            ret.nzval[j] *= v[row]
        end
    end
    ret
end
scale_rows(S, v) = scale_rows!(deepcopy(S), S,  v)


__precompile__()
module ReduceLinAlg
using Reduce, LinearAlgebra

#   This file is part of ReduceLinAlg.jl. It is licensed under the MIT license
#   Copyright (C) 2018 Michael Reed

const VectorAny = Union{Vector,Adjoint}

const lin = [
    :hessian,
    :mat_jacobian,
    :band_matrix,
    :block_matrix,
    :char_matrix,
    :char_poly,
    :diagonal,
    :extend,
    :gram_schmidt,
    :hilbert,
    :jordan_block,
    :kronecker_product,
]

const unr = [
    :cholesky,
    :coeff_matrix,
    :hermitian_tp,
    :symmetricp,
    :toeplitz,
    :triang_adjoint,
    :vandermonde,
]

:(export $([lin;unr]...)) |> eval

for fun in lin
    @eval begin
        $(Reduce.parsegen(fun,:args))
        $(Reduce.unfoldgen(fun,:args))
        function $fun(expr::String,s...;be=0)
            convert(String, $fun(RExpr(expr),s...;be=be))
        end
    end
end

for fun in unr
    @eval begin
        $(Reduce.parsegen(fun,:unary))
        $(Reduce.unfoldgen(fun,:unary))
        function $fun(expr::String;be=0)
            convert(String, $fun(RExpr(expr);be=be))
        end
    end
end

const MatExpr = Union{Array{Any,2},Array{Expr,2},Array{Symbol,2},Expr,Symbol}

band_matrix(r::Union{Vector,Adjoint,Expr,Symbol},v::Integer) = band_matrix(list(r),v) |> parse
band_matrix(r::T,v::Integer) where T <: Tuple = band_matrix(RExpr(r),v) |> parse
block_matrix(r::Integer,c::Integer,s::VectorAny) = block_matrix(RExpr(r),RExpr(c),list(s)) |> parse
block_matrix(r::Integer,c::Integer,s::T) where T <: Tuple = block_matrix(RExpr(r),RExpr(c),RExpr(s)) |> parse

char_matrix(r::MatExpr,v::Any) = mat(char_matrix(list(r),RExpr(v)) |> parse,r)
char_poly(r::MatExpr,v::Any) = mat(char_matrix(list(r),RExpr(v)) |> parse,r)

extend(a::MatExpr,r::Integer,c::Integer,s) = mat(extend(RExpr(a),r,c,RExpr(s)) |> parse,a)

hessian(r::Reduce.ExprSymbol,l::T) where T <: VectorAny  = hessian(r,list(l))
hessian(r::Reduce.ExprSymbol,l::T) where T <: Tuple  = hessian(r,RExpr(l))

@doc """
    hessian(expr,var_list::Vector)

Computes the Hessian matrix of `expr` with respect to the variables in `var_list`.

This is an n×n matrix where n is the number of variables and the (i,j)th entry is `df(expr,var_list[i],var_list[j])`.
""" hessian

hilbert(a::Integer,r) = hilbert(RExpr(a),RExpr(r)) |> parse

function mat_jacobian(r::T,v::S) where T <: VectorAny where S <: VectorAny
    mat_jacobian(list(r),list(v)) |> parse
end

function mat_jacobian(r::T,v::S) where T <: Tuple where S <: Tuple
    mat_jacobian(RExpr(r),RExpr(v)) |> parse
end

@doc """
    mat_jacobian(expr_list::Vector,var_list::Vector)

Computes the Jacobian matrix of `expr_list` with respect to `var_list`.

This is a matrix whose (i,j)th entry is `df(expr_list[i],var_list[j])`. The matrix is n×m where n is the number of variables and m is the number of expressions.
""" mat_jacobian

export jacobian

jacobian = mat_jacobian

@doc """
    jordan_block(expr,square_size::Integer)

Computes the square Jordan block matrix `J` of dimension `square_size`.

The entries of `J` are `J[i,i] = expr` for i = 1,...,n, `J[i,i+1] = 1` for i = 1,...,n-1, and all other entries are 0.
""" jordan_block

kronecker_product(a::MatExpr,b::MatExpr) = mat(kronecker(RExpr(a),RExpr(b)) |> parse,a,b)

cholesky(r::Array{T,2}) where T <: Number = cholesky(RExpr(r)) |> parse |> mat
coeff_matrix(r::VectorAny) = coeff_matrix(list(r)) |> parse
coeff_matrix(r::T) where T <: Tuple = coeff_matrix(RExpr(r)) |> parse
diagonal(r::VectorAny) = diagonal(list(r)) |> parse
diagonal(r::T) where T <: Tuple = diagonal(RExpr(r)) |> parse
gram_schmidt(r::Vector{<:Vector}) = gram_schmidt(list(r)) |> parse
gram_schmidt(r::T) where T <: Tuple = gram_schmidt(RExpr(r)) |> parse
gram_schmidt(r::Matrix) = gram_schmidt(list(r)) |> parse
hermitian_tp(r::MatExpr) = mat(hermitian_tp(RExpr(r)) |> parse, r)
symmetricp(r::MatExpr) = mat(symmetricp(RExpr(r)) |> parse, r)
toeplitz(r::VectorAny) = toeplitz(list(r)) |> parse
toeplitz(r::T) where T <: Tuple = toeplitz(RExpr(r)) |> parse
triang_adjoint(r::MatExpr) = mat(triang_adjoint(RExpr(r)) |> parse, r)
vandermonde(r::VectorAny) = vandermonde(list(r)) |> parse
vandermonde(r::T) where T <: Tuple = vandermonde(RExpr(r)) |> parse

function __init__()
    load_package(:linalg)
end

end # module


using Optim, Test
@testset "#711" begin
	# make sure it doesn't try to promote df
	dof = 7

	fun(x) = 0.0; x0 = fill(0.1, dof)
	df = TwiceDifferentiable(fun, x0)

	lx = fill(-1.2, dof); ux = fill(+1.2, dof)
	dfc = TwiceDifferentiableConstraints(lx, ux)

	res = optimize(df, dfc, x0, IPNewton(); autodiff=:forward)
	res = optimize(df, dfc, x0, IPNewton())
end

@testset "#600" begin
	function exponential(x)
		return exp((2.0 - x[1])^2) + exp((3.0 - x[2])^2)
	end

	function exponential_gradient!(storage, x)
		storage[1] = -2.0 * (2.0 - x[1]) * exp((2.0 - x[1])^2)
		storage[2] = -2.0 * (3.0 - x[2]) * exp((3.0 - x[2])^2)
		storage
	end
	function exponential_hessian!(storage, x)
		Optim.NLSolversBase.ForwardDiff.hessian!(storage, exponential, x)
	end

	function exponential_gradient(x)
		storage = similar(x)
		storage[1] = -2.0 * (2.0 - x[1]) * exp((2.0 - x[1])^2)
		storage[2] = -2.0 * (3.0 - x[2]) * exp((3.0 - x[2])^2)
		storage
	end

	initial_x = [0.0, 0.0]
	optimize(exponential, exponential_gradient!, initial_x, BFGS())
	lb = fill(-0.1, 2)
	ub = fill(1.1, 2)
	od = OnceDifferentiable(exponential, initial_x)
	optimize(od, lb, ub, initial_x, IPNewton())
	optimize(od, lb, ub, initial_x, IPNewton(), Optim.Options())
	optimize(exponential, lb, ub, initial_x, IPNewton())
	optimize(exponential, lb, ub, initial_x, IPNewton(), Optim.Options())
	optimize(exponential, exponential_gradient!, lb, ub, initial_x, IPNewton())
	optimize(exponential, exponential_gradient!, lb, ub, initial_x, IPNewton(), Optim.Options())
	optimize(exponential, exponential_gradient!, exponential_hessian!, lb, ub, initial_x, IPNewton())
	optimize(exponential, exponential_gradient!, exponential_hessian!, lb, ub, initial_x, IPNewton(), Optim.Options())
	optimize(TwiceDifferentiable(od, initial_x), lb, ub, initial_x)
	optimize(TwiceDifferentiable(od, initial_x), lb, ub, initial_x, Optim.Options())
end


module TypingTests

using Interpolations, Base.Test

nx = 10
f(x) = convert(Float32, x^3/(nx-1))
g(x) = convert(Float32, 3x^2/(nx-1))

A = Float32[f(x) for x in 1:nx]

itp = interpolate(A, BSpline(Quadratic(Flat())), OnCell())

# display(plot(
#     layer(x=1:nx,y=[f(x) for x in 1:1//1:nx],Geom.point),
#     layer(x=1:.1:nx,y=[itp[x] for x in 1:1//10:nx],Geom.path),
# ))

for x in 3.1:.2:4.3
    @test_approx_eq_eps float(f(x)) float(itp[x]) abs(.1*f(x))
end

@test typeof(itp[3.5f0]) == Float32

for x in 3.1:.2:4.3
    @test_approx_eq_eps g(x) gradient(itp, x) abs(.1*g(x))
end

@test typeof(gradient(itp, 3.5f0)[1]) == Float32

# Rational element types
R = Rational{Int}[x^2//10 for x in 1:10]
itp = interpolate(R, BSpline(Quadratic(Free())), OnCell())
itp[11//10]

@test typeof(itp[11//10]) == Rational{Int}
@test itp[11//10] == (11//10)^2//10

end


### A Pluto.jl notebook ###
# v0.14.2

using Markdown
using InteractiveUtils

# ╔═╡ dac66550-6a42-11eb-18fd-1dbb51ebb356
using DataFrames, PlutoUI

# ╔═╡ b9438ea0-6a42-11eb-3203-bdef1a59bb19
md"""
## Introduction to DataFrames / 2

ref. [Introduction to DataFrames, Bogumił Kamiński](https://github.com/bkamins/Julia-DataFrames-Tutorial/blob/master/02_basicinfo.ipynb)

$(html"
© Pascal, April 2021
")
"""

# ╔═╡ be11851f-b9a5-4140-9d56-fa0e1ec896f9
PlutoUI.TableOfContents(indent=true, depth=4, aside=true)

# ╔═╡ 0c9061f5-92fc-4861-8920-acb7f16aea51
md"""
### Getting basic information about a DataFrame
"""

# ╔═╡ e8266538-6a42-11eb-0919-f7a19fd021ba
xdf = DataFrame(A = [1, 2], B = [1.0, missing], C = ["a", "b"])

# ╔═╡ f28d6da0-6a42-11eb-1bfd-edda225bd80a
size(xdf), size(xdf, 1), size(xdf, 2)

# ╔═╡ 02630c26-6a43-11eb-375b-d3bf7b722863
nrow(xdf), ncol(xdf)

# ╔═╡ 09ef1732-6a43-11eb-3ce5-6904ca52514f
describe(xdf)

# ╔═╡ 1436e9b8-6a43-11eb-1dde-d97c58bf5218
describe(xdf, cols=1:2)

# ╔═╡ 6ca3a755-9f7b-4b49-b15c-1989144e4e44
## A custom describe
describe(xdf, :eltype, :nmissing, :first => first, :last => last)

# ╔═╡ 20d87024-6a43-11eb-0a14-d5c00e2aafde
names(xdf)

# ╔═╡ 2c9fb4c6-6a43-11eb-3e4c-5d12a291df4a
propertynames(xdf)

# ╔═╡ 3534cd7e-6a43-11eb-2eb7-0fa46c82b12d
eltype.(eachcol(xdf))

# ╔═╡ 7f69dd67-3fa6-4c74-bf8c-4fecb087b74f
md"""
Let's create a large dataframe and have peek into it using `first` and `last`.
"""

# ╔═╡ 3f6d9596-6a43-11eb-3469-5dcd7f0332e0
begin
	n = 10
	ydf = DataFrame(rand(1:n, 1000, n))
end

# ╔═╡ 546cdee8-6a43-11eb-38a2-35fe89ae2dde
first(ydf, 3)

# ╔═╡ 5bc30e06-6a43-11eb-1625-015e8cb5bce1
last(ydf, 3)

# ╔═╡ cc4ffb73-ada8-4446-8914-9e1d5cf669d4
md"""
### DataFrames get and set operations

Re-using `xdf` DataFrame as defined a few cells above.
"""

# ╔═╡ c6786444-6a43-11eb-21b9-3d4a2722cdfd
# all get the vector stored in our DataFrame without copying it
xdf.A, xdf[!, 1], xdf[!, :A]

# ╔═╡ 04e69443-e80d-45ea-9d59-fb5dd8bf11e5
xdf."A", xdf[!, "A"]   # the same using string indexing

# ╔═╡ d105dcca-6a43-11eb-07fe-cd24a5efcf2a
begin
	xdf[:, 1]                                  # note that this creates a copy...
	xdf[:, 1] === xdf[:, 1]                    # ...here is the proof

	objectid(xdf[:, 1]), objectid(xdf[:, 1])   # ...and another way to show this
end

# ╔═╡ 49729e83-ebb2-4514-bdaf-68db8847800a
md"""
To grab one row as a DataFrame, we can index as follows:
"""

# ╔═╡ 0ea18045-6d7e-4202-ab94-709ab6150201
xdf[1:1, :]

# ╔═╡ 288c1879-77db-4246-b087-5f4e7ee600c5
xdf[1, :] # this produces a DataFrameRow which is treated as 1-dim object similar to a NamedTuple

# ╔═╡ 2140fccb-bbbb-4bae-b3e0-40a850ca40b9
typeof(xdf[1:1, :]), typeof(xdf[1, :])

# ╔═╡ b9566a8c-748b-4696-8aed-d9add8a085d0
md"""
We can grab a single cell or element with the same syntax to grab an element of an array.
"""

# ╔═╡ 0ea6ef6d-d908-4888-9fa3-4bd5edefeea6
xdf[1, 2]

# ╔═╡ 2aae7a6a-21db-45ee-bcdf-619ee2ea5240
md"""
or a new DataFrame that is a subset of rows and columns:
"""

# ╔═╡ 9b8d271c-5def-46d4-a38d-a98a63e4d62c
xdf[1:2, 1:2]

# ╔═╡ 2e1155ca-0cfc-4113-b2ce-2ff770e51e52
md"""
We can also use a `Regexp` to select columns and `Not` from `InvertedIndices.jl` both to select rows and columns>
"""

# ╔═╡ af6641c1-d1eb-4ae0-9e31-63aed4793b14
xdf[Not(1), r"A"]

# ╔═╡ bd1f96af-21fb-4e9e-933b-c4b99a05d13a
md"""
**Reference (`!`) and copy (`:`)**
"""

# ╔═╡ 6f4ab986-81af-4fbd-93b2-546b3ad7c425
xdf[!, Not(1)]     # ! indicates that underlying columns are not copied

# ╔═╡ da813272-f45a-4fcd-a4ff-539bb4c924c1
xdf[:, Not(1)]     # (however) : means that the columns will get copied

# ╔═╡ 17f8d99c-0bf0-4442-b234-d8d4955482e0
md"""
Assignment of a scalar to a dataframe can be done in ranges using broadcasting:
"""

# ╔═╡ 3be6e5f8-777b-4f9a-9430-362880e842ad
begin
	xdf[!, :B] = convert.(Float64, xdf[!, :B])   ## Type conversion for column :B
	xdf[1:2, :B] .= π;                           ## broadcaset π over all rows
	xdf
end

# ╔═╡ 137dfe1f-0a3d-4d76-978a-70da3c178479
begin
	xdf[1:2, 1:2] .= 3;   ## Assignment over both columns :A(1) and :B(1), over all rows
	xdf
end

# ╔═╡ 5f890d28-43ef-40f3-b1ff-b32c9cd5773d
md"""
Assignment of a vector of length equal to the number of assigned rows using broadcasting:
"""

# ╔═╡ 20ae267b-c26b-49c5-9096-96190f868c18
begin
	xdf[1:2, 1:2] .= [2, 4]
	xdf
end

# ╔═╡ 49daec8a-0263-4f69-a27b-dc0efdf89c71
md"""
Assignment or of another data frame of matching size and column names, again using broadcasting:
"""

# ╔═╡ ed5ee6d9-ec3e-417c-8206-f62666d88c4f
begin
	xdf[1:2, 1:2] .= DataFrame([5 6; 7 8], [:A, :B])
	xdf
end

# ╔═╡ 05d0a958-6071-41ba-8219-98f040ac90ae
md"""
#### Caution

  - With `df[!, :col]` and `df.col` syntax we get a direct (non copying) access to a column of a data frame. This is *potentially unsafe* as we can easily corrupt data in the `df` dataframe if we resize, sort, etc. the column obtained in this way. *Therefore such access should be used with caution*.

  - Similarly `df[!, cols]` when `cols` is a collection of columns produces a new data frame that holds the same (not copied) columns as the source `df` dataframe. *Similarly, modifying the data frame obtained via `df[!, cols]` might cause problems with the consistency of `df`*.

  - The `df[:, :col]` and `df[:, cols]` syntaxes always copy columns so they are safe to use (and should generally be preferred except for performance or memory critical use cases).
"""

# ╔═╡ c0960534-f6a1-40f8-8b35-b19aa5b78ac2
md"""
Here are examples of how `Cols` and `Between` can be used to select columns of a data frame:
"""

# ╔═╡ 0bfe2061-cddb-4f9f-9b7e-33a3e703d084
xdf₁ = DataFrame(rand(4, 5), :auto)

# ╔═╡ 5055355b-a405-4d27-b2aa-9477bd5ee2c4
ydf₀ = xdf₁[:, Between(:x2, :x4)]     ## make a copy

# ╔═╡ 2623b999-d8b1-4cba-9f2b-4d644c672354
ydf₁ = xdf₁[:, Cols("x1", Between("x3", "x4"))]   ## make a copy

# ╔═╡ 3c8b682a-5387-40b6-b3cd-d8beaa09383c
begin
	ydf₁[!, :x3] .= 3
	ydf₁
end

# ╔═╡ b1d6b7e3-8c67-44b3-ae30-87302295e976
xdf₁   ## was not changed

# ╔═╡ 61ac92e7-f181-4554-809a-dba4b786acec
ydf₀   ## nor this dataframe

# ╔═╡ e5e723bd-aa8e-415c-b7c6-ffd49bbf1841
md"""
#### Views

We can simply create a view of a DataFrame (it is more efficient than creating a materialized selection). Here are the possible return value options.
"""

# ╔═╡ fe37621d-c903-4055-bdb9-0dbc98f9d524
@view xdf[1:2, 1]

# ╔═╡ 8624b878-775b-4e37-a5c5-9b1cf38ef614
@view xdf[1, 1]

# ╔═╡ 9d40b847-5ebc-4656-aa03-f918ccee3974
@view xdf[1, 1:2]   ## a DataFrameRow, the same as for xdf[1, 1:2] without a view

# ╔═╡ 12a63294-6a44-11eb-0f29-7dcf33acface
md"""
### Adding new columns to a DataFrame
"""

# ╔═╡ 8c59bad5-6a7c-4923-b088-07a225c57a96
xdf₂ = DataFrame();    ## Create an empty DataFrame

# ╔═╡ 91e94361-3b46-4e0f-b8c3-14ced0b2e71b
md"""
Using `setproperty`!
"""

# ╔═╡ 48c59474-ffb8-4c92-96d1-39dddcd39076
begin
	v = collect(1:5)
	xdf₂.a = v
	xdf₂
end

# ╔═╡ 2180b2ba-3201-49a6-a0d5-5549c00c7b37
xdf₂.a === v   ## no copy is performed

# ╔═╡ 4c3feedd-f3e0-4121-91b6-9b43b0840c9b
md"""
using `setindex`!
"""

# ╔═╡ dcf94057-a263-4b27-b086-db0c74953405
begin
	xdf₂[!, :b] = v
	xdf₂[:, :c] = v

	@assert xdf₂[!, :b] === v  ## no copy is performed
	@assert xdf₂[!, :c] !== v  ## copy performed

	xdf₂
end

# ╔═╡ 56ba4b95-5a94-46be-ab6c-c80a40daccec
begin
	xdf₂[!, :d] .= v
	xdf₂[:, :e] .= v

	## using broadcasting implies copy:
	@assert xdf₂[!, :d] !== v  ## copy performed
	@assert xdf₂[!, :e] !== v  ## copy performed

	xdf₂
end

# ╔═╡ f0c302ae-23c1-4019-80d9-d727f83b9815
md"""
Remember that columns `:a` and `:b` are not copies of `v`.
This can lead to silent errors.

For example the following code leads to a bug (note that calling `pairs` on `eachcol(df)` creates an iterator of (column name, column) pairs):
"""

# ╔═╡ e0f1d7c5-039a-4be6-9b84-e7434faafad6
with_terminal() do
	for (n, c) in pairs(eachcol(xdf₂))
    	println("$n: ", pop!(c))           ## side-effect !
	end
end

# ╔═╡ 73b293e6-4609-419f-afe6-5f1185ab58f7
md"""
note (above cell) that for column `:b` we printed 4 as 5 was removed from it when we used `pop!` on column `:a`.

Such mistakes sometimes happen. Because of this `DataFrames.jl` performs consistency checks before doing an expensive operation (most notably before showing a DataFrame).
"""

# ╔═╡ 09290340-e74c-4f2c-9962-ccac5dd334a8
collect(pairs(eachcol(xdf₂)))  ## The output confirms that the DataFrame got corrupted.

# ╔═╡ 5a53e3f7-1585-4d16-ad4a-1e88ec08ef83
md"""
`DataFrames.jl` supports a complete set of `getindex`, `getproperty`, `setindex!`, `setproperty!`, view, broadcasting, and broadcasting assignment operations. The details are explained here: [http://juliadata.github.io/DataFrames.jl/latest/lib/indexing/](http://juliadata.github.io/DataFrames.jl/latest/lib/indexing/).
"""

# ╔═╡ 96f4c0ff-8bd7-4622-9d32-d382f3674485
md"""
### Comparisons
"""

# ╔═╡ 0d0af2ac-a896-4f70-bc8f-8715342037f0
xdf₃ = DataFrame(rand(2,3), :auto)

# ╔═╡ f2715e53-7a02-4eb8-ac0e-28902540e3b9
xdf₄ = copy(xdf₃)

# ╔═╡ 2471303f-8618-4c09-a511-2decf60a1c6c
@assert xdf₃ == xdf₄   ## compares column names and contents

# ╔═╡ 1aa0c67e-c1b0-4f0d-958f-84562eb39d76
md"""
Create a minimally different DataFrame and use `isapprox` for comparison:
"""

# ╔═╡ bef79b4f-d498-4e4f-b635-d769d0e191fd
xdf₅ = xdf₃ .+ eps()

# ╔═╡ 14df0d21-dc58-4385-a29c-d339d54a0719
begin
	@assert xdf₅ ≠ xdf₃                          ## different
	@assert isapprox(xdf₅, xdf₅, atol=eps()/2)   ## approx. equal
end

# ╔═╡ 1bbbb4ca-5d4a-466a-8541-8cdf7fe6c92c
md"""
`missings` are handled as in `Julia Base`:
"""

# ╔═╡ 3dc2357e-0cc7-4259-95e3-bc9b41243ebe
xdfₘ = DataFrame(a=missing)

# ╔═╡ 2ea87bb2-2d60-40f3-8728-ed5460c6c0c8
xdfₘ == xdfₘ

# ╔═╡ 8d06d5d7-2fb9-4b6a-be3c-1f6fcc4fd7ba
begin
	@assert xdfₘ === xdfₘ
	isequal(xdfₘ, xdfₘ)
end

# ╔═╡ 56edf702-2972-482a-b371-5d9d5de38fcd
html"""

"""

# ╔═╡ Cell order:
# ╟─b9438ea0-6a42-11eb-3203-bdef1a59bb19
# ╠═dac66550-6a42-11eb-18fd-1dbb51ebb356
# ╟─be11851f-b9a5-4140-9d56-fa0e1ec896f9
# ╟─0c9061f5-92fc-4861-8920-acb7f16aea51
# ╠═e8266538-6a42-11eb-0919-f7a19fd021ba
# ╠═f28d6da0-6a42-11eb-1bfd-edda225bd80a
# ╠═02630c26-6a43-11eb-375b-d3bf7b722863
# ╠═09ef1732-6a43-11eb-3ce5-6904ca52514f
# ╠═1436e9b8-6a43-11eb-1dde-d97c58bf5218
# ╠═6ca3a755-9f7b-4b49-b15c-1989144e4e44
# ╠═20d87024-6a43-11eb-0a14-d5c00e2aafde
# ╠═2c9fb4c6-6a43-11eb-3e4c-5d12a291df4a
# ╠═3534cd7e-6a43-11eb-2eb7-0fa46c82b12d
# ╟─7f69dd67-3fa6-4c74-bf8c-4fecb087b74f
# ╠═3f6d9596-6a43-11eb-3469-5dcd7f0332e0
# ╠═546cdee8-6a43-11eb-38a2-35fe89ae2dde
# ╠═5bc30e06-6a43-11eb-1625-015e8cb5bce1
# ╟─cc4ffb73-ada8-4446-8914-9e1d5cf669d4
# ╠═c6786444-6a43-11eb-21b9-3d4a2722cdfd
# ╠═04e69443-e80d-45ea-9d59-fb5dd8bf11e5
# ╠═d105dcca-6a43-11eb-07fe-cd24a5efcf2a
# ╟─49729e83-ebb2-4514-bdaf-68db8847800a
# ╠═0ea18045-6d7e-4202-ab94-709ab6150201
# ╠═288c1879-77db-4246-b087-5f4e7ee600c5
# ╠═2140fccb-bbbb-4bae-b3e0-40a850ca40b9
# ╟─b9566a8c-748b-4696-8aed-d9add8a085d0
# ╠═0ea6ef6d-d908-4888-9fa3-4bd5edefeea6
# ╟─2aae7a6a-21db-45ee-bcdf-619ee2ea5240
# ╠═9b8d271c-5def-46d4-a38d-a98a63e4d62c
# ╟─2e1155ca-0cfc-4113-b2ce-2ff770e51e52
# ╠═af6641c1-d1eb-4ae0-9e31-63aed4793b14
# ╟─bd1f96af-21fb-4e9e-933b-c4b99a05d13a
# ╠═6f4ab986-81af-4fbd-93b2-546b3ad7c425
# ╠═da813272-f45a-4fcd-a4ff-539bb4c924c1
# ╟─17f8d99c-0bf0-4442-b234-d8d4955482e0
# ╠═3be6e5f8-777b-4f9a-9430-362880e842ad
# ╠═137dfe1f-0a3d-4d76-978a-70da3c178479
# ╟─5f890d28-43ef-40f3-b1ff-b32c9cd5773d
# ╠═20ae267b-c26b-49c5-9096-96190f868c18
# ╟─49daec8a-0263-4f69-a27b-dc0efdf89c71
# ╠═ed5ee6d9-ec3e-417c-8206-f62666d88c4f
# ╟─05d0a958-6071-41ba-8219-98f040ac90ae
# ╟─c0960534-f6a1-40f8-8b35-b19aa5b78ac2
# ╠═0bfe2061-cddb-4f9f-9b7e-33a3e703d084
# ╠═5055355b-a405-4d27-b2aa-9477bd5ee2c4
# ╠═2623b999-d8b1-4cba-9f2b-4d644c672354
# ╠═3c8b682a-5387-40b6-b3cd-d8beaa09383c
# ╠═b1d6b7e3-8c67-44b3-ae30-87302295e976
# ╠═61ac92e7-f181-4554-809a-dba4b786acec
# ╟─e5e723bd-aa8e-415c-b7c6-ffd49bbf1841
# ╠═fe37621d-c903-4055-bdb9-0dbc98f9d524
# ╠═8624b878-775b-4e37-a5c5-9b1cf38ef614
# ╠═9d40b847-5ebc-4656-aa03-f918ccee3974
# ╟─12a63294-6a44-11eb-0f29-7dcf33acface
# ╠═8c59bad5-6a7c-4923-b088-07a225c57a96
# ╟─91e94361-3b46-4e0f-b8c3-14ced0b2e71b
# ╠═48c59474-ffb8-4c92-96d1-39dddcd39076
# ╠═2180b2ba-3201-49a6-a0d5-5549c00c7b37
# ╟─4c3feedd-f3e0-4121-91b6-9b43b0840c9b
# ╠═dcf94057-a263-4b27-b086-db0c74953405
# ╠═56ba4b95-5a94-46be-ab6c-c80a40daccec
# ╟─f0c302ae-23c1-4019-80d9-d727f83b9815
# ╠═e0f1d7c5-039a-4be6-9b84-e7434faafad6
# ╟─73b293e6-4609-419f-afe6-5f1185ab58f7
# ╠═09290340-e74c-4f2c-9962-ccac5dd334a8
# ╟─5a53e3f7-1585-4d16-ad4a-1e88ec08ef83
# ╟─96f4c0ff-8bd7-4622-9d32-d382f3674485
# ╠═0d0af2ac-a896-4f70-bc8f-8715342037f0
# ╠═f2715e53-7a02-4eb8-ac0e-28902540e3b9
# ╠═2471303f-8618-4c09-a511-2decf60a1c6c
# ╟─1aa0c67e-c1b0-4f0d-958f-84562eb39d76
# ╠═bef79b4f-d498-4e4f-b635-d769d0e191fd
# ╠═14df0d21-dc58-4385-a29c-d339d54a0719
# ╟─1bbbb4ca-5d4a-466a-8541-8cdf7fe6c92c
# ╠═3dc2357e-0cc7-4259-95e3-bc9b41243ebe
# ╠═2ea87bb2-2d60-40f3-8728-ed5460c6c0c8
# ╠═8d06d5d7-2fb9-4b6a-be3c-1f6fcc4fd7ba
# ╟─56edf702-2972-482a-b371-5d9d5de38fcd


using BenchmarkTools
using VectorDataUtils

#Non vectorised Lp norms and metrics

l2inner_alt(x,y) = sum(x.*y)
# sql2norm_alt(x) = sum(x.*x)
l2norm_alt(x) = sqrt(sum(x.*x))
sql2dist_alt(x,y) = sum((x-y).*(x-y))
l2dist_alt(x,y) = sqrt(sql2dist(x,y))
l1norm_alt(x) = sum(abs.(x))
l1dist_alt(x,y) = sum(abs.(x-y))

function sql2norm_alt(a::AbstractVector{T}) where {T}
    s = zero(T)
    @simd for i ∈ eachindex(a)
        s += a[i] * a[i]
    end
    return s
end

function return_alt(f1::Function)
    f2_sym = Symbol(String(Symbol(f1))*"_alt")
    f2 = getfield(Main,f2_sym)
    return f2
end

f1 = l1norm

ndim = 15
Ftype = Float32
x = randn(Ftype,ndim)
y = randn(Ftype,ndim)
ip = (x,)

f2 = return_alt(f1)
m1 = median(@benchmark f1(ip...))
m2 = median(@benchmark f2(ip...))
f1(ip...) ≈ f2(ip...)
judge(m1,m2)

function fmatch(f1::Function,ip)
    f2 = return_alt(f1)
    return f1(ip...) ≈ f2(ip...)
end

function fcomp(f1::Function,ip)
    f2 = return_alt(f1)
    b1 = @benchmarkable f1(ip...)
    b2 = @benchmarkable f2(ip...)
    tune!(b1)
    tune!(b2)
    t1 = run(b1)
    t2 = run(b2)
    m1 = median(t1)
    m2 = median(t2)
    return m1,m2
end

function bench_median(f::Function,ip)
    b1 = @benchmark f(ip...)
    return median(b1)
end