text:
module lib
	export Data,eq,exitWithError,clean,CMMain,CMHelp,CMVersion,MMNone,MMSerial,MMSpawn,MMThread

	@enum CommandMode CMMain CMHelp CMVersion
	@enum MultipleMode MMNone MMSerial MMSpawn MMThread

	Base.@kwdef mutable struct Data
		command::Array{String,1}=[]
		out::String="inherit"
		err::String="inherit"
		result::String="stderr"
		multiple::MultipleMode=MMNone
		mode::CommandMode=CMMain
	end

	function eq(target,candidates...)
		for c in candidates
			if c==target return true end
		end
		return false
	end

	function exitWithError(message)
		println(stderr,message)
		exit(1)
	end

	function clean(text)
		text=replace(text,r"^\t+"m=>s"")
		return text
	end

end

max_stars_repo_path: Time Measurement/Julia/lib.jl

max_issues_repo_path: Time Measurement/Julia/lib.jl

max_forks_repo_path: Time Measurement/Julia/lib.jl


text:
module mctransf1
using FinEtools
using FinEtoolsDeforLinear: tens4symmt6x6tot!, tens4symmtto6x6t!
using FinEtoolsDeforNonlinear.MatDeforNonlinearModule: totlag2currsymm!, totlag2curr!, totlag2curr4th!
using LinearAlgebra: det, I, diagm, diag, norm
using BenchmarkTools
using Test

