text:
@testset "6.6.3 Hyperbolic cosecant functions" begin
    (a, b, c, d, n, p, x, ) = @variables a b c d n p x

    #= ::Package:: =#

    #= ::Title:: =#
    #=Integration*Problems*Involving*Hyperbolic*Cosecants=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x))^n=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*csch(a+b*x)^n=#

    @test_int [csch(a + b*x), x, 1, -(atanh(cosh(a + b*x))/b)]
    @test_int [csch(a + b*x)^2, x, 2, -coth(a + b*x)/b]
    @test_int [csch(a + b*x)^3, x, 2, atanh(cosh(a + b*x))/(2*b) - (coth(a + b*x)*csch(a + b*x))/(2*b)]
    @test_int [csch(a + b*x)^4, x, 2, coth(a + b*x)/b - coth(a + b*x)^3/(3*b)]
    @test_int [csch(a + b*x)^5, x, 3, -((3*atanh(cosh(a + b*x)))/(8*b)) + (3*coth(a + b*x)*csch(a + b*x))/(8*b) - (coth(a + b*x)*csch(a + b*x)^3)/(4*b)]
    @test_int [csch(a + b*x)^6, x, 2, -(coth(a + b*x)/b) + (2*coth(a + b*x)^3)/(3*b) - coth(a + b*x)^5/(5*b)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x))^(n/2)=#

    @test_int [csch(a + b*x)^(5/2), x, 3, -((2*cosh(a + b*x)*csch(a + b*x)^(3/2))/(3*b)) + (2*im*sqrt(csch(a + b*x))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*x), 2)*sqrt(im*sinh(a + b*x)))/(3*b)]
    @test_int [csch(a + b*x)^(3/2), x, 3, -((2*cosh(a + b*x)*sqrt(csch(a + b*x)))/b) - (2*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*x), 2))/(b*sqrt(csch(a + b*x))*sqrt(im*sinh(a + b*x)))]
    @test_int [csch(a + b*x)^(1/2), x, 2, -((2*im*sqrt(csch(a + b*x))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*x), 2)*sqrt(im*sinh(a + b*x)))/b)]
    @test_int [1/csch(a + b*x)^(1/2), x, 2, -((2*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*x), 2))/(b*sqrt(csch(a + b*x))*sqrt(im*sinh(a + b*x))))]
    @test_int [1/csch(a + b*x)^(3/2), x, 3, (2*cosh(a + b*x))/(3*b*sqrt(csch(a + b*x))) + (2*im*sqrt(csch(a + b*x))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*x), 2)*sqrt(im*sinh(a + b*x)))/(3*b)]
    @test_int [1/csch(a + b*x)^(5/2), x, 3, (2*cosh(a + b*x))/(5*b*csch(a + b*x)^(3/2)) + (6*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*x), 2))/(5*b*sqrt(csch(a + b*x))*sqrt(im*sinh(a + b*x)))]

    @test_int [(b*csch(c + d*x))^(7/2), x, 4, (6*b^3*cosh(c + d*x)*sqrt(b*csch(c + d*x)))/(5*d) - (2*b*cosh(c + d*x)*(b*csch(c + d*x))^(5/2))/(5*d) + (6*im*b^4*Elliptic.E((1/2)*(im*c - pi/2 + im*d*x), 2))/(5*d*sqrt(b*csch(c + d*x))*sqrt(im*sinh(c + d*x)))]
    @test_int [(b*csch(c + d*x))^(5/2), x, 3, -((2*b*cosh(c + d*x)*(b*csch(c + d*x))^(3/2))/(3*d)) + (2*im*b^2*sqrt(b*csch(c + d*x))*Elliptic.F((1/2)*(im*c - pi/2 + im*d*x), 2)*sqrt(im*sinh(c + d*x)))/(3*d)]
    @test_int [(b*csch(c + d*x))^(3/2), x, 3, -((2*b*cosh(c + d*x)*sqrt(b*csch(c + d*x)))/d) - (2*im*b^2*Elliptic.E((1/2)*(im*c - pi/2 + im*d*x), 2))/(d*sqrt(b*csch(c + d*x))*sqrt(im*sinh(c + d*x)))]
    @test_int [(b*csch(c + d*x))^(1/2), x, 2, -((2*im*sqrt(b*csch(c + d*x))*Elliptic.F((1/2)*(im*c - pi/2 + im*d*x), 2)*sqrt(im*sinh(c + d*x)))/d)]
    @test_int [1/(b*csch(c + d*x))^(1/2), x, 2, -((2*im*Elliptic.E((1/2)*(im*c - pi/2 + im*d*x), 2))/(d*sqrt(b*csch(c + d*x))*sqrt(im*sinh(c + d*x))))]
    @test_int [1/(b*csch(c + d*x))^(3/2), x, 3, (2*cosh(c + d*x))/(3*b*d*sqrt(b*csch(c + d*x))) + (2*im*sqrt(b*csch(c + d*x))*Elliptic.F((1/2)*(im*c - pi/2 + im*d*x), 2)*sqrt(im*sinh(c + d*x)))/(3*b^2*d)]
    @test_int [1/(b*csch(c + d*x))^(5/2), x, 3, (2*cosh(c + d*x))/(5*b*d*(b*csch(c + d*x))^(3/2)) + (6*im*Elliptic.E((1/2)*(im*c - pi/2 + im*d*x), 2))/(5*b^2*d*sqrt(b*csch(c + d*x))*sqrt(im*sinh(c + d*x)))]
    @test_int [1/(b*csch(c + d*x))^(7/2), x, 4, (2*cosh(c + d*x))/(7*b*d*(b*csch(c + d*x))^(5/2)) - (10*cosh(c + d*x))/(21*b^3*d*sqrt(b*csch(c + d*x))) - (10*im*sqrt(b*csch(c + d*x))*Elliptic.F((1/2)*(im*c - pi/2 + im*d*x), 2)*sqrt(im*sinh(c + d*x)))/(21*b^4*d)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x))^n*with*n*symbolic=#

    @test_int [(b*csch(c + d*x))^n, x, 2, (b*cosh(c + d*x)*(b*csch(c + d*x))^(-1 + n)*HypergeometricFunctions._₂F₁(1/2, (1 - n)/2, (3 - n)/2, -sinh(c + d*x)^2))/(d*(1 - n)*sqrt(cosh(c + d*x)^2))]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x)^m)^n=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x)^2)^n=#

    @test_int [(-csch(x)^2)^(5/2), x, 4, (3/8)*asin(coth(x)) + (3/8)*coth(x)*sqrt(-csch(x)^2) + (1/4)*coth(x)*(-csch(x)^2)^(3/2)]
    @test_int [(-csch(x)^2)^(3/2), x, 3, (1/2)*asin(coth(x)) + (1/2)*coth(x)*sqrt(-csch(x)^2)]
    @test_int [(-csch(x)^2)^(1/2), x, 2, asin(coth(x))]
    @test_int [1/(-csch(x)^2)^(1/2), x, 2, coth(x)/sqrt(-csch(x)^2)]
    @test_int [1/(-csch(x)^2)^(3/2), x, 3, coth(x)/(3*(-csch(x)^2)^(3/2)) + (2*coth(x))/(3*sqrt(-csch(x)^2))]
    @test_int [1/(-csch(x)^2)^(5/2), x, 4, coth(x)/(5*(-csch(x)^2)^(5/2)) + (4*coth(x))/(15*(-csch(x)^2)^(3/2)) + (8*coth(x))/(15*sqrt(-csch(x)^2))]
    @test_int [1/(-csch(x)^2)^(7/2), x, 5, coth(x)/(7*(-csch(x)^2)^(7/2)) + (6*coth(x))/(35*(-csch(x)^2)^(5/2)) + (8*coth(x))/(35*(-csch(x)^2)^(3/2)) + (16*coth(x))/(35*sqrt(-csch(x)^2))]

    @test_int [(a*csch(x)^2)^(5/2), x, 5, (-(3/8))*a^(5/2)*atanh((sqrt(a)*coth(x))/sqrt(a*csch(x)^2)) + (3/8)*a^2*coth(x)*sqrt(a*csch(x)^2) - (1/4)*a*coth(x)*(a*csch(x)^2)^(3/2)]
    @test_int [(a*csch(x)^2)^(3/2), x, 4, (1/2)*a^(3/2)*atanh((sqrt(a)*coth(x))/sqrt(a*csch(x)^2)) - (1/2)*a*coth(x)*sqrt(a*csch(x)^2)]
    @test_int [(a*csch(x)^2)^(1/2), x, 3, (-sqrt(a))*atanh((sqrt(a)*coth(x))/sqrt(a*csch(x)^2))]
    @test_int [1/(a*csch(x)^2)^(1/2), x, 2, coth(x)/sqrt(a*csch(x)^2)]
    @test_int [1/(a*csch(x)^2)^(3/2), x, 3, coth(x)/(3*(a*csch(x)^2)^(3/2)) - (2*coth(x))/(3*a*sqrt(a*csch(x)^2))]
    @test_int [1/(a*csch(x)^2)^(5/2), x, 4, coth(x)/(5*(a*csch(x)^2)^(5/2)) - (4*coth(x))/(15*a*(a*csch(x)^2)^(3/2)) + (8*coth(x))/(15*a^2*sqrt(a*csch(x)^2))]
    @test_int [1/(a*csch(x)^2)^(7/2), x, 5, coth(x)/(7*(a*csch(x)^2)^(7/2)) - (6*coth(x))/(35*a*(a*csch(x)^2)^(5/2)) + (8*coth(x))/(35*a^2*(a*csch(x)^2)^(3/2)) - (16*coth(x))/(35*a^3*sqrt(a*csch(x)^2))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x)^3)^n=#

    @test_int [(a*csch(x)^3)^(5/2), x, 7, (-(154/585))*a^2*coth(x)*sqrt(a*csch(x)^3) + (22/117)*a^2*coth(x)*csch(x)^2*sqrt(a*csch(x)^3) - (2/13)*a^2*coth(x)*csch(x)^4*sqrt(a*csch(x)^3) + (154/195)*a^2*cosh(x)*sqrt(a*csch(x)^3)*sinh(x) - (154*im*a^2*sqrt(a*csch(x)^3)*Elliptic.E(pi/4 - (im*x)/2, 2)*sinh(x)^2)/(195*sqrt(im*sinh(x)))]
    @test_int [(a*csch(x)^3)^(3/2), x, 5, (10/21)*a*cosh(x)*sqrt(a*csch(x)^3) - (2/7)*a*coth(x)*csch(x)*sqrt(a*csch(x)^3) + (10/21)*im*a*sqrt(a*csch(x)^3)*Elliptic.F(pi/4 - (im*x)/2, 2)*sqrt(im*sinh(x))*sinh(x)]
    @test_int [(a*csch(x)^3)^(1/2), x, 4, -2*im*sqrt(a*csch(x)^3)*Elliptic.E(pi/4 - (im*x)/2, 2)*(im*sinh(x))^(3/2) - 2*cosh(x)*sqrt(a*csch(x)^3)*sinh(x), -2*cosh(x)*sqrt(a*csch(x)^3)*sinh(x) + (2*im*sqrt(a*csch(x)^3)*Elliptic.E(pi/4 - (im*x)/2, 2)*sinh(x)^2)/sqrt(im*sinh(x))]
    @test_int [1/(a*csch(x)^3)^(1/2), x, 4, (2*coth(x))/(3*sqrt(a*csch(x)^3)) - (2*im*csch(x)^2*Elliptic.F(pi/4 - (im*x)/2, 2)*sqrt(im*sinh(x)))/(3*sqrt(a*csch(x)^3))]
    @test_int [1/(a*csch(x)^3)^(3/2), x, 5, -((14*cosh(x))/(45*a*sqrt(a*csch(x)^3))) + (14*im*csch(x)*Elliptic.E(pi/4 - (im*x)/2, 2))/(15*a*sqrt(a*csch(x)^3)*sqrt(im*sinh(x))) + (2*cosh(x)*sinh(x)^2)/(9*a*sqrt(a*csch(x)^3))]
    @test_int [1/(a*csch(x)^3)^(5/2), x, 7, -((26*coth(x))/(77*a^2*sqrt(a*csch(x)^3))) + (26*im*csch(x)^2*Elliptic.F(pi/4 - (im*x)/2, 2)*sqrt(im*sinh(x)))/(77*a^2*sqrt(a*csch(x)^3)) + (78*cosh(x)*sinh(x))/(385*a^2*sqrt(a*csch(x)^3)) - (26*cosh(x)*sinh(x)^3)/(165*a^2*sqrt(a*csch(x)^3)) + (2*cosh(x)*sinh(x)^5)/(15*a^2*sqrt(a*csch(x)^3))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x)^4)^n=#

    @test_int [(a*csch(x)^4)^(7/2), x, 3, 2*a^3*cosh(x)^2*coth(x)*sqrt(a*csch(x)^4) - 3*a^3*cosh(x)^2*coth(x)^3*sqrt(a*csch(x)^4) + (20/7)*a^3*cosh(x)^2*coth(x)^5*sqrt(a*csch(x)^4) - (5/3)*a^3*cosh(x)^2*coth(x)^7*sqrt(a*csch(x)^4) + (6/11)*a^3*cosh(x)^2*coth(x)^9*sqrt(a*csch(x)^4) - (1/13)*a^3*cosh(x)^2*coth(x)^11*sqrt(a*csch(x)^4) - a^3*cosh(x)*sqrt(a*csch(x)^4)*sinh(x)]
    @test_int [(a*csch(x)^4)^(5/2), x, 3, (4/3)*a^2*cosh(x)^2*coth(x)*sqrt(a*csch(x)^4) - (6/5)*a^2*cosh(x)^2*coth(x)^3*sqrt(a*csch(x)^4) + (4/7)*a^2*cosh(x)^2*coth(x)^5*sqrt(a*csch(x)^4) - (1/9)*a^2*cosh(x)^2*coth(x)^7*sqrt(a*csch(x)^4) - a^2*cosh(x)*sqrt(a*csch(x)^4)*sinh(x)]
    @test_int [(a*csch(x)^4)^(3/2), x, 3, (2/3)*a*cosh(x)^2*coth(x)*sqrt(a*csch(x)^4) - (1/5)*a*cosh(x)^2*coth(x)^3*sqrt(a*csch(x)^4) - a*cosh(x)*sqrt(a*csch(x)^4)*sinh(x)]
    @test_int [(a*csch(x)^4)^(1/2), x, 3, (-cosh(x))*sqrt(a*csch(x)^4)*sinh(x)]
    @test_int [1/(a*csch(x)^4)^(1/2), x, 3, coth(x)/(2*sqrt(a*csch(x)^4)) - (x*csch(x)^2)/(2*sqrt(a*csch(x)^4))]
    @test_int [1/(a*csch(x)^4)^(3/2), x, 5, (5*coth(x))/(16*a*sqrt(a*csch(x)^4)) - (5*x*csch(x)^2)/(16*a*sqrt(a*csch(x)^4)) - (5*cosh(x)*sinh(x))/(24*a*sqrt(a*csch(x)^4)) + (cosh(x)*sinh(x)^3)/(6*a*sqrt(a*csch(x)^4))]
    @test_int [1/(a*csch(x)^4)^(5/2), x, 7, (63*coth(x))/(256*a^2*sqrt(a*csch(x)^4)) - (63*x*csch(x)^2)/(256*a^2*sqrt(a*csch(x)^4)) - (21*cosh(x)*sinh(x))/(128*a^2*sqrt(a*csch(x)^4)) + (21*cosh(x)*sinh(x)^3)/(160*a^2*sqrt(a*csch(x)^4)) - (9*cosh(x)*sinh(x)^5)/(80*a^2*sqrt(a*csch(x)^4)) + (cosh(x)*sinh(x)^7)/(10*a^2*sqrt(a*csch(x)^4))]

    #= ::Subsection:: =#
    #=Integrands*of*the*form*(c*csch(a+b*x)^m)^n=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*Hyper(c+d*x)^m*(a+b*csch(c+d*x))^n=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*sinh(c+d*x)^m*(a+b*csch(c+d*x))^n=#

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2=0=#

    @test_int [1/(a + im*a*csch(a + b*x)), x, 2, x/a - coth(a + b*x)/(b*(a + im*a*csch(a + b*x)))]

    @test_int [1/(a - im*a*csch(a + b*x)), x, 2, x/a - coth(a + b*x)/(b*(a - im*a*csch(a + b*x)))]

    @test_int [(a + a*im*csch(c + d*x))^(5/2), x, 5, (2*a^(5/2)*atanh((sqrt(a)*coth(c + d*x))/sqrt(a + im*a*csch(c + d*x))))/d + (14*a^3*coth(c + d*x))/(3*d*sqrt(a + im*a*csch(c + d*x))) + (2*a^2*coth(c + d*x)*sqrt(a + im*a*csch(c + d*x)))/(3*d)]
    @test_int [(a + a*im*csch(c + d*x))^(3/2), x, 4, (2*a^(3/2)*atanh((sqrt(a)*coth(c + d*x))/sqrt(a + im*a*csch(c + d*x))))/d + (2*a^2*coth(c + d*x))/(d*sqrt(a + im*a*csch(c + d*x)))]
    @test_int [(a + a*im*csch(c + d*x))^(1/2), x, 2, (2*sqrt(a)*atanh((sqrt(a)*coth(c + d*x))/sqrt(a + im*a*csch(c + d*x))))/d]
    @test_int [1/(a + a*im*csch(c + d*x))^(1/2), x, 5, (2*atanh((sqrt(a)*coth(c + d*x))/sqrt(a + im*a*csch(c + d*x))))/(sqrt(a)*d) - (sqrt(2)*atanh((sqrt(a)*coth(c + d*x))/(sqrt(2)*sqrt(a + im*a*csch(c + d*x)))))/(sqrt(a)*d)]
    @test_int [1/(a + a*im*csch(c + d*x))^(3/2), x, 6, (2*atanh((sqrt(a)*coth(c + d*x))/sqrt(a + im*a*csch(c + d*x))))/(a^(3/2)*d) - (5*atanh((sqrt(a)*coth(c + d*x))/(sqrt(2)*sqrt(a + im*a*csch(c + d*x)))))/(2*sqrt(2)*a^(3/2)*d) - coth(c + d*x)/(2*d*(a + im*a*csch(c + d*x))^(3/2))]

    @test_int [sqrt(a - a*im*csch(c + d*x)), x, 2, (2*sqrt(a)*atanh((sqrt(a)*coth(c + d*x))/sqrt(a - im*a*csch(c + d*x))))/d]
    @test_int [1/sqrt(a - im*a*csch(c + d*x)), x, 5, (2*atanh((sqrt(a)*coth(c + d*x))/sqrt(a - im*a*csch(c + d*x))))/(sqrt(a)*d) - (sqrt(2)*atanh((sqrt(a)*coth(c + d*x))/(sqrt(2)*sqrt(a - im*a*csch(c + d*x)))))/(sqrt(a)*d)]

    @test_int [sqrt(3 + 3*im*csch(x)), x, 2, 2*sqrt(3)*atanh(coth(x)/sqrt(1 + im*csch(x)))]
    @test_int [sqrt(3 - 3*im*csch(x)), x, 2, 2*sqrt(3)*atanh(coth(x)/sqrt(1 - im*csch(x)))]
    @test_int [sqrt(-3 + 3*im*csch(x)), x, 2, -2*sqrt(3)*atan(coth(x)/sqrt(-1 + im*csch(x)))]
    @test_int [sqrt(-3 - 3*im*csch(x)), x, 2, -2*sqrt(3)*atan(coth(x)/sqrt(-1 - im*csch(x)))]

    @test_int [sinh(x)^4/(im + csch(x)), x, 7, -((15*im*x)/8) - 4*cosh(x) + (4*cosh(x)^3)/3 + (15/8)*im*cosh(x)*sinh(x) - (5/4)*im*cosh(x)*sinh(x)^3 - (cosh(x)*sinh(x)^3)/(im + csch(x))]
    @test_int [sinh(x)^3/(im + csch(x)), x, 6, -((3*x)/2) + 4*im*cosh(x) - (4/3)*im*cosh(x)^3 + (3/2)*cosh(x)*sinh(x) - (cosh(x)*sinh(x)^2)/(im + csch(x))]
    @test_int [sinh(x)^2/(im + csch(x)), x, 5, (3*im*x)/2 + 2*cosh(x) - (3/2)*im*cosh(x)*sinh(x) - (cosh(x)*sinh(x))/(im + csch(x))]
    @test_int [sinh(x)^1/(im + csch(x)), x, 4, x - 2*im*cosh(x) - cosh(x)/(im + csch(x))]
    @test_int [csch(x)^1/(im + csch(x)), x, 1, (im*coth(x))/(im + csch(x))]
    @test_int [csch(x)^2/(im + csch(x)), x, 3, -atanh(cosh(x)) + coth(x)/(im + csch(x))]
    @test_int [csch(x)^3/(im + csch(x)), x, 4, im*atanh(cosh(x)) - coth(x) - (im*coth(x))/(im + csch(x))]
    @test_int [csch(x)^4/(im + csch(x)), x, 6, (3/2)*atanh(cosh(x)) + 2*im*coth(x) - (3/2)*coth(x)*csch(x) + (coth(x)*csch(x)^2)/(im + csch(x))]

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2!=0=#

    @test_int [(a + b*csch(c + d*x))^4, x, 6, a^4*x - (2*a*b*(2*a^2 - b^2)*atanh(cosh(c + d*x)))/d - (b^2*(17*a^2 - 2*b^2)*coth(c + d*x))/(3*d) - (4*a*b^3*coth(c + d*x)*csch(c + d*x))/(3*d) - (b^2*coth(c + d*x)*(a + b*csch(c + d*x))^2)/(3*d)]
    @test_int [(a + b*csch(c + d*x))^3, x, 5, a^3*x - (b*(6*a^2 - b^2)*atanh(cosh(c + d*x)))/(2*d) - (5*a*b^2*coth(c + d*x))/(2*d) - (b^2*coth(c + d*x)*(a + b*csch(c + d*x)))/(2*d)]
    @test_int [(a + b*csch(c + d*x))^2, x, 4, a^2*x - (2*a*b*atanh(cosh(c + d*x)))/d - (b^2*coth(c + d*x))/d]
    @test_int [(a + b*csch(c + d*x))^1, x, 2, a*x - (b*atanh(cosh(c + d*x)))/d]
    @test_int [1/(a + b*csch(c + d*x))^1, x, 4, x/a + (2*b*atanh((a - b*tanh((1/2)*(c + d*x)))/sqrt(a^2 + b^2)))/(a*sqrt(a^2 + b^2)*d)]
    @test_int [1/(a + b*csch(c + d*x))^2, x, 6, x/a^2 + (2*b*(2*a^2 + b^2)*atanh((a - b*tanh((1/2)*(c + d*x)))/sqrt(a^2 + b^2)))/(a^2*(a^2 + b^2)^(3/2)*d) - (b^2*coth(c + d*x))/(a*(a^2 + b^2)*d*(a + b*csch(c + d*x)))]
    @test_int [1/(a + b*csch(c + d*x))^3, x, 7, x/a^3 + (b*(6*a^4 + 5*a^2*b^2 + 2*b^4)*atanh((a - b*tanh((1/2)*(c + d*x)))/sqrt(a^2 + b^2)))/(a^3*(a^2 + b^2)^(5/2)*d) - (b^2*coth(c + d*x))/(2*a*(a^2 + b^2)*d*(a + b*csch(c + d*x))^2) - (b^2*(5*a^2 + 2*b^2)*coth(c + d*x))/(2*a^2*(a^2 + b^2)^2*d*(a + b*csch(c + d*x)))]

    @test_int [sinh(x)^3/(a + b*csch(x)), x, 8, (b*(a^2 - 2*b^2)*x)/(2*a^4) - (2*b^4*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a^4*sqrt(a^2 + b^2)) - ((2*a^2 - 3*b^2)*cosh(x))/(3*a^3) - (b*cosh(x)*sinh(x))/(2*a^2) + (cosh(x)*sinh(x)^2)/(3*a)]
    @test_int [sinh(x)^2/(a + b*csch(x)), x, 7, -(((a^2 - 2*b^2)*x)/(2*a^3)) + (2*b^3*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a^3*sqrt(a^2 + b^2)) - (b*cosh(x))/a^2 + (cosh(x)*sinh(x))/(2*a)]
    @test_int [sinh(x)^1/(a + b*csch(x)), x, 6, -((b*x)/a^2) - (2*b^2*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a^2*sqrt(a^2 + b^2)) + cosh(x)/a]
    @test_int [csch(x)^1/(a + b*csch(x)), x, 4, -((2*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/sqrt(a^2 + b^2))]
    @test_int [csch(x)^2/(a + b*csch(x)), x, 6, -(atanh(cosh(x))/b) + (2*a*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(b*sqrt(a^2 + b^2))]
    @test_int [csch(x)^3/(a + b*csch(x)), x, 7, (a*atanh(cosh(x)))/b^2 - (2*a^2*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(b^2*sqrt(a^2 + b^2)) - coth(x)/b]
    @test_int [csch(x)^4/(a + b*csch(x)), x, 8, -(((2*a^2 - b^2)*atanh(cosh(x)))/(2*b^3)) + (2*a^3*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(b^3*sqrt(a^2 + b^2)) + (a*coth(x))/b^2 - (coth(x)*csch(x))/(2*b)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*cosh(c+d*x)^m*(a+b*csch(c+d*x))^n=#

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2=0=#

    @test_int [cosh(x)^4/(im + csch(x)), x, 7, (im*x)/8 + cosh(x)^3/3 + (1/8)*im*cosh(x)*sinh(x) - (1/4)*im*cosh(x)^3*sinh(x)]
    @test_int [cosh(x)^3/(im + csch(x)), x, 6, sinh(x)^2/2 - (1/3)*im*sinh(x)^3]
    @test_int [cosh(x)^2/(im + csch(x)), x, 5, (im*x)/2 + cosh(x) - (1/2)*im*cosh(x)*sinh(x)]
    @test_int [cosh(x)^1/(im + csch(x)), x, 4, log(im - sinh(x)) - im*sinh(x)]
    @test_int [sech(x)^1/(im + csch(x)), x, 6, (-(1/2))*im*atan(sinh(x)) - sech(x)^2/2 + (1/2)*im*sech(x)*tanh(x)]
    @test_int [sech(x)^2/(im + csch(x)), x, 6, (-(1/3))*sech(x)^3 - (1/3)*im*tanh(x)^3]
    @test_int [sech(x)^3/(im + csch(x)), x, 7, (-(1/8))*im*atan(sinh(x)) - sech(x)^4/4 - (1/8)*im*sech(x)*tanh(x) + (1/4)*im*sech(x)^3*tanh(x)]
    @test_int [sech(x)^4/(im + csch(x)), x, 7, (-(1/5))*sech(x)^5 - (1/3)*im*tanh(x)^3 + (1/5)*im*tanh(x)^5]

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2!=0=#

    @test_int [cosh(x)^5/(a + b*csch(x)), x, 5, -((b*(a^2 + b^2)^2*log(b + a*sinh(x)))/a^6) + ((a^2 + b^2)^2*sinh(x))/a^5 - (b*(2*a^2 + b^2)*sinh(x)^2)/(2*a^4) + ((2*a^2 + b^2)*sinh(x)^3)/(3*a^3) - (b*sinh(x)^4)/(4*a^2) + sinh(x)^5/(5*a)]
    @test_int [cosh(x)^4/(a + b*csch(x)), x, 7, ((3*a^4 + 12*a^2*b^2 + 8*b^4)*x)/(8*a^5) + (2*b*(a^2 + b^2)^(3/2)*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/a^5 - (cosh(x)^3*(4*b - 3*a*sinh(x)))/(12*a^2) - (cosh(x)*(8*b*(a^2 + b^2) - a*(3*a^2 + 4*b^2)*sinh(x)))/(8*a^4)]
    @test_int [cosh(x)^3/(a + b*csch(x)), x, 5, -((b*(a^2 + b^2)*log(b + a*sinh(x)))/a^4) + ((a^2 + b^2)*sinh(x))/a^3 - (b*sinh(x)^2)/(2*a^2) + sinh(x)^3/(3*a)]
    @test_int [cosh(x)^2/(a + b*csch(x)), x, 6, ((a^2 + 2*b^2)*x)/(2*a^3) + (2*b*sqrt(a^2 + b^2)*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/a^3 - (cosh(x)*(2*b - a*sinh(x)))/(2*a^2)]
    @test_int [cosh(x)^1/(a + b*csch(x)), x, 5, -((b*log(b + a*sinh(x)))/a^2) + sinh(x)/a]
    @test_int [sech(x)^1/(a + b*csch(x)), x, 4, log(im - sinh(x))/(2*(im*a + b)) - log(im + sinh(x))/(2*(im*a - b)) - (b*log(b + a*sinh(x)))/(a^2 + b^2)]
    @test_int [sech(x)^2/(a + b*csch(x)), x, 6, (2*a*b*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a^2 + b^2)^(3/2) - (sech(x)*(b - a*sinh(x)))/(a^2 + b^2)]
    @test_int [sech(x)^3/(a + b*csch(x)), x, 6, -((im*a*log(im - sinh(x)))/(4*(a - im*b)^2)) + (im*a*log(im + sinh(x)))/(4*(a + im*b)^2) - (a^2*b*log(b + a*sinh(x)))/(a^2 + b^2)^2 - (sech(x)^2*(b - a*sinh(x)))/(2*(a^2 + b^2))]
    @test_int [sech(x)^4/(a + b*csch(x)), x, 7, (2*a^3*b*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a^2 + b^2)^(5/2) - (sech(x)^3*(b - a*sinh(x)))/(3*(a^2 + b^2)) - (sech(x)*(3*a^2*b - a*(2*a^2 - b^2)*sinh(x)))/(3*(a^2 + b^2)^2)]
    @test_int [sech(x)^5/(a + b*csch(x)), x, 7, -((a*(3*im*a + b)*log(im - sinh(x)))/(16*(a - im*b)^3)) + (a*(3*a + im*b)*log(im + sinh(x)))/(16*(im*a - b)^3) - (a^4*b*log(b + a*sinh(x)))/(a^2 + b^2)^3 - (sech(x)^4*(b - a*sinh(x)))/(4*(a^2 + b^2)) - (sech(x)^2*(4*a^2*b - a*(3*a^2 - b^2)*sinh(x)))/(8*(a^2 + b^2)^2)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*tanh(c+d*x)^m*(a+b*csch(c+d*x))^n=#

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2=0=#

    @test_int [tanh(x)^5/(im + csch(x)), x, 3, (-(21/32))*im*log(im - sinh(x)) - (11/32)*im*log(im + sinh(x)) + im/(32*(1 - im*sinh(x))^2) - im/(4*(1 - im*sinh(x))) - im/(24*(1 + im*sinh(x))^3) + (9*im)/(32*(1 + im*sinh(x))^2) - (15*im)/(16*(1 + im*sinh(x)))]
    @test_int [tanh(x)^4/(im + csch(x)), x, 5, (-im)*x + (1/15)*(15*im - 8*csch(x))*tanh(x) + (1/15)*(5*im - 4*csch(x))*tanh(x)^3 + (1/5)*(im - csch(x))*tanh(x)^5]
    @test_int [tanh(x)^3/(im + csch(x)), x, 3, (-(11/16))*im*log(im - sinh(x)) - (5/16)*im*log(im + sinh(x)) - im/(8*(1 - im*sinh(x))) + im/(8*(1 + im*sinh(x))^2) - (3*im)/(4*(1 + im*sinh(x)))]
    @test_int [tanh(x)^2/(im + csch(x)), x, 4, (-im)*x + (1/3)*(3*im - 2*csch(x))*tanh(x) + (1/3)*(im - csch(x))*tanh(x)^3]
    @test_int [tanh(x)^1/(im + csch(x)), x, 3, (-(3/4))*im*log(im - sinh(x)) - (1/4)*im*log(im + sinh(x)) - im/(2*(1 + im*sinh(x)))]
    @test_int [coth(x)^1/(im + csch(x)), x, 2, (-im)*log(im - sinh(x))]
    @test_int [coth(x)^2/(im + csch(x)), x, 3, (-im)*x - atanh(cosh(x))]
    @test_int [coth(x)^3/(im + csch(x)), x, 3, -csch(x) - im*log(sinh(x))]
    @test_int [coth(x)^4/(im + csch(x)), x, 4, (-im)*x - (1/2)*atanh(cosh(x)) + (1/2)*coth(x)*(2*im - csch(x))]
    @test_int [coth(x)^5/(im + csch(x)), x, 3, -csch(x) + (1/2)*im*csch(x)^2 - csch(x)^3/3 - im*log(sinh(x))]
    @test_int [coth(x)^6/(im + csch(x)), x, 5, (-im)*x - (3/8)*atanh(cosh(x)) + (1/12)*coth(x)^3*(4*im - 3*csch(x)) + (1/8)*coth(x)*(8*im - 3*csch(x))]

    #= ::Subsubsection::Closed:: =#
    #=a^2+b^2!=0=#

    @test_int [tanh(x)^5/(a + b*csch(x)), x, 11, -((b^5*atan(sinh(x)))/(a^2 + b^2)^3) - (b^3*atan(sinh(x)))/(2*(a^2 + b^2)^2) - (3*b*atan(sinh(x)))/(8*(a^2 + b^2)) + (b^6*log(a + b*csch(x)))/(a*(a^2 + b^2)^3) + log(sinh(x))/a - (a*(a^4 + 3*a^2*b^2 + 3*b^4)*log(tanh(x)))/(a^2 + b^2)^3 + (3*b*sech(x)*tanh(x))/(8*(a^2 + b^2)) - ((a*(a^2 + 2*b^2) - b^3*csch(x))*tanh(x)^2)/(2*(a^2 + b^2)^2) - ((a - b*csch(x))*tanh(x)^4)/(4*(a^2 + b^2))]
    @test_int [tanh(x)^4/(a + b*csch(x)), x, 16, (a*b^2*x)/(a^2 + b^2)^2 + (b^4*x)/(a*(a^2 + b^2)^2) + (a*x)/(a^2 + b^2) + (2*b^5*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a*(a^2 + b^2)^(5/2)) + (b^3*sech(x))/(a^2 + b^2)^2 + (b*sech(x))/(a^2 + b^2) - (b*sech(x)^3)/(3*(a^2 + b^2)) - (a*b^2*tanh(x))/(a^2 + b^2)^2 - (a*tanh(x))/(a^2 + b^2) - (a*tanh(x)^3)/(3*(a^2 + b^2))]
    @test_int [tanh(x)^3/(a + b*csch(x)), x, 8, -((b^3*atan(sinh(x)))/(a^2 + b^2)^2) - (b*atan(sinh(x)))/(2*(a^2 + b^2)) + (b^4*log(a + b*csch(x)))/(a*(a^2 + b^2)^2) + log(sinh(x))/a - (a*(a^2 + 2*b^2)*log(tanh(x)))/(a^2 + b^2)^2 - ((a - b*csch(x))*tanh(x)^2)/(2*(a^2 + b^2))]
    @test_int [tanh(x)^2/(a + b*csch(x)), x, 10, (a*x)/(a^2 + b^2) + (b^2*x)/(a*(a^2 + b^2)) + (2*b^3*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a*(a^2 + b^2)^(3/2)) + (b*sech(x))/(a^2 + b^2) - (a*tanh(x))/(a^2 + b^2)]
    @test_int [tanh(x)^1/(a + b*csch(x)), x, 6, -((b*atan(sinh(x)))/(a^2 + b^2)) + (b^2*log(a + b*csch(x)))/(a*(a^2 + b^2)) + log(sinh(x))/a - (a*log(tanh(x)))/(a^2 + b^2)]
    @test_int [coth(x)^1/(a + b*csch(x)), x, 4, log(a + b*csch(x))/a + log(sinh(x))/a]
    @test_int [coth(x)^2/(a + b*csch(x)), x, 8, x/a - atanh(cosh(x))/b + (2*sqrt(a^2 + b^2)*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a*b)]
    @test_int [coth(x)^3/(a + b*csch(x)), x, 3, -(csch(x)/b) + (1/a + a/b^2)*log(a + b*csch(x)) + log(sinh(x))/a]
    @test_int [coth(x)^4/(a + b*csch(x)), x, 7, x/a - ((2*a^2 + 3*b^2)*atanh(cosh(x)))/(2*b^3) + (2*(a^2 + b^2)^(3/2)*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a*b^3) + (a*coth(x))/b^2 - (coth(x)*csch(x))/(2*b)]
    @test_int [coth(x)^5/(a + b*csch(x)), x, 3, -(((a^2 + 2*b^2)*csch(x))/b^3) + (a*csch(x)^2)/(2*b^2) - csch(x)^3/(3*b) + ((a^2 + b^2)^2*log(a + b*csch(x)))/(a*b^4) + log(sinh(x))/a]
    @test_int [coth(x)^6/(a + b*csch(x)), x, 16, x/a - (3*atanh(cosh(x)))/(8*b) + ((a^2 + 3*b^2)*atanh(cosh(x)))/(2*b^3) - ((a^4 + 3*a^2*b^2 + 3*b^4)*atanh(cosh(x)))/b^5 + (2*(a^2 + b^2)^(5/2)*atanh((a - b*tanh(x/2))/sqrt(a^2 + b^2)))/(a*b^5) - (a*coth(x))/b^2 + (a*(a^2 + 3*b^2)*coth(x))/b^4 + (a*coth(x)^3)/(3*b^2) + (3*coth(x)*csch(x))/(8*b) - ((a^2 + 3*b^2)*coth(x)*csch(x))/(2*b^3) - (coth(x)*csch(x)^3)/(4*b)]
    @test_int [coth(x)^7/(a + b*csch(x)), x, 3, -(((a^4 + 3*a^2*b^2 + 3*b^4)*csch(x))/b^5) + (a*(a^2 + 3*b^2)*csch(x)^2)/(2*b^4) - ((a^2 + 3*b^2)*csch(x)^3)/(3*b^3) + (a*csch(x)^4)/(4*b^2) - csch(x)^5/(5*b) + ((a^2 + b^2)^3*log(a + b*csch(x)))/(a*b^6) + log(sinh(x))/a]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*ℯ^(a+b*x)*csch(c+d*x)^m=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*ℯ^(c*(a+b*x))*(csch(a*c+b*c*x)^2)^(m/2)=#

    @test_int [ℯ^(c*(a + b*x))*(csch(a*c + b*c*x)^2)^(7/2), x, 6, -((32*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(3*b*c*(1 - ℯ^(2*c*(a + b*x)))^6)) + (192*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(5*b*c*(1 - ℯ^(2*c*(a + b*x)))^5) - (48*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(b*c*(1 - ℯ^(2*c*(a + b*x)))^4) + (64*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(3*b*c*(1 - ℯ^(2*c*(a + b*x)))^3)]
    @test_int [ℯ^(c*(a + b*x))*(csch(a*c + b*c*x)^2)^(5/2), x, 6, (-4*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(b*c*(1 - ℯ^(2*c*(a + b*x)))^4) + (32*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(3*b*c*(1 - ℯ^(2*c*(a + b*x)))^3) - (8*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(b*c*(1 - ℯ^(2*c*(a + b*x)))^2)]
    @test_int [ℯ^(c*(a + b*x))*(csch(a*c + b*c*x)^2)^(3/2), x, 4, (-2*ℯ^(4*c*(a + b*x))*sqrt(csch(a*c + b*c*x)^2)*sinh(a*c + b*c*x))/(b*c*(1 - ℯ^(2*c*(a + b*x)))^2)]
    @test_int [ℯ^(c*(a + b*x))*sqrt(csch(a*c + b*c*x)^2), x, 4, (sqrt(csch(a*c + b*c*x)^2)*log(1 - ℯ^(2*c*(a + b*x)))*sinh(a*c + b*c*x))/(b*c)]
    @test_int [ℯ^(c*(a + b*x))/sqrt(csch(a*c + b*c*x)^2), x, 5, (ℯ^(2*c*(a + b*x))*csch(a*c + b*c*x))/(4*b*c*sqrt(csch(a*c + b*c*x)^2)) - (x*csch(a*c + b*c*x))/(2*sqrt(csch(a*c + b*c*x)^2))]
    @test_int [ℯ^(c*(a + b*x))/(csch(a*c + b*c*x)^2)^(3/2), x, 6, csch(a*c + b*c*x)/(16*b*c*ℯ^(2*c*(a + b*x))*sqrt(csch(a*c + b*c*x)^2)) - (3*ℯ^(2*c*(a + b*x))*csch(a*c + b*c*x))/(16*b*c*sqrt(csch(a*c + b*c*x)^2)) + (ℯ^(4*c*(a + b*x))*csch(a*c + b*c*x))/(32*b*c*sqrt(csch(a*c + b*c*x)^2)) + (3*x*csch(a*c + b*c*x))/(8*sqrt(csch(a*c + b*c*x)^2))]
    @test_int [ℯ^(c*(a + b*x))/(csch(a*c + b*c*x)^2)^(5/2), x, 6, csch(a*c + b*c*x)/(128*b*c*ℯ^(4*c*(a + b*x))*sqrt(csch(a*c + b*c*x)^2)) - (5*csch(a*c + b*c*x))/(64*b*c*ℯ^(2*c*(a + b*x))*sqrt(csch(a*c + b*c*x)^2)) + (5*ℯ^(2*c*(a + b*x))*csch(a*c + b*c*x))/(32*b*c*sqrt(csch(a*c + b*c*x)^2)) - (5*ℯ^(4*c*(a + b*x))*csch(a*c + b*c*x))/(128*b*c*sqrt(csch(a*c + b*c*x)^2)) + (ℯ^(6*c*(a + b*x))*csch(a*c + b*c*x))/(192*b*c*sqrt(csch(a*c + b*c*x)^2)) - (5*x*csch(a*c + b*c*x))/(16*sqrt(csch(a*c + b*c*x)^2))]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*x^m*csch(a+b*log(c*x^n))^p=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*csch(b*log(c*x^n))^(p/2)=#

    @test_int [x^5/csch(2*log(c*x))^(1/2), x, 6, -((2*x^2)/(21*c^4*sqrt(csch(2*log(c*x))))) + x^6/(7*sqrt(csch(2*log(c*x)))) + (2*Elliptic.F(acsc(c*x), -1))/(21*c^7*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x))))]
    @test_int [x^4/csch(2*log(c*x))^(1/2), x, 3, ((c^4 - 1/x^4)*x^5)/(6*c^4*sqrt(csch(2*log(c*x))))]
    @test_int [x^3/csch(2*log(c*x))^(1/2), x, 9, -(2/(5*c^4*sqrt(csch(2*log(c*x))))) + x^4/(5*sqrt(csch(2*log(c*x)))) - (2*Elliptic.E(acsc(c*x), -1))/(5*c^5*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x)))) + (2*Elliptic.F(acsc(c*x), -1))/(5*c^5*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x))))]
    @test_int [x^2/csch(2*log(c*x))^(1/2), x, 6, x^3/(4*sqrt(csch(2*log(c*x)))) - atanh(sqrt(1 - 1/(c^4*x^4)))/(4*c^4*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x))))]
    @test_int [x^1/csch(2*log(c*x))^(1/2), x, 5, x^2/(3*sqrt(csch(2*log(c*x)))) + (2*Elliptic.F(acsc(c*x), -1))/(3*c^3*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x))))]
    @test_int [x^0/csch(2*log(c*x))^(1/2), x, 6, x/(2*sqrt(csch(2*log(c*x)))) + acsc(c^2*x^2)/(2*c^2*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x))))]
    @test_int [csch(2*log(c*x))^(1/2)/x^1, x, 3, im*sqrt(csch(2*log(c*x)))*Elliptic.F(pi/4 - im*log(c*x), 2)*sqrt(im*sinh(2*log(c*x)))]
    @test_int [csch(2*log(c*x))^(1/2)/x^2, x, 5, (-(1/2))*c^2*sqrt(1 - 1/(c^4*x^4))*x*acsc(c^2*x^2)*sqrt(csch(2*log(c*x)))]
    @test_int [csch(2*log(c*x))^(1/2)/x^3, x, 7, (-c^3)*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x)))*Elliptic.E(acsc(c*x), -1) + c^3*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x)))*Elliptic.F(acsc(c*x), -1)]
    @test_int [csch(2*log(c*x))^(1/2)/x^4, x, 3, (1/2)*(c^4 - 1/x^4)*x*sqrt(csch(2*log(c*x)))]
    @test_int [csch(2*log(c*x))^(1/2)/x^5, x, 5, (1/3)*(c^4 - 1/x^4)*sqrt(csch(2*log(c*x))) - (1/3)*c^5*sqrt(1 - 1/(c^4*x^4))*x*sqrt(csch(2*log(c*x)))*Elliptic.F(acsc(c*x), -1)]

    @test_int [x^8/csch(2*log(c*x))^(3/2), x, 8, x/(32*c^4*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2)) - x^5/(16*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2)) + x^9/(12*csch(2*log(c*x))^(3/2)) + atanh(sqrt(1 - 1/(c^4*x^4)))/(32*c^12*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^7/csch(2*log(c*x))^(3/2), x, 7, 4/(77*c^4*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2)) - (6*x^4)/(77*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2)) + x^8/(11*csch(2*log(c*x))^(3/2)) - (4*Elliptic.F(acsc(c*x), -1))/(77*c^11*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^6/csch(2*log(c*x))^(3/2), x, 3, ((c^4 - 1/x^4)*x^7)/(10*c^4*csch(2*log(c*x))^(3/2))]
    @test_int [x^5/csch(2*log(c*x))^(3/2), x, 10, 4/(15*c^4*(c^4 - 1/x^4)*x^2*csch(2*log(c*x))^(3/2)) - (2*x^2)/(15*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2)) + x^6/(9*csch(2*log(c*x))^(3/2)) + (4*Elliptic.E(acsc(c*x), -1))/(15*c^9*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2)) - (4*Elliptic.F(acsc(c*x), -1))/(15*c^9*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^4/csch(2*log(c*x))^(3/2), x, 7, -((3*x)/(16*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2))) + x^5/(8*csch(2*log(c*x))^(3/2)) + (3*atanh(sqrt(1 - 1/(c^4*x^4))))/(16*c^8*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^3/csch(2*log(c*x))^(3/2), x, 6, -(2/(7*(c^4 - 1/x^4)*csch(2*log(c*x))^(3/2))) + x^4/(7*csch(2*log(c*x))^(3/2)) - (4*Elliptic.F(acsc(c*x), -1))/(7*c^7*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^2/csch(2*log(c*x))^(3/2), x, 7, -(1/(2*(c^4 - 1/x^4)*x*csch(2*log(c*x))^(3/2))) + x^3/(6*csch(2*log(c*x))^(3/2)) - acsc(c^2*x^2)/(2*c^6*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^1/csch(2*log(c*x))^(3/2), x, 9, -(6/(5*(c^4 - 1/x^4)*x^2*csch(2*log(c*x))^(3/2))) + x^2/(5*csch(2*log(c*x))^(3/2)) - (12*Elliptic.E(acsc(c*x), -1))/(5*c^5*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2)) + (12*Elliptic.F(acsc(c*x), -1))/(5*c^5*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [x^0/csch(2*log(c*x))^(3/2), x, 7, 3/(4*(c^4 - 1/x^4)*x^3*csch(2*log(c*x))^(3/2)) + x/(4*csch(2*log(c*x))^(3/2)) - (3*atanh(sqrt(1 - 1/(c^4*x^4))))/(4*c^4*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2))]
    @test_int [csch(2*log(c*x))^(3/2)/x^1, x, 4, (-cosh(2*log(c*x)))*sqrt(csch(2*log(c*x))) + (im*Elliptic.E(pi/4 - im*log(c*x), 2))/(sqrt(csch(2*log(c*x)))*sqrt(im*sinh(2*log(c*x))))]
    @test_int [csch(2*log(c*x))^(3/2)/x^2, x, 3, (-(1/2))*(c^4 - 1/x^4)*x^3*csch(2*log(c*x))^(3/2)]
    @test_int [csch(2*log(c*x))^(3/2)/x^3, x, 5, (-(1/2))*(c^4 - 1/x^4)*x^2*csch(2*log(c*x))^(3/2) + (1/2)*c^5*(1 - 1/(c^4*x^4))^(3/2)*x^3*csch(2*log(c*x))^(3/2)*Elliptic.F(acsc(c*x), -1)]
    @test_int [csch(2*log(c*x))^(3/2)/x^4, x, 6, (-(1/2))*(c^4 - 1/x^4)*x*csch(2*log(c*x))^(3/2) + (1/2)*c^6*(1 - 1/(c^4*x^4))^(3/2)*x^3*acsc(c^2*x^2)*csch(2*log(c*x))^(3/2)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*csch(a+b*log(c*x^n))^p=#

    @test_int [csch(a + b*log(c*x^n))^1, x, 4, -((2*ℯ^a*x*(c*x^n)^b*HypergeometricFunctions._₂F₁(1, (b + 1/n)/(2*b), (1/2)*(3 + 1/(b*n)), ℯ^(2*a)*(c*x^n)^(2*b)))/(1 + b*n))]
    @test_int [csch(a + b*log(c*x^n))^2, x, 4, (4*ℯ^(2*a)*x*(c*x^n)^(2*b)*HypergeometricFunctions._₂F₁(2, (1/2)*(2 + 1/(b*n)), (1/2)*(4 + 1/(b*n)), ℯ^(2*a)*(c*x^n)^(2*b)))/(1 + 2*b*n)]
    @test_int [csch(a + b*log(c*x^n))^3, x, 4, -((8*ℯ^(3*a)*x*(c*x^n)^(3*b)*HypergeometricFunctions._₂F₁(3, (3*b + 1/n)/(2*b), (1/2)*(5 + 1/(b*n)), ℯ^(2*a)*(c*x^n)^(2*b)))/(1 + 3*b*n))]
    @test_int [csch(a + b*log(c*x^n))^4, x, 4, (16*ℯ^(4*a)*x*(c*x^n)^(4*b)*HypergeometricFunctions._₂F₁(4, (1/2)*(4 + 1/(b*n)), (1/2)*(6 + 1/(b*n)), ℯ^(2*a)*(c*x^n)^(2*b)))/(1 + 4*b*n)]

    @test_int [2*b^2*n^2*csch(a + b*log(c*x^n))^3 - (1 - b^2*n^2)*csch(a + b*log(c*x^n)), x, -9, (-x)*csch(a + b*log(c*x^n)) - b*n*x*coth(a + b*log(c*x^n))*csch(a + b*log(c*x^n))]

    @test_int [csch(a + 2*log(c*x^(1/2)))^3, x, 3, -((2*c^6)/(ℯ^a*(c^4 - 1/(ℯ^(2*a)*x^2))^2))]
    @test_int [csch(a + 2*log(c/x^(1/2)))^3, x, 4, (2*c^2)/(ℯ^(3*a)*(ℯ^(-2*a) - c^4/x^2)^2)]
    @test_int [csch(a + 1/(n*(-2 + p))*log(c*x^n))^p, x, 3, -((ℯ^(2*a)*(2 - p)*x*(1 - (c*x^n)^(2/(n*(2 - p)))/ℯ^(2*a))*csch(a - log(c*x^n)/(n*(2 - p)))^p)/((c*x^n)^(2/(n*(2 - p)))*(2*(1 - p))))]
    @test_int [csch(a - 1/(n*(-2 + p))*log(c*x^n))^p, x, 3, ((2 - p)*x*(1 - 1/(ℯ^(2*a)*(c*x^n)^(2/(n*(2 - p)))))*csch(a + log(c*x^n)/(n*(2 - p)))^p)/(2*(1 - p))]

    @test_int [csch(a + b*log(c*x^n))/x, x, 2, -(atanh(cosh(a + b*log(c*x^n)))/(b*n))]
    @test_int [csch(a + b*log(c*x^n))^2/x, x, 3, -(coth(a + b*log(c*x^n))/(b*n))]
    @test_int [csch(a + b*log(c*x^n))^3/x, x, 3, atanh(cosh(a + b*log(c*x^n)))/(2*b*n) - (coth(a + b*log(c*x^n))*csch(a + b*log(c*x^n)))/(2*b*n)]
    @test_int [csch(a + b*log(c*x^n))^4/x, x, 3, coth(a + b*log(c*x^n))/(b*n) - coth(a + b*log(c*x^n))^3/(3*b*n)]
    @test_int [csch(a + b*log(c*x^n))^5/x, x, 4, -((3*atanh(cosh(a + b*log(c*x^n))))/(8*b*n)) + (3*coth(a + b*log(c*x^n))*csch(a + b*log(c*x^n)))/(8*b*n) - (coth(a + b*log(c*x^n))*csch(a + b*log(c*x^n))^3)/(4*b*n)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*csch(a+b*log(c*x^n))^(p/2)=#

    @test_int [csch(a + b*log(c*x^n))^(5/2)/x, x, 4, -((2*cosh(a + b*log(c*x^n))*csch(a + b*log(c*x^n))^(3/2))/(3*b*n)) + (2*im*sqrt(csch(a + b*log(c*x^n)))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2)*sqrt(im*sinh(a + b*log(c*x^n))))/(3*b*n)]
    @test_int [csch(a + b*log(c*x^n))^(3/2)/x, x, 4, -((2*cosh(a + b*log(c*x^n))*sqrt(csch(a + b*log(c*x^n))))/(b*n)) - (2*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2))/(b*n*sqrt(csch(a + b*log(c*x^n)))*sqrt(im*sinh(a + b*log(c*x^n))))]
    @test_int [sqrt(csch(a + b*log(c*x^n)))/x, x, 3, -((2*im*sqrt(csch(a + b*log(c*x^n)))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2)*sqrt(im*sinh(a + b*log(c*x^n))))/(b*n))]
    @test_int [1/(x*sqrt(csch(a + b*log(c*x^n)))), x, 3, -((2*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2))/(b*n*sqrt(csch(a + b*log(c*x^n)))*sqrt(im*sinh(a + b*log(c*x^n)))))]
    @test_int [1/(x*csch(a + b*log(c*x^n))^(3/2)), x, 4, (2*cosh(a + b*log(c*x^n)))/(3*b*n*sqrt(csch(a + b*log(c*x^n)))) + (2*im*sqrt(csch(a + b*log(c*x^n)))*Elliptic.F((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2)*sqrt(im*sinh(a + b*log(c*x^n))))/(3*b*n)]
    @test_int [1/(x*csch(a + b*log(c*x^n))^(5/2)), x, 4, (2*cosh(a + b*log(c*x^n)))/(5*b*n*csch(a + b*log(c*x^n))^(3/2)) + (6*im*Elliptic.E((1/2)*(im*a - pi/2 + im*b*log(c*x^n)), 2))/(5*b*n*sqrt(csch(a + b*log(c*x^n)))*sqrt(im*sinh(a + b*log(c*x^n))))]
    end

max_stars_repo_path: test/6 Hyperbolic functions/6.6 Hyperbolic cosecant/6.6.3 Hyperbolic cosecant functions.jl


text:
#! /usr/bin/julia

# Rosetta Code, Formatted numeric output

test = [7.125, [rand()*10^rand(0:4) for i in 1:9]]

println("Formatting some numbers with the @sprintf macro (using \"%09.3f\"):")
for i in test
    println(@sprintf "    %09.3f" i)
end

using Formatting
println()
println("The same thing using the Formatting package:")
fe = FormatExpr("    {1:09.3f}")
for i in test
    printfmtln(fe, i)
end

ext: jl

max_stars_repo_name: MichaeLeroy/rosetta-code

max_issues_repo_name: MichaeLeroy/rosetta-code

max_forks_repo_name: MichaeLeroy/rosetta-code


text:
module Inform

export activeinfo

include("deps.jl")
include("activeinfo.jl")

end


text:
@testset "poly" begin
    p = Polynomial([3 1; 1 1; 0 2], [-2.0, 3.0])
    @test string(p) == "-2.0x₁³x₂+3.0x₁x₂x₃²"
    @test p isa Polynomial{Float64}
    @test eltype(p) == Float64
    @test exponents(p) == [3 1; 1 1; 0 2]
    @test coefficients(p) == [-2.0, 3.0]
    @test nvariables(p) == 3
    @test nterms(p) == 2
    @test length(p) == 2
    @test variables(p) == [:x1, :x2, :x3]
    @test degree(p) == 4

    @test (convert(Polynomial{Complex128}, p) isa Polynomial{Complex128})
    q = Polynomial([3 1; 1 1; 0 2], [-2, 3], [:x_1, :x_2, :x_3])
    prom_p, prom_q = promote(p,q)
    @test typeof(prom_p) == typeof(prom_q)
    @test prom_q isa Polynomial{Float64}

    Impl.@polyvar z[1:3]
    f = -2z[1]^3*z[2]+3z[1]*z[2]*z[3]^2
    @test "$(Polynomial(f))" == "-2z₁³z₂+3z₁z₂z₃²"
    @test "$(Polynomial{Float64}(f))" == "-2.0z₁³z₂+3.0z₁z₂z₃²"
    @test string(substitute(Polynomial(f), 2, 2.0)) == "-4.0z₁³+6.0z₁z₃²"
    @test string(substitute(Polynomial(f), 1, 2.0)) == "6.0z₂z₃²-16.0z₂"

    @test "$(Polynomial(z[1]))" == "z₁"
    @test "$(Polynomial(z[1]^2))" == "z₁²"
    @test "$(Polynomial(2z[1]))" == "2z₁"

    f, g = promote(Polynomial(2z[1]), Polynomial(3.0z[1]))
    @test f isa Polynomial{Float64}
    @test g isa Polynomial{Float64}

    @test promote_type(Polynomial{Int64}, Float64) == Polynomial{Float64}
    @test promote_type(Polynomial{Int64}, Polynomial{Float64}) == Polynomial{Float64}

    F = convert(Vector{Polynomial{Float64}}, [2z[2], 3z[1]])
    @test nvariables(F[1]) == 2
    @test nvariables(F[2]) == 2
    @test variables(F[1]) == [:z1, :z2]

    @test string(Polynomial(reshape(collect(1:9), (9,1)), [1.0])) == "x₁x₂²x₃³x₄⁴x₅⁵x₆⁶x₇⁷x₈⁸x₉⁹"
    @test string(Polynomial((2.3+0im)*z[1] - (2.2-2.2im) * z[2])) == "2.3z₁+(-2.2 + 2.2im)z₂"

    q = Polynomial(reshape([3; 1; 0], (3,1)), [-2.0], [:x1, :x2, :x3])
    @test q([1, 2.0, 3.0]) == -4
    q = Polynomial(reshape([1; 1; 2],(3,1)), [3.0], [:x1, :x2, :x3])
    @test q([1, 2.0, 3.0]) == 54
    @test p([1, 2.0, 3.0]) == 50

    @test differentiate(p, 1) == Polynomial([2 0; 1 1; 0 2], [-6.0, 3.0], [:x1, :x2])
    @test differentiate(p) == [differentiate(p, 1), differentiate(p, 2), differentiate(p, 3)]
    @test differentiate(p) == ∇(p)
    Impl.@polyvar y z
    @test size(differentiate(Polynomial(z^2+2+y), 1).exponents) == (2, 1)
    @test size(differentiate(Polynomial(z^2+2+y), 2).exponents) == (2, 1)

    @test ishomogenous(p) == true
    @test string(homogenize(Polynomial([1 1; 0 2], [-2.0, 3.0]))) == "-2.0x₀²x₁+3.0x₁x₂²"
    @test ishomogenized(p) == false
    @test ishomogenized(homogenize(p)) == true
    @test dehomogenize(p) == p
    @test dehomogenize(homogenize(p)) == p
    @test dehomogenize(homogenize(homogenize(p))) == p

    exponents(homogenize(p))[2:end, :]

    f = Polynomial([2 1 0;0 1 2], [3.0, 2.0, -1.0])
    g = Polynomial([2 1 0;0 1 2], [-2.5+2im,-3.0, 4.0])
    @test weyldot(f,g) == 3.0 * conj(-2.5 + 2im) + 2.0 * (-3.0) / 2 + (-1.0) * 4.0
    @test weyldot(f, f) == 9.0 + 4.0  / 2 + 1.0
    @test weylnorm(f)^2 ≈ weyldot(f,f)
    @test weyldot([f, f], [g, g]) == 2 * weyldot(f, g)
    @test weylnorm([f, f]) == √weyldot([f, f], [f, f])

    Impl.@polyvar x y z

    @test evaluate(Polynomial{Float64}(x^3+x), [2.0]) ≈ 2.0^3 + 2.0

    f = x + y + 2z
    g = x + z
    h = y + z

    # Due to bug during evaluation of "empty" polynomials
    F = convert(Vector{Polynomial{Float64}}, [f, g, h])

    J = [differentiate(f, i) for f in F, i=1:nvariables.(F[1])]
    u = rand(3)
    @test map(f -> evaluate(f, u), J) == [1.0  1.0  2.0; 1.0  0.0  1.0; 0.0  1.0  1.0]
end


text:
"""
    C_iio_get_backend(index)

Retrieve the name of a given backend.

# Parameters
- `index::UInt32` : The index corresponding to the attribute

# Returns
- On success, a NULL-terminated string
- If the index is invalid, an empty string is returned

Introduced in version 0.9.

[libIIO documentation](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga0b950d578c5e4e06232949159c491dab)
"""
function C_iio_get_backend(index::UInt32)
    @assert_Cstring backend = ccall(
        (:iio_get_backend, libIIO),
        Cstring, (Cuint,),
        index
    );
    return backend != C_NULL ? Base.unsafe_string(backend) : "";
end

"""
    C_iio_get_backends_count()

Get the number of available backends.

# Returns
- The number of available backends

Introduced in version 0.9.

[libIIO documentation](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#gabe08d9f1e10801b0334575063a66a56c)
"""
function C_iio_get_backends_count()
    return Base.convert(UInt32, ccall(
        (:iio_get_backends_count, libIIO),
        Cuint, ()
    ));
end

"""
    C_iio_has_backend(backend)

Check if the specified backend is available.

# Parameters
- `backend::String` : The name of the backend to query

# Returns
- True if the backend is available, false otherwise

Introduced in version 0.9.

[libIIO documentation](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga8cf6a3818d471333f4115f3d0d8d95a2)
"""
function C_iio_has_backend(backend::String)
    return Base.convert(Bool, ccall(
        (:iio_has_backend, libIIO),
        Cuchar, (Cstring,),
        backend
    ));
end

"""
    C_iio_library_get_version()

Get the version of the libiio library.

# Returns
- `major::Int` : The major version
- `minor::Int` : The minor version
- `git_tag::String` : The git tag

[libIIO documentation](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#gaaa29e5bac86d00a1cef6e2d00b0ea24c)
"""
function C_iio_library_get_version()
    major, minor, git_tag = Ref{Cuint}(0), Ref{Cuint}(0), zeros(UInt8, 8);
    ccall(
        (:iio_library_get_version, libIIO),
        Cvoid, (Ref{Cuint}, Ref{Cuint}, Ptr{Cchar}),
        major, minor, pointer(git_tag)
    );
    return Int(major[]), Int(minor[]), toString(git_tag);
end

"""
    C_iio_strerror(error)

Get a string description of an error code.

# Parameters
- `error::Int` : The error code

[libIIO documentation](https://analogdevicesinc.github.io/libiio/master/libiio/group__TopLevel.html#ga4a117b0ac02e97aeda92e33c063f7cf0)
"""
function C_iio_strerror(error::Int)
    buffer = zeros(UInt8, 256);
    ccall(
        (:iio_strerror, libIIO),
        Cvoid, (Cint, Ptr{Cuchar}, Csize_t),
        error, pointer(buffer), length(buffer)
    );
    return toString(buffer);
end


text:
include("../interpolation/interpolation.jl")
include("../interpolation/hermite_interpolation.jl")
include("../tableaus/tableaus_erk.jl")

type InitialGuess{T, FT, IT <: Interpolator}
    int::IT
    rk4::IntegratorERK{T,FT}
    sol::SolutionODE{T}
    f::FT
    Δt::T
    y₀::Vector{T}
    f₀::Vector{T}
    y₁::Vector{T}
    f₁::Vector{T}
end

function InitialGuess{T,FT}(int, equ::ODE{T,FT}, Δt::T)
    interp = int(zero(T), one(T), equ.d)
    rk4 = IntegratorERK(equ, getTableauERK4(), -Δt)
    sol = SolutionODE(equ, Δt, 1)
    InitialGuess{T, FT, int}(interp, rk4, sol, equ.f, Δt,
                             zeros(T, equ.d), zeros(T, equ.d),
                             zeros(T, equ.d), zeros(T, equ.d))
end

function initialize!{T,FT,IT}(ig::InitialGuess{T,FT,IT}, t₁::T, y₁::Vector{T})
    set_initial_conditions!(ig.sol, t₁, y₁)
    integrate!(ig.rk4, ig.sol)
    simd_copy_xy_first!(ig.y₁, ig.sol, 1, 1)
    ig.f(t₁-ig.Δt, ig.y₁, ig.f₁)
    simd_scale!(ig.f₁, ig.Δt)
end

function update!{T,FT,IT}(ig::InitialGuess{T,FT,IT}, t₁::T, y₁::Vector{T})
    simd_copy!(ig.y₁, ig.y₀)
    simd_copy!(ig.f₁, ig.f₀)
    simd_copy!(y₁, ig.y₁)
    ig.f(t₁, ig.y₁, ig.f₁)
    simd_scale!(ig.f₁, ig.Δt)
end

function evaluate{T,FT,IT}(ig::InitialGuess{T,FT,IT}, guess::Vector{T}, c::T=one(T))
    evaluate(ig.int, ig.y₀, ig.y₁, ig.f₀, ig.f₁, one(T)+c, guess)
end


text:
closing_ref(img, dims, r) = closing_ref(img, strel_box(img, dims; r))
closing_ref(img, se) = erode(dilate(img, se), se)

@testset "closing" begin
    test_types = [Bool, Int, Float64, Gray{N0f8}, Gray{Float64}]
    for T in test_types
        for N in (1, 2, 3)
            sz = ntuple(_ -> 32, N)
            img = rand(T, sz...)

            out = closing(img)
            @test out == closing(img, strel_box(img, ntuple(identity, N); r=1))
            @test out == closing_ref(img, ntuple(identity, N), 1)

            @test closing(img; dims=(1,), r=2) == closing_ref(img, (1,), 2)

            se = centered(rand(Bool, ntuple(_ -> 3, N)))
            @test closing(img, se) == closing_ref(img, se)
        end
    end

    img = rand(1:5, 7, 7)
    out = similar(img)
    closing!(out, img, similar(img))
    @test out == closing(img)

    img = rand(RGB, 7, 7)
    @test_throws ArgumentError("color image is not supported") closing(img)
end


text:
module UndirectedGraphGates

    export OneQubitGateTensor, TwoQubitGateTensor, UG_Gate, UG_OneQubitGate, UG_TwoQubitGate, UndirectedGraphTensor
    abstract type UndirectedGraphTensor end
    abstract type UG_Gate end
    abstract type UG_OneQubitGate <: UG_Gate end
    abstract type UG_TwoQubitGate <: UG_Gate end

    mutable struct OneQubitGateTensor <: UndirectedGraphTensor
        item::Array{ComplexF64, 2}
        target::Int
        worldline1::Int
        worldline2::Int
    end

    mutable struct TwoQubitGateTensor <: UndirectedGraphTensor
        item::Array{ComplexF64, 2}
        control::Int
        target::Int
        worldline1::Int
        worldline2::Int
    end

    mutable struct X <: UG_OneQubitGate
        _target::Int64
    end

    mutable struct Y <: UG_OneQubitGate
        _target::Int64
    end

    mutable struct Z <: UG_OneQubitGate
        _target::Int64
    end

    mutable struct H <: UG_OneQubitGate
        _target::Int64
    end

    mutable struct T <: UG_OneQubitGate
        _target::Int64
    end

    struct S <: UG_OneQubitGate
        _target::Int64
    end

    struct RX <: UG_OneQubitGate
        _target::Int64
        _theta::Float64
    end

    struct RY <: UG_OneQubitGate
        _target::Int64
        _theta::Float64
    end

    struct RZ <: UG_OneQubitGate
        _target::Int64
        _theta::Float64
    end

    struct U3 <: UG_OneQubitGate
        _target::Int64
        _theta::Float64
        _phi::Float64
        _lambd::Float64
    end

    struct CZ <: UG_TwoQubitGate
        _control::Int64
        _target::Int64
    end

    struct CX <: UG_TwoQubitGate
        _control::Int64
        _target::Int64
    end

    struct CP <: UG_TwoQubitGate
        _control::Int64
        _target::Int64
        _theta::Float64
    end

    # export all UG_Gate and TwoQubitGate
    for n in names(@__MODULE__; all=true)
        if Base.isidentifier(n) && n ∉ (Symbol(@__MODULE__), :eval, :include)
            if @eval typeof($n) <: DataType
                if @eval $n <: UG_Gate
                    @eval export $n
                end
            end
        end
    end
end

max_stars_repo_name: ryuNagai/blueqat-julia

max_issues_repo_name: ryuNagai/blueqat-julia

max_forks_repo_name: ryuNagai/blueqat-julia


text:
__precompile__(true)
module HTTP

export Request, Response, FIFOBuffer

using MbedTLS

const TLS = MbedTLS

import Base.==

const DEBUG = false
const PARSING_DEBUG = false

struct ParsingError <: Exception
    msg::String
end
Base.show(io::IO, p::ParsingError) = println("HTTP.ParsingError: ", p.msg)

const CRLF = "\r\n"

include("consts.jl")
include("utils.jl")
include("uri.jl")
using .URIs
include("fifobuffer.jl")
using .FIFOBuffers
include("cookies.jl")
using .Cookies
include("multipart.jl")
include("types.jl")

include("parser.jl")
include("sniff.jl")

include("client.jl")
include("handlers.jl")
using .Handlers
include("server.jl")
using .Nitrogen

function __init__()
    global const DEFAULT_CLIENT = Client()
end

end # module
try
    HTTP.parse(HTTP.Response, "HTTP/1.1 200 OK\r\n\r\n")
    HTTP.parse(HTTP.Request, "GET / HTTP/1.1\r\n\r\n")
    HTTP.get(HTTP.Client(nothing), "www.google.com")
end


text:
module Environments
import MPI

abstract type  AbstractInterconnect end
begin
    struct SSH_IC  <: AbstractInterconnect end
    struct MPI_IC  <: AbstractInterconnect end
    struct TCP_IC  <: AbstractInterconnect end
    struct No_IC   <: AbstractInterconnect end
end

abstract type AbstractCommunicator end
begin
    struct NoCommunicator <: AbstractCommunicator end
    struct MPI_World <: AbstractCommunicator
        comm::MPI.Comm
    end
    struct MachineList <: AbstractCommunicator
        machines::Array{String}
    end
    struct TCPList <: AbstractCommunicator
        ports::Array{String}
    end
end

abstract type AbstractAccelerator end
begin
    struct NoAccelerator <: AbstractAccelerator end
    abstract type AbstractGPU <: AbstractAccelerator end
    begin
        struct AMD_GPU <: AbstractGPU
            memory::UInt128
        end
        struct NVIDIA_GPU <: AbstractGPU
            memory::UInt128
        end
    end
    abstract type AbstractFPGA <: AbstractAccelerator end
    abstract type AbstractCoprocessor <: AbstractAccelerator end
end

abstract type AbstractContractor end
begin
    struct TTGT <: AbstractContractor end
    struct TBLIS <: AbstractContractor end
end

struct Environment
    interconnect::T where T <: AbstractInterconnect
    homogenous::Bool
    accelerator::T  where T <: AbstractAccelerator
    communicator::T         where T <: AbstractCommunicator
    contractor::T   where T <: AbstractContractor
end

function detect_Environment()
end
end #module


text:
"""
    AbstractGroupAction

An abstract group action on a manifold.
"""
abstract type AbstractGroupAction{AD<:ActionDirection} end

"""
    base_group(A::AbstractGroupAction)

The group that acts in action `A`.
"""
base_group(A::AbstractGroupAction) = error("base_group not implemented for $(typeof(A)).")

"""
    g_manifold(A::AbstractGroupAction)

The manifold the action `A` acts upon.
"""
g_manifold(A::AbstractGroupAction) = error("g_manifold not implemented for $(typeof(A)).")

allocate_result(A::AbstractGroupAction, f, x...) = allocate_result(g_manifold(A), f, x...)

"""
    direction(::AbstractGroupAction{AD}) -> AD

Get the direction of the action
"""
direction(::AbstractGroupAction{AD}) where {AD} = AD()

@doc doc"""
    apply(A::AbstractGroupAction, a, x)

Apply action `a` to the point `x`. The action is specified by `A`.
Unless otherwise specified, right actions are defined in terms of the left action. For
point $x ∈ M$ and action element $a$, the right action is

````math
x ⋅ a ≐ a^{-1} ⋅ x.
````
"""
function apply(A::AbstractGroupAction, a, x)
    y = allocate_result(A, apply, x, a)
    return apply!(A, y, a, x)
end

"""
    apply!(A::AbstractGroupAction, y, a, x)

Apply action `a` to the point `x` with the rule specified by `A`.
The result is saved in `y`.
"""
function apply!(A::AbstractGroupAction{LeftAction}, y, a, x)
    error("apply! not implemented for action $(typeof(A)) and points $(typeof(y)), $(typeof(x)) and $(typeof(a)).")
end
function apply!(A::AbstractGroupAction{RightAction}, y, a, x)
    ainv = inv(base_group(A), a)
    return apply!(switch_direction(A), y, ainv, x)
end

"""
    inverse_apply(A::AbstractGroupAction, a, x)

Apply inverse of action `a` to the point `x`. The action is specified by `A`.
"""
function inverse_apply(A::AbstractGroupAction, a, x)
    y = allocate_result(A, inverse_apply, x, a)
    return inverse_apply!(A, y, a, x)
end

"""
    inverse_apply!(A::AbstractGroupAction, y, a, x)

Apply inverse of action `a` to the point `x` with the rule specified by `A`.
The result is saved in `y`.
"""
function inverse_apply!(A::AbstractGroupAction, y, a, x)
    inva = inv(base_group(A), a)
    return apply!(A, y, inva, x)
end

@doc doc"""
    apply_diff(A::AbstractGroupAction, a, x, v)

For group point $x ∈ M$ and tangent vector $v ∈ T_x M$, compute the action of the
differential of the action of $a ∈ G$ on $v$, specified by rule `A`. Written as
$(\mathrm{d}τ_a)_x (v)$, with the specified left or right convention, the differential
transports vectors

````math
\begin{aligned}
(\mathrm{d}L_a)_x (v) &: T_x M → T_{a ⋅ x} M\\
(\mathrm{d}R_a)_x (v) &: T_x M → T_{x ⋅ a} M
\end{aligned}
````
"""
function apply_diff(A::AbstractGroupAction, a, x, v)
    return error("apply_diff not implemented for action $(typeof(A)), points $(typeof(a)) and $(typeof(x)), and vector $(typeof(v))")
end

function apply_diff!(A::AbstractGroupAction, vout, a, x, v)
    return error("apply_diff! not implemented for action $(typeof(A)), points $(typeof(a)) and $(typeof(x)), vectors $(typeof(vout)) and $(typeof(v))")
end

@doc doc"""
    inverse_apply_diff(A::AbstractGroupAction, a, x, v)

For group point $x ∈ M$ and tangent vector $v ∈ T_x M$, compute the action of the
differential of the inverse action of $a ∈ G$ on $v$, specified by rule `A`. Written as
$(\mathrm{d}τ_a)_x^{-1} (v)$, with the specified left or right convention, the
differential transports vectors

````math
\begin{aligned}
(\mathrm{d}L_a)_x^{-1} (v) &: T_x M → T_{a^{-1} ⋅ x} M\\
(\mathrm{d}R_a)_x^{-1} (v) &: T_x M → T_{x ⋅ a^{-1}} M
\end{aligned}
````
"""
function inverse_apply_diff(A::AbstractGroupAction, a, x, v)
    return apply_diff(A, inv(base_group(A), a), x, v)
end

function inverse_apply_diff!(A::AbstractGroupAction, vout, a, x, v)
    return apply_diff!(A, vout, inv(base_group(A), a), x, v)
end

compose(A::AbstractGroupAction{LeftAction}, a, b) = compose(base_group(A), a, b)
compose(A::AbstractGroupAction{RightAction}, a, b) = compose(base_group(A), b, a)

compose!(A::AbstractGroupAction{LeftAction}, y, a, b) = compose!(base_group(A), y, a, b)
compose!(A::AbstractGroupAction{RightAction}, y, a, b) = compose!(base_group(A), y, b, a)

@doc doc"""
    optimal_alignment(A::AbstractGroupAction, x1, x2)

Calculate an action element of action `A` that acts upon `x1` to produce
the element closest to `x2` in the metric of the G-manifold:
```math
\arg\min_{g ∈ G} d_M(g ⋅ x_1, x_2)
```
where $G$ is the group that acts on the G-manifold $M$.
"""
function optimal_alignment(A::AbstractGroupAction, x1, x2)
    error("optimal_alignment not implemented for $(typeof(A)) and points $(typeof(x1)) and $(typeof(x2)).")
end

"""
    optimal_alignment!(A::AbstractGroupAction, y, x1, x2)

Calculate an action element of action `A` that acts upon `x1` to produce the element closest
to `x2`.
The result is written to `y`.
"""
function optimal_alignment!(A::AbstractGroupAction, y, x1, x2)
    return copyto!(y, optimal_alignment(A, x1, x2))
end

@doc doc"""
    center_of_orbit(
        A::AbstractGroupAction,
        pts,
        q,
        mean_method::AbstractEstimationMethod = GradientDescentEstimation()
    )

Calculate an action element $g$ of action `A` that is the mean element of the orbit of `q`
with respect to given set of points `pts`. The [`mean`](@ref) is calculated using the method
`mean_method`.

The orbit of $q$ with respect to the action of a group $G$ is the set
````math
O = \{ g ⋅ q : g ∈ G \}.
```
This function is useful for computing means on quotients of manifolds by a Lie group action.
"""
function center_of_orbit(
    A::AbstractGroupAction,
    pts::AbstractVector,
    q,
    mean_method::AbstractEstimationMethod = GradientDescentEstimation(),
)

    alignments = map(p -> optimal_alignment(A, q, p), pts)
    return mean(g_manifold(A), alignments, mean_method)
end


text:
include("operators.jl")

function calcforces(rvecs,charges,ρ,grid;rmax=grid.dx*norm(grid.sz))
    name = :inverse_squared_field
    rmin=2grid.dx
    efield_op = LinearOperator(name; dx,rmin, rmax)
    efield =efield_op(ρ)
hcat([charge*get(efield,grid,rvec) for (charge,rvec) in zip(charges,eachcol(rvecs))]...)
end
function calcfield(name,ρ,grid;rmax=grid.dx*norm(grid.sz))
@unpack dx=grid
    op = LinearOperator(name; dx, rmax)
    op(ρ)
end

function prep(positions, charges, grid)
    ρp = zeros(grid.sz..., 1)
    put_point_source!(
        ρp,
        grid,
        positions,
        reshape(charges, (1, length(charges))),
    )
    ψ=calcfield(:potential,ρp,grid)
    E=calcfield("inverse_squared_field",ρp,grid)
ρp,ψ,E
end
function predict_density(positions, charges, grid)
    ρp,ψ,E
    electronic_density = f(ρp)
    @assert sum(charges) ≈
            sum(electronic_density) * dV ≈
            sum(ρp) * dV
    electronic_density, ρp
end


text:
module v2_tiny
#Tiny Yolo V2-tiny model configuration

using Knet: Knet, progress, progress!, gpu, KnetArray, relu, minibatch, conv4, pool, softmax

import ..sigmoid, ..Settings

mutable struct v2TinyChain
    layers
    v2TinyChain(layers...) = new(layers)
end

mutable struct Conv #Define convolutional layer
    w
    b
    stride
    padding
    f
end
mutable struct YoloPad #Define Yolo padding layer (assymetric padding).
    w
    grid_x::Int
    grid_y::Int
    minibatch_size::Int
end
struct Pool # Define pool layer
    size
    stride
    pad
end

YoloPad(w1::Int, w2::Int, cx::Int, cy::Int, grid_x::Int, grid_y::Int, minibatch_size::Int) =
    YoloPad(zeros(Float32, w1, w2, cx, cy), grid_x, grid_y, minibatch_size)#Constructor for Yolopad

Conv(w1::Int, w2::Int, cx::Int, cy::Int, st, pd, f) =
    Conv(randn(Float32, w1, w2, cx, cy), randn(Float32, 1, 1, cy, 1), st, pd, f)#Constructor for convolutional layer

#Assymetric padding function
function (y::YoloPad)(x)
    x = reshape(x, y.grid_x + 1, y.grid_y + 1, 1, 512 * y.minibatch_size)
    return reshape(conv4(y.w, x; stride = 1), y.grid_x, y.grid_y, 512, y.minibatch_size)
end

(p::Pool)(x) = pool(x; window = p.size, stride = p.stride, padding = p.pad) #pool function

(c::v2TinyChain)(x) = (for l in c.layers #chain function
    x = l(x)
end; x)

(c::Conv)(x) =
    c.f.(conv4(c.w, x; stride = c.stride, padding = c.padding) .+ c.b) #convolutional layer function

#leaky function
function leaky(x)
    return max(Float32(0.1) * x, x)
end

"""
    load(sets::Settings)

Loads the YOLOv2_tiny model.

Note on Asymmetric Padding (see https://github.com/Ybakman/YoloV2#asymmetric-padding)
An alternative solution for asymmetric padding on pooling. We solved the asymmetric padding process in the following 4 steps: Let's assume we have a matrix as (d1,d2,depth,minibatch_size)

1- Apply symmetric padding = 1 with the pooling function

2- reshape it into => (d1,d2,1,minibatch_size*depth)

3- apply the following convolutional layer => 1 0  with stride = 1, padding = 0
                                              0 0

4- Lastly, reshape again into => (d1,d2,depth,minibatch_size)

Now, we made pooling with asymmetric padding on the right and bottom side. If you want to
make it on left and top side, apply this conv layer =>  0 0
                                                        0 1

The last 3 steps are implemented in YoloPad(x) function
The symmetric padding part is implemented in the pooling function just before Yolopad(x)
"""
function load(sets::Settings)
return v2TinyChain(
    Conv(3, 3, 3, 16, 1, 1, leaky),
    Pool(2, 2, 0),
    Conv(3, 3, 16, 32, 1, 1, leaky),
    Pool(2, 2, 0),
    Conv(3, 3, 32, 64, 1, 1, leaky),
    Pool(2, 2, 0),
    Conv(3, 3, 64, 128, 1, 1, leaky),
    Pool(2, 2, 0),
    Conv(3, 3, 128, 256, 1, 1, leaky),
    Pool(2, 2, 0),
    Conv(3, 3, 256, 512, 1, 1, leaky),
    Pool(2, 1, 1),
    YoloPad(2, 2, 1, 1, sets.grid_x, sets.grid_y, sets.minibatch_size),
    Conv(3, 3, 512, 1024, 1, 1, leaky),
    Conv(3, 3, 1024, 1024, 1, 1, leaky),
    Conv(1, 1, 1024, sets.cell_bboxes * (5 + sets.num_classes), 1, 0, identity),
)
end

include(joinpath(@__DIR__, "loadweights.jl"))

end #module


text:
import Test: @test, @testset
import Cubature: hcubature
import LinearAlgebra: dot, norm
import Luna: RectModes
import Luna.Modes
import Luna.PhysData: c, ε_0, μ_0, wlfreq

a = 50e-6
b = 12.5e-6

m = RectModes.RectMode(a, b, :Ar, 0.0, :Ag)

# these were checked with FEM using JCMwave
@test isapprox(Modes.Aeff(m), 1.111111111111111e-09)
@test isapprox(Modes.dB_per_m(m, wlfreq(210e-9)), 3.908368640803528, rtol=1e-2)
@test isapprox(Modes.dB_per_m(m, wlfreq(800e-9)), 0.44317059469197245, rtol=1e-2)
@test isapprox(Modes.β(m, wlfreq(800e-9)), 7852915.234685494)
@test isapprox(Modes.β(m, wlfreq(210e-9)), 29919650.305427298)

@test abs(1e9*Modes.zdw(RectModes.RectMode(a, b, :Ar, 5.0, :Ag)) - 563.5) < 1

@testset "normalisation" begin
    # Copied definitions from Modes.jl to force manual calculation of Aeff and N
    function Aeff(m; z=0)
        em = Modes.absE(m, z=z)
        dl = Modes.dimlimits(m, z=z)
        # Numerator
        function Aeff_num(xs)
            e = em(xs)
            dl[1] == :polar ? xs[1]*e^2 : e^2
        end
        val, err = hcubature(Aeff_num, dl[2], dl[3])
        num = val^2
        # Denominator
        function Aeff_den(xs)
            e = em(xs)
            dl[1] == :polar ? xs[1]*e^4 : e^4
        end
        den, err = hcubature(Aeff_den, dl[2], dl[3])
        return num / den
    end
    function N(m; z=0)
        f = Modes.field(m, z=z)
        dl = Modes.dimlimits(m, z=z)
        function Nfunc(xs)
            E = f(xs)
            ret = sqrt(ε_0/μ_0)*dot(E, E)
            dl[1] == :polar ? xs[1]*ret : ret
        end
        val, err = hcubature(Nfunc, dl[2], dl[3])
        0.5*abs(val)
    end

    for n=1:6
        for m = 1:6
            rm = RectModes.RectMode(a, b, :Ar, 0.0, :Ag, n=n, m=m)
            @test Modes.N(rm) ≈ N(rm)
            @test Modes.Aeff(rm) ≈ Aeff(rm)
        end
    end

    m = RectModes.RectMode(a, b, :Ar, 0.0, :Ag)
    ω = wlfreq(800e-9)
    @test Modes.N(m, z=1) == Modes.N(m, z=0)
    @test Modes.Aeff(m, z=1) == Modes.Aeff(m, z=0)
    @test Modes.neff(m, ω, z=1) == Modes.neff(m, ω, z=0)

    a0 = a
    aL = a/2
    L = 1
    afun = let a0=a0, aL=aL, L=L
        afun(z) = a0 + (aL-a0)*z/L
    end
    m = RectModes.RectMode(afun, b, :Ar, 0.0, :Ag)
    @test Modes.N(m) ≈ N(m)
    @test Modes.N(m, z=L) ≈ N(m, z=L)
    @test Modes.N(m, z=L) ≈ Modes.N(m, z=0)/2
    @test Modes.Aeff(m) ≈ Aeff(m)
    @test Modes.Aeff(m, z=L/2) ≈ Aeff(m, z=L/2)
    @test Modes.Aeff(m, z=L) ≈ Aeff(m, z=L)
    @test Modes.Aeff(m, z=L) ≈ Modes.Aeff(m, z=0)/2

    m = RectModes.RectMode(afun, afun, :Ar, 0.0, :Ag)
    @test Modes.N(m) ≈ N(m)
    @test Modes.N(m, z=L) ≈ N(m, z=L)
    @test Modes.N(m, z=L) ≈ Modes.N(m, z=0)/4
    @test Modes.Aeff(m) ≈ Aeff(m)
    @test Modes.Aeff(m, z=L/2) ≈ Aeff(m, z=L/2)
    @test Modes.Aeff(m, z=L) ≈ Aeff(m, z=L)
    @test Modes.Aeff(m, z=L) ≈ Modes.Aeff(m, z=0)/4
end


text:
# original (inspired by):
#   qref.c: Copyright (C) 1991-1995,1997,1998,2000,2001 Tadayoshi Funaba All rights reserved
#   $Id: qref.c,v 1.7 2001-02-06 23:35:44+09 tadf Exp $

module QREF

abstract type AbstractQDInfo end

struct QDInfo <: AbstractQDInfo
    idx::Int
    j::Int
    y::Int
    m::Int
    leap::Bool
    md::Int
end

abstract type QDError <: AbstractQDInfo end
struct QDRecordError{I} <: QDError
    idx::I
end
struct QDJulianError{I} <: QDError
    j::I
end
struct QDYearError{I} <: QDError
    y::I
end
struct QDMonthError{I} <: QDError
    m::I
end
struct QDLeapMonthError{Y, M} <: QDError
    y::Y
    m::M
end
struct QDDayError{I, D} <: QDError
    idx::I
    md::D
end

struct CQDate
    j::Int32
    y::Int16
    m::Int8
    leap::Bool
end

const qt = let qtsrcpath = joinpath(dirname(@__FILE__), "QTSRC.bin")
    _dims = filesize(qtsrcpath) + 1
    _qt = Vector{CQDate}(undef, _dims)
    open(qtsrcpath, "r") do f_in
        j = 0
        m = 1
        y = -1
        idx = 1
        while !eof(f_in)
            qts = read(f_in, UInt8)
            ny = isodd(qts >> 1)
            l = isodd(qts)
            l || (m = ny ? 1 : m + 1)
            ny && (y += 1)
            _qt[idx] = CQDate(j, y, m, l)
            j += qts >> 2
            idx += 1
        end
        _qt[idx] = CQDate(j, y + 1, 1, false)
    end
    _qt
end

const FIRST_RECORD = 1
const LAST_RECORD = length(qt) - 1

const FIRST_JULIAN = 1883618  # 旧0445年01月01日
const LAST_JULIAN = FIRST_JULIAN + qt[end].j - qt[1].j - 1
# LAST_JULIAN == 2524992  # 旧2200年12月29日

const FIRST_YEAR = 445
const LAST_YEAR = FIRST_YEAR + qt[LAST_RECORD].y
# LAST_YEAR == 2200

function qi(j::Int)
    l = FIRST_RECORD
    u = LAST_RECORD
    while l < u
        m = Int(Int64(j - qt[l].j) * (u - l) ÷ (qt[u].j - qt[l].j)) + l
        if qt[m].j < j
            l = m + 1
            qt[l].j > j && return l - 1
        elseif qt[m].j > j
            u = m - 1
            qt[u].j < j && return u
        else
            return m
        end
    end
    # NOTREACHED
    return -1
end

function qref(j::Int)
    if j < FIRST_JULIAN || j > LAST_JULIAN
        # Note: Not to be thrown `ArgumentError` here.
        return QDJulianError(j)
    end
    idx = qi(j - FIRST_JULIAN)
    p = qt[idx]
    m = p.m
    y = p.y + FIRST_YEAR
    md = 1 + j - (p.j + FIRST_JULIAN)
    leap = p.leap
    return QDInfo(idx, j, y, m, leap, md)
end
qref(j::Integer) = qref(Int(j))

function nextmonth(qdinfo::QDInfo)
    idx = qdinfo.idx + 1
    p = qt[idx]
    j = p.j + FIRST_JULIAN
    m = p.m
    y = p.y + FIRST_YEAR
    leap = p.leap
    return QDInfo(idx, j, y, m, leap, 1)
    # Note: returns QDInfo of 1st day of next month
end

function addmonth(qdinfo::QDInfo, month::Integer)
    idx = qdinfo.idx + month
    if !(FIRST_RECORD ≤ idx ≤ LAST_RECORD)
        # Note: Not to be thrown `ArgumentError` here.
        return QDRecordError(idx)
    end
    p = qt[idx]
    j = p.j + FIRST_JULIAN
    m = p.m
    y = p.y + FIRST_YEAR
    leap = p.leap
    return QDInfo(idx, j, y, m, leap, 1)
    # Note: returns QDInfo of 1st day of the month
end

function nextyear(qdinfo::QDInfo)
    idx = qdinfo.idx + 12 - qdinfo.m
    p = qt[idx]
    if p.y + FIRST_YEAR == qdinfo.y
        idx += 1
        p = qt[idx]
    end
    j = p.j + FIRST_JULIAN
    y = p.y + FIRST_YEAR
    return QDInfo(idx, j, y, 1, false, 1)
    # Note: returns QDInfo of 1st day of next year
end

function rqi2(y::Int)
    l = FIRST_RECORD
    u = LAST_RECORD
    while l < u
        m = (y - qt[l].y) * (u - l) ÷ (qt[u].y - qt[l].y) + l
    	if qt[m].y < y
    	    l = m + 1
            qt[l].y > y && return l - 1
        elseif qt[m].y > y
    	    u = m - 1
    	    qt[u].y < y && return u
        else
            return m
        end
    end
    # NOTREACHED
    return -1
end

function _firstidxofyear(idx)
    o = qt[idx]
    if o.m > 1 || o.leap
        idx -= o.m - 1 + o.leap
        o = qt[idx]
        while o.m > 1 || o.leap
            idx -= 1
            o = qt[idx]
        end
    end
    idx
end

function rqi(y::Int)
    _firstidxofyear(rqi2(y))
end
rqi(y::Integer) = rqi(Int(y))

function rqref(y::Integer, month::Integer=1, leap::Bool=false, day::Integer=1)
    if !(FIRST_YEAR ≤ y ≤ LAST_YEAR)
        # Note: Not to be thrown `ArgumentError` here.
        return QDYearError(y)
    end
    if !(1 ≤ month ≤ 12)
        # Note: Not to be thrown `ArgumentError` here.
        return QDMonthError(month)
    end

    idx = rqi(y - FIRST_YEAR)
    if month > 1 || leap
        idx += month - 1 + leap
        if leap && !qt[idx].leap
            # Note: Not to be thrown `ArgumentError` here.
            return QDLeapMonthError(y, month)
        end
        while !(qt[idx].m == month && qt[idx].leap == leap)
            idx += 1
        end
    end
    j = day - 1 + qt[idx].j + FIRST_JULIAN
    if !(qt[idx].j ≤ j - FIRST_JULIAN < qt[idx + 1].j)
        # Note: Not to be thrown `ArgumentError` here.
        return qref(j)
    end
    return QDInfo(idx, j, y, month, leap, day)
end
function rqref_strict(y::Integer, month::Integer=1, leap::Bool=false, day::Integer=1)
    qdinfo = _check_qdinfo(rqref(y, month, leap, day))
    if qdinfo.md != day
        qdinfo1 = rqref(y, month, leap, 1)
        _check_qdinfo(QDDayError(qdinfo1.idx, day))
    end
    qdinfo
end
_check_qdinfo(qdinfo::QDInfo) = qdinfo
function _check_qdinfo(qderror::QDRecordError)
    throw(ArgumentError("Idx: $(qderror.idx) out of range ($FIRST_RECORD:$LAST_RECORD)"))
end
function _check_qdinfo(qderror::QDJulianError)
    throw(ArgumentError("Jdn: $(qderror.j) out of range ($FIRST_JULIAN:$LAST_JULIAN)"))
end
function _check_qdinfo(qderror::QDYearError)
    throw(ArgumentError("Year: $(qderror.y) out of range ($FIRST_YEAR:$LAST_YEAR)"))
end
function _check_qdinfo(qderror::QDMonthError)
    throw(ArgumentError("Month: $(qderror.m) out of range (1:12)"))
end
function _check_qdinfo(qderror::QDLeapMonthError)
    throw(ArgumentError("Month: $(qderror.y)/$(qderror.m) not a leap month"))
end
function _check_qdinfo(qderror::QDDayError)
    _daysinmonth = qt[qderror.idx + 1].j - qt[qderror.idx].j
    throw(ArgumentError("Day: $(qderror.md) out of range (1:$(_daysinmonth))"))
end

function dayofyear(q::QDInfo)
    idx = _firstidxofyear(q.idx)
    return 1 + q.j - (qt[idx].j + FIRST_JULIAN)
end

function lastjdninyear(q::QDInfo)
    idx = q.idx
    y = qt[idx].y
    while qt[idx].y == y
        idx += 1
    end
    qt[idx].j - 1 + FIRST_JULIAN
end

function daysinmonth(q::QDInfo)
    # Note: Not to be thrown `ArgumentError` here.
    FIRST_RECORD ≤ q.idx ≤ LAST_RECORD || return 0
    qt[q.idx + 1].j - qt[q.idx].j
end
daysinmonth(q::QDError) = 0

function daysinyear(q::QDInfo)
    sidx = _firstidxofyear(q.idx)
    sqt = qt[sidx]
    eidx = sidx + 12
    eqt = qt[eidx]
    eqt.y == sqt.y && (eqt = qt[eidx + 1])
    return eqt.j - sqt.j
end

end


text:
# Functions

# Point
#rand(rng::Random.AbstractRNG, ::Random.SamplerType{Point{T, N}}) where N where T = Point{T, N}(NTuple{N, T}(rand(rng, T, N)))
distance(p1::Point{T, N}, p2::Point{T, N}) where N where T = sqrt(sum((p1.coordinates .- p2.coordinates).^2))

function area(arr::Array{Point{T, 2}, 1}) where T
    length(arr) <= 2 && error("Area for two points cannot be computed!")
    area = 0.0
    x = 2
    y = 3
    flag = false
    while(x <= length(arr) && y <= length(arr))
        a = distance(arr[1], arr[x])
        b = distance(arr[x], arr[y])
        c = distance(arr[1], arr[y])
        s = (a + b + c)/2.0
        area += sqrt(s*(s - a)*(s - b)*(s - c))
        if flag == false
            flag = true
            x = y + 1
        else
            flag = false
            y = x + 1
        end
    end
    return area
end

function convexHull(points::Array{Point{T,2},1}) where T
    if length(points) < 3
        error("Minimum three points required")
    end
    n = length(points)
    function orientation(p::Point{T, 2}, q::Point{T, 2}, r::Point{T, 2}) where T <: Real
        v = (q.coordinates[2] - p.coordinates[2])*(r.coordinates[1] - q.coordinates[1])- (q.coordinates[1] - p.coordinates[1])*(r.coordinates[2] - q.coordinates[2])
        if v == 0 return 0 end
        return v > 0 ? 1 : 2
    end
    hull = Array{Point{T, 2}, 1}(undef, 0)
    l = 1
    for i in 2:n
        if points[i].coordinates[1] < points[l].coordinates[1]
            l = i
        end
    end
    p = l - 1
    q = -1
    while true
        push!(hull, points[p + 1])
        q = (p + 1) % n
        for i in 0:(n - 1)
            if(orientation(points[p + 1], points[i + 1], points[q+1]) == 2)
                q = i
            end
        end
        p = q
        if p == l - 1
            break
        end
    end
    return hull
end
# Line
function distance(p::Point{T, N}, l::Line{T, N}) where N where T
    t = dot(p.coordinates .- l.p.coordinates, l.v)/dot(l.v, l.v)
    return norm(p.coordinates .- l.p.coordinates .- t*l.v)
end
distance(l::Line{T, N}, p::Point{T, N}) where N where T = distance(p::Point{T, N}, l::Line{T, N})

function distance(l1::Line{T, N}, l2::Line{T, N}; err = 1e-10) where N where T
    if norm(l1.v .- l2.v) ≦ err
        return distance(l1.p, l2)
    else
        return zero(T)
    end
end

# Plane

function distance(p::Point{T, N}, q::Plane{T, N}) where N where T
    x = distance(p, q.p)
    y = distance(p, q.n)
    return sqrt(x^2 - y^2)
end

function boundingbox(a::Array{Point{T, N}, 1}) where N where T
    mn = Array{T,1}(undef, N)
    mn .= typemax(T)
    mx = Array{T,1}(undef, N)
    mx .= typemin(T)
    for i in 1:N, j in 1:length(a)
        mn[i] = min(mn[i], a[j].coordinates[i])
        mx[i] = max(mx[i], a[j].coordinates[i])
    end
    return (Point{T, N}(mn), Point{T, N}(mx))
end


text:
"""
    Step{T<:Number, S<:Integer} <: DecaySchedule
    Step(λ, γ, step_size::Integer)
    Step(;λ, γ, step_sizes)

A step schedule decays exponentially by `γ` every step
in `step_sizes`.
The output conforms to
```
λ * γ^{i - 1}
```
where `sum(step_sizes[1:(i - 1)]) < t <= sum(step_sizes[1:i])`

# Arguments:
- `λ::Number`: the base value
- `γ::Number`: the decay rate
- `step_sizes::Union{<:Integer, <:Vector}`: the step sizes
"""
struct Step{T<:Number, S<:Integer} <: DecaySchedule
    λ::T
    γ::T
    step_sizes::Vector{S}
end
Step(λ, γ, step_size::Integer) = Step(λ, γ, [step_size])
Step(;λ, γ, step_sizes) = Step(λ, γ, step_sizes)

basevalue(schedule::Step) = schedule.λ
function decay(schedule::Step, t)
    i = findlast(x -> t > x, cumsum(schedule.step_sizes))
    i = isnothing(i) ? 0 :
            (i >= length(schedule.step_sizes)) ? length(schedule.step_sizes) - 1 : i

    return schedule.γ^i
end

Base.eltype(::Type{<:Step{T}}) where T = T
Base.IteratorSize(::Type{<:Step}) = Base.IsInfinite()

# override default behavior for decay schedules
function Base.iterate(schedule::Step, state = (1, 1, 1))
    t, i, t0 = state
    if (i <= length(schedule.step_sizes)) && (t >= t0 + schedule.step_sizes[i])
        # move onto next step range
        i += 1
        t0 = t
    end

    return basevalue(schedule) * schedule.γ^(i - 1), (t + 1, i, t0)
end

"""
    Exp{T<:Number} <: DecaySchedule
    Exp(;λ, γ)

A exponential decay schedule at rate `γ`.
The output conforms to
```
λ * γ^{t - 1}
```

# Arguments:
- `λ::Number`: the base value
- `γ::Number`: the decay rate
"""
struct Exp{T<:Number} <: DecaySchedule
    λ::T
    γ::T
end
Exp(;λ, γ) = Exp(λ, γ)

basevalue(schedule::Exp) = schedule.λ
decay(schedule::Exp, t) = schedule.γ^(t - 1)

Base.eltype(::Type{<:Exp{T}}) where T = T
Base.IteratorSize(::Type{<:Exp}) = Base.IsInfinite()

"""
    Poly{T<:Number, S<:Integer} <: DecaySchedule
    Poly(;λ, p, max_iter)

A polynomial schedule decays with degree `p`.
The output conforms to
```
λ / (1 - floor((t - 1) / max_iter))^p
```

# Arguments
- `λ::Number`: the base value
- `p::Integer`: the degree of the polynomial
- `max_iter::Integer`: the total number of iterations
"""
struct Poly{T<:Number, S<:Integer} <: DecaySchedule
    λ::T
    p::S
    max_iter::S
end
Poly(;λ, p, max_iter) = Poly(λ, p, max_iter)

basevalue(schedule::Poly) = schedule.λ
decay(schedule::Poly, t) = (1 - (t - 1) / schedule.max_iter)^schedule.p

Base.eltype(::Type{<:Poly{T}}) where T = T
Base.IteratorSize(::Type{<:Poly}) = Base.HasLength()
Base.length(schedule::Poly) = schedule.max_iter

"""
    Inv{T<:Number, S<:Integer} <: DecaySchedule
    Inv(;λ, γ, p)

A decay schedule that inversely decays with rate `γ`.
The output conforms to
```
λ / (1 + (t - 1) * γ)^p
```

# Arguments
- `λ::Number`: the base value
- `γ::Number`: the decay rate
- `p::Integer`: the degree of decay
"""
struct Inv{T<:Number, S<:Integer} <: DecaySchedule
    λ::T
    γ::T
    p::S
end
Inv(;λ, γ, p) = Inv(λ, γ, p)

basevalue(schedule::Inv) = schedule.λ
decay(schedule::Inv, t) = 1 / (1 + (t - 1) * schedule.γ)^schedule.p

Base.eltype(::Type{<:Inv{T}}) where T = T
Base.IteratorSize(::Type{<:Inv}) = Base.IsInfinite()


text:
"""
# Weighted Rendezvous Hashing

## References

- [wiki]: <https://en.wikipedia.org/wiki/Rendezvous_hashing>.
- [wrh]: Jason Resch. "New Hashing Algorithms for Data Storage",
  <http://www.snia.org/sites/default/files/SDC15_presentations/dist_sys/Jason_Resch_New_Consistent_Hashings_Rev.pdf>.
- [wdht]: Christian Schindelhauer, and Gunnar Schomaker. "Weighted distributed hash tables." SPAA
  2005: Proceedings of the 17th Annual ACM Symposium on Parallelism in Algorithms and Architectures,
  July 18-20, 2005, Las Vegas, Nevada, USA ACM, 2005.
"""
module RendezvousHashing

export RvCoordinator, insert_node!, remove_node!, choose_nodes, num_nodes, node_weight

# Bit operations for hashing
const MASK = UInt64(typemax(Int64))
const MAX_HASH = MASK + UInt64(1)

abstract type RvCoordinator end
function insert_node!(coordinator::RvCoordinator, id::String, weight::Float64)
    error("Unimplemented")
end
function remove_node!(coordinator::RvCoordinator, id::String)
    error("Unimplemented")
end
function choose_nodes(
    coordinator::RvCoordinator,
    data::String,
    n::Union{Int, Nothing}=nothing,
)::Vector{String}
    error("Unimplemented")
end
function num_nodes(coordinator::RvCoordinator)::Int
    error("Unimplemented")
end
function node_weight(coordinator::RvCoordinator, id::String)::Float64
    error("Unimplemented")
end

include("wrh.jl")
include("wdht.jl")

end # module

max_stars_repo_name: gyk/TrivialSolutions

max_issues_repo_name: gyk/TrivialSolutions

max_forks_repo_name: gyk/TrivialSolutions


text:
# Checks for methods being read in correctly.
module MethodDocsTests

using Base.Test

using Docile
@docstrings

@doc """""" { :sig => (String,) } ->
f(x::String) = x

@doc """""" { :sig => (Int,) } ->
f(x::Int) = x

@doc """""" { :sig => (Vector, Int) } ->
f(x::Vector, y::Int) = x

@doc """""" { :sig => (Int, String) } ->
f(x::Int, y::String) = x

@doc """""" { :sig => (Char, Complex, String) } ->
f(x::Char, y::Complex, z::String) = x

@doc """""" { :sig => (Vector, Char, Real) } ->
f(x::Vector, y::Char, z::Real) = x

@doc """""" { :sig => (String, Matrix{Int}) } ->
f(x::String, y::Matrix{Int}) = x

@doc """Generic function docstring.""" -> f

@test isdefined(:__METADATA__)
@test length(__METADATA__.entries) == 8

# Have the methods been added correctly to __METADATA__
# with the right :sig associated with each?
for mt in f.env
    obj, ent = query(mt)[1]

    @test mt === obj
    @test mt.sig === ent.meta[:sig]
end

# querying a function should give back function and all methods
results = query(f)

@test length(results) == 8

# passing ; all = false should only give the function itself
results = query(f; all = false)

@test length(results) == 1
@test isa(results[1][1], Function)
@test isa(results[1][2], Docile.Entry{:function})
@test length(results[1][2].meta) == 1

end


text:
# SAM Record
# ==========

type SAMRecord
    name::StringField
    flag::UInt16
    refname::StringField
    pos::Int64
    mapq::UInt8
    cigar::StringField
    next_refname::StringField
    next_pos::Int64
    tlen::Int32
    seq::StringField
    qual::StringField
    optional_fields::Dict{String,Any}
end

function SAMRecord()
    return SAMRecord("*", SAM_FLAG_UNMAP, "*", 0, 0, "*", "*", 0, 0, "*", "*", Dict())
end

function Base.isless(rec1::SAMRecord, rec2::SAMRecord)
    # compared by the left-most position of an alignment
    if rec1.name == rec2.name
        return isless(rec1.pos, rec2.pos)
    else
        return isless(rec1.name, rec2.name)
    end
end

function Base.:(==)(rec1::SAMRecord, rec2::SAMRecord)
    return (
        rec1.name            == rec2.name         &&
        rec1.flag            == rec2.flag         &&
        rec1.refname         == rec2.refname      &&
        rec1.pos             == rec2.pos          &&
        rec1.mapq            == rec2.mapq         &&
        rec1.cigar           == rec2.cigar        &&
        rec1.next_refname    == rec2.next_refname &&
        rec1.next_pos        == rec2.next_pos     &&
        rec1.tlen            == rec2.tlen         &&
        rec1.seq             == rec2.seq          &&
        rec1.qual            == rec2.qual         &&
        rec1.optional_fields == rec2.optional_fields)
end

function Base.copy(rec::SAMRecord)
    return SAMRecord(
        copy(rec.name),
        rec.flag,
        copy(rec.refname),
        rec.pos,
        rec.mapq,
        copy(rec.cigar),
        copy(rec.next_refname),
        rec.next_pos,
        rec.tlen,
        copy(rec.seq),
        copy(rec.qual),
        deepcopy(rec.optional_fields))
end

function ismapped(rec::SAMRecord)
    return flag(rec) & SAM_FLAG_UNMAP == 0
end

function Bio.Seq.seqname(rec::SAMRecord)
    return rec.name
end

function flag(rec::SAMRecord)
    return rec.flag
end

function refname(rec::SAMRecord)
    return rec.refname
end

function nextrefname(rec::SAMRecord)
    return rec.next_refname
end

function Bio.Intervals.leftposition(rec::SAMRecord)
    return rec.pos
end

function Bio.Intervals.rightposition(rec::SAMRecord)
    return leftposition(rec) + alignment_length(rec) - 1
end

function nextleftposition(rec::SAMRecord)
    return rec.next_pos
end

function mappingquality(rec::SAMRecord)
    return rec.mapq
end

function templatelength(rec::SAMRecord)
    return rec.tlen
end

function cigar(rec::SAMRecord)
    return rec.cigar
end

function alignment(rec::SAMRecord)
    if ismapped(rec)
        return Alignment(rec.cigar, 1, leftposition(rec))
    else
        return Alignment(AlignmentAnchor[])
    end
end

function Bio.Seq.sequence(rec::SAMRecord)
    return rec.seq
end

function seqlength(rec::SAMRecord)
    if rec.seq == "*"
        throw(ArgumentError("no sequence available"))
    end
    return length(rec.seq)
end

function qualities(rec::SAMRecord)
    return rec.qual
end

function Base.getindex(rec::SAMRecord, tag::AbstractString)
    checkkeytag(tag)
    return rec.optional_fields[tag]
end

function Base.setindex!(rec::SAMRecord, val, tag::AbstractString)
    checkkeytag(tag)
    setindex!(rec.optional_fields, val, tag)
    return rec
end

function Base.delete!(rec::SAMRecord, tag::AbstractString)
    checkkeytag(tag)
    delete!(rec.optional_fields, tag)
    return rec
end

function Base.haskey(rec::SAMRecord, tag::AbstractString)
    checkkeytag(tag)
    return haskey(rec.optional_fields, tag)
end

function optional_fields(rec::SAMRecord)
    return rec.optional_fields
end

# Return the length of alignment.
function alignment_length(rec::SAMRecord)
    if rec.cigar == "*"
        return 0
    end
    length = 0
    len = 0  # operation length
    for c in rec.cigar
        if isnumber(c)
            len = len * 10 + (c - '0')
        elseif isalpha(c)
            op = convert(Operation, c)
            if ismatchop(op) || isdeleteop(op)
                length += len
                len = 0
            end
        else
            error("invalid character in CIGAR: '$(c)'")
        end
    end
    return length
end


text:
using MATLAB

x = 1:10
y = rand(5,10)

mat"""
plot($x,$y)
"""

max_stars_repo_name: csimal/metaplex-networks

max_issues_repo_name: csimal/metaplex-networks

max_forks_repo_name: csimal/metaplex-networks


text:
using SHIPs
using Test, Printf, LinearAlgebra, StaticArrays, BenchmarkTools, Test
using JuLIP, JuLIP.Testing
using JuLIP.Potentials: evaluate!, evaluate_d!, evaluate, evaluate_d
using SHIPs: PolyTransform, PolyCutoff1s, PolyCutoff2s, eval_basis

@testset "SHIPs.jl" begin
    include("test_jacobi.jl")
    include("test_transforms.jl")
    include("test_ylm.jl")
    include("test_cg.jl")
    include("test_basis.jl")
    include("test_filter_rpi_alg.jl")
    include("test_fast.jl")
    include("test_multispecies.jl")
    include("test_orth.jl")
    include("test_descriptor.jl")
end

# TODO: this test needs to be rewritten!
#       but maybe it is no longer needed? The rotation-invariance tests
#       somehow take care of it???
# include("test_Bcoeffs.jl")

max_stars_repo_name: cortner/SHIPs

max_issues_repo_name: cortner/SHIPs

max_forks_repo_name: cortner/SHIPs


text:
module GeoGreensFunctions

using LinearAlgebra

const KERNELDIR = joinpath(@__DIR__, "funcs")
foreach(x -> include(joinpath(KERNELDIR, x)), filter!(x -> endswith(x, ".jl") && !startswith(x, "_"), readdir(KERNELDIR)))

end # module


text:
device(::Type{T}) where {T} = T <: Array ? CPU() : CUDADevice()
device(A) = device(ArrayInterface.parent_type(A))


text:
using MathOptInterfaceECOS
using Base.Test

using MathOptInterface
const MOI = MathOptInterface
const MOIT = MOI.Test
const MOIU = MOI.Utilities
const MOIB = MOI.Bridges

MOIU.@model ECOSModelData () (EqualTo, GreaterThan, LessThan) (Zeros, Nonnegatives, Nonpositives, SecondOrderCone, ExponentialCone) () (SingleVariable,) (ScalarAffineFunction,) (VectorOfVariables,) (VectorAffineFunction,)

MOIB.@bridge SplitInterval MOIB.SplitIntervalBridge () (Interval,) () () () (ScalarAffineFunction,) () ()

# SOC2 requires 1e-5
const config = MOIT.TestConfig(atol=1e-5, rtol=1e-5)

@testset "Continuous linear problems" begin
    MOIT.contlineartest(SplitInterval{Float64}(MOIU.CachingOptimizer(ECOSModelData{Float64}(), ECOSOptimizer())), config)
end

@testset "Continuous conic problems" begin
    MOIT.contconictest(MOIU.CachingOptimizer(ECOSModelData{Float64}(), ECOSOptimizer()), config, ["rsoc", "geomean", "sdp", "rootdet", "logdet"])
end


text:
parametrisation = POSSIBLE_PARAMS[5]
include(joinpath(SRC_DIR, "types.jl"))
include(joinpath(SRC_DIR, "fitzHughNagumo.jl"))
include(joinpath(SRC_DIR, "guid_prop_bridge.jl"))
include(joinpath(SRC_DIR, "blocking_schedule.jl"))
include(joinpath(SRC_DIR, "vern7.jl"))

function blocking_test_prep(obs=ℝ.([1.0, 1.2, 0.8, 1.3, 2.0]),
                            tt=[0.0, 1.0, 1.5, 2.3, 4.0],
                            knots=collect(1:length(obs)-2)[1:1:end],
                            changePtBuffer=100)
    θ₀ = [10.0, -8.0, 25.0, 0.0, 3.0]
    P˟ = FitzhughDiffusion(θ₀...)
    P̃ = [FitzhughDiffusionAux(θ₀..., t₀, u[1], T, v[1]) for (t₀,T,u,v)
         in zip(tt[1:end-1], tt[2:end], obs[1:end-1], obs[2:end])]
    L = @SMatrix [1. 0.]
    Σdiagel = 10^(-10)
    Σ = @SMatrix [Σdiagel]

    Ls = [L for _ in P̃]
    Σs = [Σ for _ in P̃]
    τ(t₀,T) = (x) ->  t₀ + (x-t₀) * (2-(x-t₀)/(T-t₀))
    m = length(obs) - 1
    P = Array{ContinuousTimeProcess,1}(undef,m)
    dt = 1/50
    for i in m:-1:1
        numPts = Int64(ceil((tt[i+1]-tt[i])/dt))+1
        t = τ(tt[i], tt[i+1]).( range(tt[i], stop=tt[i+1], length=numPts) )
        P[i] = ( (i==m) ? GuidPropBridge(Float64, t, P˟, P̃[i], Ls[i], obs[i+1], Σs[i];
                                         changePt=NoChangePt(changePtBuffer),
                                         solver=Vern7()) :
                          GuidPropBridge(Float64, t, P˟, P̃[i], Ls[i], obs[i+1], Σs[i],
                                         P[i+1].H[1], P[i+1].Hν[1], P[i+1].c[1];
                                         changePt=NoChangePt(changePtBuffer),
                                         solver=Vern7()) )
    end

    T = SArray{Tuple{2},Float64,1,2}
    TW = typeof(sample([0], Wiener{Float64}()))
    TX = typeof(SamplePath([], zeros(T, 0)))
    XX = Vector{TX}(undef,m)
    WW = Vector{TW}(undef,m)
    for i in 1:m
        XX[i] = SamplePath(P[i].tt, zeros(T, length(P[i].tt)))
        XX[i].yy .= [T(obs[i+1][1], i) for _ in 1:length(XX[i].yy)]
    end

    blockingParams = (knots, 10^(-7), SimpleChangePt(changePtBuffer))
    𝔅 = ChequeredBlocking(blockingParams..., P, WW, XX)
    for i in 1:m
        𝔅.XXᵒ[i].yy .= [T(obs[i+1][1], 10+i) for _ in 1:length(XX[i].yy)]
    end
    𝔅
end

@testset "blocking object" begin
    obs = ℝ.([1.0, 1.2, 0.8, 1.3, 2.0])
    tt = [0.0, 1.0, 1.5, 2.3, 4.0]
    L = @SMatrix [1. 0.]
    ϵ = 10^(-7)
    Σ = @SMatrix [10^(-10)]

    𝔅 = blocking_test_prep(obs, tt)

    @testset "validity of initial set-up" begin
        @test 𝔅.idx == 1
        @test 𝔅.knots[1] == [1, 3]
        @test 𝔅.knots[2] == [2]
        @test 𝔅.blocks[1] == [[1], [2, 3], [4]]
        @test 𝔅.blocks[2] == [[1, 2], [3, 4]]
        @test 𝔅.changePts[1] == [SimpleChangePt(100), NoChangePt(100), SimpleChangePt(100), NoChangePt(100)]
        @test 𝔅.changePts[2] == [NoChangePt(100), SimpleChangePt(100), NoChangePt(100), NoChangePt(100)]
        @test 𝔅.vs == obs[2:end]
        @test 𝔅.Ls[1] == [I, L, I, L]
        @test 𝔅.Ls[2] == [L, I, L, L]
        @test 𝔅.Σs[1] == [I*ϵ, Σ, I*ϵ, Σ]
        @test 𝔅.Σs[2] == [Σ, I*ϵ, Σ, Σ]
    end

    θ = [10.0, -8.0, 15.0, 0.0, 3.0]
    𝔅 = next(𝔅, 𝔅.XX, θ)

    @testset "validity of blocking state after calling next" begin
        @test 𝔅.idx == 2
        @testset "checking if θ has been propagated everywhere" for i in 1:length(tt)-1
            @test params(𝔅.P[i].Target) == θ
            @test params(𝔅.P[i].Pt) == θ
        end
        @test [𝔅.P[i].Σ for i in 1:length(tt)-1 ] == 𝔅.Σs[2] == [Σ, I*ϵ, Σ, Σ]
        @test [𝔅.P[i].L for i in 1:length(tt)-1 ] == 𝔅.Ls[2] == [L, I, L, L]
        @test [𝔅.P[i].v for i in 1:length(tt)-1 ] == [obs[2], 𝔅.XX[2].yy[end], obs[4], obs[5]]
        @test [𝔅.P[i].changePt for i in 1:length(tt)-1 ] == 𝔅.changePts[2] == [NoChangePt(100), SimpleChangePt(100), NoChangePt(100), NoChangePt(100)]
    end

    θᵒ = [1.0, -7.0, 10.0, 2.0, 1.0]

    @testset "checking container swaps" begin
        @testset "checking before the swap" for i in 1:length(tt)-1
            @test 𝔅.XX[i].yy[10][2] == i
            @test 𝔅.XXᵒ[i].yy[10][2] == 10 + i
        end
        for i in 1:length(tt)-1
            𝔅.XX[i], 𝔅.XXᵒ[i] = 𝔅.XXᵒ[i], 𝔅.XX[i]
        end
        @testset "checking if containers swapped" for i in 1:length(tt)-1
            @test 𝔅.XX[i].yy[10][2] == 10 + i
            @test 𝔅.XXᵒ[i].yy[10][2] == i
        end
    end

    𝔅 = next(𝔅, 𝔅.XX, θᵒ)

    @testset "validity of blocking state after second call to next" begin
        @test 𝔅.idx == 1
        @testset "checking if θᵒ has been propagated everywhere" for i in 1:length(tt)-1
            @test params(𝔅.P[i].Target) == θᵒ
            @test params(𝔅.P[i].Pt) == θᵒ
        end
        @test [𝔅.P[i].Σ for i in 1:length(tt)-1 ] == 𝔅.Σs[1] == [I*ϵ, Σ, I*ϵ, Σ]
        @test [𝔅.P[i].L for i in 1:length(tt)-1 ] == 𝔅.Ls[1] == [I, L, I, L]
        @test [𝔅.P[i].v for i in 1:length(tt)-1 ] == [𝔅.XX[1].yy[end], obs[3], 𝔅.XX[3].yy[end], obs[5]]
        @test [𝔅.P[i].changePt for i in 1:length(tt)-1 ] == 𝔅.changePts[1] == [SimpleChangePt(100), NoChangePt(100), SimpleChangePt(100), NoChangePt(100)]
    end
end


text:
include("agents.jl")

"""
Model declarations
"""

mutable struct GeneModel{A <: AbstractIndividual}
    individuals::Dict{Int, A}
    # maxid::Base.RefValue{Int64}
end


text:
"""
    make_sub_holo!(
        tensor::AbstractArray{T,3},
        holo::AbstractMatrix{T},
        windows_size::Tuple{Integer,Integer},
        interval::Tuple{Integer,Integer},
        nums_of_holo::Tuple{Integer,Integer}
    ) -> AbstractArray{T,3} where T <: AbstractFloat

生成子全息图并将其存放到`tenosr`序列上

# Arguments
- tensor: 子全息图序列
- holo: 原始全息图
- windows_size: 掩膜窗口的大小
- interval: 窗口偏移量
- nums_of_holo: 子全息图的数量（与`tensor`的第三个维度一致）

# Notice
- 当子全息图大小与原始全息图一致时，则对位于窗口外的地方补零
- 当子全息图大小与掩膜窗口大小一致时，则抛弃窗口外的数据
"""
function make_sub_holo!(tensor::AbstractArray{T,3}, holo::AbstractMatrix{T},
    windows_size::Tuple{Integer,Integer}, interval::Tuple{Integer,Integer},
    nums_of_holo::Tuple{Integer,Integer}) where {T <: AbstractFloat}

    dx, dy = interval
    Dx, Dy = windows_size
    nx, ny = nums_of_holo
    # 如果tensor与holo相同维度，则把窗口外的地方补零，如果与windows同维度
    if size(tensor)[1:2] == size(holo)
        @inbounds Threads.@threads for ind in CartesianIndices((0:nx, 0:ny))
            i, j = ind.I
            tensor[1 + i * dx:Dx + i * dx, 1 + j * dy:Dy + j * dy, i * (ny + 1) + (j + 1)] .= @view holo[1 + i * dx:Dx + i * dx, 1 + j * dy:Dy + j * dy]
        end
    elseif size(tensor)[1:2] == windows_size
        @inbounds Threads.@threads for ind in CartesianIndices((0:nx, 0:ny))
            i, j = ind.I
            tensor[:, :, i * (ny + 1) + (j + 1)] .= @view holo[1 + i * dx:Dx + i * dx, 1 + j * dy:Dy + j * dy]
        end
    else
        @error "tensor的维度与全息图或者窗口大小不匹配..."
    end

    return tensor
end

"""
    reconst_tensor!(
        re_tensor::AbstractArray{T,3},
        holo_tensor::AbstractArray{T,3},
        P::FFTW.FFTWPlan,
        scale::Integer;
        shift = false
        ) -> AbstractArray{T,3} where T <: AbstractFloat

对子全息图序列进行数值重建并存放到`re_tensor`

# Arguments
- re_tensor: 子再现像序列
- holo_tensor: 子全息图序列
- P: 其类型为FFTW.FFTWPlan，表示重建采用`fft`傅立叶变换
- scale: 由于零级像强度过大，故需要用`scale`拉升±1级像的强度
- shift: 是否旋转图像，默认为否（除非是想展示完整的重建像，否则不建议将`shift`设为`true`，因为其内存和时间开销比较大）
"""
function reconst_tensor!(re_tensor::AbstractArray{T,3}, holo_tensor::AbstractArray{T,3},
    P::FFTW.FFTWPlan, scale::Integer; shift = false) where {T <: AbstractFloat}

    FFTW.set_num_threads(Sys.CPU_THREADS)
    @inbounds Threads.@threads for k in 1:size(holo_tensor, 3)
        re_tensor[:, :, k] .= reconst((@view holo_tensor[:, :, k]), P, scale; shift = shift)
    end
    return re_tensor
end


text:
# Check that the given folder is indead the root of a git repo.
function _check_gitdir(reporoot)
    !isdir(reporoot) && return false
    out = _run("git -C $(reporoot) rev-parse --git-dir 2>&1"; verbose = false, ignorestatus = true)
    reporoot1 = strip(out)
    reporoot1 == ".git" && return true
    reporoot1 == "." && return true
    return false
end


text:
using LinearAlgebra

"""

Structure to hold data for Ehrenfest dynamics

"""
struct EhrenfestOps
    No :: Int64
    ρ  :: Matrix{Complex{Float64}}
    p  :: Vector{Float64}
    q  :: Vector{Float64}
    function EhrenfestOps(ρ0, sbm :: SBModel)
        ρ = zeros(ComplexF64,2,2)
        ρ .= ρ0
        p = zeros(Float64,sbm.No)
        q = zeros(Float64,sbm.No)
        new(sbm.No,ρ,p,q)
    end
end

"""

Leapfrog bootstrap of data (Ehrenfest)

"""
function ehbootstrap!(ops :: EhrenfestOps, oldops :: EhrenfestOps,
                      dotops :: EhrenfestOps, dt :: Float64)
    oldops.ρ .= ops.ρ - dt * dotops.ρ
    oldops.p .= ops.p - dt * dotops.p
    oldops.q .= ops.q - dt * dotops.q

    return nothing
end

"""

Leapfrog step forward (Ehrenfest)

"""
function ehforward!(ops :: EhrenfestOps, oldops :: EhrenfestOps,
                    dotops :: EhrenfestOps, dt :: Float64)
    oldops.ρ .= oldops.ρ + 2 * dt * dotops.ρ
    oldops.p .= oldops.p + 2 * dt * dotops.p
    oldops.q .= oldops.q + 2 * dt * dotops.q

    return nothing
end

"""

Leapfrog Ehrenfest calculate EOM RHS

"""
function ehcalcdots!(dotops :: EhrenfestOps, ops :: EhrenfestOps,
                    dt :: Float64, sbm :: SBModel)
    dotops.ρ .= - IOHBAR * comm(H(sbm,ops.q,ops.p),ops.ρ)
    for i in 1:ops.No
        dotops.p[i] = real(tr(F(sbm,ops.q,i)*ops.ρ))
        dotops.q[i] = ops.p[i]
    end

    return nothing
end

"""

Ehrenfest total energy

"""
function ehenergy(ops :: EhrenfestOps, sbm :: SBModel)
    energy =  real(tr(H(sbm,ops.q,ops.p) * ops.ρ))
    for ν in 1:ops.No
        energy += 0.5 * ops.p[ν]^2
    end
    return energy
end

"""

This function integrates the Ehrenfest EOMs starting from the
initial condition provided in ops for nsteps of dt.
The store! callback function is called at every timestep.

"""
function RunEhrenfest!(sbm, ops, nsteps, dt, store!, storage)

    dotops = EhrenfestOps(zm,sbm)
    oldops = EhrenfestOps(zm,sbm)

    # Bootstrap the integrator
    ehcalcdots!(dotops, ops ,dt , sbm)
    ehbootstrap!(ops,oldops,dotops,dt)

    # call results storage function at t = 0
    t = 0.0
    store!(storage,t,ops,sbm)

    # integrate
    for i in 1:nsteps-1
        t = i*dt
        ehcalcdots!(dotops,ops,dt,sbm)
        ehforward!(ops,oldops,dotops,dt)
        (ops,oldops) = (oldops,ops)
        store!(storage,t,ops,sbm)
    end

    return nothing
end


text:
@testset "QR ambiguity methods" begin
    qrmat = Base.LinAlg.getq(qrfact(eye(3)))
    v = [2,3,4]
    tv = v.'

    @test (tv*qrmat')::TransposedVector == [2 3 4]
end


text:
using sem, Feather, ModelingToolkit, Statistics, LinearAlgebra,
    Optim, SparseArrays, Test, ReverseDiff, Zygote, ForwardDiff,
    BenchmarkTools, Optim

## Observed Data
three_path_dat = Feather.read("test/comparisons/three_path_dat.feather")
three_path_par = Feather.read("test/comparisons/three_path_par.feather")

semobserved = SemObsCommon(data = Matrix(three_path_dat))

loss = Loss([SemML(semobserved)])

diff = SemForwardDiff(LBFGS(), Optim.Options())

diff2 = SemFiniteDiff(LBFGS(), Optim.Options())

## Model definition
@variables x[1:31]

S =[x[1]  0     0     0     0     0     0     0     0     0     0     0     0     0
    0     x[2]  0     0     0     0     0     0     0     0     0     0     0     0
    0     0     x[3]  0     0     0     0     0     0     0     0     0     0     0
    0     0     0     x[4]  0     0     0     x[15] 0     0     0     0     0     0
    0     0     0     0     x[5]  0     x[16] 0     x[17] 0     0     0     0     0
    0     0     0     0     0     x[6]  0     0     0     x[18] 0     0     0     0
    0     0     0     0     x[16] 0     x[7]  0     0     0     x[19] 0     0     0
    0     0     0     x[15] 0     0     0     x[8]  0     0     0     0     0     0
    0     0     0     0     x[17] 0     0     0     x[9]  0     x[20] 0     0     0
    0     0     0     0     0     x[18] 0     0     0     x[10] 0     0     0     0
    0     0     0     0     0     0     x[19] 0     x[20] 0     x[11] 0     0     0
    0     0     0     0     0     0     0     0     0     0     0     x[12] 0     0
    0     0     0     0     0     0     0     0     0     0     0     0     x[13] 0
    0     0     0     0     0     0     0     0     0     0     0     0     0     x[14]]

F =[1.0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 1 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 1 0 0 0 0 0 0 0 0 0 0 0
    0 0 0 1 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 1 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 1 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 1 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 1 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 1 0 0 0]

A =[0  0  0  0  0  0  0  0  0  0  0     1     0     0
    0  0  0  0  0  0  0  0  0  0  0     x[21] 0     0
    0  0  0  0  0  0  0  0  0  0  0     x[22] 0     0
    0  0  0  0  0  0  0  0  0  0  0     0     1     0
    0  0  0  0  0  0  0  0  0  0  0     0     x[23] 0
    0  0  0  0  0  0  0  0  0  0  0     0     x[24] 0
    0  0  0  0  0  0  0  0  0  0  0     0     x[25] 0
    0  0  0  0  0  0  0  0  0  0  0     0     0     1
    0  0  0  0  0  0  0  0  0  0  0     0     0     x[26]
    0  0  0  0  0  0  0  0  0  0  0     0     0     x[27]
    0  0  0  0  0  0  0  0  0  0  0     0     0     x[28]
    0  0  0  0  0  0  0  0  0  0  0     0     0     0
    0  0  0  0  0  0  0  0  0  0  0     x[29] 0     0
    0  0  0  0  0  0  0  0  0  0  0     x[30] x[31] 0]

S = sparse(S)

#F
F = sparse(F)

#A
A = sparse(A)

start_val = vcat(
    vec(var(Matrix(three_path_dat), dims = 1))./2,
    fill(0.05, 3),
    fill(0.0, 6),
    fill(1.0, 8),
    fill(0, 3)
    )

imply = sem.ImplySymbolicAlloc(A, S, F, x, start_val)
imply2 = ImplySymbolic(A, S, F, x, start_val)

model = Sem(semobserved, imply, loss, diff)
model2 = Sem(semobserved, imply2, loss, diff2)

model(start_val)

model

ForwardDiff.gradient(model, start_val)

@btime sol1 = optimize(model2, start_val, LBFGS())
@btime sol2 = optimize(model, start_val, LBFGS(), autodiff = :forward)

sem_fit(model2)

pars = [1.0 0]
pars2 = fill(1.0,4)

Zygote.@nograd isposdef

A = DiffEqBase.dualcache(zeros(2,2))

function myf(pars, A)
    A = DiffEqBase.get_tmp(A, pars)
    A[1] = pars[1]
    A[2] = pars[2]
    A[3] = pars[2]
    A[4] = pars[1]

    if !isposdef(A)
        return Inf
    else
        F = logdet(A) + tr(inv(A))
        return F
    end
end

function myf(pars)
    A = [pars[1] pars[2]
        pars[2] pars[1]]

    if !isposdef(A)
        return Inf
    else
        F = logdet(A) + tr(inv(A))
        return F
    end
end

Zygote.gradient(myf, pars, A)
ForwardDiff.gradient(par -> myf(par, A), pars)

@benchmark sol1 = optimize(par -> myf(par, A), pars; autodiff = :forward)
@benchmark sol2 = optimize(par -> myf(par), pars; autodiff = :forward)

sol1.minimizer

sol2 = optimize(myf,
    par -> Zygote.gradient(myf, par)[1], pars;
    inplace = false)

sol2.minimizer

sol3 = optimize(par -> myf(par), pars, autodiff = :forward)
sol3.minimizer

## ForwardDiff gradients with build functions
@variables x[1:4]

A = [x[1] x[2]
    x[3] x[4]]

A = UpperTriangular(A)

myf2 = eval.(ModelingToolkit.build_function(A, x))[2]

mat = rand(2,2)

mat = UpperTriangular(mat)

myf2(mat, fill(1.0, 4))

myf3(x) = x[1]^2

ForwardDiff.gradient(myf2, [1.0])