function totalLagrangean2current0!(cout, C, F)
	@assert size(C) == (6, 6)
    F11 = F[1, 1]; F12 = F[1, 2]; F13 = F[1, 3]; F21 = F[2, 1]; F22 = F[2, 2]; F23 = F[2, 3]; F31 = F[3, 1]; F32 = F[3, 2]; F33 = F[3, 3];
    C11 = C[1, 1]; C12 = C[1, 2]; C13 = C[1, 3]; C14 = C[1, 4]; C15 = C[1, 5]; C16 = C[1, 6]; C21 = C[2, 1]; C22 = C[2, 2]; C23 = C[2, 3]; C24 = C[2, 4]; C25 = C[2, 5]; C26 = C[2, 6]; C31 = C[3, 1]; C32 = C[3, 2]; C33 = C[3, 3]; C34 = C[3, 4]; C35 = C[3, 5]; C36 = C[3, 6]; C41 = C[4, 1]; C42 = C[4, 2]; C43 = C[4, 3]; C44 = C[4, 4]; C45 = C[4, 5]; C46 = C[4, 6]; C51 = C[5, 1]; C52 = C[5, 2]; C53 = C[5, 3]; C54 = C[5, 4]; C55 =
    C[5, 5]; C56 = C[5, 6]; C61 = C[6, 1]; C62 = C[6, 2]; C63 = C[6, 3]; C64 = C[6, 4]; C65 = C[6, 5]; C66 = C[6, 6];
    @inbounds begin
	    cout[1,1] = (C11*F11^4+4*C14*F11^3*F12+4*C15*F11^3*F13+2*C12*F11^2*F12^2+4*C16*F11^2*F12*F13+2*C13*F11^2*F13^2+4*C44*F11^2*F12^2+8*C45*F11^2*F12*F13+4*C24*F11*F12^3+8*C46*F11*F12^2*F13+4*C34*F11*F12*F13^2+4*C55*F11^2*F13^2+4*C25*F11*F13*F12^2+8*C56*F11*F13^2*F12+4*C35*F11*F13^3+C22*F12^4+4*C26*F12^3*F13+2*C23*F12^2*F13^2+4*C66*F12^2*F13^2+4*C36*F12*F13^3+C33*F13^4);
	    cout[1,2] = (C12*F12^2*F21^2+4*C56*F13*F12*F21*F23+4*C66*F13*F12*F22*F23+4*C56*F11*F13*F22*F23+4*C44*F11*F12*F21*F22+4*C45*F11*F12*F21*F23+4*C45*F11*F13*F21*F22+4*C55*F11*F13*F21*F23+4*C46*F11*F12*F22*F23+4*C46*F13*F12*F21*F22+C12*F11^2*F22^2+C22*F12^2*F22^2+C13*F13^2*F21^2+C11*F11^2*F21^2+C13*F11^2*F23^2+C23*F12^2*F23^2+C33*F13^2*F23^2+C23*F13^2*F22^2+2*C24*F11*F12*F22^2+2*C34*F13^2*F21*F22+2*C15*F11^2*F21*F23+2*C15*F11*F13*F21^2+2*C26*F13*F12*F22^2+2*C36*F13^2*F22*F23+2*C36*F13*F12*F23^2+2*C35*F11*F13*F23^2+2*C35*F13^2*F21*F23+2*C16*F11^2*F22*F23+2*C34*F11*F12*F23^2+2*C14*F11*F12*F21^2+2*C14*F11^2*F21*F22+2*C16*F12*F13*F21^2+2*C25*F11*F13*F22^2+2*C26*F12^2*F22*F23+2*C25*F12^2*F21*F23+2*C24*F12^2*F21*F22);
	    cout[1,3] = (4*C66*F13*F12*F32*F33+C13*F11^2*F33^2+C33*F13^2*F33^2+C12*F12^2*F31^2+C12*F11^2*F32^2+C22*F12^2*F32^2+C11*F11^2*F31^2+C23*F13^2*F32^2+C23*F12^2*F33^2+C13*F13^2*F31^2+4*C45*F11*F13*F31*F32+4*C55*F11*F13*F31*F33+4*C45*F11*F12*F31*F33+4*C46*F11*F12*F32*F33+4*C46*F12*F13*F31*F32+4*C56*F11*F13*F32*F33+4*C56*F13*F12*F31*F33+4*C44*F11*F12*F31*F32+2*C34*F11*F12*F33^2+2*C16*F12*F13*F31^2+2*C34*F13^2*F31*F32+2*C15*F11*F13*F31^2+2*C15*F11^2*F31*F33+2*C16*F11^2*F32*F33+2*C25*F11*F13*F32^2+2*C35*F11*F13*F33^2+2*C35*F13^2*F31*F33+2*C26*F12^2*F32*F33+2*C26*F13*F12*F32^2+2*C14*F11*F12*F31^2+2*C14*F11^2*F31*F32+2*C24*F12^2*F31*F32+2*C24*F11*F12*F32^2+2*C36*F13^2*F32*F33+2*C36*F13*F12*F33^2+2*C25*F12^2*F31*F33);
	    cout[1,4] = (C26*F12^3*F23+C36*F13^3*F22+C11*F11^3*F21+C14*F11^3*F22+C35*F13^3*F21+C22*F12^3*F22+C24*F12^3*F21+2*C45*F11^2*F13*F22+2*C66*F12^2*F13*F23+2*C56*F12*F13^2*F21+2*C56*F11*F13^2*F22+C15*F11^3*F23+C16*F11^2*F13*F22+C25*F12^2*F11*F23+C25*F12^2*F13*F21+4*C56*F11*F13*F12*F23+C16*F11^2*F12*F23+3*C14*F11^2*F12*F21+2*C44*F11*F12^2*F21+3*C15*F11^2*F13*F21+C33*F13^3*F23+2*C34*F11*F12*F13*F23+4*C46*F11*F12*F13*F22+2*C16*F12*F13*F11*F21+C13*F11^2*F13*F23+C13*F13^2*F11*F21+2*C44*F11^2*F12*F22+3*C36*F12*F13^2*F23+3*C35*F11*F13^2*F23+2*C46*F11*F12^2*F23+2*C46*F12^2*F13*F21+2*C66*F12*F13^2*F22+C12*F12^2*F11*F21+C34*F13^2*F11*F22+C23*F12^2*F13*F23+C23*F13^2*F12*F22+C34*F13^2*F12*F21+3*C24*F11*F12^2*F22+C12*F11^2*F12*F22+4*C45*F11*F12*F13*F21+2*C55*F11^2*F13*F23+2*C25*F11*F13*F12*F22+2*C45*F11^2*F12*F23+2*C55*F11*F13^2*F21+3*C26*F12^2*F13*F22);
	    cout[1,5] = (4*C46*F11*F12*F13*F32+4*C56*F11*F13*F12*F33+2*C25*F11*F13*F12*F32+4*C45*F11*F12*F13*F31+2*C16*F12*F13*F11*F31+2*C66*F12*F13^2*F32+2*C66*F12^2*F13*F33+3*C26*F12^2*F13*F32+2*C46*F12^2*F13*F31+2*C46*F11*F12^2*F33+C24*F12^3*F31+C22*F12^3*F32+3*C15*F11^2*F13*F31+2*C55*F11^2*F13*F33+2*C55*F11*F13^2*F31+2*C56*F12*F13^2*F31+2*C56*F11*F13^2*F32+C26*F12^3*F33+C35*F13^3*F31+C36*F13^3*F32+C11*F11^3*F31+C14*F11^3*F32+2*C45*F11^2*F13*F32+C12*F12^2*F11*F31+C16*F11^2*F13*F32+C25*F12^2*F11*F33+C25*F12^2*F13*F31+C34*F13^2*F11*F32+2*C45*F11^2*F12*F33+C23*F12^2*F13*F33+C34*F13^2*F12*F31+C23*F13^2*F12*F32+3*C14*F12*F11^2*F31+3*C35*F11*F13^2*F33+2*C44*F11*F12^2*F31+2*C44*F11^2*F12*F32+C15*F11^3*F33+2*C34*F11*F12*F13*F33+C13*F13^2*F11*F31+C13*F11^2*F13*F33+3*C36*F12*F13^2*F33+C16*F11^2*F12*F33+3*C24*F11*F12^2*F32+C12*F11^2*F12*F32+C33*F13^3*F33);
	    cout[1,6] = (C22*F12^2*F22*F32+C24*F12^2*F22*F31+C24*F12^2*F21*F32+C12*F11^2*F22*F32+C11*F11^2*F21*F31+C12*F12^2*F21*F31+C14*F11^2*F21*F32+C14*F11^2*F22*F31+C15*F11^2*F23*F31+C16*F11^2*F22*F33+C23*F13^2*F22*F32+C13*F11^2*F23*F33+C16*F11^2*F23*F32+2*C56*F12*F13*F23*F31+2*C25*F11*F13*F22*F32+2*C34*F11*F12*F23*F33+2*C55*F13*F11*F23*F31+2*C35*F13*F11*F23*F33+2*C55*F13*F11*F21*F33+2*C36*F12*F13*F23*F33+2*C45*F11*F12*F23*F31+2*C45*F11*F12*F21*F33+2*C45*F11*F13*F21*F32+2*C45*F11*F13*F22*F31+2*C66*F12*F13*F22*F33+2*C24*F11*F12*F22*F32+2*C15*F11*F13*F21*F31+2*C16*F13*F12*F21*F31+2*C46*F11*F12*F22*F33+2*C46*F11*F12*F23*F32+2*C46*F13*F12*F21*F32+2*C46*F13*F12*F22*F31+2*C26*F12*F13*F22*F32+2*C14*F11*F12*F21*F31+2*C44*F11*F12*F22*F31+2*C66*F12*F13*F23*F32+2*C56*F13*F12*F21*F33+2*C56*F13*F11*F22*F33+2*C44*F11*F12*F21*F32+2*C56*F13*F11*F23*F32+C26*F12^2*F23*F32+C15*F11^2*F21*F33+C36*F13^2*F23*F32+C35*F13^2*F21*F33+C23*F12^2*F23*F33+C33*F13^2*F23*F33+C36*F13^2*F22*F33+C26*F12^2*F22*F33+C13*F13^2*F21*F31+C34*F13^2*F21*F32+C34*F13^2*F22*F31+C25*F12^2*F21*F33+C25*F12^2*F23*F31+C35*F13^2*F23*F31);
	    cout[2,1] = (C33*F23^2*F13^2+C11*F21^2*F11^2+C22*F22^2*F12^2+C13*F21^2*F13^2+C12*F22^2*F11^2+C23*F23^2*F12^2+C23*F22^2*F13^2+C13*F23^2*F11^2+2*C24*F22^2*F11*F12+2*C35*F23^2*F11*F13+2*C35*F21*F13^2*F23+2*C36*F22*F13^2*F23+4*C46*F21*F12*F13*F22+2*C14*F21^2*F11*F12+4*C45*F21*F12*F11*F23+4*C46*F22*F11*F12*F23+4*C45*F21*F13*F11*F22+2*C14*F21*F11^2*F22+4*C56*F21*F13*F12*F23+2*C36*F23^2*F12*F13+4*C56*F22*F13*F11*F23+4*C44*F21*F12*F11*F22+2*C15*F21*F11^2*F23+4*C66*F22*F13*F12*F23+2*C15*F21^2*F11*F13+2*C24*F21*F12^2*F22+4*C55*F21*F13*F11*F23+2*C26*F22*F12^2*F23+2*C26*F22^2*F12*F13+2*C16*F21^2*F12*F13+2*C25*F22^2*F11*F13+2*C34*F23^2*F11*F12+2*C34*F21*F22*F13^2+2*C25*F21*F23*F12^2+2*C16*F22*F23*F11^2+C12*F21^2*F12^2);
	    cout[2,2] = (C11*F21^4+4*C14*F21^3*F22+4*C15*F21^3*F23+2*C12*F21^2*F22^2+4*C16*F21^2*F22*F23+2*C13*F21^2*F23^2+4*C44*F22^2*F21^2+8*C45*F22*F21^2*F23+4*C24*F22^3*F21+8*C46*F22^2*F21*F23+4*C34*F21*F22*F23^2+4*C55*F21^2*F23^2+4*C25*F21*F23*F22^2+8*C56*F21*F23^2*F22+4*C35*F21*F23^3+C22*F22^4+4*C26*F22^3*F23+2*C23*F22^2*F23^2+4*C66*F22^2*F23^2+4*C36*F22*F23^3+C33*F23^4);
	    cout[2,3] = (2*C25*F21*F23*F32^2+2*C25*F22^2*F31*F33+2*C34*F21*F22*F33^2+2*C34*F23^2*F31*F32+2*C26*F22^2*F32*F33+2*C35*F23*F21*F33^2+2*C35*F23^2*F31*F33+2*C26*F23*F22*F32^2+2*C36*F23*F22*F33^2+2*C36*F23^2*F32*F33+2*C24*F22^2*F31*F32+2*C24*F21*F22*F32^2+2*C15*F21*F23*F31^2+2*C14*F21*F22*F31^2+2*C15*F21^2*F31*F33+2*C16*F23*F22*F31^2+C13*F21^2*F33^2+C13*F23^2*F31^2+C23*F23^2*F32^2+C23*F22^2*F33^2+C12*F22^2*F31^2+C33*F23^2*F33^2+4*C46*F21*F22*F32*F33+4*C55*F21*F23*F31*F33+4*C56*F23*F22*F31*F33+4*C56*F21*F23*F32*F33+4*C66*F23*F22*F32*F33+4*C45*F21*F23*F31*F32+4*C45*F21*F22*F31*F33+4*C44*F21*F22*F31*F32+4*C46*F23*F22*F31*F32+C11*F21^2*F31^2+C12*F21^2*F32^2+C22*F22^2*F32^2+2*C16*F21^2*F32*F33+2*C14*F21^2*F31*F32);
	    cout[2,4] = (C26*F22^3*F13+C11*F21^3*F11+C33*F23^3*F13+C24*F22^3*F11+C36*F23^3*F12+C15*F21^3*F13+C22*F22^3*F12+4*C46*F21*F12*F22*F23+C35*F23^3*F11+C25*F23*F11*F22^2+2*C44*F22^2*F11*F21+2*C46*F22^2*F13*F21+2*C44*F21^2*F12*F22+3*C15*F21^2*F11*F23+2*C25*F22*F12*F21*F23+4*C45*F22*F11*F21*F23+3*C35*F23^2*F13*F21+2*C45*F21^2*F12*F23+2*C45*F21^2*F13*F22+C13*F21*F11*F23^2+2*C55*F21^2*F13*F23+3*C26*F22^2*F12*F23+C12*F21*F11*F22^2+C13*F23*F13*F21^2+C34*F22*F11*F23^2+C12*F22*F12*F21^2+C23*F22*F12*F23^2+C16*F22*F13*F21^2+C34*F21*F12*F23^2+C23*F23*F13*F22^2+2*C46*F22^2*F11*F23+C16*F23*F12*F21^2+2*C34*F23*F13*F21*F22+2*C55*F23^2*F11*F21+2*C56*F23^2*F12*F21+C25*F21*F13*F22^2+2*C16*F21*F11*F22*F23+3*C24*F21*F12*F22^2+3*C36*F23^2*F13*F22+2*C56*F23^2*F11*F22+2*C66*F22^2*F13*F23+4*C56*F21*F13*F22*F23+3*C14*F21^2*F11*F22+2*C66*F23^2*F12*F22+C14*F21^3*F12);
	    cout[2,5] = (C35*F23^2*F13*F31+C11*F21^2*F11*F31+C26*F22^2*F13*F32+C26*F22^2*F12*F33+C14*F21^2*F12*F31+2*C46*F22*F11*F23*F32+2*C56*F23*F11*F22*F33+2*C46*F21*F12*F22*F33+2*C56*F23*F12*F21*F33+2*C56*F21*F13*F23*F32+2*C56*F22*F13*F23*F31+2*C66*F23*F12*F22*F33+C14*F21^2*F11*F32+2*C66*F22*F13*F23*F32+C36*F23^2*F13*F32+2*C45*F23*F11*F21*F32+C36*F23^2*F12*F33+C22*F22^2*F12*F32+C24*F22^2*F11*F32+C33*F23^2*F13*F33+C24*F22^2*F12*F31+C35*F23^2*F11*F33+2*C14*F21*F11*F22*F31+2*C15*F21*F11*F23*F31+2*C26*F23*F12*F22*F32+2*C35*F23*F13*F21*F33+2*C24*F21*F12*F22*F32+2*C45*F22*F11*F21*F33+2*C36*F22*F13*F23*F33+2*C45*F21*F12*F23*F31+2*C45*F21*F13*F22*F31+C15*F21^2*F13*F31+2*C55*F23*F11*F21*F33+C15*F21^2*F11*F33+2*C55*F21*F13*F23*F31+2*C46*F22*F13*F21*F32+2*C46*F23*F12*F22*F31+2*C44*F21*F12*F22*F31+2*C44*F22*F11*F21*F32+2*C25*F21*F23*F12*F32+C25*F22^2*F11*F33+C23*F22^2*F13*F33+C23*F23^2*F12*F32+C16*F21^2*F13*F32+C13*F23^2*F11*F31+C34*F23^2*F11*F32+C25*F22^2*F13*F31+2*C16*F22*F23*F11*F31+C13*F21^2*F13*F33+C34*F23^2*F12*F31+C12*F21^2*F12*F32+C12*F22^2*F11*F31+C16*F21^2*F12*F33+2*C34*F21*F22*F13*F33);
	    cout[2,6] = (C11*F21^3*F31+3*C15*F21^2*F23*F31+2*C66*F22^2*F23*F33+2*C45*F21^2*F23*F32+2*C45*F21^2*F22*F33+2*C55*F21*F23^2*F31+2*C44*F22^2*F21*F31+2*C66*F22*F23^2*F32+2*C44*F22*F21^2*F32+3*C14*F22*F21^2*F31+2*C55*F21^2*F23*F33+2*C46*F22^2*F23*F31+3*C26*F22^2*F23*F32+3*C35*F21*F23^2*F33+2*C46*F22^2*F21*F33+3*C36*F22*F23^2*F33+2*C56*F21*F23^2*F32+2*C56*F22*F23^2*F31+C25*F22^2*F23*F31+C34*F23^2*F22*F31+C25*F22^2*F21*F33+C34*F23^2*F21*F32+C36*F23^3*F32+C26*F22^3*F33+C33*F23^3*F33+C14*F21^3*F32+C15*F21^3*F33+C22*F22^3*F32+3*C24*F22^2*F21*F32+2*C25*F21*F23*F22*F32+2*C16*F22*F23*F21*F31+4*C46*F22*F21*F23*F32+4*C56*F21*F23*F22*F33+2*C34*F22*F21*F23*F33+C13*F21^2*F23*F33+C12*F22^2*F21*F31+C13*F23^2*F21*F31+C12*F21^2*F22*F32+C24*F22^3*F31+C23*F23^2*F22*F32+C35*F23^3*F31+C16*F21^2*F23*F32+C23*F22^2*F23*F33+C16*F21^2*F22*F33+4*C45*F21*F22*F23*F31);
	    cout[3,1] = (C13*F33^2*F11^2+C23*F33^2*F12^2+C13*F31^2*F13^2+C23*F32^2*F13^2+C11*F31^2*F11^2+C33*F33^2*F13^2+C12*F31^2*F12^2+C22*F32^2*F12^2+4*C66*F32*F33*F12*F13+2*C14*F31^2*F11*F12+2*C34*F33^2*F11*F12+2*C15*F31^2*F11*F13+2*C36*F33^2*F12*F13+2*C36*F32*F33*F13^2+2*C14*F31*F32*F11^2+2*C15*F31*F33*F11^2+4*C45*F31*F33*F11*F12+4*C55*F31*F33*F11*F13+4*C46*F32*F33*F11*F12+2*C24*F32^2*F11*F12+4*C45*F31*F32*F11*F13+2*C35*F33^2*F11*F13+2*C25*F32^2*F11*F13+2*C35*F31*F33*F13^2+2*C25*F31*F33*F12^2+2*C34*F31*F32*F13^2+2*C16*F32*F33*F11^2+2*C26*F32^2*F12*F13+2*C26*F32*F33*F12^2+2*C24*F31*F32*F12^2+4*C44*F31*F32*F11*F12+4*C46*F31*F32*F12*F13+4*C56*F31*F33*F12*F13+4*C56*F32*F33*F11*F13+2*C16*F31^2*F12*F13+C12*F32^2*F11^2);
	    cout[3,2] = (C22*F32^2*F22^2+C33*F33^2*F23^2+4*C45*F31*F22*F21*F33+4*C45*F31*F23*F21*F32+C11*F31^2*F21^2+C23*F33^2*F22^2+C23*F32^2*F23^2+C12*F31^2*F22^2+C13*F31^2*F23^2+C13*F33^2*F21^2+2*C26*F32*F22^2*F33+4*C56*F31*F23*F22*F33+2*C26*F32^2*F22*F23+4*C56*F32*F23*F21*F33+4*C66*F32*F23*F22*F33+2*C24*F31*F22^2*F32+2*C35*F33^2*F21*F23+C12*F32^2*F21^2+2*C36*F33^2*F22*F23+2*C14*F31^2*F21*F22+2*C14*F31*F21^2*F32+2*C24*F32^2*F21*F22+2*C15*F31^2*F21*F23+2*C35*F31*F23^2*F33+2*C36*F32*F23^2*F33+4*C44*F31*F22*F21*F32+2*C15*F31*F21^2*F33+4*C55*F31*F23*F21*F33+4*C46*F31*F22*F23*F32+4*C46*F32*F21*F22*F33+2*C34*F33^2*F21*F22+2*C34*F31*F32*F23^2+2*C25*F31*F33*F22^2+2*C25*F32^2*F21*F23+2*C16*F31^2*F22*F23+2*C16*F32*F33*F21^2);
	    cout[3,3] = (C11*F31^4+4*C14*F31^3*F32+4*C15*F31^3*F33+2*C12*F31^2*F32^2+4*C16*F31^2*F32*F33+2*C13*F31^2*F33^2+4*C44*F31^2*F32^2+8*C45*F31^2*F32*F33+4*C24*F31*F32^3+8*C46*F31*F32^2*F33+4*C34*F31*F32*F33^2+4*C55*F33^2*F31^2+4*C25*F33*F31*F32^2+8*C56*F32*F33^2*F31+4*C35*F33^3*F31+C22*F32^4+4*C26*F32^3*F33+2*C23*F32^2*F33^2+4*C66*F32^2*F33^2+4*C36*F32*F33^3+C33*F33^4);
	    cout[3,4] = (C26*F22*F32^2*F13+C14*F21*F31^2*F12+C14*F22*F31^2*F11+C35*F21*F33^2*F13+C35*F23*F33^2*F11+C26*F23*F32^2*F12+C33*F23*F33^2*F13+2*C56*F23*F32*F11*F33+C11*F21*F31^2*F11+C22*F22*F32^2*F12+2*C25*F31*F33*F12*F22+2*C16*F32*F33*F11*F21+2*C34*F31*F32*F13*F23+C12*F31^2*F12*F22+C34*F33^2*F11*F22+C23*F32^2*F13*F23+C16*F31^2*F13*F22+C13*F31^2*F13*F23+C13*F33^2*F11*F21+C25*F32^2*F13*F21+C25*F32^2*F11*F23+C12*F32^2*F11*F21+C16*F31^2*F12*F23+C34*F33^2*F12*F21+C23*F33^2*F12*F22+C24*F22*F32^2*F11+C15*F23*F31^2*F11+2*C46*F23*F32*F12*F31+C36*F23*F33^2*F12+2*C46*F22*F31*F13*F32+2*C46*F22*F33*F11*F32+2*C46*F21*F32*F12*F33+2*C55*F21*F33*F13*F31+2*C55*F23*F31*F11*F33+2*C56*F22*F33*F13*F31+2*C56*F23*F31*F12*F33+2*C56*F21*F33*F13*F32+2*C66*F22*F33*F13*F32+2*C66*F23*F32*F12*F33+C24*F21*F32^2*F12+2*C45*F22*F31*F11*F33+2*C45*F21*F33*F12*F31+2*C45*F21*F32*F13*F31+C15*F21*F31^2*F13+C36*F22*F33^2*F13+2*C26*F22*F32*F12*F33+2*C14*F21*F31*F11*F32+2*C35*F23*F31*F13*F33+2*C36*F23*F32*F13*F33+2*C24*F22*F31*F12*F32+2*C15*F21*F31*F11*F33+2*C45*F23*F31*F11*F32+2*C44*F22*F31*F11*F32+2*C44*F21*F32*F12*F31);
	    cout[3,5] = (C26*F32^3*F13+C11*F31^3*F11+C36*F33^3*F12+C35*F33^3*F11+C14*F31^3*F12+C15*F31^3*F13+C24*F32^3*F11+C22*F32^3*F12+C33*F33^3*F13+4*C46*F31*F12*F32*F33+4*C56*F31*F13*F32*F33+2*C34*F33*F13*F31*F32+4*C45*F32*F11*F31*F33+2*C25*F32*F12*F31*F33+2*C16*F31*F11*F32*F33+2*C44*F31^2*F12*F32+3*C36*F32*F13*F33^2+2*C44*F32^2*F11*F31+3*C24*F31*F12*F32^2+2*C45*F31^2*F13*F32+2*C45*F31^2*F12*F33+2*C55*F31^2*F13*F33+C34*F32*F11*F33^2+C34*F31*F12*F33^2+2*C55*F33^2*F11*F31+C23*F33*F13*F32^2+C25*F33*F11*F32^2+C23*F32*F12*F33^2+C25*F31*F13*F32^2+3*C15*F31^2*F11*F33+C16*F32*F13*F31^2+C16*F33*F12*F31^2+2*C66*F33^2*F12*F32+C13*F31*F11*F33^2+2*C46*F32^2*F11*F33+2*C56*F33^2*F12*F31+2*C56*F33^2*F11*F32+3*C26*F32^2*F12*F33+2*C46*F32^2*F13*F31+3*C14*F31^2*F11*F32+2*C66*F32^2*F13*F33+3*C35*F31*F13*F33^2+C13*F33*F13*F31^2+C12*F32*F12*F31^2+C12*F31*F11*F32^2);
	    cout[3,6] = (C26*F32^3*F23+C22*F32^3*F22+C15*F31^3*F23+C11*F31^3*F21+C33*F33^3*F23+C35*F33^3*F21+C36*F33^3*F22+4*C46*F31*F22*F32*F33+2*C34*F33*F23*F31*F32+2*C56*F33^2*F22*F31+2*C56*F33^2*F21*F32+2*C16*F31*F21*F32*F33+2*C45*F31^2*F22*F33+2*C66*F32^2*F23*F33+2*C55*F31^2*F23*F33+3*C36*F32*F23*F33^2+2*C44*F31^2*F22*F32+2*C44*F32^2*F21*F31+3*C15*F31^2*F21*F33+4*C45*F32*F21*F31*F33+2*C25*F32*F22*F31*F33+4*C56*F31*F23*F32*F33+2*C45*F31^2*F23*F32+2*C55*F33^2*F21*F31+3*C14*F31^2*F21*F32+3*C35*F31*F23*F33^2+3*C26*F32^2*F22*F33+2*C46*F32^2*F23*F31+2*C46*F32^2*F21*F33+2*C66*F33^2*F22*F32+C23*F33*F23*F32^2+C12*F31*F21*F32^2+C34*F32*F21*F33^2+C12*F32*F22*F31^2+C34*F31*F22*F33^2+C13*F31*F21*F33^2+C25*F31*F23*F32^2+C13*F33*F23*F31^2+C25*F33*F21*F32^2+C16*F32*F23*F31^2+C23*F32*F22*F33^2+C16*F33*F22*F31^2+3*C24*F31*F22*F32^2+C14*F31^3*F22+C24*F32^3*F21);
	    cout[4,1] = (C26*F23*F12^3+C24*F21*F12^3+C35*F21*F13^3+C36*F22*F13^3+C22*F22*F12^3+C33*F23*F13^3+C14*F22*F11^3+C15*F23*F11^3+C11*F21*F11^3+2*C25*F22*F12*F11*F13+4*C45*F21*F12*F11*F13+2*C16*F21*F11*F12*F13+4*C46*F22*F11*F12*F13+4*C56*F23*F11*F12*F13+2*C34*F23*F13*F11*F12+C25*F21*F13*F12^2+C16*F23*F12*F11^2+C16*F22*F13*F11^2+C13*F23*F13*F11^2+C13*F21*F11*F13^2+C34*F21*F12*F13^2+C34*F22*F11*F13^2+C25*F23*F11*F12^2+C23*F22*F12*F13^2+C12*F21*F11*F12^2+C12*F22*F12*F11^2+2*C46*F21*F12^2*F13+3*C36*F23*F12*F13^2+3*C24*F22*F11*F12^2+3*C26*F22*F12^2*F13+2*C56*F21*F13^2*F12+2*C56*F22*F13^2*F11+2*C66*F23*F12^2*F13+3*C14*F21*F11^2*F12+2*C44*F21*F12^2*F11+2*C44*F22*F11^2*F12+2*C66*F22*F13^2*F12+C23*F23*F13*F12^2+2*C55*F23*F11^2*F13+2*C55*F21*F13^2*F11+3*C15*F21*F11^2*F13+2*C45*F22*F11^2*F13+2*C45*F23*F11^2*F12+2*C46*F23*F12^2*F11+3*C35*F23*F11*F13^2);
	    cout[4,2] = (C26*F22^3*F13+C11*F21^3*F11+C33*F23^3*F13+C24*F22^3*F11+C36*F23^3*F12+C15*F21^3*F13+C22*F22^3*F12+4*C46*F21*F12*F22*F23+C35*F23^3*F11+C25*F23*F11*F22^2+2*C44*F22^2*F11*F21+2*C46*F22^2*F13*F21+2*C44*F21^2*F12*F22+3*C15*F21^2*F11*F23+2*C25*F22*F12*F21*F23+4*C45*F22*F11*F21*F23+3*C35*F23^2*F13*F21+2*C45*F21^2*F12*F23+2*C45*F21^2*F13*F22+C13*F21*F11*F23^2+2*C55*F21^2*F13*F23+3*C26*F22^2*F12*F23+C12*F21*F11*F22^2+C13*F23*F13*F21^2+C34*F22*F11*F23^2+C12*F22*F12*F21^2+C23*F22*F12*F23^2+C16*F22*F13*F21^2+C34*F21*F12*F23^2+C23*F23*F13*F22^2+2*C46*F22^2*F11*F23+C16*F23*F12*F21^2+2*C34*F23*F13*F21*F22+2*C55*F23^2*F11*F21+2*C56*F23^2*F12*F21+C25*F21*F13*F22^2+2*C16*F21*F11*F22*F23+3*C24*F21*F12*F22^2+3*C36*F23^2*F13*F22+2*C56*F23^2*F11*F22+2*C66*F22^2*F13*F23+4*C56*F21*F13*F22*F23+3*C14*F21^2*F11*F22+2*C66*F23^2*F12*F22+C14*F21^3*F12);
	    cout[4,3] = (C26*F12*F23*F32^2+C26*F13*F22*F32^2+C24*F11*F22*F32^2+C36*F13*F22*F33^2+2*C35*F13*F23*F31*F33+2*C66*F12*F23*F32*F33+2*C45*F11*F22*F31*F33+2*C15*F11*F21*F31*F33+2*C55*F13*F21*F31*F33+2*C26*F12*F22*F32*F33+2*C46*F12*F23*F31*F32+2*C45*F11*F23*F31*F32+2*C44*F11*F22*F31*F32+2*C44*F12*F21*F31*F32+2*C36*F13*F23*F32*F33+2*C55*F11*F23*F31*F33+2*C24*F12*F22*F31*F32+2*C45*F12*F21*F31*F33+2*C46*F13*F22*F31*F32+2*C45*F13*F21*F31*F32+2*C56*F12*F23*F31*F33+C36*F12*F23*F33^2+C11*F11*F21*F31^2+C14*F11*F22*F31^2+C33*F13*F23*F33^2+C14*F12*F21*F31^2+C35*F11*F23*F33^2+C22*F12*F22*F32^2+C35*F13*F21*F33^2+2*C66*F13*F22*F32*F33+2*C56*F13*F21*F32*F33+2*C56*F11*F23*F32*F33+2*C56*F13*F22*F31*F33+C15*F11*F23*F31^2+C15*F13*F21*F31^2+C24*F12*F21*F32^2+2*C46*F11*F22*F32*F33+2*C46*F12*F21*F32*F33+C23*F23*F13*F32^2+C23*F22*F12*F33^2+C34*F21*F12*F33^2+C34*F22*F11*F33^2+C25*F23*F11*F32^2+C25*F21*F13*F32^2+2*C16*F21*F11*F32*F33+C13*F23*F13*F31^2+C16*F22*F13*F31^2+2*C34*F23*F13*F31*F32+C12*F21*F11*F32^2+C16*F23*F12*F31^2+C12*F22*F12*F31^2+2*C25*F22*F12*F31*F33+C13*F21*F11*F33^2+2*C14*F11*F21*F31*F32);
	    cout[4,4] = (C33*F23^2*F13^2+C44*F22^2*F11^2+C44*F21^2*F12^2+C66*F22^2*F13^2+C66*F23^2*F12^2+C11*F21^2*F11^2+C22*F22^2*F12^2+C55*F21^2*F13^2+C55*F23^2*F11^2+2*C23*F22*F12*F13*F23+2*C34*F22*F11*F13*F23+2*C24*F22^2*F11*F12+2*C35*F23^2*F11*F13+2*C35*F21*F13^2*F23+2*C36*F22*F13^2*F23+2*C46*F21*F12*F13*F22+2*C14*F21^2*F11*F12+2*C45*F21*F12*F11*F23+2*C46*F22*F11*F12*F23+2*C45*F21*F13*F11*F22+2*C14*F21*F11^2*F22+2*C56*F21*F13*F12*F23+2*C36*F23^2*F12*F13+2*C56*F22*F13*F11*F23+2*C44*F21*F12*F11*F22+2*C15*F21*F11^2*F23+2*C25*F22*F12*F11*F23+2*C25*F21*F13*F12*F22+2*C16*F21*F11*F12*F23+2*C16*F21*F11*F13*F22+2*C66*F22*F13*F12*F23+2*C12*F21*F11*F12*F22+2*C15*F21^2*F11*F13+2*C56*F23^2*F11*F12+2*C46*F21*F12^2*F23+2*C24*F21*F12^2*F22+2*C13*F21*F11*F13*F23+2*C46*F22^2*F11*F13+2*C34*F21*F12*F13*F23+2*C45*F22*F11^2*F23+2*C55*F21*F13*F11*F23+2*C45*F21^2*F12*F13+2*C56*F21*F13^2*F22+2*C26*F22*F12^2*F23+2*C26*F22^2*F12*F13);
	    cout[4,5] = (C11*F21*F11^2*F31+C22*F22*F12^2*F32+C26*F23*F12^2*F32+C15*F21*F11^2*F33+C26*F22*F12^2*F33+C56*F22*F13^2*F31+C66*F22*F13^2*F32+C66*F23*F12^2*F33+C56*F21*F13^2*F32+C45*F22*F11^2*F33+C45*F23*F11^2*F32+C55*F21*F13^2*F31+C55*F23*F11^2*F33+C15*F23*F11^2*F31+C14*F21*F11^2*F32+C14*F22*F11^2*F31+C44*F21*F12^2*F31+C44*F22*F11^2*F32+C46*F23*F12^2*F31+C36*F22*F13^2*F33+C46*F21*F12^2*F33+C36*F23*F13^2*F32+C35*F21*F13^2*F33+C35*F23*F13^2*F31+C33*F23*F13^2*F33+C24*F21*F12^2*F32+C24*F22*F12^2*F31+C23*F22*F12*F13*F33+C23*F23*F13*F12*F32+C46*F22*F11*F12*F33+C46*F23*F12*F11*F32+C46*F22*F13*F12*F31+C46*F21*F12*F13*F32+C12*F21*F11*F12*F32+C12*F22*F12*F11*F31+C16*F22*F13*F11*F31+C56*F23*F12*F13*F31+C56*F23*F11*F13*F32+C56*F21*F13*F12*F33+C56*F22*F13*F11*F33+C45*F23*F11*F12*F31+C66*F22*F13*F12*F33+C66*F23*F12*F13*F32+C25*F21*F13*F12*F32+C25*F22*F12*F11*F33+C25*F22*F12*F13*F31+C25*F23*F11*F12*F32+C45*F22*F11*F13*F31+C45*F21*F12*F11*F33+C45*F21*F13*F11*F32+C13*F21*F11*F13*F33+C13*F23*F13*F11*F31+C55*F21*F13*F11*F33+2*C24*F22*F11*F12*F32+2*C15*F21*F11*F13*F31+2*C26*F22*F12*F13*F32+2*C56*F23*F11*F12*F33+2*C45*F21*F12*F13*F31+2*C14*F21*F11*F12*F31+2*C36*F23*F12*F13*F33+2*C46*F22*F11*F13*F32+2*C35*F23*F11*F13*F33+C55*F23*F11*F13*F31+C16*F21*F11*F13*F32+C16*F21*F11*F12*F33+C16*F23*F12*F11*F31+C34*F22*F11*F13*F33+C34*F21*F12*F13*F33+C34*F23*F13*F11*F32+C34*F23*F13*F12*F31+C44*F21*F12*F11*F32+C44*F22*F11*F12*F31);
	    cout[4,6] = (C35*F23^2*F13*F31+C46*F22^2*F13*F31+C11*F21^2*F11*F31+C26*F22^2*F13*F32+C44*F22^2*F11*F31+C26*F22^2*F12*F33+C44*F21^2*F12*F32+C14*F21^2*F12*F31+C46*F22*F11*F23*F32+C12*F22*F12*F21*F31+C56*F23*F11*F22*F33+C46*F21*F12*F22*F33+C56*F23*F12*F21*F33+C56*F21*F13*F23*F32+C12*F21*F11*F22*F32+C56*F22*F13*F23*F31+C56*F23^2*F12*F31+C66*F23*F12*F22*F33+C14*F21^2*F11*F32+C66*F22*F13*F23*F32+C36*F23^2*F13*F32+C13*F21*F11*F23*F33+C13*F23*F13*F21*F31+C25*F23*F11*F22*F32+C45*F23*F11*F21*F32+C25*F22*F12*F21*F33+C25*F22*F12*F23*F31+C55*F23^2*F11*F31+C36*F23^2*F12*F33+C22*F22^2*F12*F32+C24*F22^2*F11*F32+C33*F23^2*F13*F33+C24*F22^2*F12*F31+C45*F21^2*F12*F33+C66*F23^2*F12*F32+C35*F23^2*F11*F33+C56*F23^2*F11*F32+C66*F22^2*F13*F33+C34*F21*F12*F23*F33+2*C14*F21*F11*F22*F31+2*C15*F21*F11*F23*F31+2*C26*F23*F12*F22*F32+2*C35*F23*F13*F21*F33+2*C45*F22*F11*F23*F31+2*C46*F23*F12*F21*F32+2*C56*F21*F13*F22*F33+2*C24*F21*F12*F22*F32+C45*F22*F11*F21*F33+2*C36*F22*F13*F23*F33+C25*F21*F13*F22*F32+C45*F21^2*F13*F32+C45*F21*F12*F23*F31+C45*F21*F13*F22*F31+C46*F22^2*F11*F33+C15*F21^2*F13*F31+C16*F22*F13*F21*F31+C55*F23*F11*F21*F33+C16*F21*F11*F22*F33+C15*F21^2*F11*F33+C34*F23*F13*F22*F31+C16*F21*F11*F23*F32+C55*F21*F13*F23*F31+C16*F23*F12*F21*F31+C34*F22*F11*F23*F33+C23*F23*F13*F22*F32+C46*F22*F13*F21*F32+C34*F23*F13*F21*F32+C46*F23*F12*F22*F31+C44*F21*F12*F22*F31+C55*F21^2*F13*F33+C44*F22*F11*F21*F32+C23*F22*F12*F23*F33);
	    cout[5,1] = (C26*F33*F12^3+C11*F31*F11^3+C35*F31*F13^3+C36*F32*F13^3+C24*F31*F12^3+C22*F32*F12^3+C33*F33*F13^3+C14*F32*F11^3+2*C55*F31*F13^2*F11+3*C36*F33*F12*F13^2+2*C46*F33*F12^2*F11+3*C14*F31*F11^2*F12+C12*F32*F12*F11^2+2*C16*F31*F11*F12*F13+4*C46*F32*F11*F12*F13+4*C56*F33*F11*F12*F13+2*C55*F33*F11^2*F13+3*C15*F31*F11^2*F13+2*C46*F31*F12^2*F13+2*C56*F31*F13^2*F12+2*C66*F33*F12^2*F13+3*C35*F33*F11*F13^2+2*C45*F33*F11^2*F12+2*C45*F32*F11^2*F13+2*C44*F31*F12^2*F11+2*C44*F32*F11^2*F12+3*C26*F32*F12^2*F13+2*C34*F33*F13*F11*F12+2*C25*F32*F12*F11*F13+4*C45*F31*F12*F11*F13+C16*F33*F12*F11^2+2*C56*F32*F13^2*F11+C13*F31*F11*F13^2+C13*F33*F13*F11^2+C16*F32*F13*F11^2+2*C66*F32*F13^2*F12+C25*F33*F11*F12^2+C25*F31*F13*F12^2+C15*F33*F11^3+C12*F31*F11*F12^2+C34*F32*F11*F13^2+C23*F32*F12*F13^2+C23*F33*F13*F12^2+3*C24*F32*F11*F12^2+C34*F31*F12*F13^2);
	    cout[5,2] = (C24*F22^2*F32*F11+C26*F22^2*F33*F12+C26*F22^2*F32*F13+C35*F23^2*F31*F13+C35*F23^2*F33*F11+C36*F23^2*F33*F12+C11*F21^2*F31*F11+C14*F21^2*F32*F11+C33*F23^2*F33*F13+C14*F21^2*F31*F12+C15*F21^2*F33*F11+C15*F21^2*F31*F13+C36*F23^2*F32*F13+C24*F22^2*F31*F12+C22*F22^2*F32*F12+2*C55*F23*F31*F13*F21+2*C55*F21*F33*F11*F23+2*C35*F21*F33*F13*F23+2*C14*F21*F31*F11*F22+2*C36*F22*F33*F13*F23+2*C24*F21*F32*F12*F22+2*C15*F21*F31*F11*F23+2*C26*F22*F32*F12*F23+2*C45*F21*F32*F11*F23+2*C45*F22*F31*F13*F21+2*C45*F23*F31*F12*F21+2*C66*F22*F33*F12*F23+2*C56*F22*F33*F11*F23+2*C66*F23*F32*F13*F22+2*C56*F23*F31*F13*F22+2*C56*F21*F33*F12*F23+2*C56*F23*F32*F13*F21+2*C45*F21*F33*F11*F22+2*C46*F22*F33*F12*F21+2*C46*F23*F32*F11*F22+2*C46*F21*F32*F13*F22+2*C46*F22*F31*F12*F23+2*C44*F22*F31*F12*F21+2*C44*F21*F32*F11*F22+C13*F33*F13*F21^2+C23*F33*F13*F22^2+C23*F32*F12*F23^2+C34*F31*F12*F23^2+C34*F32*F11*F23^2+C13*F31*F11*F23^2+2*C16*F31*F11*F22*F23+2*C34*F33*F13*F21*F22+2*C25*F32*F12*F21*F23+C16*F33*F12*F21^2+C25*F33*F11*F22^2+C25*F31*F13*F22^2+C16*F32*F13*F21^2+C12*F32*F12*F21^2+C12*F31*F11*F22^2);
	    cout[5,3] = (C26*F32^3*F13+C11*F31^3*F11+C36*F33^3*F12+C35*F33^3*F11+C14*F31^3*F12+C15*F31^3*F13+C24*F32^3*F11+C22*F32^3*F12+C33*F33^3*F13+4*C46*F31*F12*F32*F33+4*C56*F31*F13*F32*F33+2*C34*F33*F13*F31*F32+4*C45*F32*F11*F31*F33+2*C25*F32*F12*F31*F33+2*C16*F31*F11*F32*F33+2*C44*F31^2*F12*F32+3*C36*F32*F13*F33^2+2*C44*F32^2*F11*F31+3*C24*F31*F12*F32^2+2*C45*F31^2*F13*F32+2*C45*F31^2*F12*F33+2*C55*F31^2*F13*F33+C34*F32*F11*F33^2+C34*F31*F12*F33^2+2*C55*F33^2*F11*F31+C23*F33*F13*F32^2+C25*F33*F11*F32^2+C23*F32*F12*F33^2+C25*F31*F13*F32^2+3*C15*F31^2*F11*F33+C16*F32*F13*F31^2+C16*F33*F12*F31^2+2*C66*F33^2*F12*F32+C13*F31*F11*F33^2+2*C46*F32^2*F11*F33+2*C56*F33^2*F12*F31+2*C56*F33^2*F11*F32+3*C26*F32^2*F12*F33+2*C46*F32^2*F13*F31+3*C14*F31^2*F11*F32+2*C66*F32^2*F13*F33+3*C35*F31*F13*F33^2+C13*F33*F13*F31^2+C12*F32*F12*F31^2+C12*F31*F11*F32^2);
	    cout[5,4] = (C46*F33*F12^2*F21+C44*F32*F11^2*F22+C45*F33*F11^2*F22+C45*F32*F11^2*F23+C46*F31*F12^2*F23+C11*F21*F11^2*F31+C22*F22*F12^2*F32+C26*F23*F12^2*F32+C15*F21*F11^2*F33+C12*F31*F11*F12*F22+C34*F33*F13*F12*F21+C12*F32*F12*F11*F21+2*C45*F31*F12*F13*F21+C26*F22*F12^2*F33+C13*F33*F13*F11*F21+2*C46*F32*F11*F13*F22+C34*F33*F13*F11*F22+C56*F32*F13^2*F21+C56*F31*F13^2*F22+C66*F32*F13^2*F22+C55*F33*F11^2*F23+C23*F33*F13*F12*F22+C34*F32*F11*F13*F23+C34*F31*F12*F13*F23+C55*F31*F13^2*F21+C23*F32*F12*F13*F23+C13*F31*F11*F13*F23+C25*F32*F12*F13*F21+C25*F32*F12*F11*F23+C25*F31*F13*F12*F22+2*C56*F33*F11*F12*F23+C25*F33*F11*F12*F22+C16*F33*F12*F11*F21+C16*F31*F11*F13*F22+C16*F31*F11*F12*F23+C66*F33*F12^2*F23+C15*F23*F11^2*F31+C14*F21*F11^2*F32+C14*F22*F11^2*F31+C16*F32*F13*F11*F21+C36*F22*F13^2*F33+C36*F23*F13^2*F32+C35*F21*F13^2*F33+C35*F23*F13^2*F31+C33*F23*F13^2*F33+C24*F21*F12^2*F32+C24*F22*F12^2*F31+C46*F22*F11*F12*F33+C46*F23*F12*F11*F32+C46*F22*F13*F12*F31+C46*F21*F12*F13*F32+C56*F23*F12*F13*F31+C56*F23*F11*F13*F32+C56*F21*F13*F12*F33+C56*F22*F13*F11*F33+C45*F23*F11*F12*F31+C66*F22*F13*F12*F33+C66*F23*F12*F13*F32+C45*F22*F11*F13*F31+C45*F21*F12*F11*F33+C45*F21*F13*F11*F32+C55*F21*F13*F11*F33+C44*F31*F12^2*F21+2*C24*F22*F11*F12*F32+2*C15*F21*F11*F13*F31+2*C26*F22*F12*F13*F32+2*C14*F21*F11*F12*F31+2*C36*F23*F12*F13*F33+2*C35*F23*F11*F13*F33+C55*F23*F11*F13*F31+C44*F21*F12*F11*F32+C44*F22*F11*F12*F31);
	    cout[5,5] = (C66*F32^2*F13^2+C55*F31^2*F13^2+C44*F32^2*F11^2+C44*F31^2*F12^2+C55*F33^2*F11^2+C11*F31^2*F11^2+C66*F33^2*F12^2+2*C24*F31*F12^2*F32+2*C16*F31*F11*F13*F32+2*C16*F31*F11*F12*F33+2*C23*F32*F12*F13*F33+2*C36*F33^2*F12*F13+2*C14*F31^2*F11*F12+C33*F33^2*F13^2+2*C46*F31*F12^2*F33+2*C24*F32^2*F11*F12+2*C46*F32^2*F11*F13+2*C12*F31*F11*F12*F32+2*C46*F31*F12*F13*F32+2*C46*F32*F11*F12*F33+2*C26*F32*F12^2*F33+2*C35*F33^2*F11*F13+2*C36*F32*F13^2*F33+2*C14*F31*F11^2*F32+2*C35*F31*F13^2*F33+2*C26*F32^2*F12*F13+2*C56*F31*F13^2*F32+2*C56*F33^2*F11*F12+2*C15*F31^2*F11*F13+2*C15*F31*F11^2*F33+2*C45*F31*F12*F11*F33+2*C25*F32*F12*F11*F33+2*C66*F32*F13*F12*F33+2*C45*F31^2*F12*F13+2*C13*F31*F11*F13*F33+2*C56*F31*F13*F12*F33+2*C25*F31*F13*F12*F32+2*C44*F31*F12*F11*F32+2*C55*F31*F13*F11*F33+2*C34*F31*F12*F13*F33+2*C34*F32*F11*F13*F33+2*C45*F31*F13*F11*F32+2*C45*F32*F11^2*F33+2*C56*F32*F13*F11*F33+C22*F32^2*F12^2);
	    cout[5,6] = (C55*F23*F31^2*F13+C26*F22*F32^2*F13+C14*F21*F31^2*F12+C14*F22*F31^2*F11+C44*F21*F32^2*F11+C44*F22*F31^2*F12+C35*F21*F33^2*F13+C35*F23*F33^2*F11+C26*F23*F32^2*F12+C33*F23*F33^2*F13+C46*F23*F32^2*F11+C56*F23*F32*F11*F33+C11*F21*F31^2*F11+C66*F22*F33^2*F12+C22*F22*F32^2*F12+C45*F23*F31^2*F12+C45*F22*F31^2*F13+C66*F23*F32^2*F13+C55*F21*F33^2*F11+C56*F21*F33^2*F12+C56*F22*F33^2*F11+C24*F22*F32^2*F11+C15*F23*F31^2*F11+C23*F22*F32*F13*F33+C46*F23*F32*F12*F31+C36*F23*F33^2*F12+C12*F21*F31*F12*F32+C12*F22*F32*F11*F31+C46*F22*F31*F13*F32+C46*F22*F33*F11*F32+C46*F21*F32*F12*F33+C55*F21*F33*F13*F31+C55*F23*F31*F11*F33+C56*F22*F33*F13*F31+C56*F23*F31*F12*F33+C56*F21*F33*F13*F32+C66*F22*F33*F13*F32+C66*F23*F32*F12*F33+C24*F21*F32^2*F12+C45*F22*F31*F11*F33+C45*F21*F33*F12*F31+C45*F21*F32*F13*F31+C15*F21*F31^2*F13+C36*F22*F33^2*F13+2*C26*F22*F32*F12*F33+2*C56*F23*F31*F13*F32+2*C45*F21*F32*F11*F33+2*C14*F21*F31*F11*F32+2*C35*F23*F31*F13*F33+2*C36*F23*F32*F13*F33+2*C46*F22*F31*F12*F33+2*C24*F22*F31*F12*F32+2*C15*F21*F31*F11*F33+C45*F23*F31*F11*F32+C16*F23*F32*F11*F31+C13*F21*F31*F13*F33+C13*F23*F33*F11*F31+C16*F22*F33*F11*F31+C16*F21*F31*F13*F32+C16*F21*F31*F12*F33+C25*F23*F31*F12*F32+C34*F23*F33*F12*F31+C25*F22*F32*F11*F33+C25*F21*F33*F12*F32+C25*F22*F32*F13*F31+C23*F23*F33*F12*F32+C34*F22*F31*F13*F33+C34*F23*F33*F11*F32+C34*F21*F32*F13*F33+C44*F22*F31*F11*F32+C44*F21*F32*F12*F31+C46*F21*F32^2*F13);
	    cout[6,1] = (C35*F33*F21*F13^2+C35*F31*F23*F13^2+C34*F31*F22*F13^2+C36*F33*F22*F13^2+C36*F32*F23*F13^2+C33*F33*F23*F13^2+C12*F31*F21*F12^2+C12*F32*F22*F11^2+C24*F31*F22*F12^2+C24*F32*F21*F12^2+C22*F32*F22*F12^2+C15*F31*F23*F11^2+C15*F33*F21*F11^2+C25*F31*F23*F12^2+C25*F33*F21*F12^2+C13*F31*F21*F13^2+C13*F33*F23*F11^2+C26*F32*F23*F12^2+C34*F32*F21*F13^2+C26*F33*F22*F12^2+C23*F32*F22*F13^2+C16*F33*F22*F11^2+C23*F33*F23*F12^2+C11*F31*F21*F11^2+C16*F32*F23*F11^2+C14*F32*F21*F11^2+C14*F31*F22*F11^2+2*C66*F33*F22*F12*F13+2*C66*F32*F23*F12*F13+2*C24*F32*F22*F11*F12+2*C15*F31*F21*F11*F13+2*C45*F32*F21*F11*F13+2*C45*F31*F22*F11*F13+2*C45*F31*F23*F11*F12+2*C45*F33*F21*F11*F12+2*C25*F32*F22*F11*F13+2*C46*F33*F22*F11*F12+2*C55*F33*F21*F11*F13+2*C46*F32*F21*F12*F13+2*C46*F32*F23*F11*F12+2*C55*F31*F23*F11*F13+2*C34*F33*F23*F11*F12+2*C26*F32*F22*F12*F13+2*C46*F31*F22*F12*F13+2*C14*F31*F21*F11*F12+2*C44*F32*F21*F11*F12+2*C35*F33*F23*F11*F13+2*C56*F33*F22*F11*F13+2*C36*F33*F23*F12*F13+2*C56*F32*F23*F11*F13+2*C56*F31*F23*F12*F13+2*C56*F33*F21*F12*F13+2*C44*F31*F22*F11*F12+2*C16*F31*F21*F12*F13);
	    cout[6,2] = (C36*F32*F23^3+C24*F31*F22^3+3*C15*F31*F21^2*F23+3*C26*F32*F22^2*F23+2*C46*F31*F22^2*F23+2*C46*F33*F22^2*F21+3*C36*F33*F22*F23^2+2*C44*F31*F22^2*F21+2*C55*F31*F23^2*F21+2*C45*F33*F21^2*F22+3*C14*F31*F21^2*F22+C12*F31*F21*F22^2+C12*F32*F22*F21^2+2*C66*F33*F22^2*F23+2*C45*F32*F21^2*F23+C25*F31*F23*F22^2+C25*F33*F21*F22^2+C16*F33*F22*F21^2+C13*F31*F21*F23^2+C16*F32*F23*F21^2+2*C55*F33*F21^2*F23+3*C35*F33*F21*F23^2+C26*F33*F22^3+C15*F33*F21^3+3*C24*F32*F21*F22^2+C23*F32*F22*F23^2+C23*F33*F23*F22^2+2*C56*F31*F23^2*F22+C34*F31*F22*F23^2+C34*F32*F21*F23^2+2*C56*F32*F23^2*F21+C13*F33*F23*F21^2+C22*F32*F22^3+C11*F31*F21^3+C14*F32*F21^3+2*C34*F33*F23*F21*F22+C33*F33*F23^3+4*C46*F32*F21*F22*F23+4*C56*F33*F21*F22*F23+2*C25*F32*F22*F21*F23+4*C45*F31*F22*F21*F23+2*C66*F32*F23^2*F22+2*C16*F31*F21*F22*F23+2*C44*F32*F21^2*F22+C35*F31*F23^3);
	    cout[6,3] = (C26*F32^3*F23+C22*F32^3*F22+C15*F31^3*F23+C11*F31^3*F21+C33*F33^3*F23+C35*F33^3*F21+C36*F33^3*F22+4*C46*F31*F22*F32*F33+2*C34*F33*F23*F31*F32+2*C56*F33^2*F22*F31+2*C56*F33^2*F21*F32+2*C16*F31*F21*F32*F33+2*C45*F31^2*F22*F33+2*C66*F32^2*F23*F33+2*C55*F31^2*F23*F33+3*C36*F32*F23*F33^2+2*C44*F31^2*F22*F32+2*C44*F32^2*F21*F31+3*C15*F31^2*F21*F33+4*C45*F32*F21*F31*F33+2*C25*F32*F22*F31*F33+4*C56*F31*F23*F32*F33+2*C45*F31^2*F23*F32+2*C55*F33^2*F21*F31+3*C14*F31^2*F21*F32+3*C35*F31*F23*F33^2+3*C26*F32^2*F22*F33+2*C46*F32^2*F23*F31+2*C46*F32^2*F21*F33+2*C66*F33^2*F22*F32+C23*F33*F23*F32^2+C12*F31*F21*F32^2+C34*F32*F21*F33^2+C12*F32*F22*F31^2+C34*F31*F22*F33^2+C13*F31*F21*F33^2+C25*F31*F23*F32^2+C13*F33*F23*F31^2+C25*F33*F21*F32^2+C16*F32*F23*F31^2+C23*F32*F22*F33^2+C16*F33*F22*F31^2+3*C24*F31*F22*F32^2+C14*F31^3*F22+C24*F32^3*F21);
	    cout[6,4] = (C26*F33*F22^2*F12+C26*F32*F22^2*F13+C11*F31*F21^2*F11+C56*F31*F23^2*F12+C56*F32*F23^2*F11+C14*F31*F21^2*F12+C14*F32*F21^2*F11+C35*F33*F23^2*F11+C35*F31*F23^2*F13+C66*F32*F23^2*F12+C44*F32*F21^2*F12+C44*F31*F22^2*F11+C66*F33*F22^2*F13+C36*F32*F23^2*F13+C36*F33*F23^2*F12+C33*F33*F23^2*F13+C45*F33*F21^2*F12+C24*F32*F22^2*F11+C24*F31*F22^2*F12+C22*F32*F22^2*F12+C45*F32*F21^2*F13+C55*F31*F23^2*F11+C55*F33*F21^2*F13+C46*F33*F22^2*F11+C46*F31*F22^2*F13+C15*F31*F21^2*F13+C15*F33*F21^2*F11+C12*F32*F22*F11*F21+C45*F33*F21*F11*F22+C45*F32*F21*F11*F23+C45*F31*F22*F13*F21+C25*F33*F21*F12*F22+C25*F31*F23*F12*F22+C25*F32*F22*F11*F23+C25*F32*F22*F13*F21+C55*F31*F23*F13*F21+C55*F33*F21*F11*F23+C16*F31*F21*F13*F22+C16*F33*F22*F11*F21+C13*F33*F23*F11*F21+C45*F31*F23*F12*F21+2*C24*F32*F21*F12*F22+2*C45*F31*F22*F11*F23+2*C46*F32*F21*F12*F23+2*C26*F32*F22*F12*F23+2*C15*F31*F21*F11*F23+2*C14*F31*F21*F11*F22+2*C56*F33*F21*F13*F22+2*C35*F33*F21*F13*F23+2*C36*F33*F22*F13*F23+C13*F31*F21*F13*F23+C46*F32*F21*F13*F22+C46*F31*F22*F12*F23+C46*F32*F23*F11*F22+C16*F32*F23*F11*F21+C16*F31*F21*F12*F23+C23*F33*F23*F12*F22+C56*F31*F23*F13*F22+C56*F33*F21*F12*F23+C56*F32*F23*F13*F21+C56*F33*F22*F11*F23+C34*F32*F21*F13*F23+C34*F33*F23*F11*F22+C34*F31*F22*F13*F23+C34*F33*F23*F12*F21+C66*F33*F22*F12*F23+C66*F32*F23*F13*F22+C46*F33*F22*F12*F21+C23*F32*F22*F13*F23+C44*F32*F21*F11*F22+C44*F31*F22*F12*F21+C12*F31*F21*F12*F22);
	    cout[6,5] = (C55*F23*F31^2*F13+C26*F22*F32^2*F13+C14*F21*F31^2*F12+C14*F22*F31^2*F11+C44*F21*F32^2*F11+C44*F22*F31^2*F12+C35*F21*F33^2*F13+C35*F23*F33^2*F11+C26*F23*F32^2*F12+C33*F23*F33^2*F13+C46*F23*F32^2*F11+C56*F23*F32*F11*F33+C11*F21*F31^2*F11+C66*F22*F33^2*F12+C22*F22*F32^2*F12+C45*F23*F31^2*F12+C45*F22*F31^2*F13+C66*F23*F32^2*F13+C55*F21*F33^2*F11+C56*F21*F33^2*F12+C56*F22*F33^2*F11+C24*F22*F32^2*F11+C15*F23*F31^2*F11+C23*F22*F32*F13*F33+C46*F23*F32*F12*F31+C36*F23*F33^2*F12+C12*F21*F31*F12*F32+C12*F22*F32*F11*F31+C46*F22*F31*F13*F32+C46*F22*F33*F11*F32+C46*F21*F32*F12*F33+C55*F21*F33*F13*F31+C55*F23*F31*F11*F33+C56*F22*F33*F13*F31+C56*F23*F31*F12*F33+C56*F21*F33*F13*F32+C66*F22*F33*F13*F32+C66*F23*F32*F12*F33+C24*F21*F32^2*F12+C45*F22*F31*F11*F33+C45*F21*F33*F12*F31+C45*F21*F32*F13*F31+C15*F21*F31^2*F13+C36*F22*F33^2*F13+2*C26*F22*F32*F12*F33+2*C56*F23*F31*F13*F32+2*C45*F21*F32*F11*F33+2*C14*F21*F31*F11*F32+2*C35*F23*F31*F13*F33+2*C36*F23*F32*F13*F33+2*C46*F22*F31*F12*F33+2*C24*F22*F31*F12*F32+2*C15*F21*F31*F11*F33+C45*F23*F31*F11*F32+C16*F23*F32*F11*F31+C13*F21*F31*F13*F33+C13*F23*F33*F11*F31+C16*F22*F33*F11*F31+C16*F21*F31*F13*F32+C16*F21*F31*F12*F33+C25*F23*F31*F12*F32+C34*F23*F33*F12*F31+C25*F22*F32*F11*F33+C25*F21*F33*F12*F32+C25*F22*F32*F13*F31+C23*F23*F33*F12*F32+C34*F22*F31*F13*F33+C34*F23*F33*F11*F32+C34*F21*F32*F13*F33+C44*F22*F31*F11*F32+C44*F21*F32*F12*F31+C46*F21*F32^2*F13);
	    cout[6,6] = (C55*F31^2*F23^2+C44*F31^2*F22^2+C66*F33^2*F22^2+C66*F32^2*F23^2+C22*F32^2*F22^2+C33*F33^2*F23^2+C55*F33^2*F21^2+2*C45*F31*F22*F21*F33+2*C45*F31*F23*F21*F32+2*C25*F31*F23*F22*F32+C11*F31^2*F21^2+C44*F32^2*F21^2+2*C45*F32*F21^2*F33+2*C26*F32*F22^2*F33+2*C46*F32^2*F21*F23+2*C56*F31*F23*F22*F33+2*C23*F32*F22*F23*F33+2*C16*F31*F21*F23*F32+2*C16*F31*F21*F22*F33+2*C26*F32^2*F22*F23+2*C56*F32*F23*F21*F33+2*C66*F32*F23*F22*F33+2*C12*F31*F21*F22*F32+2*C46*F31*F22^2*F33+2*C56*F31*F23^2*F32+2*C56*F33^2*F21*F22+2*C24*F31*F22^2*F32+2*C35*F33^2*F21*F23+2*C36*F33^2*F22*F23+2*C45*F31^2*F22*F23+2*C14*F31^2*F21*F22+2*C14*F31*F21^2*F32+2*C24*F32^2*F21*F22+2*C15*F31^2*F21*F23+2*C35*F31*F23^2*F33+2*C36*F32*F23^2*F33+2*C13*F31*F21*F23*F33+2*C25*F32*F22*F21*F33+2*C44*F31*F22*F21*F32+2*C34*F31*F22*F23*F33+2*C15*F31*F21^2*F33+2*C34*F32*F21*F23*F33+2*C55*F31*F23*F21*F33+2*C46*F31*F22*F23*F32+2*C46*F32*F21*F22*F33);
	    cout .= cout .* (1/det(F));
	end
    return cout
end

function test()
	F = rand(3, 3)
	C = rand(6,6)
	C = C + C'
	C4th = fill(0.0, 3, 3, 3, 3)
	C4th = tens4symmt6x6tot!(C4th, C)

	c0 = fill(0.0, 6, 6)
	# @btime totalLagrangean2current0!($c0, $C, $F)
	totalLagrangean2current0!(c0, C, F)

	c14th = fill(0.0, 3, 3, 3, 3)
	# @btime totlag2curr4th!($c14th, $C4th, $F)
	totlag2curr4th!(c14th, C4th, F)
	c1 = fill(0.0, 6, 6)
	tens4symmtto6x6t!(c1, c14th)
	@test norm(c1 - c0) <= 1.0e-12 * norm(c0)

	c3 = fill(0.0, 6, 6)
	# @btime totlag2curr!($c3, $C, $F)
	totlag2curr!(c3, C, F)
	@test norm(c3 - c0) <= 1.0e-12 * norm(c0)

	c4 = fill(0.0, 6, 6)
	# @btime totlag2currsymm!($c4, $C, $F)
	totlag2currsymm!(c4, C, F)
	@test norm(c4 - c0) <= 1.0e-12 * norm(c0)
end
end
using .mctransf1
mctransf1.test()

ext: jl


text:
const dummyNode = BaseNode( "dummy" )

"""
```
isPersonnelOfNode(
    persAttrVals::Dict{String, Any},
    node::BaseNode )
```
This function tests if the personnel members with initialised attributes
`persAttrVals` satisfies the requirements of node `node`.

If the node has a requirement on an attribute which isn't in the list of attribute/value pairs, it means the requirement isn't satisfied.

This function returns a `Bool` with the result of the test.
"""
function isPersonnelOfNode( persAttrVals::Dict{String,String},
    node::BaseNode )

    for attribute in keys( node.requirements )
        # If the attribute isn't initialised for the personnel member, the
        #   personnel doesn't satisfy it, and isn't in the node. Otherwise,
        #   the attribute's value must match with the requirements of the node.
        if !haskey( persAttrVals, attribute ) ||
            ( persAttrVals[attribute] != node.requirements[attribute] )
            return false
        end  # if !haskey( persAttrVals, attribute ) || ...
    end  # for attr in keys( node.requirements )

    return true

end  # isPersonnelOfNode( persAttrs, node )


text:
### A Pluto.jl notebook ###
# v0.14.7

using Markdown
using InteractiveUtils

# ╔═╡ a36447e6-5f1d-11ec-1709-ddde3526118e
begin
	(a,b,c)=1:3
	b
end

# ╔═╡ d00f94f1-d34d-4798-a1c4-a3ca44884dde
b

# ╔═╡ eae59af1-74e9-4f01-830e-01c7222f98bd
function two_methods(a,b)
			  a+b,a*b

end

# ╔═╡ 005e4570-8e73-46ad-97fb-39ed5586c7f2
two_methods(2,3)

# ╔═╡ Cell order:
# ╠═a36447e6-5f1d-11ec-1709-ddde3526118e
# ╠═d00f94f1-d34d-4798-a1c4-a3ca44884dde
# ╠═eae59af1-74e9-4f01-830e-01c7222f98bd
# ╠═005e4570-8e73-46ad-97fb-39ed5586c7f2

max_stars_repo_name: BioMedAI/Pluto-Note

max_issues_repo_name: BioMedAI/Pluto-Note

max_forks_repo_name: BioMedAI/Pluto-Note


text:
"""
    GDAX has a restriction on the size of a bunch of data that is return by getHistoricRates() call.
    This function returns vector of `buckets` safely with multiple requests
    See https://docs.gdax.com/#get-historic-rates
"""
function safely_load_historical_data( product_id::String,
                                from::DateTime,
                                until::DateTime,
                                granularity::Int64;
                                verbose::Bool = true)::Vector{Dict{String, Any}}

   num_fails_max = 10
   num_fails = 0
   storage = Vector{Any}(0)
   user = GDAXUser("https://api.gdax.com", "", "", "")
   while num_fails < num_fails_max
       m_start = until - Dates.Second(granularity) * 349
       resp = getHistoricRates(user, product_id, m_start, until, granularity)
       if Requests.statuscode(resp) != 200
           num_fails += 1
           msg = Requests.json(resp)
           verbose && @printf("Error respond: %ls\n", msg)
           sleep(15)
           continue
       end

       data = Requests.json(resp)
       if isempty(data)
           #does not mean that there is no data left
           verbose && @printf("Empty data\n")
           break
       end

       append!(storage, data)

       times = [first(x) for x in data]
       first_time = minimum(times)
       next_until = Dates.unix2datetime(first_time)

       if next_until == until
           verbose && @printf("The same start\n")
           break
       end

       until = next_until
       if until < from
           break
       end

       verbose && @printf("[Loading %ls] Start: %ls. Total points loaded: %d\n", product_id, until, length(storage))
       sleep(rand() + 2)
   end

   return storage
end

max_stars_repo_name: DatName/gdax-julia

max_issues_repo_name: DatName/gdax-julia

max_forks_repo_name: DatName/gdax-julia


text:
module CSVImageData

using Images, Color, FixedPointNumbers

end

max_stars_repo_name: torrange/RODClf

max_issues_repo_name: torrange/RODClf

max_forks_repo_name: torrange/RODClf


text:
# --------------------------------------------------------------------------- #
# Image Operations and, more general, random Image Operations

abstract type ImageOp end

# --------------------------------------------------------------------------- #
# Fallback apply methods

apply(o :: ImageOp, img :: Image) = apply(o, img, Label())[1]
apply(o :: ImageOp, lmg :: LabeledImage) = apply(o, lmg...)

# --------------------------------------------------------------------------- #
# Identity operation

struct Id <: ImageOp end

apply(:: Id, img :: Image, lbl :: Label) = (img, lbl)

# --------------------------------------------------------------------------- #
# Random operations - randomly choose one of several possible ops

struct RandomImageOp{N} <: ImageOp
  options :: NTuple{N, ImageOp}
  freqs :: NTuple{N, Float64}

  function RandomImageOp{N}(opts, freqs) where {N}
    return new(opts, clamp.(freqs, 0, Inf))
  end
end

function RandomImageOp(options, freqs)
  N = length(options)
  return RandomImageOp{N}(tuple(options...), tuple(freqs...))
end

RandomImageOp(o :: ImageOp, f :: Real) = RandomImageOp((o, Id()), (f, 1))

function apply(o :: RandomImageOp, img :: Image, lbl :: Label)
  r = rand()
  p = collect(o.freqs ./ sum(o.freqs))
  k = findfirst(x -> x > r, cumsum(p))
  apply(o.options[k], img, lbl)
end

import Base.+

addone(o :: ImageOp) = (o, 1.)
addone(o :: Tuple{ImageOp, Real}) = (o[1], float(o[2]))

function +(o :: Union{ImageOp, Tuple{ImageOp, Real}}, os...)
  os = addone.([o; os...])
  return RandomImageOp((first.(os)...), (second.(os)...))
end

# --------------------------------------------------------------------------- #
# Processing Pipeline - operations in sequence

struct Pipeline{N} <: ImageOp
  ops   :: NTuple{N, ImageOp}
end

function apply(pip :: Pipeline, img :: Image, lbl :: Label)
  for op in pip.ops
    img, lbl = apply(op, img, lbl)
  end
  return img, lbl
end

import Base.*

mkrandom(o :: ImageOp) = o

function mkrandom(o :: Tuple{ImageOp, Real})
  return RandomImageOp((o[1], Id()), (o[2], 1.))
end

function *(o :: Union{ImageOp, Tuple{ImageOp, Real}}, os...)
  os = (mkrandom.([o; os...]) ...)
  return Pipeline(os)
end

# --------------------------------------------------------------------------- #
# Parsing Image Operations

function Base.parse(::Type{ImageOp}, s::String)
  return eval(parse(s))
end

# --------------------------------------------------------------------------- #
# Flips along vertical and horizontal axis

struct FlipV <: ImageOp end
struct FlipH <: ImageOp end

function apply{I <: Image}(:: FlipV, img :: I, lbl :: Label)
  img = I(flipdim(imgdata(img), 1))
  lbl = Label([ (x, size(img, 1) - y + 1) for (x,y) in lbl ])
  return img, lbl
end

function apply{I <: Image}(:: FlipH, img :: I, lbl :: Label)
  img = I(flipdim(imgdata(img), 2))
  lbl = Label([ (size(img, 2) - x + 1, y) for (x,y) in lbl ])
  return img, lbl
end

MaybeFlip(fv = 1, fh = fv) = (FlipV(), fv) * (FlipH(), fh)

# --------------------------------------------------------------------------- #
# Jitter -- move the label spots randomly without effecting the image

struct Jitter <: ImageOp
  d :: Int
end

Jitter() = Jitter(3)

function apply{I <: Image}(o :: Jitter, img :: I, lbl :: Label)
  lbl = Label([c .+ (rand(-o.d:o.d, 2)...) for c in lbl])
  return img, crop(lbl, 1, 1, imgsize(img)...)
end

# --------------------------------------------------------------------------- #
# Softening the image with gaussian kernel

struct Soften <: ImageOp
  r :: Int
end

Soften() = Soften(3)

function apply{I <: Image}(o :: Soften, img :: I, lbl :: Label)
  data = copy(imgdata(img)[:,:,:])
  for c in 1:imgchannels(img)
    data[:,:,c] = ImageFiltering.imfilter(imgdata(img)[:, :, c],
                                          Images.Kernel.gaussian(o.r))
  end
  return I(data), lbl
end

# --------------------------------------------------------------------------- #
# Add pixelwise, independent noise

struct PixelNoise <: ImageOp
  amp :: Float64
  source :: Function
end

PixelNoise(amp = 0.1; source = rand) = PixelNoise(amp, source)

function apply{I <: Image}(o :: PixelNoise, img :: I, lbl :: Label)
  return I(imgdata(img) + o.amp * o.source(size(img))), lbl
end

# --------------------------------------------------------------------------- #
# Stretch Image in vertical or horizontal direction

struct StretchV <: ImageOp
  f :: Float64
  StretchV(f) = new(clamp(f, 1, Inf))
end

struct StretchH <: ImageOp
  f :: Float64
  StretchH(f) = new(clamp(f, 1, Inf))
end

StretchV() = StretchV(1.1)
StretchH() = StretchH(1.1)

function apply{I <: Image}(o :: StretchV, img :: I, lbl :: Label)

  # Prepare
  n, m = imgsize(img)
  n2 = round(Int, o.f*n)
  a = div((n2 - n), 2) + 1

  # Stretch and crop data
  data = copy(imgdata(img)[:,:,:])
  for c in 1:imgchannels(img)
    data[:,:,c] = crop(Images.imresize(data[:,:,c], n2, m), 1, a, m, n)
  end

  # Also stretch and crop label
  lbl = Label([(x, round(Int, o.f*y)) for (x,y) in lbl])
  lbl = crop(lbl, 1, a, m, n)

  return I(data), lbl
end

function apply{I <: Image}(o :: StretchH, img :: I, lbl :: Label)

  # Prepare
  n, m = imgsize(img)
  m2 = round(Int, o.f*m)
  a = div((m2 - m), 2) + 1

  # Stretch and crop data
  data = copy(imgdata(img)[:,:,:])
  for c in 1:imgchannels(img)
    data[:,:,c] = crop(Images.imresize(data[:,:,c], n, m2), a, 1, m, n)
  end

  # Also stretch and crop label
  lbl = Label([(round(Int, o.f*x), y) for (x,y) in lbl])
  lbl = crop(lbl, a, 1, m, n)

  return I(data), lbl
end

Stretch(f = 1.1) = StretchV(f) * StretchH(f)

# --------------------------------------------------------------------------- #
# Gamma scaling

struct Gamma <: ImageOp
  gamma :: Float64
end

function apply{I <: Image}(o :: Gamma, img :: I, lbl :: Label)
  return I(imgdata(data).^(1/o.gamma)), lbl
end

# --------------------------------------------------------------------------- #
# Background offset

struct Offset <: ImageOp
  c :: NTuple{3, Float64}
end

Offset(c :: Float64) = Offset((c,c,c))

function apply(o :: Offset, img :: GreyscaleImage, lbl :: Label)
  return GreyscaleImage(imgdata(img) + mean(o.c)), lbl
end

function apply(o :: Offset, img :: RGBImage, lbl :: Label)
  return RGBImage(imgdata(img) .+ reshape([o.c...], (1,1,3))), lbl
end

# --------------------------------------------------------------------------- #
# TODO: Rotation, Shear, Crop...
# TODO: HSV wiggling for RGB images!

max_stars_repo_name: tscode/DCellC

max_issues_repo_name: tscode/DCellC


text:
# Julia wrapper for header: /usr/include/scip/cons_soc.h
# Automatically generated using Clang.jl wrap_c

function SCIPincludeConshdlrSOC(scip)
    ccall((:SCIPincludeConshdlrSOC, libscip), SCIP_RETCODE, (Ptr{SCIP_},), scip)
end

function SCIPcreateConsSOC(scip, cons, name, nvars, vars, coefs, offsets, constant, rhsvar, rhscoeff, rhsoffset, initial, separate, enforce, check, propagate, _local, modifiable, dynamic, removable)
    ccall((:SCIPcreateConsSOC, libscip), SCIP_RETCODE, (Ptr{SCIP_}, Ptr{Ptr{SCIP_CONS}}, Cstring, Cint, Ptr{Ptr{SCIP_VAR}}, Ptr{Cdouble}, Ptr{Cdouble}, Cdouble, Ptr{SCIP_VAR}, Cdouble, Cdouble, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32), scip, cons, name, nvars, vars, coefs, offsets, constant, rhsvar, rhscoeff, rhsoffset, initial, separate, enforce, check, propagate, _local, modifiable, dynamic, removable)
end

function SCIPcreateConsBasicSOC(scip, cons, name, nvars, vars, coefs, offsets, constant, rhsvar, rhscoeff, rhsoffset)
    ccall((:SCIPcreateConsBasicSOC, libscip), SCIP_RETCODE, (Ptr{SCIP_}, Ptr{Ptr{SCIP_CONS}}, Cstring, Cint, Ptr{Ptr{SCIP_VAR}}, Ptr{Cdouble}, Ptr{Cdouble}, Cdouble, Ptr{SCIP_VAR}, Cdouble, Cdouble), scip, cons, name, nvars, vars, coefs, offsets, constant, rhsvar, rhscoeff, rhsoffset)
end

function SCIPgetNlRowSOC(scip, cons, nlrow)
    ccall((:SCIPgetNlRowSOC, libscip), SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_CONS}, Ptr{Ptr{SCIP_NLROW}}), scip, cons, nlrow)
end

function SCIPgetNLhsVarsSOC(scip, cons)
    ccall((:SCIPgetNLhsVarsSOC, libscip), Cint, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetLhsVarsSOC(scip, cons)
    ccall((:SCIPgetLhsVarsSOC, libscip), Ptr{Ptr{SCIP_VAR}}, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetLhsCoefsSOC(scip, cons)
    ccall((:SCIPgetLhsCoefsSOC, libscip), Ptr{Cdouble}, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetLhsOffsetsSOC(scip, cons)
    ccall((:SCIPgetLhsOffsetsSOC, libscip), Ptr{Cdouble}, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetLhsConstantSOC(scip, cons)
    ccall((:SCIPgetLhsConstantSOC, libscip), Cdouble, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetRhsVarSOC(scip, cons)
    ccall((:SCIPgetRhsVarSOC, libscip), Ptr{SCIP_VAR}, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetRhsCoefSOC(scip, cons)
    ccall((:SCIPgetRhsCoefSOC, libscip), Cdouble, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPgetRhsOffsetSOC(scip, cons)
    ccall((:SCIPgetRhsOffsetSOC, libscip), Cdouble, (Ptr{SCIP_}, Ptr{SCIP_CONS}), scip, cons)
end

function SCIPaddToNlpiProblemSOC(scip, cons, nlpi, nlpiprob, scipvar2nlpivar, names)
    ccall((:SCIPaddToNlpiProblemSOC, libscip), SCIP_RETCODE, (Ptr{SCIP_}, Ptr{SCIP_CONS}, Ptr{SCIP_NLPI}, Ptr{SCIP_NLPIPROBLEM}, Ptr{SCIP_HASHMAP}, UInt32), scip, cons, nlpi, nlpiprob, scipvar2nlpivar, names)
end


text:
using Base.Meta: isexpr

function actual_hasproperty(x, s::Symbol)
    try
        getproperty(x, s)
        return true
    catch e
        e isa UndefVarError || rethrow()
        return false
    end
end

_std_modules = Dict(:Core=>Core, :Base=>Base, :Main=>Main)
module _䷀Empty end
_default_names = Set(names(_䷀Empty, all=true))
for std_mod in values(_std_modules)
    union!(_default_names,
           Set(sym for sym in names(std_mod, all=true, imported=true)
                   if actual_hasproperty(_䷀Empty, sym)))
end

"""
    @repl import ...
    @repl using ...
    @repl include("MyFile.jl")
    @repl include("MyFile.jl") using .MyFile
    @repl [flag] function ... end
    @repl struct ... end
    @repl [flag] begin ... end

    # In an IJulia cell
    @@repl [flag]
    ...

Make the decorated function or struct redefinable in a REPL.

- Import/using: Reload a package.  Decorate the first import for a package with
    `@reset` and later imports with `@repl`.  `_fast_deinit_` will be called on
    the top module before a re-import if it exists.  Do not use when importing
    functions to add methods.
- Include: Run the content of a file.  Any import statements involving any
    modules defined in that file must be included in the same macro call.
- Function: Decorate the first method with `@reset` and the rest with `@repl`.
- Struct: Decorate the definition with `@repl`.
- Block: Apply the `@repl` macro to the top-level of an entire block of code in
    a REPL like Jupyter.

Flags:
- reset: Applies `@reset` to the first method of each function in the block (if
    not a constructor function).

Broken:
- Docstrings on decorated definitions don't work currently.
"""
macro repl(expr)
    esc(_macro_repl(expr, __module__))
end
macro repl(flag::Symbol, expr)
    esc(_macro_repl(expr, __module__, [flag]))
end
macro repl(expr::Expr, expr2, exprs...)
    if is_include_expr(expr)
        _macro_repl_include(__module__, expr, expr2, exprs...)
    else
        println("Error: Unsupported arguments to @repl.  $([expr, exprs...])")
        expr
    end
end
macro repl_reset(expr)
    esc(_macro_repl(expr, __module__, [:reset]))
end
function _macro_repl(expr, mod, flags=Symbol[])
    if is_function_expr(expr)
        _macro_repl_function(expr, mod)
    elseif isexpr(expr, :struct)
        _macro_repl_struct(expr, mod)
    elseif expr isa Expr && expr.head in (:block, :toplevel)
        _macro_repl_block(expr, mod, flags)
    elseif is_import_expr(expr)
        _macro_repl_import(expr, mod; reset=false)
    elseif is_include_expr(expr)
        _macro_repl_include(mod, expr)
    elseif expr === nothing
        nothing
    else
        println("Warning: Unsupported argument to @repl.  $(expr)")
        expr
    end
end

"""
    @reset function ... end

Define the decorated function or struct from a fresh state.

- Import/using: Reload a package.  Decorate the first import for a package with
    `@reset` and later imports with `@repl`.
- Symbol: Clear a previously defined function or struct.
- Function: Clear all previously defined methods.
"""
macro reset(expr)
    if expr isa Symbol
        esc(_macro_reset_symbol(expr, __module__))
    elseif is_function_expr(expr)
        esc(_macro_reset_function(expr, __module__))
    elseif is_import_expr(expr)
        _macro_repl_import(expr, __module__; reset=true)
    elseif expr === nothing
        nothing
    else
        println("Warning: Unsupported argument to @reset.  $(expr)")
        esc(expr)
    end
end

function is_function_expr(expr)
    isexpr(expr, :function) && return true
    isexpr(expr, :macro) && return true
    if isexpr(expr, :(=))
        sub_expr = expr.args[1]
        while sub_expr isa Expr && sub_expr.head in (:where, :(::), :curly)
            sub_expr = sub_expr.args[1]
        end
        isexpr(sub_expr, :call) && return true
    end
    false
end

function function_symbol(expr::Expr)
    @assert is_function_expr(expr)
    if expr.args[1] isa Symbol
        expr.args[1]
    else
        sub_expr = expr.args[1]
        while (sub_expr isa Expr
                && sub_expr.head in (:where, :(::), :curly, :call))
            sub_expr = sub_expr.args[1]
        end
        sub_expr
    end
end

function function_with_symbol(expr::Expr, sym)
    @assert is_function_expr(expr)
    if expr.args[1] isa Symbol
        Expr(expr.head, sym, expr.args[2:end]...)
    else
        decl = copy(expr.args[1])
        sub_expr = decl
        while (sub_expr isa Expr
                && sub_expr.head in (:where, :(::), :curly, :call)
                && sub_expr.args[1] isa Expr)
            sub_expr = sub_expr.args[1] = copy(sub_expr.args[1])
        end
        sub_expr.args[1] = sym
        Expr(expr.head, decl, expr.args[2:end]...)
    end
end

function _get_temp_symbol(mod::Module, sym, increment::Bool=false)
    if isdefined(mod, :䷀symbol_map)
        map = getproperty(mod, :䷀symbol_map)
    else
        map = Base.eval(mod, :(䷀symbol_map = Dict{Any, Any}()))
    end
    if isdefined(mod, :䷀symbol_counters)
        counters = getproperty(mod, :䷀symbol_counters)
    else
        counters = Base.eval(mod, :(䷀symbol_counters = Dict{Any, Int}()))
    end

    if increment || !haskey(map, sym)
        i = get!(counters, sym, 0)
        if increment || i == 0
            i = counters[sym] += 1
        end
        map[sym] = _temp_function_symbol(sym, i)
    else
        map[sym]
    end
end

"""
Helper for `@repl function ...`.
"""
function _macro_repl_function(expr::Expr, mod::Module; nofail::Bool=false,
                              reset::Bool=false)
    @assert is_function_expr(expr)
    quote
        # Defer to runtime
        $_do_temporary_function($(Core.Box(expr)), $mod, $nofail, $reset)
    end
end

_temp_function_symbol(sym, i) = Symbol("䷀$(sym)_v$(i)")

function _do_temporary_function(expr_box, mod, nofail, reset)
    expr = expr_box.contents
    sym = function_symbol(expr)
    out_expr = make_top_level!(quote end)
    tmp_sym = _get_temp_symbol(mod, sym, reset)
    def_sym = tmp_sym
    if isexpr(expr, :macro)
        sym = Symbol("@" * string(sym))
        def_sym = Symbol("@" * string(def_sym))
    end
    new_expr = function_with_symbol(expr, tmp_sym)

    fallback = true
    try
        Base.eval(mod, :($sym = $no_longer_defined))
        fallback = false
    catch e
        e isa ErrorException || rethrow()
        println("$(nofail ? "Info" : "Warning"): $(sym) is not "
                   * "resettable.")
    end
    if fallback
        push!(out_expr.args, expr)
    else
        push!(out_expr.args, new_expr)
        push!(out_expr.args, :($sym = $def_sym))
    end
    Base.eval(mod, out_expr)  # Returns the defined function
end

"""
Helper for `@reset function ...`.
"""
function _macro_reset_function(expr::Expr, mod::Module; nofail::Bool=false)
    _macro_repl_function(expr, mod, nofail=nofail, reset=true)
end

"""
Helper for `@reset function_name`.
"""
function _macro_reset_symbol(sym::Symbol, mod::Module)
    sym_box = Core.Box(sym)
    quote
        if isdefined($mod, $sym_box.contents)
            ($_get_temp_symbol)($mod, $sym_box.contents,
                                $sym !== $no_longer_defined)
            $sym = $no_longer_defined
        end
        nothing
    end
end

function make_top_level!(expr::Expr)
    if isexpr(expr, :block)
        expr.head = :toplevel
        expr
    else
        expr = quote $expr end
        @assert isexpr(expr, :block)
        expr.head = :toplevel
        expr
    end
end

function struct_name(expr::Expr)::Symbol
    @assert isexpr(expr, :struct)
    expr.args[2] isa Symbol && return expr.args[2]
    root_expr = _first_root_expr(expr.args[2])
    root_expr.args[1]
end

function struct_with_name(expr::Expr, sym::Symbol)
    @assert isexpr(expr, :struct)
    if expr.args[2] isa Symbol
        Expr(expr.head, expr.args[1], sym, expr.args[3:end]...)
    else
        root_expr = _first_root_expr(expr.args[2])
        Expr(expr.head,
             expr.args[1],
             _with_first_root_expr(
                expr.args[2],
                Expr(root_expr.head, sym, root_expr.args[2:end]...)),
             expr.args[3:end]...)
    end
end

function expr_with_vals_replaced(expr, old_val, new_val)
    expr == old_val && return new_val
    expr isa Expr || return expr
    new_args = [expr_with_vals_replaced(a, old_val, new_val)
                for a in expr.args]
    Expr(expr.head, new_args...)
end

"""
Helper for `@repl struct ...`.
"""
function _macro_repl_struct(expr::Expr, mod::Module)
    @assert isexpr(expr, :struct)
    quote
        # Defer to runtime
        $_do_temporary_struct($(Core.Box(expr)), $mod)
    end
end

function _do_temporary_struct(expr_box, mod)
    expr = expr_box.contents
    sym = struct_name(expr)
    out_expr = make_top_level!(quote end)
    tmp_sym = _get_temp_symbol(mod, sym, true)
    new_expr = expr_with_vals_replaced(expr, sym, tmp_sym)

    fallback = true
    try
        Base.eval(mod, :($sym = $no_longer_defined))
        fallback = false
    catch e
        e isa ErrorException || rethrow()
        println("Warning: $(sym) is not resettable.")
    end
    if fallback
        push!(out_expr.args, expr)
    else
        push!(out_expr.args, new_expr)
        push!(out_expr.args, :($sym = $tmp_sym))
    end
    Base.eval(mod, out_expr)  # Returns the defined function
end

"""
Helper for `@repl begin ...` and `@@repl ...`.
"""
function _macro_repl_block(expr::Expr, mod::Module, flags=Symbol::[],
                           was_defined=Set())
    reset_flag = :reset in flags
    known_flags = [:reset]
    if !all(f in known_flags for f in flags)
        unknown = setdiff(flags, known_flags)
        print("Warning: Unknown flag(s) to @@repl: [$(join(unknown, ", "))]")
    end
    if expr isa Expr && expr.head in (:block, :toplevel)
        # A block of statements
        for i in axes(expr.args, 1)
            sub_expr = expr.args[i]
            if isexpr(sub_expr, :struct)
                sym = struct_name(sub_expr)
                if sym in was_defined
                    println(
                        "Warning: Definition for $(sym) overwritten by a later "
                        * "struct definition.")
                end
                expr.args[i] = _macro_repl_struct(sub_expr, mod)
                push!(was_defined, sym)
            elseif is_function_expr(sub_expr)
                sym = function_symbol(sub_expr)
                if reset_flag && !(sym in was_defined)
                    expr.args[i] = _macro_reset_function(sub_expr, mod,
                                                         nofail=true)
                else
                    expr.args[i] = _macro_repl_function(sub_expr, mod,
                                                        nofail=true)
                end
                push!(was_defined, sym)
            elseif sub_expr isa Expr && expr.head in (:block, :toplevel)
                expr.args[i] = _macro_repl_block(sub_expr, mod, flags,
                                                 was_defined)
            end
        end
        expr
    else
        # A single statement
        if is_function_expr(expr)
            _macro_repl_function(expr, mod, nofail=true)
        else
            expr
        end
    end
end

function is_import_expr(expr)
    expr isa Expr && expr.head in (:using, :import)
end

function _first_root_expr(expr)
    @assert expr isa Expr
    if length(expr.args) <= 0 || !(expr.args[1] isa Expr)
        expr
    else
        _first_root_expr(expr.args[1])
    end
end

function _with_first_root_expr(expr, new_root_expr)
    @assert expr isa Expr
    if length(expr.args) <= 0 || !(expr.args[1] isa Expr)
        new_root_expr
    else
        Expr(expr.head,
             _with_first_root_expr(expr.args[1], new_root_expr),
             expr.args[2:end]...)
    end
end

function import_expr_package_syms(expr::Expr)
    @assert is_import_expr(expr)
    root_expr = _first_root_expr(expr)
    @assert isexpr(root_expr, :(.))
    @assert length(root_expr.args) > 0
    syms = root_expr.args
    @assert all(sym isa Symbol for sym in syms)
    syms
end

function import_expr_package_syms!(expr::Expr, new_syms...)
    @assert is_import_expr(expr)
    root_expr = _first_root_expr(expr)
    @assert length(root_expr.args) > 0
    sym = root_expr.args[1]
    @assert sym isa Symbol
    root_expr.args = [new_syms...]
    expr
end

function actual_getproperty(x, s::Symbol, default=nothing)
    try
        return getproperty(x, s)
    catch e
        e isa UndefVarError || rethrow()
        return default
    end
end

function _exported_names(mod::Module, imported_mod::Module, ignore=())
    all_names = Set(sym for sym in names(imported_mod, all=true, imported=true)
                        if actual_hasproperty(mod, sym))
    setdiff!(all_names, _default_names, ignore)
end

function actual_all_names(mod, include_default=false, include_hidden=false)
    visible_names = names(mod, all=true, imported=true)
    all_names = Set{Symbol}()
    for sym in visible_names
        name = string(sym)
        if !include_hidden
            name[1] in "#䷀" && continue  # Skip hidden names
        end
        push!(all_names, sym)
        val = getproperty(mod, sym)
        if val isa Module
            for sub_sym in names(val, all=true, imported=true)
                if !include_hidden
                    string(sub_sym)[1] in "#䷀" && continue  # Skip hidden names
                end
                actual_hasproperty(mod, sub_sym) || continue
                push!(all_names, sub_sym)
            end
        end
    end
    if !include_default
        setdiff!(all_names, _default_names)
    end
    all_names
end

"""
Reload a package but don't rebind any names.
"""
function _reload_package(into::Module, pkg_name; force::Bool=true)
    sym = Symbol(pkg_name)
    haskey(_std_modules, sym) && return _std_modules[sym]
    uuidkey = Base.identify_package(into, pkg_name)
    if uuidkey === nothing
        throw(ArgumentError("""
            Package $(pkg_name) not found.
            - Run `import Pkg; Pkg.add($(repr(pkg_name)))` to install the $pkg_name package.
            """))
    end
    if force || !Base.root_module_exists(uuidkey)
        Base._require(uuidkey)  # Force reload
        for callback in Base.package_callbacks
            Base.invokelatest(callback, uuidkey)
        end
    end
    return Base.root_module(uuidkey)
end

"""
Helper for `@repl import ...`, `@repl using ...`, `@reset import/using`.
"""
function _macro_repl_import(expr::Expr, mod::Module; reset::Bool=false,
                            pkg_sym_out=Ref(:(!)),
                            already_reset=Set{Symbol}())
    @assert expr.head in (:import, :using) && length(expr.args) >= 1
    # Handle multiple imports on one line
    if length(expr.args) > 1
        out_expr = quote end
        for item in expr.args
            pkg_sym_out = Ref(:(!))
            out_item = _macro_repl_import(Expr(expr.head, item),
                                          mod, reset=reset,
                                          pkg_sym_out=pkg_sym_out,
                                          already_reset=already_reset)
            push!(already_reset, pkg_sym_out[])
            push!(out_expr.args, out_item)
        end
        return out_expr
    end

    syms = import_expr_package_syms(expr)
    i = 1
    while i<length(syms) && syms[i] == :(.)
        i += 1
    end
    relative = i-1
    @assert syms[i] != :(.)
    pkg_name = string(syms[i])
    pkg_sym_out[] = syms[i]
    if syms[i] in already_reset
        reset = false
    end
    if relative > 0
        expr = import_expr_package_syms!(expr, :(.), syms...)
    end
    path = syms[i:end-isexpr(expr, :import)]
    quote
        $(_do_temporary_import)($pkg_name, $path, $(Core.Box(expr)), $mod,
                                $relative, $reset)
    end
end

function _do_temporary_import(pkg_name, path, expr_box, mod::Module,
                              relative::Int, reset::Bool)
    cleanup_dict = actual_getproperty(mod, :䷀import_variables,
                                      Dict{String, Set{Symbol}}())
    module_dict = actual_getproperty(mod, :䷀import_modules,
                                     Dict{String, Module}())

    # Make temporary module
    # Reload and import the package
    if relative > 0
        in_mod = mod
        for i in 2:relative
            in_mod = parentmodule(in_mod)
        end
        tmp_mod_sym = _get_temp_symbol(mod, Symbol("Mod䷀"*pkg_name), true)
        out_mod = Base.eval(mod, :(
            module $tmp_mod_sym
                $(expr_box.contents)
            end
        ))
        pkg_name = "."^relative * pkg_name
    else
        in_mod = _reload_package(mod, pkg_name, force=reset)
        out_mod = Module(:䷀)
        Base.eval(out_mod, expr_box.contents)
    end
    sub_in_mod = in_mod
    if length(path) >= 1
        for s in path[1+(relative==0):end]
            t = getproperty(sub_in_mod, s)
            t isa Module || break
            sub_in_mod = t
        end
    end

    if reset
        # De-init old module
        old_mod = get(module_dict, pkg_name, nothing)
        module_dict[pkg_name] = in_mod
        if old_mod !== nothing && isdefined(old_mod, :_fast_deinit_)
            try
                old_mod._fast_deinit_()
            catch e
                println(stderr, "Error during fast deinit: $(e)")
                showerror(stderr, e)
            end
        end
    end

    # Assign the correct variables to the imported names
    expr = quote end
    @assert isexpr(expr, :block)
    all_names = _exported_names(out_mod, sub_in_mod,
                                [:䷀, Symbol("Mod䷀"*pkg_name)])
    if reset
        # Clear old values
        for sym in get(cleanup_dict, pkg_name, Set{Symbol}())
            assignment = :($sym = $no_longer_defined)
            push!(expr.args, assignment)
        end
    end
    # Set new values
    for sym in all_names
        push!(expr.args, :($sym = $out_mod.$sym))
    end
    # Save names for later cleanup
    if reset || !haskey(cleanup_dict, pkg_name)
        cleanup_dict[pkg_name] = all_names
    else
        union!(cleanup_dict[pkg_name], all_names)
    end
    push!(expr.args, :(䷀import_variables = $cleanup_dict))
    push!(expr.args, :(䷀import_modules = $module_dict))
    Base.eval(mod, expr)
    nothing
end

function is_include_expr(expr)
    isexpr(expr, :call) && length(expr.args) == 2 && expr.args[1] == :include
end

"""
Helper for `@repl include(...)` and `@repl include(...) ...`.
"""
function _macro_repl_include(mod::Module, exprs...)
    @assert is_include_expr(exprs[1])
    quote
        $(_do_temporary_include)($exprs, $mod)
    end
end

function _do_temporary_include(exprs, mod::Module)
    # Make temporary module
    out_mod = Module(:䷀, true)
    Base.eval(out_mod,
              :(include(path::AbstractString) = Base.include($out_mod, path)))
    for expr in exprs
        Base.eval(out_mod, expr)
    end

    # Assign the correct variables to the imported names
    expr = quote end
    @assert isexpr(expr, :block)
    all_names = setdiff!(actual_all_names(out_mod, false), [:䷀])
    # Set new values
    for sym in all_names
        push!(expr.args, :($sym = $out_mod.$sym))
    end
    Base.eval(mod, expr)
    nothing
end


text:
using TwoPeriodAltruism
using Test

@testset "TwoPeriodAltruism.jl" begin
    # Redundant test just to check whether the package development worked (deleted later)
    @test TwoPeriodAltruism.ModPar().β > 0
end


text:
function testGradient()
    M = 32
    N = 64

    grid = Grid2d(M,N)
    ft   = FourierTransform(grid)
    D    = get_gradient(ft)

    u  = get_field(grid)
    ux = zero(u)
    uy = zero(u)

    evaluate_function_on_grid(grid, u_test, u)
    evaluate_function_on_grid(grid, dudx_test, ux)
    evaluate_function_on_grid(grid, dudy_test, uy)

    û = get_trans(ft)
    prfft!(ft, u, û)
    Dû = [zero(û), zero(û)]
    apply_operator!(D, û, Dû)

    uxfft = zero(ux)
    uyfft = zero(uy)

    irfft!(ft, Dû[1], uxfft)
    irfft!(ft, Dû[2], uyfft)

    @test maximum(abs.(ux - uxfft)) ≈ zero(eltype(u)) atol=1E-12
    @test maximum(abs.(uy - uyfft)) ≈ zero(eltype(u)) atol=1E-12

end

function testInverseLaplacian()
    M = 32
    N = 64

    grid = Grid2d(M,N)
    ft   = FourierTransform(grid)
    Δ⁻¹  = get_inverse_laplacian(ft)

    u = get_field(grid)
    f = get_field(grid)

    evaluate_function_on_grid(grid, u_test, u)
    evaluate_function_on_grid(grid, f_test, f)

    uhat = get_trans(ft)
    fhat = get_trans(ft)

    prfft!(ft, u, uhat)
    prfft!(ft, f, fhat)

    Δ⁻¹fhat = zero(fhat)

    apply_operator!(Δ⁻¹, fhat, Δ⁻¹fhat)

    u₀hat = zero(uhat)
    u₀hat[1,1] = uhat[1,1]

    Δ⁻¹f_fft = zero(u)
    u₀fft    = zero(u)

    irfft!(ft, Δ⁻¹fhat, Δ⁻¹f_fft)
    irfft!(ft, u₀hat, u₀fft)

    Δ⁻¹f_ana = u .- u₀fft

    @test maximum(abs.(Δ⁻¹f_ana - Δ⁻¹f_fft)) ≈ zero(eltype(f)) atol=1E-14

end

testGradient()
testInverseLaplacian()


text:
import Pkg

Pkg.test("Plots")
Pkg.test("Markdown")
Pkg.test("DataFrames")

max_stars_repo_name: Jblew/towards-julia-notebook

max_issues_repo_name: Jblew/towards-julia-notebook

max_forks_repo_name: Jblew/towards-julia-notebook


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

@doc raw"""NodeSpec describes the attributes that a node is created with.

    IoK8sApiCoreV1NodeSpec(;
        configSource=nothing,
        externalID=nothing,
        podCIDR=nothing,
        podCIDRs=nothing,
        providerID=nothing,
        taints=nothing,
        unschedulable=nothing,
    )

    - configSource::IoK8sApiCoreV1NodeConfigSource : If specified, the source to get node configuration from The DynamicKubeletConfig feature gate must be enabled for the Kubelet to use this field
    - externalID::String : Deprecated. Not all kubelets will set this field. Remove field after 1.13. see: https://issues.k8s.io/61966
    - podCIDR::String : PodCIDR represents the pod IP range assigned to the node.
    - podCIDRs::Vector{String} : podCIDRs represents the IP ranges assigned to the node for usage by Pods on that node. If this field is specified, the 0th entry must match the podCIDR field. It may contain at most 1 value for each of IPv4 and IPv6.
    - providerID::String : ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>
    - taints::Vector{IoK8sApiCoreV1Taint} : If specified, the node's taints.
    - unschedulable::Bool : Unschedulable controls node schedulability of new pods. By default, node is schedulable. More info: https://kubernetes.io/docs/concepts/nodes/node/#manual-node-administration
"""
mutable struct IoK8sApiCoreV1NodeSpec <: SwaggerModel
    configSource::Any # spec type: Union{ Nothing, IoK8sApiCoreV1NodeConfigSource } # spec name: configSource
    externalID::Any # spec type: Union{ Nothing, String } # spec name: externalID
    podCIDR::Any # spec type: Union{ Nothing, String } # spec name: podCIDR
    podCIDRs::Any # spec type: Union{ Nothing, Vector{String} } # spec name: podCIDRs
    providerID::Any # spec type: Union{ Nothing, String } # spec name: providerID
    taints::Any # spec type: Union{ Nothing, Vector{IoK8sApiCoreV1Taint} } # spec name: taints
    unschedulable::Any # spec type: Union{ Nothing, Bool } # spec name: unschedulable

    function IoK8sApiCoreV1NodeSpec(;configSource=nothing, externalID=nothing, podCIDR=nothing, podCIDRs=nothing, providerID=nothing, taints=nothing, unschedulable=nothing)
        o = new()
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("configSource"), configSource)
        setfield!(o, Symbol("configSource"), configSource)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("externalID"), externalID)
        setfield!(o, Symbol("externalID"), externalID)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("podCIDR"), podCIDR)
        setfield!(o, Symbol("podCIDR"), podCIDR)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("podCIDRs"), podCIDRs)
        setfield!(o, Symbol("podCIDRs"), podCIDRs)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("providerID"), providerID)
        setfield!(o, Symbol("providerID"), providerID)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("taints"), taints)
        setfield!(o, Symbol("taints"), taints)
        validate_property(IoK8sApiCoreV1NodeSpec, Symbol("unschedulable"), unschedulable)
        setfield!(o, Symbol("unschedulable"), unschedulable)
        o
    end
end # type IoK8sApiCoreV1NodeSpec

const _property_map_IoK8sApiCoreV1NodeSpec = Dict{Symbol,Symbol}(Symbol("configSource")=>Symbol("configSource"), Symbol("externalID")=>Symbol("externalID"), Symbol("podCIDR")=>Symbol("podCIDR"), Symbol("podCIDRs")=>Symbol("podCIDRs"), Symbol("providerID")=>Symbol("providerID"), Symbol("taints")=>Symbol("taints"), Symbol("unschedulable")=>Symbol("unschedulable"))
const _property_types_IoK8sApiCoreV1NodeSpec = Dict{Symbol,String}(Symbol("configSource")=>"IoK8sApiCoreV1NodeConfigSource", Symbol("externalID")=>"String", Symbol("podCIDR")=>"String", Symbol("podCIDRs")=>"Vector{String}", Symbol("providerID")=>"String", Symbol("taints")=>"Vector{IoK8sApiCoreV1Taint}", Symbol("unschedulable")=>"Bool")
Base.propertynames(::Type{ IoK8sApiCoreV1NodeSpec }) = collect(keys(_property_map_IoK8sApiCoreV1NodeSpec))
Swagger.property_type(::Type{ IoK8sApiCoreV1NodeSpec }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApiCoreV1NodeSpec[name]))}
Swagger.field_name(::Type{ IoK8sApiCoreV1NodeSpec }, property_name::Symbol) =  _property_map_IoK8sApiCoreV1NodeSpec[property_name]

function check_required(o::IoK8sApiCoreV1NodeSpec)
    true
end

function validate_property(::Type{ IoK8sApiCoreV1NodeSpec }, name::Symbol, val)
end


text:
"""
Helper function fills a newly initalized protobuf message with zeros
"""
function fill_protobuf!(msg::MSG_TYPE) where {MSG_TYPE <: ProtoBuf.ProtoType}
    names_list = propertynames(msg)
    attr_dict = msg.__protobuf_jl_internal_meta.symdict

    for name in names_list
        # Verify we can generate a random message
        @assert attr_dict[name].jtyp <: Real
        setproperty!(msg, name, zero(attr_dict[name].jtyp))
    end
end

"""
Helper function gets the size of an initalized protobuf message
"""
function get_msg_size(msg::MSG_TYPE) where {MSG_TYPE <: ProtoBuf.ProtoType}
    if isinitialized(msg)
        return writeproto(IOBuffer(), msg)
    else
        error("Must initialize the protobuf message.")
    end
end


text:
abstract type AbstractShape end

#####
# StandardPoint
#####

struct StandardPoint{T} <: AbstractShape end

#####
# StandardLine
#####

struct StandardLine{T} <: AbstractShape
    half_length::T
end

get_half_length(line::StandardLine) = line.half_length

# head, tail, and vertices for StandardLine
get_head(line::StandardLine{T}) where {T} = Vector2D(get_half_length(line), zero(T))
get_tail(line::StandardLine{T}) where {T} = Vector2D(-get_half_length(line), zero(T))
get_vertices(line::StandardLine) = (get_tail(line), get_head(line))

# head, tail, and vertices for StandardLine at arbitrary position
get_head(line::StandardLine{T}, pos::Vector2D{T}) where {T} = pos + get_head(line)
get_tail(line::StandardLine{T}, pos::Vector2D{T}) where {T} = pos + get_tail(line)
get_vertices(line::StandardLine{T}, pos::Vector2D{T}) where {T} = (get_tail(line, pos), get_head(line, pos))

# head, tail, and vertices for StandardLine at arbitrary position and orientation
get_head(line::StandardLine{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos + get_half_length(line) * dir
get_tail(line::StandardLine{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos - get_half_length(line) * dir
get_vertices(line::StandardLine{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = (get_tail(line, pos, dir), get_head(line, pos, dir))

#####
# StandardCircle
#####

struct StandardCircle{T} <: AbstractShape
    radius::T
end

get_radius(circle::StandardCircle) = circle.radius

function get_area(circle::StandardCircle{T}) where {T}
    radius = get_radius(circle)
    return convert(T, pi * radius * radius)
end

#####
# StandardRect
#####

struct StandardRect{T} <: AbstractShape
    half_width::T
    half_height::T
end

get_half_width(rect::StandardRect) = rect.half_width
get_half_height(rect::StandardRect) = rect.half_height

get_width(rect::StandardRect) = 2 * get_half_width(rect)
get_height(rect::StandardRect) = 2 * get_half_height(rect)

# bottom_left, bottom_right, top_left, top_right, and vertices for StandardRect
get_bottom_left(rect::StandardRect) = Vector2D(-get_half_width(rect), -get_half_height(rect))
get_bottom_right(rect::StandardRect) = Vector2D(get_half_width(rect), -get_half_height(rect))
get_top_right(rect::StandardRect) = Vector2D(get_half_width(rect), get_half_height(rect))
get_top_left(rect::StandardRect) = Vector2D(-get_half_width(rect), get_half_height(rect))
get_vertices(rect::StandardRect{T}) where {T} = (get_bottom_left(rect), get_bottom_right(rect), get_top_right(rect), get_top_left(rect))

# bottom_left, bottom_right, top_left, top_right, and vertices for StandardRect at arbitrary position
get_bottom_left(rect::StandardRect{T}, pos::Vector2D{T}) where {T} = pos + Vector2D(-get_half_width(rect), -get_half_height(rect))
get_bottom_right(rect::StandardRect{T}, pos::Vector2D{T}) where {T} = pos + Vector2D(get_half_width(rect), -get_half_height(rect))
get_top_right(rect::StandardRect{T}, pos::Vector2D{T}) where {T} = pos + Vector2D(get_half_width(rect), get_half_height(rect))
get_top_left(rect::StandardRect{T}, pos::Vector2D{T}) where {T} = pos + Vector2D(-get_half_width(rect), get_half_height(rect))
get_vertices(rect::StandardRect{T}, pos::Vector2D{T}) where {T} = (get_bottom_left(rect, pos), get_bottom_right(rect, pos), get_top_right(rect, pos), get_top_left(rect, pos))

# bottom_left, bottom_right, top_left, top_right, and vertices for StandardRect at arbitrary position and orientation
get_bottom_left(rect::StandardRect{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos - get_half_width(rect) * dir - get_half_height(rect) * rotate_plus_90(dir)
get_bottom_right(rect::StandardRect{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos + get_half_width(rect) * dir - get_half_height(rect) * rotate_plus_90(dir)
get_top_right(rect::StandardRect{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos + get_half_width(rect) * dir + get_half_height(rect) * rotate_plus_90(dir)
get_top_left(rect::StandardRect{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = pos - get_half_width(rect) * dir + get_half_height(rect) * rotate_plus_90(dir)
get_vertices(rect::StandardRect{T}, pos::Vector2D{T}, dir::Vector2D{T}) where {T} = (get_bottom_left(rect, pos, dir), get_bottom_right(rect, pos, dir), get_top_right(rect, pos, dir), get_top_left(rect, pos, dir))

get_area(rect::StandardRect{T}) where {T} = convert(T, 4 * get_half_width(rect) * get_half_height(rect))

get_normals(rect::StandardRect{T}) where {T} = get_normals(rect, Vector2D(one(T), zero(T)))

function get_normals(rect::StandardRect{T}, dir::Vector2D{T}) where {T}
    x_cap = dir
    y_cap = rotate_plus_90(dir)
    return (-y_cap, x_cap, y_cap, -x_cap)
end


text:
#
#  The following functions allow us to more slickly do probmods (not including any Gen functions!)
#
#	flip(p=0.5)
# 	flip(output1::Any, output2::Any, p::Float64)
# 	inverse_sample(ys::Vector{Float64}; consideration_interval=[0.,1.])
# 	get_beta_params(desired_mode)#mode, spread
#
#  NOT INCLUDING ANY GEN FILES
#
using Distributions

function logmeanexp(scores::Vector{Float64})
    logsumexp(scores) - log(length(scores))
end;

function flip(p::Float64=0.5)
    rand() < p;
end;

# @gen function flip(output1::Any, output2::Any, p::Float64)
#     if ({:flip} ~ bernoulli(p))
#         return output1
#     else
#         return output2
#     end
# end;

function inverse_sample(ys::Vector{Float64}; consideration_interval=[0.,1.])
    ys_idxs_sort = sortperm(ys)
    ys_cdf_fx = StatsBase.ecdf(ys)
    ys_cdf = ys_cdf_fx(ys[ys_idxs_sort])
    xi = uniform(consideration_interval[1],consideration_interval[2])
    yi = findfirst(y -> y >= xi, ys_cdf)
    y0 = findfirst(y -> y >= consideration_interval[1], ys_cdf)
    y1 = findfirst(y -> y >= consideration_interval[2], ys_cdf)
    consideration_interval_std = StatsBase.std(ys[ys_idxs_sort[y0:y1]])
    selected_ys_index = ys_idxs_sort[yi]
    return (selected_ys_index, consideration_interval_std)
end

function get_beta_params(desired_mode)#mode, spread
    m = desired_mode
    a = 10
    b = (a*(1-m) + 2*m - 1)/m
    return (a, b)
end


text:
abstract type AbstractPInv{Style, Typ} end

eltype(::AbstractPInv{<:Any,Typ}) where Typ = eltype(Typ)
eltype(::Type{<:AbstractPInv{<:Any,Typ}}) where Typ = eltype(Typ)

struct PInv{Style, Typ} <: AbstractPInv{Style, Typ}
    style::Style
    A::Typ
end
struct Inv{Style, Typ} <: AbstractPInv{Style, Typ}
    style::Style
    A::Typ
    function Inv{Style,Typ}(style::Style, A::Typ) where {Style,Typ}
        checksquare(A)
        new{Style,Typ}(style,A)
    end
end

Inv(style::Style, A::Typ) where {Style,Typ} = Inv{Style,Typ}(style, A)

PInv(A) = PInv(MemoryLayout(A), A)
Inv(A) = Inv(MemoryLayout(A), A)

pinv(A::PInv) = A.A
function inv(A::PInv)
    checksquare(A.A)
    A.A
end

inv(A::Inv) = A.A
pinv(A::Inv) = inv(A)

parent(A::AbstractPInv) = A.A

size(A::AbstractPInv) = reverse(size(parent(A)))
axes(A::AbstractPInv) = reverse(axes(parent(A)))
size(A::AbstractPInv, k) = size(A)[k]
axes(A::AbstractPInv, k) = axes(A)[k]

abstract type AbstractPInvLayout{ML} <: MemoryLayout end

# struct InverseLayout{ML} <: AbstractPInvLayout{ML}
#     layout::ML
# end

struct PInvLayout{ML} <: AbstractPInvLayout{ML}
    layout::ML
end

MemoryLayout(Ai::AbstractPInv) = PInvLayout(MemoryLayout(Ai.A))

const Ldiv{StyleA, StyleB, AType, BType} =
    Mul2{<:AbstractPInvLayout{StyleA}, StyleB, <:AbstractPInv{StyleA,AType}, BType}
const ArrayLdivArray{styleA, styleB, p, q, T, V} =
    Ldiv{styleA, styleB, <:AbstractArray{T,p}, <:AbstractArray{V,q}}
const ArrayLdivArrayStyle{StyleA,StyleB,p,q} =
    ArrayMulArrayStyle{PInvLayout{StyleA}, StyleB, p, q}
const BArrayLdivArray{styleA, styleB, p, q, T, V} =
    Broadcasted{ArrayLdivArrayStyle{styleA,styleB,p,q}, <:Any, typeof(identity),
                <:Tuple{<:ArrayLdivArray{styleA,styleB,p,q,T,V}}}

BroadcastStyle(::Type{<:ArrayLdivArray{StyleA,StyleB,p,q}}) where {StyleA,StyleB,p,q} =
    ArrayLdivArrayStyle{StyleA,StyleB,p,q}()
broadcastable(M::ArrayLdivArray) = M

Ldiv(A, B) = Mul(PInv(A), B)

macro lazyldiv(Typ)
    esc(quote
        LinearAlgebra.ldiv!(A::$Typ, x::AbstractVector) = (x .= LazyArrays.Ldiv(A,x))
        LinearAlgebra.ldiv!(A::$Typ, x::AbstractMatrix) = (x .= LazyArrays.Ldiv(A,x))
        LinearAlgebra.ldiv!(A::$Typ, x::StridedVector) = (x .= LazyArrays.Ldiv(A,x))
        LinearAlgebra.ldiv!(A::$Typ, x::StridedMatrix) = (x .= LazyArrays.Ldiv(A,x))

        Base.:\(A::$Typ, x::AbstractVector) = PInv(A) * x
        Base.:\(A::$Typ, x::AbstractMatrix) = PInv(A) * x
    end)
end

*(A::AbstractPInv, B, C...) = materialize(Mul(A,B, C...))
*(A::AbstractPInv, B::Mul) = materialize(Mul(A, B.factors...))

similar(A::AbstractPInv, ::Type{T}) where T = Array{T}(undef, size(A))
similar(M::ArrayLdivArray, ::Type{T}) where T = Array{T}(undef, size(M))

materialize(M::ArrayLdivArray) = copyto!(similar(M), M)

@inline function _copyto!(_, dest::AbstractArray, bc::BArrayLdivArray)
    (M,) = bc.args
    copyto!(dest, M)
end

if VERSION ≥ v"1.1-pre"
    function _copyto!(_, dest::AbstractArray, M::ArrayLdivArray)
        Ai, B = M.factors
        ldiv!(dest, factorize(pinv(Ai)), B)
    end
else
    function _copyto!(_, dest::AbstractArray, M::ArrayLdivArray)
        Ai, B = M.factors
        ldiv!(dest, factorize(pinv(Ai)), copy(B))
    end
end

const MatLdivVec{styleA, styleB, T, V} = ArrayLdivArray{styleA, styleB, 2, 1, T, V}
const MatLdivMat{styleA, styleB, T, V} = ArrayLdivArray{styleA, styleB, 2, 2, T, V}

broadcastable(M::MatLdivVec) = M

###
# Triangular
###

function _copyto!(_, dest::AbstractArray, M::ArrayLdivArray{<:TriangularLayout})
    Ai, B = M.factors
    dest ≡ B || (dest .= B)
    ldiv!(pinv(Ai), dest)
end

@inline function _copyto!(::AbstractStridedLayout, dest::AbstractVector{T},
         M::MatLdivVec{<:TriangularLayout{UPLO,UNIT,<:AbstractColumnMajor},
                                   <:AbstractStridedLayout, T, T}) where {UPLO,UNIT,T <: BlasFloat}
    Ai,B = M.factors
    B ≡ dest || copyto!(dest, B)
    BLAS.trsv!(UPLO, 'N', UNIT, triangulardata(pinv(Ai)), dest)
end

@inline function _copyto!(::AbstractStridedLayout, dest::AbstractVector{T},
         M::MatLdivVec{<:TriangularLayout{'U',UNIT,<:AbstractRowMajor},
                                   <:AbstractStridedLayout, T, T}) where {UNIT,T <: BlasFloat}
    Ai,B = M.factors
    B ≡ dest || copyto!(dest, B)
    BLAS.trsv!('L', 'T', UNIT, transpose(triangulardata(pinv(Ai))), dest)
end

@inline function _copyto!(::AbstractStridedLayout, dest::AbstractVector{T},
         M::MatLdivVec{<:TriangularLayout{'L',UNIT,<:AbstractRowMajor},
                                   <:AbstractStridedLayout, T, T}) where {UNIT,T <: BlasFloat}
    Ai,B = M.factors
    B ≡ dest || copyto!(dest, B)
    BLAS.trsv!('U', 'T', UNIT, transpose(triangulardata(pinv(Ai))), dest)
end

@inline function _copyto!(::AbstractStridedLayout, dest::AbstractVector{T},
         M::MatLdivVec{T, <:TriangularLayout{'U',UNIT,<:ConjLayout{<:AbstractRowMajor}},
                                   <:AbstractStridedLayout, T, T}) where {UNIT,T <: BlasFloat}
    Ai,B = M.factors
    B ≡ dest || copyto!(dest, B)
    BLAS.trsv!('L', 'C', UNIT, triangulardata(pinv(Ai))', dest)
end

@inline function _copyto!(::AbstractStridedLayout, dest::AbstractVector{T},
         M::MatLdivVec{<:TriangularLayout{'L',UNIT,<:ConjLayout{<:AbstractRowMajor}},
                                   <:AbstractStridedLayout, T, T}) where {UNIT,T <: BlasFloat}
    Ai,B = M.factors
    B ≡ dest || copyto!(dest, B)
    BLAS.trsv!('U', 'C', UNIT, triangulardata(pinv(Ai))', dest)
end

function _copyto!(_, dest::AbstractMatrix, M::MatLdivMat{<:TriangularLayout})
    A,X = M.factors
    size(dest,2) == size(X,2) || thow(DimensionMismatch("Dimensions must match"))
    @views for j in axes(dest,2)
        dest[:,j] .= Mul(A, X[:,j])
    end
    dest
end

function _PInvMatrix end

struct PInvMatrix{T, PINV<:AbstractPInv} <: AbstractMatrix{T}
    pinv::PINV
    global _PInvMatrix(pinv::PINV) where PINV = new{eltype(pinv), PINV}(pinv)
end

const InvMatrix{T, INV<:Inv} = PInvMatrix{T,INV}

PInvMatrix(M) = _PInvMatrix(PInv(M))
InvMatrix(M) = _PInvMatrix(Inv(M))

axes(A::PInvMatrix) = axes(A.pinv)
size(A::PInvMatrix) = map(length, axes(A))

@propagate_inbounds getindex(A::PInvMatrix{T}, k::Int, j::Int) where T =
    (A.pinv*[Zeros(j-1); one(T); Zeros(size(A,2) - j)])[k]

MemoryLayout(M::PInvMatrix) = MemoryLayout(M.pinv)


text:
function exclude(df, sd_cutoff)
    n = nrow(df)
    # compute SD per subject and exlude based on that
    for s in unique(df[:Subject])
        # compute mean + sd per subject
        s_mean = mean(df[(df.Subject .== s),:ReadingTime])
        s_sd = std(df[df.Subject .==s ,:ReadingTime])
        df = df[.!((df.Subject .== s) .& (df.ReadingTime .> (s_mean + sd_cutoff * s_sd)) .| (df.ReadingTime .< (s_mean - sd_cutoff * s_sd))),:]
    end
    percent_excluded = ((n - nrow(df)) / nrow(df) * 100)
    print("Excluded ", round(percent_excluded, digits=2), "% of data based on ", sd_cutoff, " per-subject SD.\n")

    df
end

function exclude_trial(df, lower, upper, lower_rc, upper_rc)
    df_out = df
    for s in unique(df[:Subject])
        # subset for current subject
        dts = df[(df.Subject .== s),:];
        for i in unique(dts[:Item])
            # subset current item
            dti = dts[(dts.Item .== i),:];

            if sum(dti.ReactionTime .=== missing) > 1
                exc = sum((dti.ReadingTime .> upper) .| (dti.ReadingTime .< lower)) > 0;
                if exc == true
                    #print(dti[:,[:ReadingTime]], "\n")
                    df_out = df_out[.!((df_out.Subject .== s) .& (df_out.Item .== i)),:];
                end
            elseif sum(dti.ReactionTime .=== missing) == 0
                exc = sum((dti.ReadingTime .> upper) .| (dti.ReadingTime .< lower) .| (dti.ReactionTime .> upper_rc) .| (dti.ReactionTime .< lower_rc)) > 0;
                if exc == true
                    #print(dti[:,[:ReactionTime, :ReadingTime]], "\n")
                    df_out = df_out[.!((df_out.Subject .== s) .& (df_out.Item .== i)),:];
                end
            end
        end
    end

    df_out
end

function read_spr_data(path)
    dt = transform!(
    DataFrame(CSV.File(path)),
    :Subject => PooledArray => :Subject,
    :Item => PooledArray => :Item);

    dt = dt[(dt.Condition .== "A"),:]

    dt.srp = log.(dt.Cloze .+ 0.01)
    dt.inter = zscore(dt.srp .* dt.rcnoun)

    dt.logrcnoun = zscore(log.(dt.rcnoun))
    dt.rcnoun = zscore(dt.rcnoun)
    dt.rcverb = zscore(dt.rcverb)
    dt.srp = zscore(dt.srp)
    dt.Cloze = zscore(dt.Cloze)

    dt.logRT = log.(dt.ReadingTime)

    dt
end

function item_coef(b_array,index,n_sub,n_it,n_pred)
    collect(Iterators.flatten(fill(reshape(b_array,(n_it*n_pred))[index:n_pred:(n_it*n_pred)],n_sub)))
end

function subj_coef(b_array,index,n_sub,n_it,n_pred)
    repeat(reshape(b_array,(n_sub*n_pred))[index:n_pred:(n_sub*n_pred)], inner=(n_it))
end

function fit_models(data, form, f_contr)
    # Determine data properties
    num_groupings = length(f_contr);             # number of grouping factors (in ranefs)
    numpred = length(form.rhs) - num_groupings;  # number of predictors (including zval_intercept)
    pred_names = string.(form.rhs[1:numpred]);   # get predictor names
    tl = length(unique(data[:Region]));          # num of unique Regions
    su = length(unique(data[:Subject]));         # num of unique subjects
    it = length(unique(data[:Item]));            # num of unique items
    n = tl * su * it;                            # nrows of final data frame
    r = su * it;                                 # nrows that are written
    subj = unique(data[:Subject]);               # array of unique subjects
    items = unique(data[:Item]);                 # array of unique items

    # Allocate output
    output_names = vcat([:Region, :Subject, :Item], [Symbol.(string("zval_",string(x))) for x in Symbol.(pred_names)],
                         [Symbol.(string("pval_",string(x))) for x in Symbol.(pred_names)],
                         [Symbol.(string("SE_",string(x))) for x in Symbol.(pred_names)],
                         [x for x in Symbol.(pred_names)],
                        [Symbol.(string("s_",string(x))) for x in Symbol.(pred_names)], [Symbol.(string("i_",string(x))) for x in Symbol.(pred_names)], :AIC, :BIC);
    ncols = (3 + numpred * 4 + numpred * num_groupings + 2);
    output = DataFrame(zeros(n, ncols));
    names!(output, output_names);
    output[:Region] = string.(output[:Region]);

    counter = 0;
    startind = 1;
    for (i, t) in enumerate(unique(data[:Region]))
        counter = counter + 1
        # subset data for Region
        te_dt = data[(data.Region .== t),:];

        # fit model
        m = fit(MixedModel, form, te_dt, contrasts=f_contr);
        zvals = m.beta ./ m.stderror
        aic = m.objective + 2 * dof(m)
        bic = m.objective + dof(m) * log(nobs(m))

        # TO DO : use ranef names. Currently only supports fixef = ranef models.
        output[startind:(startind+r-1),:] = DataFrame(vcat([fill(t,r), repeat(subj,inner=it), repeat(items,outer=su)], [fill(y,r) for y in zvals], [fill(y,r) for y in m.pvalues], [fill(y,r) for y in m.stderror],
                                            [fill(y,r) for y in m.beta], [subj_coef(m.b[2],x,su,it,numpred) for x in 1:numpred], [item_coef(m.b[1],x,su,it,numpred) for x in 1:numpred], [fill(aic,r), fill(bic, r)]))

        startind = startind + r

        print("> ", round((counter*100) / tl, digits=2), "% done. Model = ", counter, " / ", tl, "; Region = ", t, ".\r")
    end

    output
end

function combine_datasets(data, lmer_data, preds)
    # collapse eeg data to item * subject subset of non-excluded trials. Rename predictor cols to z*. (zscored predictors)
    stim = combine(groupby(data, [:Subject, :Item, :Condition]), [x => mean => string("z_", x) for x in preds]);
    lmer_data = innerjoin(lmer_data, stim, on = [:Subject, :Item]);
    lmer_data = innerjoin(lmer_data, data[:,[:Region, :Subject, :Item, :logRT, :ReadingTime]], on = [:Region, :Subject, :Item]);

    lmer_data
end

function compute_RTs(lmer_data, preds)
    # Exclude intercept in combinations
    if preds[1] == Symbol("1")
        combi = [[x] for x in preds[2:length(preds)]];
    else
        combi = [[x] for x in preds];
    end

    # TODO: improve to include more than two combis
    # Genereate predictor combinations
    combi_cp = combi
    global excludelist = [:plc]
    global combi
    for x in combi_cp
        for y in combi_cp
            if (x != y) & (sum([[x, y] == z for z in excludelist]) == 0)
                # TODO: avoid global
                global combi = vcat(combi, [[x, y]]);
                global excludelist = vcat(excludelist, [[y, x]]);
            end
        end
    end

    # vcat intercept with combination
    if preds[1] == Symbol("1")
        combi = vcat([[preds[1]]], combi);
        combi =  vcat(combi, [[[x] for x in preds[2:length(preds)]]]);
    else
        combi = vcat(combi, [[[x] for x in preds[2:length(preds)]]])
    end

    for x in combi
        if x[1] == Symbol("1") # intercept
            lmer_data[:est_1] = lmer_data[Symbol("1")] .+ lmer_data[:s_1]  .+ lmer_data[:i_1]
        elseif typeof(x[1]) == Symbol # intercept + single pred
            lmer_data[Symbol(string("est_"), x[1])] = lmer_data[:est_1] + (lmer_data[x[1]] .+ lmer_data[Symbol("s_", x[1])] .+ lmer_data[Symbol("i_", x[1])]) .* lmer_data[Symbol("z_", x[1])];
        elseif typeof(x[1]) == Array{Symbol,1} # intercept + combination of preds
            # start with intercept
            temp_data = lmer_data[:est_1]
            colname = "est_"
            # for each element within combination
            for y in x
                colname = string(colname, y[1])
                temp_data = temp_data .+ (lmer_data[Symbol(y[1])] .+ lmer_data[Symbol("s_", y[1])] .+ lmer_data[Symbol("i_", y[1])]) .* lmer_data[Symbol("z_", y[1])]
            end
            lmer_data[Symbol(colname)] = temp_data
        end
    end

    lmer_data
end

function compute_residuals(lmer_data, preds)
    # Residuals: observed - estimated
    for x in preds
        lmer_data[Symbol(string("res_", string(x[5:lastindex(x)])))] = lmer_data[:logRT] .- lmer_data[Symbol(x)]
    end

    lmer_data
end

function compute_coefs(lmer_data, preds)
    # Compute sum of intercept and coefs (fixef + subject ranef + item ranef)
    for x in preds
        if x == Symbol("1")
            lmer_data[:coef_1] = lmer_data[Symbol("1")] .+ lmer_data[:s_1] .+ lmer_data[:i_1]
        else
            lmer_data[Symbol(string("coef_intercept_", string(x)))] = lmer_data[:coef_1] .+ lmer_data[x] .+ lmer_data[Symbol(string("s_", string(x)))] .+ lmer_data[Symbol(string("i_", string(x)))]
        end
    end

    lmer_data
end


text:
using MPIExecutor
using Test

@testset "Start and shutdown" begin
    MPIPoolExecutor(1) do pool
        @test size(pool) == 1
    end
end

@testset "Empty pool" begin
    MPIPoolExecutor(0) do pool
        @test size(pool) == 1 # master behaves as slave
    end
end

@testset "Simple call once" begin
    MPIPoolExecutor(1) do pool
        x = submit!(pool, identity, 123)
        @test get!(x) == 123
        run!(pool)
    end
end

@testset "Simple remote once" begin
    MPIPoolExecutor(1) do pool
        test = @remote pool function()
            123
        end

        x = submit!(pool, test)

        @test get!(x) == 123

        run!(pool)
    end
end

@testset "Run everywhere" begin
    worker_count = 2
    MPIPoolExecutor(worker_count) do pool
        test = @remote pool function()
            123
        end

        x = run_broadcast!(pool, test)

        @test get!(x) == [123, 123]
    end
end

@testset "Futures: whenall" begin
    MPIPoolExecutor(0) do pool
        func = @remote pool (x) -> x^2
        Future = MPIExecutor.Future
        futs = [then!(f, func) for f in [Future(pool, Some(1)), Future(pool, Some(2))]]
        f = then!(whenall!(futs), identity)
        @test get!(f) == [1,4]
    end
end

@testset "Futures: whenall throws" begin
    MPIPoolExecutor(0) do pool
        func = @remote pool (x) -> x^2
        Future = MPIExecutor.Future
        futs = [then!(f, func) for f in [Future(pool, InterruptException()), Future(pool, Some(2))]]
        f = then!(whenall!(futs), identity)
        @test_throws InterruptException get!(f)
    end
end

@testset "Futures: then remote" begin
    MPIPoolExecutor(0) do pool
        f = @remote pool () -> 2
        g = @remote pool (x) -> x^2

        fut = submit!(pool, f)
        fut = then!(fut, g)
        @test get!(fut) == 4
    end
end

@testset "Futures: then remote throws" begin
    MPIPoolExecutor(0) do pool
        f = @remote pool () -> error("bla")
        g = @remote pool (x) -> x^2

        fut = submit!(pool, f)
        fut = then!(fut, g)
        @test_throws ErrorException get!(fut)
    end
end