text:
using Rubin
using Tests
using Elliptic
using HypergeometricFunctions
using Polylogarithms
using SpecialFunctions

@test integrate(x^3*cosh(a+b*x^2), x) == :(-1//2*b^-2*cosh(a+b*x^2)+(1/2)*b^-1*x^2*sinh(a+b*x^2))
@test integrate(x^2*cosh(a+b*x^2), x) == :((1/2)*x*b^-1*sinh(a+b*x^2)+-1//8*pi^(1/2)*b^-3//2*erfi(x*b^(1/2))*exp(a)+1//8*pi^(1/2)*b^-3//2*erf(x*b^(1/2))*exp(-1a))
@test integrate(x*cosh(a+b*x^2), x) == :((1/2)*b^-1*sinh(a+b*x^2))
@test integrate(cosh(a+b*x^2), x) == :(1//4*pi^(1/2)*b^-1//2*erf(x*b^(1/2))*exp(-1a)+1//4*pi^(1/2)*b^-1//2*erfi(x*b^(1/2))*exp(a))
@test integrate(x^-1*cosh(a+b*x^2), x) == :((1/2)*cosh(a)*coshintegral(b*x^2)+(1/2)*sinh(a)*sinhintegral(b*x^2))
@test integrate(x^-2*cosh(a+b*x^2), x) == :(-1*x^-1*cosh(a+b*x^2)+(1/2)*pi^(1/2)*b^(1/2)*erfi(x*b^(1/2))*exp(a)+-1//2*pi^(1/2)*b^(1/2)*erf(x*b^(1/2))*exp(-1a))
@test integrate(x^-3*cosh(a+b*x^2), x) == :(-1//2*x^-2*cosh(a+b*x^2)+(1/2)*b*cosh(a)*sinhintegral(b*x^2)+(1/2)*b*coshintegral(b*x^2)*sinh(a))
@test integrate(x^3*cosh(a+b*x^2)^2, x) == :(1//8*x^4+-1//8*b^-2*cosh(a+b*x^2)^2+1//4*b^-1*x^2*cosh(a+b*x^2)*sinh(a+b*x^2))
@test integrate(x^2*cosh(a+b*x^2)^2, x) == :(1//6*x^3+1//8*x*b^-1*sinh(2a+2*b*x^2)+-1//64*2^(1/2)*pi^(1/2)*b^-3//2*erfi(x*2^(1/2)*b^(1/2))*exp(2a)+1//64*2^(1/2)*pi^(1/2)*b^-3//2*erf(x*2^(1/2)*b^(1/2))*exp(-2a))
@test integrate(x*cosh(a+b*x^2)^2, x) == :(1//4*x^2+1//4*b^-1*cosh(a+b*x^2)*sinh(a+b*x^2))
@test integrate(cosh(a+b*x^2)^2, x) == :((1/2)*x+1//16*2^(1/2)*pi^(1/2)*b^-1//2*erf(x*2^(1/2)*b^(1/2))*exp(-2a)+1//16*2^(1/2)*pi^(1/2)*b^-1//2*erfi(x*2^(1/2)*b^(1/2))*exp(2a))
@test integrate(x^-1*cosh(a+b*x^2)^2, x) == :((1/2)*log(x)+1//4*cosh(2a)*coshintegral(2*b*x^2)+1//4*sinh(2a)*sinhintegral(2*b*x^2))
@test integrate(x^-2*cosh(a+b*x^2)^2, x) == :(-1*x^-1*cosh(a+b*x^2)^2+-1//4*2^(1/2)*pi^(1/2)*b^(1/2)*erf(x*2^(1/2)*b^(1/2))*exp(-2a)+1//4*2^(1/2)*pi^(1/2)*b^(1/2)*erfi(x*2^(1/2)*b^(1/2))*exp(2a))
@test integrate(x^-3*cosh(a+b*x^2)^2, x) == :(-1//4*x^-2+-1//4*x^-2*cosh(2a+2*b*x^2)+(1/2)*b*cosh(2a)*sinhintegral(2*b*x^2)+(1/2)*b*coshintegral(2*b*x^2)*sinh(2a))
@test integrate(x^3*cosh(a+b*x^2)^3, x) == :(-1//3*b^-2*cosh(a+b*x^2)+-1//18*b^-2*cosh(a+b*x^2)^3+1//3*b^-1*x^2*sinh(a+b*x^2)+1//6*b^-1*x^2*cosh(a+b*x^2)^2*sinh(a+b*x^2))
@test integrate(x^2*cosh(a+b*x^2)^3, x) == :(1//24*x*b^-1*sinh(3a+3*b*x^2)+3//8*x*b^-1*sinh(a+b*x^2)+-3//32*pi^(1/2)*b^-3//2*erfi(x*b^(1/2))*exp(a)+3//32*pi^(1/2)*b^-3//2*erf(x*b^(1/2))*exp(-1a)+-1//288*3^(1/2)*pi^(1/2)*b^-3//2*erfi(x*3^(1/2)*b^(1/2))*exp(3a)+1//288*3^(1/2)*pi^(1/2)*b^-3//2*erf(x*3^(1/2)*b^(1/2))*exp(-3a))
@test integrate(x*cosh(a+b*x^2)^3, x) == :((1/2)*b^-1*sinh(a+b*x^2)+1//6*b^-1*sinh(a+b*x^2)^3)
@test integrate(cosh(a+b*x^2)^3, x) == :(3//16*pi^(1/2)*b^-1//2*erf(x*b^(1/2))*exp(-1a)+3//16*pi^(1/2)*b^-1//2*erfi(x*b^(1/2))*exp(a)+1//48*3^(1/2)*pi^(1/2)*b^-1//2*erf(x*3^(1/2)*b^(1/2))*exp(-3a)+1//48*3^(1/2)*pi^(1/2)*b^-1//2*erfi(x*3^(1/2)*b^(1/2))*exp(3a))
@test integrate(x^-1*cosh(a+b*x^2)^3, x) == :(1//8*cosh(3a)*coshintegral(3*b*x^2)+1//8*sinh(3a)*sinhintegral(3*b*x^2)+3//8*cosh(a)*coshintegral(b*x^2)+3//8*sinh(a)*sinhintegral(b*x^2))
@test integrate(x^-2*cosh(a+b*x^2)^3, x) == :(-1*x^-1*cosh(a+b*x^2)^3+-3//8*pi^(1/2)*b^(1/2)*erf(x*b^(1/2))*exp(-1a)+3//8*pi^(1/2)*b^(1/2)*erfi(x*b^(1/2))*exp(a)+-1//8*3^(1/2)*pi^(1/2)*b^(1/2)*erf(x*3^(1/2)*b^(1/2))*exp(-3a)+1//8*3^(1/2)*pi^(1/2)*b^(1/2)*erfi(x*3^(1/2)*b^(1/2))*exp(3a))
@test integrate(x^-3*cosh(a+b*x^2)^3, x) == :(-3//8*x^-2*cosh(a+b*x^2)+-1//8*x^-2*cosh(3a+3*b*x^2)+3//8*b*cosh(a)*sinhintegral(b*x^2)+3//8*b*cosh(3a)*sinhintegral(3*b*x^2)+3//8*b*coshintegral(b*x^2)*sinh(a)+3//8*b*coshintegral(3*b*x^2)*sinh(3a))
@test integrate(x*cosh(a+b*x^2)^7, x) == :((1/2)*b^-1*sinh(a+b*x^2)^3+(1/2)*b^-1*sinh(a+b*x^2)+1//14*b^-1*sinh(a+b*x^2)^7+3//10*b^-1*sinh(a+b*x^2)^5)
@test integrate(x^2*cosh(x^3), x) == :(1//3*sinh(x^3))
@test integrate(x^-6*cosh(x^-5), x) == :(-1//5*sinh(x^-5))
@test integrate(cosh(a+b*x^-1), x) == :(x*cosh(a+b*x^-1)+-1*b*cosh(a)*sinhintegral(b*x^-1)+-1*b*coshintegral(b*x^-1)*sinh(a))
@test integrate(x^-1*cosh(a+b*x^-1), x) == :(-1*cosh(a)*coshintegral(b*x^-1)+-1*sinh(a)*sinhintegral(b*x^-1))
@test integrate(x^-2*cosh(a+b*x^-1), x) == :(-1*b^-1*sinh(a+b*x^-1))
@test integrate(x^-3*cosh(a+b*x^-1), x) == :(b^-2*cosh(a+b*x^-1)+-1*b^-1*x^-1*sinh(a+b*x^-1))
@test integrate(x^-4*cosh(a+b*x^-1), x) == :(-2*b^-3*sinh(a+b*x^-1)+-1*b^-1*x^-2*sinh(a+b*x^-1)+2*b^-2*x^-1*cosh(a+b*x^-1))
@test integrate(cosh(a+b*x^-2), x) == :(x*cosh(a+b*x^-2)+(1/2)*pi^(1/2)*b^(1/2)*erf(b^(1/2)*x^-1)*exp(-1a)+-1//2*pi^(1/2)*b^(1/2)*erfi(b^(1/2)*x^-1)*exp(a))
@test integrate(x^-1*cosh(a+b*x^-2), x) == :(-1//2*cosh(a)*coshintegral(b*x^-2)+-1//2*sinh(a)*sinhintegral(b*x^-2))
@test integrate(x^-2*cosh(a+b*x^-2), x) == :(-1//4*pi^(1/2)*b^-1//2*erf(b^(1/2)*x^-1)*exp(-1a)+-1//4*pi^(1/2)*b^-1//2*erfi(b^(1/2)*x^-1)*exp(a))
@test integrate(x^-3*cosh(a+b*x^-2), x) == :(-1//2*b^-1*sinh(a+b*x^-2))
@test integrate(x^-4*cosh(a+b*x^-2), x) == :(-1//2*b^-1*x^-1*sinh(a+b*x^-2)+-1//8*pi^(1/2)*b^-3//2*erf(b^(1/2)*x^-1)*exp(-1a)+1//8*pi^(1/2)*b^-3//2*erfi(b^(1/2)*x^-1)*exp(a))
@test integrate(cosh(a+b*x^n), x) == :(-1//2*x*n^-1*(b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,b*x^n)*exp(-1a)+-1//2*x*n^-1*(-1*b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,-1*b*x^n)*exp(a))
@test integrate(x^-1*cosh(a+b*x^n), x) == :(n^-1*cosh(a)*coshintegral(b*x^n)+n^-1*sinh(a)*sinhintegral(b*x^n))
@test integrate(cosh(a+b*x^n)^2, x) == :((1/2)*x+-1*x*2^(-2+-1*n^-1)*n^-1*(b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,2*b*x^n)*exp(-2a)+-1*x*2^(-2+-1*n^-1)*n^-1*(-1*b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,-2*b*x^n)*exp(2a))
@test integrate(x^-1*cosh(a+b*x^n)^2, x) == :((1/2)*log(x)+(1/2)*n^-1*cosh(2a)*coshintegral(2*b*x^n)+(1/2)*n^-1*sinh(2a)*sinhintegral(2*b*x^n))
@test integrate(cosh(a+b*x^n)^3, x) == :(-3//8*x*n^-1*(b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,b*x^n)*exp(-1a)+-3//8*x*n^-1*(-1*b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,-1*b*x^n)*exp(a)+-1//8*x*3^(-1*n^-1)*n^-1*(b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,3*b*x^n)*exp(-3a)+-1//8*x*3^(-1*n^-1)*n^-1*(-1*b*x^n)^(-1*n^-1)*SpecialFunctions.gamma(n^-1,-3*b*x^n)*exp(3a))
@test integrate(x^-1*cosh(a+b*x^n)^3, x) == :(1//4*n^-1*cosh(3a)*coshintegral(3*b*x^n)+1//4*n^-1*sinh(3a)*sinhintegral(3*b*x^n)+3//4*n^-1*cosh(a)*coshintegral(b*x^n)+3//4*n^-1*sinh(a)*sinhintegral(b*x^n))
@test integrate(x^m*cosh(a+b*x^n), x) == :(-1//2*n^-1*x^(1+m)*(b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),b*x^n)*exp(-1a)+-1//2*n^-1*x^(1+m)*(-1*b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),-1*b*x^n)*exp(a))
@test integrate(x^m*cosh(a+b*x^n)^2, x) == :(x^(1+m)*(2+2m)^-1+-1*2^(-1*n^-1*(1+m+2n))*n^-1*x^(1+m)*(b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),2*b*x^n)*exp(-2a)+-1*2^(-1*n^-1*(1+m+2n))*n^-1*x^(1+m)*(-1*b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),-2*b*x^n)*exp(2a))
@test integrate(x^m*cosh(a+b*x^n)^3, x) == :(-3//8*n^-1*x^(1+m)*(b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),b*x^n)*exp(-1a)+-3//8*n^-1*x^(1+m)*(-1*b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),-1*b*x^n)*exp(a)+-1//8*3^(-1*n^-1*(1+m))*n^-1*x^(1+m)*(b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),3*b*x^n)*exp(-3a)+-1//8*3^(-1*n^-1*(1+m))*n^-1*x^(1+m)*(-1*b*x^n)^(-1*n^-1*(1+m))*SpecialFunctions.gamma(n^-1*(1+m),-3*b*x^n)*exp(3a))
@test integrate(x^(-1+-1n)*cosh(a+b*x^n), x) == :(-1*n^-1*x^(-1n)*cosh(a+b*x^n)+b*n^-1*cosh(a)*sinhintegral(b*x^n)+b*n^-1*coshintegral(b*x^n)*sinh(a))
@test integrate(x^(-1+-1n)*cosh(a+b*x^n)^2, x) == :(-1//2*n^-1*x^(-1n)+-1//2*n^-1*x^(-1n)*cosh(2a+2*b*x^n)+b*n^-1*cosh(2a)*sinhintegral(2*b*x^n)+b*n^-1*coshintegral(2*b*x^n)*sinh(2a))
@test integrate(x^(-1+-1n)*cosh(a+b*x^n)^3, x) == :(-3//4*n^-1*x^(-1n)*cosh(a+b*x^n)+-1//4*n^-1*x^(-1n)*cosh(3a+3*b*x^n)+3//4*b*n^-1*cosh(a)*sinhintegral(b*x^n)+3//4*b*n^-1*cosh(3a)*sinhintegral(3*b*x^n)+3//4*b*n^-1*coshintegral(b*x^n)*sinh(a)+3//4*b*n^-1*coshintegral(3*b*x^n)*sinh(3a))
@test integrate(x^(-1+(1/2)*n)*cosh(a+b*x^n), x) == :((1/2)*pi^(1/2)*b^-1//2*n^-1*erf(b^(1/2)*x^((1/2)*n))*exp(-1a)+(1/2)*pi^(1/2)*b^-1//2*n^-1*erfi(b^(1/2)*x^((1/2)*n))*exp(a))
@test integrate(x^2*cosh((a+b*x)^2), x) == :((1/2)*b^-3*(a+b*x)*sinh((a+b*x)^2)+-1*a*b^-3*sinh((a+b*x)^2)+-1//8*pi^(1/2)*b^-3*erfi(a+b*x)+1//8*pi^(1/2)*b^-3*erf(a+b*x)+1//4*pi^(1/2)*a^2*b^-3*erf(a+b*x)+1//4*pi^(1/2)*a^2*b^-3*erfi(a+b*x))
@test integrate(x*cosh((a+b*x)^2), x) == :((1/2)*b^-2*sinh((a+b*x)^2)+-1//4*a*pi^(1/2)*b^-2*erf(a+b*x)+-1//4*a*pi^(1/2)*b^-2*erfi(a+b*x))
@test integrate(cosh((a+b*x)^2), x) == :(1//4*pi^(1/2)*b^-1*erf(a+b*x)+1//4*pi^(1/2)*b^-1*erfi(a+b*x))
@test integrate(x^2*cosh(a+b*(c+d*x)^(1/2)), x) == :(-240*b^-6*d^-3*cosh(a+b*(c+d*x)^(1/2))+-1*b^-4*d^-3*(120c+120*d*x)*cosh(a+b*(c+d*x)^(1/2))+-10*b^-2*d^-3*(c+d*x)^2*cosh(a+b*(c+d*x)^(1/2))+-2*b^-2*c^2*d^-3*cosh(a+b*(c+d*x)^(1/2))+2*b^-1*d^-3*(c+d*x)^5//2*sinh(a+b*(c+d*x)^(1/2))+24*c*b^-4*d^-3*cosh(a+b*(c+d*x)^(1/2))+40*b^-3*d^-3*(c+d*x)^3//2*sinh(a+b*(c+d*x)^(1/2))+240*b^-5*d^-3*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2))+-24*c*b^-3*d^-3*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2))+-4*c*b^-1*d^-3*(c+d*x)^3//2*sinh(a+b*(c+d*x)^(1/2))+2*b^-1*c^2*d^-3*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2))+12*c*b^-2*d^-3*(c+d*x)*cosh(a+b*(c+d*x)^(1/2)))
@test integrate(x*cosh(a+b*(c+d*x)^(1/2)), x) == :(-12*b^-4*d^-2*cosh(a+b*(c+d*x)^(1/2))+-1*b^-2*d^-2*(6c+6*d*x)*cosh(a+b*(c+d*x)^(1/2))+2*c*b^-2*d^-2*cosh(a+b*(c+d*x)^(1/2))+2*b^-1*d^-2*(c+d*x)^3//2*sinh(a+b*(c+d*x)^(1/2))+12*b^-3*d^-2*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2))+-2*c*b^-1*d^-2*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2)))
@test integrate(cosh(a+b*(c+d*x)^(1/2)), x) == :(-2*b^-2*d^-1*cosh(a+b*(c+d*x)^(1/2))+2*b^-1*d^-1*(c+d*x)^(1/2)*sinh(a+b*(c+d*x)^(1/2)))
@test integrate(x^-1*cosh(a+b*(c+d*x)^(1/2)), x) == :(cosh(a+b*c^(1/2))*coshintegral(b*(c^(1/2)+-1*(c+d*x)^(1/2)))+cosh(a+-1*b*c^(1/2))*coshintegral(b*(c^(1/2)+(c+d*x)^(1/2)))+sinh(a+-1*b*c^(1/2))*sinhintegral(b*(c^(1/2)+(c+d*x)^(1/2)))+-1*sinh(a+b*c^(1/2))*sinhintegral(b*(c^(1/2)+-1*(c+d*x)^(1/2))))
@test integrate(x^-2*cosh(a+b*(c+d*x)^(1/2)), x) == :(-1*x^-1*cosh(a+b*(c+d*x)^(1/2))+(1/2)*b*d*c^-1//2*coshintegral(b*(c^(1/2)+-1*(c+d*x)^(1/2)))*sinh(a+b*c^(1/2))+-1//2*b*d*c^-1//2*cosh(a+b*c^(1/2))*sinhintegral(b*(c^(1/2)+-1*(c+d*x)^(1/2)))+-1//2*b*d*c^-1//2*cosh(a+-1*b*c^(1/2))*sinhintegral(b*(c^(1/2)+(c+d*x)^(1/2)))+-1//2*b*d*c^-1//2*coshintegral(b*(c^(1/2)+(c+d*x)^(1/2)))*sinh(a+-1*b*c^(1/2)))
@test integrate(x^2*cosh(a+b*(c+d*x)^1//3), x) == :(120960*b^-9*d^-3*sinh(a+b*(c+d*x)^1//3)+-1*b^-6*d^-3*(20160c+20160*d*x)*cosh(a+b*(c+d*x)^1//3)+-120960*b^-8*d^-3*(c+d*x)^1//3*cosh(a+b*(c+d*x)^1//3)+-1008*b^-4*d^-3*(c+d*x)^5//3*cosh(a+b*(c+d*x)^1//3)+-24*b^-2*d^-3*(c+d*x)^7//3*cosh(a+b*(c+d*x)^1//3)+3*b^-1*d^-3*(c+d*x)^8//3*sinh(a+b*(c+d*x)^1//3)+6*b^-3*c^2*d^-3*sinh(a+b*(c+d*x)^1//3)+168*b^-3*d^-3*(c+d*x)^2*sinh(a+b*(c+d*x)^1//3)+720*c*b^-6*d^-3*cosh(a+b*(c+d*x)^1//3)+5040*b^-5*d^-3*(c+d*x)^4//3*sinh(a+b*(c+d*x)^1//3)+60480*b^-7*d^-3*(c+d*x)^2//3*sinh(a+b*(c+d*x)^1//3)+-720*c*b^-5*d^-3*(c+d*x)^1//3*sinh(a+b*(c+d*x)^1//3)+-120*c*b^-3*d^-3*(c+d*x)*sinh(a+b*(c+d*x)^1//3)+-6*c*b^-1*d^-3*(c+d*x)^5//3*sinh(a+b*(c+d*x)^1//3)+-6*b^-2*c^2*d^-3*(c+d*x)^1//3*cosh(a+b*(c+d*x)^1//3)+3*b^-1*c^2*d^-3*(c+d*x)^2//3*sinh(a+b*(c+d*x)^1//3)+30*c*b^-2*d^-3*(c+d*x)^4//3*cosh(a+b*(c+d*x)^1//3)+360*c*b^-4*d^-3*(c+d*x)^2//3*cosh(a+b*(c+d*x)^1//3))
@test integrate(x*cosh(a+b*(c+d*x)^1//3), x) == :(-360*b^-6*d^-2*cosh(a+b*(c+d*x)^1//3)+b^-3*d^-2*(60c+60*d*x)*sinh(a+b*(c+d*x)^1//3)+-180*b^-4*d^-2*(c+d*x)^2//3*cosh(a+b*(c+d*x)^1//3)+-15*b^-2*d^-2*(c+d*x)^4//3*cosh(a+b*(c+d*x)^1//3)+-6*c*b^-3*d^-2*sinh(a+b*(c+d*x)^1//3)+3*b^-1*d^-2*(c+d*x)^5//3*sinh(a+b*(c+d*x)^1//3)+360*b^-5*d^-2*(c+d*x)^1//3*sinh(a+b*(c+d*x)^1//3)+-3*c*b^-1*d^-2*(c+d*x)^2//3*sinh(a+b*(c+d*x)^1//3)+6*c*b^-2*d^-2*(c+d*x)^1//3*cosh(a+b*(c+d*x)^1//3))
@test integrate(cosh(a+b*(c+d*x)^1//3), x) == :(6*b^-3*d^-1*sinh(a+b*(c+d*x)^1//3)+-6*b^-2*d^-1*(c+d*x)^1//3*cosh(a+b*(c+d*x)^1//3)+3*b^-1*d^-1*(c+d*x)^2//3*sinh(a+b*(c+d*x)^1//3))
@test integrate(x^-1*cosh(a+b*(c+d*x)^1//3), x) == :(cosh(a+b*c^1//3)*coshintegral(b*(c^1//3+-1*(c+d*x)^1//3))+cosh(a+b*(-1)^2//3*c^1//3)*coshintegral(-1*b*(-1*(c+d*x)^1//3+(-1)^2//3*c^1//3))+cosh(a+-1*b*(-1)^1//3*c^1//3)*coshintegral(b*((c+d*x)^1//3+(-1)^1//3*c^1//3))+sinh(a+-1*b*(-1)^1//3*c^1//3)*sinhintegral(b*((c+d*x)^1//3+(-1)^1//3*c^1//3))+-1*sinh(a+b*c^1//3)*sinhintegral(b*(c^1//3+-1*(c+d*x)^1//3))+-1*sinh(a+b*(-1)^2//3*c^1//3)*sinhintegral(b*(-1*(c+d*x)^1//3+(-1)^2//3*c^1//3)))
@test integrate(x^-2*cosh(a+b*(c+d*x)^1//3), x) == :(-1*x^-1*cosh(a+b*(c+d*x)^1//3)+-1//3*b*d*c^-2//3*cosh(a+b*c^1//3)*sinhintegral(b*(c^1//3+-1*(c+d*x)^1//3))+1//3*b*d*c^-2//3*coshintegral(b*(c^1//3+-1*(c+d*x)^1//3))*sinh(a+b*c^1//3)+-1//3*b*d*(-1)^1//3*c^-2//3*cosh(a+-1*b*(-1)^1//3*c^1//3)*sinhintegral(b*((c+d*x)^1//3+(-1)^1//3*c^1//3))+-1//3*b*d*(-1)^1//3*c^-2//3*coshintegral(b*((c+d*x)^1//3+(-1)^1//3*c^1//3))*sinh(a+-1*b*(-1)^1//3*c^1//3)+-1//3*b*d*(-1)^2//3*c^-2//3*cosh(a+b*(-1)^2//3*c^1//3)*sinhintegral(b*(-1*(c+d*x)^1//3+(-1)^2//3*c^1//3))+1//3*b*d*(-1)^2//3*c^-2//3*coshintegral(-1*b*(-1*(c+d*x)^1//3+(-1)^2//3*c^1//3))*sinh(a+b*(-1)^2//3*c^1//3))

max_stars_repo_path: test/6 Hyperbolic functions/6.2 Hyperbolic cosine/6.2.3 (e x)^m (a+b cosh(c+d x^n))^p.jl


text:
# Vectors defining a point source: the direction of the dipole current.

export PointSrc

# When put a point source in space discretized by a finite-difference grid, the point source
# must specify current dipole I∆r rather current I or current density J.
#
# - If it assigns current density J, it is assumed to flow uniformly through the area
# element ∆a where J is centered, so the total current is I = J ∆a, which decreases with
# increasing resolution.  If J is electric current density and if it decreases into a half,
# the induced magnetic field that circuits around I decreases into a half at the same
# distance from I.  Therefore, in order to keep the simulation result independent of grid
# resolution for sufficiently high resolution (i.e., in order to make the simulation result
# converges), current I instead of current density J should be assigned.
#
# - Now, if it assigns current I, the current is assumed to flow uniformly in the edge
# element ∆l along the direction of the current.  (The fact that this assumption is made in
# finite difference is evident if we consider a loop of electric current formed along the
# perimeter of a pixel: the magnetic current dipole induced by this electric current loop is
# proportional to the line integral of the current, and on the finite-difference grid, this
# line integral is calculated by assuming each edge has a uniform current over its length.)
# For the same current I, if ∆l decreases, the current dipole I ∆l decreases.  When the
# current dipole decreases, the E-field induced by the dipole decreases.
#
# In conclusion, a point source must specify the dipole current I∆r, and from that it must
# recover J = I∆r / (∆a ∆l) to assign to the field point.
#
# Wait, if we put a z-directional electric current component in a system that is periodic
# and one-cell-thick in the z-direction, shouldn't Jz be independent of the thickness ∆z of
# the system?  If we put a point source described above, then changing ∆z will change Jz to
# assign.  This is not what we want in general in simulating a 2D system.
#
# This means that a point source is not the correct source type to simulate a 2D system.
# This is obvious if we think about the actual physical systems represented by discretized
# systems.  The physical source distribution represented by the above-described situation is
# a periodic array of point sources separated by ∆z.  Here, by reducing ∆z while keeping the
# strength of each point source, we actually change the physical situation.  We have more
# charges per unit z oscillating along the z-direction; in other words, the charge density
# per unit z along the source line increases.  This change of charge density with varying ∆z
# should be captured in the discretized system, and the above-described point source
# specification in terms of the current dipole I∆r does so: as ∆z decreases, Iz = Jz ∆x ∆y
# = I∆r / ∆z increases indeed.
#
# On the other hand, the similar 2D situation we usually want to simulate is a 3D system
# with a z-directional line source with a constant current Iz.  Here, choosing ∆z is just to
# pick a certain ∆z-long section of the current, in which the current Iz does not change
# with the choice of ∆z.  Therefore, we must have a line source type that is specified with
# a current I instead of a current dipole I∆r.  Using such a line source would not change
# Jz = I / (∆x ∆y) to assign on each edge element even if ∆z changes.

mutable struct PointSrc{K,Kf} <: Source{K,Kf}
    # Specify geometry first, current next (because the value of current is optional).
    c::SFloat{K}  # location in shape dimension (c menas center)
    p::SFloat{Kf}  # polarization direction in field dimension
    I∆r::ComplexF  # source strength (= dipole current I∆r); complex in order to represent phase difference between point sources
    isfield˔shp::Bool  # true if spaces where field and shapes are defined are orthogonal complement of each other; false if they are the same

    PointSrc{K,Kf}(c::AbsVecReal, p::AbsVecReal, I∆r::Number, isfield˔shp::Bool) where {K,Kf} = new(c, normalize(p), I∆r, isfield˔shp)
end

PointSrc(c::AbsVecReal, p::AbsVecReal, I∆r::Number=1.0; isfield˔shp::Bool=isfield_ortho_shape(length(p),length(c))) =
    (K = length(c); Kf = length(p); PointSrc{K,Kf}(c, p, I∆r, isfield˔shp))

function add_src!(jKd::AbsArrNumber{K₊₁},  # (K+1)-dimensional array of Je (electric) or Jm (magnetic); first K dimensions specify location; last 1 dimension specify field component
                  gt₀::SVec{K,GridType},  # grid type of voxel corners; generated by ft2gt.(ft, boundft)
                  bounds::Tuple2{SFloat{K}},  # bounds[NEG][k] = boundary of domain at negative end in k-direction
                  l::Tuple2{NTuple{K,VecFloat}},  # l[PRIM][k] = primal vertex locations in k-direction
                  ∆l::Tuple2{NTuple{K,VecFloat}},  # ∆l[PRIM][k] = (∆l at primal vertices in w) == diff(l[DUAL][k] including ghost point)
                  isbloch::SBool{K},  # Bloch boundary conditions
                  src::PointSrc{K,Kf}  # point source to add
                  ) where {K,K₊₁,Kf}
    @assert K₊₁==K+1

    for nw = 1:Kf  # set Jw (w-component of J)
        gt_cmp = src.isfield˔shp ? gt₀ : gt_w(nw, gt₀)  # grid type of location of Jw

        lcmp = t_ind(l, gt_cmp)
        ∆lcmp = t_ind(∆l, gt_cmp)

        ind_cmp = ntuple(k->@SVector(zeros(Int,2)), Val(K))  # ind_cmp[nu]: indices of voxel points in nu-direction
        wt_vxl = SArray{Tuple{ntuple(k->2,Val(K))...}}(ntuple(k->1.0, Val(2^K)))  # 2(-by-2)^(K-1) array of weight factors
        for nu = 1:K  # u-coordinate of location
            u, ∆u = lcmp[nu], ∆lcmp[nu]
            ind_u, wt_u = distweights(src.c[nu], gt_cmp[nu], t_ind(bounds,nu,nu), u, ∆u, isbloch[nu])

            # Using ntuple(), replace nu-entry of ind_vxl to create a new tuple
            wt_vxl = wt_vxl .* SArray{Tuple{ntuple(k->(k==nu ? 2 : 1),Val(K))...}}(wt_u)
            ind_cmp = ntuple(k->(k==nu ? ind_u : ind_cmp[k]), Val(K))
        end

        # Calculate the w-component (I∆r)_w of the dipole current I∆r.  Once the w-component
        # of the dipole current is obtained, we obtain the w-component Iw of the current
        # by dividing (I∆r)_w by ∆w.  Therefore, (I∆r)_w / ∆w = Iw, or Iw∆w = (I∆r)_w.
        Iw∆w = src.I∆r * src.p[nw]
        Jw = Iw∆w .* wt_vxl  # Jw = Iw / (∆u ∆v) = (Iw ∆w / ∆w) / (∆u ∆v) = (Iw ∆w) / (∆u ∆v ∆w)
        for ci = CartesianIndices(ntuple(k->1:2, Val(K)))
            ind_cnr = t_ind(ind_cmp, ci)  # SInt{K}: index of voxel corner
            jKd[ind_cnr.data..., nw] += Jw[ci]
        end
    end

    return nothing
end

# # The above function for an arbitrary K is the generalization of the following function for
# # K = 3.
# function add_src!(jKd::AbsArrNumber{4},  # (3+1)-dimensional array of Je (electric) or Jm (magnetic); first 3 dimensions specify location; last 1 dimension specify field component
#                   gt₀::SVec{3,GridType},  # grid type of voxel corners; generated by ft2gt.(ft, boundft)
#                   bounds::Tuple2{SFloat{3}},  # bounds[NEG][k] = boundary of domain at negative end in k-direction
#                   l::Tuple23{VecFloat},  # l[PRIM][k] = primal vertex locations in k-direction
#                   ∆l::Tuple23{VecFloat},  # ∆l[PRIM][k] = (∆l at primal vertices in w) == diff(l[DUAL][k] including ghost point)
#                   isbloch::SBool{3},  # Bloch boundary conditions
#                   src::PointSrc{3,3})  # point source to add
#     for nw = 1:3  # set Jw (w-component of J)
#         Iw∆w = src.I∆r * src.p[nw]  # w-component of I∆r
#
#         gt_cmp = gt_w(nw, gt₀)  # grid type of Jw
#
#         lcmp = t_ind(l, gt_cmp)
#         ∆lcmp = t_ind(∆l, gt_cmp)
#
#         x, ∆x = lcmp[1], ∆lcmp[1]
#         indx, wtx = distweights(src.c[1], gt_cmp[1], t_ind(bounds,1,1), x, ∆x, isbloch[1])
#
#         y, ∆y = lcmp[2], ∆lcmp[2]
#         indy, wty = distweights(src.c[2], gt_cmp[2], t_ind(bounds,2,2), y, ∆y, isbloch[2])
#
#         z, ∆z = lcmp[3], ∆lcmp[3]
#         indz, wtz = distweights(src.c[3], gt_cmp[3], t_ind(bounds,3,3), z, ∆z, isbloch[3])
#
#         wt_vxl = SArray{Tuple{2,1,1}}(wtx) .* SArray{Tuple{1,2,1}}(wty) .* SArray{Tuple{1,1,2}}(wtz)  # 2×2×2 SArray
#         Jw = Iw∆w .* wt_vxl
#
#         for k = 1:2, j = 1:2, i = 1:2
#             j3d[indx[i],indy[j],indz[k],nw] += Jw[i,j,k]
#         end
#     end
#
#     return nothing
# end

ext: jl


text:
"""A node which emits the last `window` knots as an array."""
struct History{T} <: UnaryNodeOp{Vector{T}}
    window::Int64
end

always_ticks(::History) = false  # only tick with a full window
stateless_operator(::History) = false
time_agnostic(::History) = true

struct HistoryState{T} <: NodeEvaluationState
    value_buffer::CircularBuffer{T}
end

function create_operator_evaluation_state(::Tuple{Node}, op::History{T}) where {T}
    return HistoryState(CircularBuffer{T}(op.window))
end

function operator!(
    ::History{T}, state::HistoryState{T}, value::T
)::Maybe{Vector{T}} where {T}
    buf = state.value_buffer
    push!(buf, value)
    isfull(buf) || return Maybe{Vector{T}}()
    return Maybe(copy(buf))
end

"""
    history(x::Node{T}, window::Int) -> Node{Vector{T}}

Create a node whose values represent the last `window` values seen in `x`.

Each value will be vector of length `window`, and the result will only start ticking once
`window` values have been seen. The vector value contains time-ordered observations, with
the most recent observation last.
"""
function history(x::Node, window::Int)
    window > 0 || throw(ArgumentError("history requires a positive window, got $window"))
    return obtain_node((x,), History{value_type(x)}(window))
end


text:
module SubModule
using Test

RUN = []
@testset "A" begin
    push!(RUN, 1)
end

if VERSION >= v"1.6"
    include("subsubmodule.jl")
end
end # SubModule


text:
# Julia wrapper for header: /usr/include/libavcodec/avcodec.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

export
    av_codec_get_pkt_timebase,
    av_codec_set_pkt_timebase,
    av_codec_get_codec_descriptor,
    av_codec_set_codec_descriptor,
    av_codec_get_codec_properties,
    av_codec_get_lowres,
    av_codec_set_lowres,
    av_codec_get_seek_preroll,
    av_codec_set_seek_preroll,
    av_codec_get_chroma_intra_matrix,
    av_codec_set_chroma_intra_matrix,
    av_codec_get_max_lowres,
    avcodec_get_hw_config,
    av_codec_iterate,
    av_codec_next,
    avcodec_version,
    avcodec_configuration,
    avcodec_license,
    avcodec_register,
    avcodec_register_all,
    avcodec_alloc_context3,
    avcodec_free_context,
    avcodec_get_context_defaults3,
    avcodec_get_class,
    avcodec_get_frame_class,
    avcodec_get_subtitle_rect_class,
    avcodec_copy_context,
    avcodec_parameters_alloc,
    avcodec_parameters_free,
    avcodec_parameters_copy,
    avcodec_parameters_from_context,
    avcodec_parameters_to_context,
    avcodec_open2,
    avcodec_close,
    avsubtitle_free,
    av_packet_alloc,
    av_packet_clone,
    av_packet_free,
    av_init_packet,
    av_new_packet,
    av_shrink_packet,
    av_grow_packet,
    av_packet_from_data,
    av_dup_packet,
    av_copy_packet,
    av_copy_packet_side_data,
    av_free_packet,
    av_packet_new_side_data,
    av_packet_add_side_data,
    av_packet_shrink_side_data,
    av_packet_get_side_data,
    av_packet_merge_side_data,
    av_packet_split_side_data,
    av_packet_side_data_name,
    av_packet_pack_dictionary,
    av_packet_unpack_dictionary,
    av_packet_free_side_data,
    av_packet_ref,
    av_packet_unref,
    av_packet_move_ref,
    av_packet_copy_props,
    av_packet_make_refcounted,
    av_packet_make_writable,
    av_packet_rescale_ts,
    avcodec_find_decoder,
    avcodec_find_decoder_by_name,
    avcodec_default_get_buffer2,
    avcodec_align_dimensions,
    avcodec_align_dimensions2,
    avcodec_enum_to_chroma_pos,
    avcodec_chroma_pos_to_enum,
    avcodec_decode_audio4,
    avcodec_decode_video2,
    avcodec_decode_subtitle2,
    avcodec_send_packet,
    avcodec_receive_frame,
    avcodec_send_frame,
    avcodec_receive_packet,
    avcodec_get_hw_frames_parameters,
    av_parser_iterate,
    av_parser_next,
    av_register_codec_parser,
    av_parser_init,
    av_parser_parse2,
    av_parser_change,
    av_parser_close,
    avcodec_find_encoder,
    avcodec_find_encoder_by_name,
    avcodec_encode_audio2,
    avcodec_encode_video2,
    avcodec_encode_subtitle,
    avpicture_alloc,
    avpicture_free,
    avpicture_fill,
    avpicture_layout,
    avpicture_get_size,
    av_picture_copy,
    av_picture_crop,
    av_picture_pad,
    avcodec_get_chroma_sub_sample,
    avcodec_pix_fmt_to_codec_tag,
    avcodec_get_pix_fmt_loss,
    avcodec_find_best_pix_fmt_of_list,
    avcodec_find_best_pix_fmt_of_2,
    avcodec_find_best_pix_fmt2,
    avcodec_default_get_format,
    av_get_codec_tag_string,
    avcodec_string,
    av_get_profile_name,
    avcodec_profile_name,
    avcodec_default_execute,
    avcodec_default_execute2,
    avcodec_fill_audio_frame,
    avcodec_flush_buffers,
    av_get_bits_per_sample,
    av_get_pcm_codec,
    av_get_exact_bits_per_sample,
    av_get_audio_frame_duration,
    av_get_audio_frame_duration2,
    av_register_bitstream_filter,
    av_bitstream_filter_init,
    av_bitstream_filter_filter,
    av_bitstream_filter_close,
    av_bitstream_filter_next,
    av_bsf_get_by_name,
    av_bsf_iterate,
    av_bsf_next,
    av_bsf_alloc,
    av_bsf_init,
    av_bsf_send_packet,
    av_bsf_receive_packet,
    av_bsf_flush,
    av_bsf_free,
    av_bsf_get_class,
    av_bsf_list_alloc,
    av_bsf_list_free,
    av_bsf_list_append,
    av_bsf_list_append2,
    av_bsf_list_finalize,
    av_bsf_list_parse_str,
    av_bsf_get_null_filter,
    av_fast_padded_malloc,
    av_fast_padded_mallocz,
    av_xiphlacing,
    av_register_hwaccel,
    av_hwaccel_next,
    av_lockmgr_register,
    avcodec_get_type,
    avcodec_get_name,
    avcodec_is_open,
    av_codec_is_encoder,
    av_codec_is_decoder,
    avcodec_descriptor_get,
    avcodec_descriptor_next,
    avcodec_descriptor_get_by_name,
    av_cpb_properties_alloc

function av_codec_get_pkt_timebase(avctx)
    ccall((:av_codec_get_pkt_timebase, libavcodec), AVRational, (Ptr{AVCodecContext},), avctx)
end

function av_codec_set_pkt_timebase(avctx, val::AVRational)
    ccall((:av_codec_set_pkt_timebase, libavcodec), Cvoid, (Ptr{AVCodecContext}, AVRational), avctx, val)
end

function av_codec_get_codec_descriptor(avctx)
    ccall((:av_codec_get_codec_descriptor, libavcodec), Ptr{AVCodecDescriptor}, (Ptr{AVCodecContext},), avctx)
end

function av_codec_set_codec_descriptor(avctx, desc)
    ccall((:av_codec_set_codec_descriptor, libavcodec), Cvoid, (Ptr{AVCodecContext}, Ptr{AVCodecDescriptor}), avctx, desc)
end

function av_codec_get_codec_properties(avctx)
    ccall((:av_codec_get_codec_properties, libavcodec), UInt32, (Ptr{AVCodecContext},), avctx)
end

function av_codec_get_lowres(avctx)
    ccall((:av_codec_get_lowres, libavcodec), Cint, (Ptr{AVCodecContext},), avctx)
end

function av_codec_set_lowres(avctx, val::Integer)
    ccall((:av_codec_set_lowres, libavcodec), Cvoid, (Ptr{AVCodecContext}, Cint), avctx, val)
end

function av_codec_get_seek_preroll(avctx)
    ccall((:av_codec_get_seek_preroll, libavcodec), Cint, (Ptr{AVCodecContext},), avctx)
end

function av_codec_set_seek_preroll(avctx, val::Integer)
    ccall((:av_codec_set_seek_preroll, libavcodec), Cvoid, (Ptr{AVCodecContext}, Cint), avctx, val)
end

function av_codec_get_chroma_intra_matrix(avctx)
    ccall((:av_codec_get_chroma_intra_matrix, libavcodec), Ptr{UInt16}, (Ptr{AVCodecContext},), avctx)
end

function av_codec_set_chroma_intra_matrix(avctx, val)
    ccall((:av_codec_set_chroma_intra_matrix, libavcodec), Cvoid, (Ptr{AVCodecContext}, Ptr{UInt16}), avctx, val)
end

function av_codec_get_max_lowres(codec)
    ccall((:av_codec_get_max_lowres, libavcodec), Cint, (Ptr{AVCodec},), codec)
end

function avcodec_get_hw_config(codec, index::Integer)
    ccall((:avcodec_get_hw_config, libavcodec), Ptr{AVCodecHWConfig}, (Ptr{AVCodec}, Cint), codec, index)
end

function av_codec_iterate(opaque)
    ccall((:av_codec_iterate, libavcodec), Ptr{AVCodec}, (Ptr{Ptr{Cvoid}},), opaque)
end

function av_codec_next(c)
    ccall((:av_codec_next, libavcodec), Ptr{AVCodec}, (Ptr{AVCodec},), c)
end

function avcodec_version()
    ccall((:avcodec_version, libavcodec), UInt32, ())
end

function avcodec_configuration()
    ccall((:avcodec_configuration, libavcodec), Cstring, ())
end

function avcodec_license()
    ccall((:avcodec_license, libavcodec), Cstring, ())
end

function avcodec_register(codec)
    ccall((:avcodec_register, libavcodec), Cvoid, (Ptr{AVCodec},), codec)
end

function avcodec_register_all()
    ccall((:avcodec_register_all, libavcodec), Cvoid, ())
end

function avcodec_alloc_context3(codec)
    ccall((:avcodec_alloc_context3, libavcodec), Ptr{AVCodecContext}, (Ptr{AVCodec},), codec)
end

function avcodec_free_context(avctx)
    ccall((:avcodec_free_context, libavcodec), Cvoid, (Ptr{Ptr{AVCodecContext}},), avctx)
end

function avcodec_get_context_defaults3(s, codec)
    ccall((:avcodec_get_context_defaults3, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVCodec}), s, codec)
end

function avcodec_get_class()
    ccall((:avcodec_get_class, libavcodec), Ptr{AVClass}, ())
end

function avcodec_get_frame_class()
    ccall((:avcodec_get_frame_class, libavcodec), Ptr{AVClass}, ())
end

function avcodec_get_subtitle_rect_class()
    ccall((:avcodec_get_subtitle_rect_class, libavcodec), Ptr{AVClass}, ())
end

function avcodec_copy_context(dest, src)
    ccall((:avcodec_copy_context, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVCodecContext}), dest, src)
end

function avcodec_parameters_alloc()
    ccall((:avcodec_parameters_alloc, libavcodec), Ptr{AVCodecParameters}, ())
end

function avcodec_parameters_free(par)
    ccall((:avcodec_parameters_free, libavcodec), Cvoid, (Ptr{Ptr{AVCodecParameters}},), par)
end

function avcodec_parameters_copy(dst, src)
    ccall((:avcodec_parameters_copy, libavcodec), Cint, (Ptr{AVCodecParameters}, Ptr{AVCodecParameters}), dst, src)
end

function avcodec_parameters_from_context(par, codec)
    ccall((:avcodec_parameters_from_context, libavcodec), Cint, (Ptr{AVCodecParameters}, Ptr{AVCodecContext}), par, codec)
end

function avcodec_parameters_to_context(codec, par)
    ccall((:avcodec_parameters_to_context, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVCodecParameters}), codec, par)
end

function avcodec_open2(avctx, codec, options)
    ccall((:avcodec_open2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVCodec}, Ref{Ptr{AVDictionary}}), avctx, codec, options)
end

function avcodec_close(avctx)
    ccall((:avcodec_close, libavcodec), Cint, (Ptr{AVCodecContext},), avctx)
end

function avsubtitle_free(sub)
    ccall((:avsubtitle_free, libavcodec), Cvoid, (Ptr{AVSubtitle},), sub)
end

function av_packet_alloc()
    ccall((:av_packet_alloc, libavcodec), Ptr{AVPacket}, ())
end

function av_packet_clone(src)
    ccall((:av_packet_clone, libavcodec), Ptr{AVPacket}, (Ptr{AVPacket},), src)
end

function av_packet_free(pkt)
    ccall((:av_packet_free, libavcodec), Cvoid, (Ptr{Ptr{AVPacket}},), pkt)
end

function av_init_packet(pkt)
    ccall((:av_init_packet, libavcodec), Cvoid, (Ptr{AVPacket},), pkt)
end

function av_new_packet(pkt, size::Integer)
    ccall((:av_new_packet, libavcodec), Cint, (Ptr{AVPacket}, Cint), pkt, size)
end

function av_shrink_packet(pkt, size::Integer)
    ccall((:av_shrink_packet, libavcodec), Cvoid, (Ptr{AVPacket}, Cint), pkt, size)
end

function av_grow_packet(pkt, grow_by::Integer)
    ccall((:av_grow_packet, libavcodec), Cint, (Ptr{AVPacket}, Cint), pkt, grow_by)
end

function av_packet_from_data(pkt, data, size::Integer)
    ccall((:av_packet_from_data, libavcodec), Cint, (Ptr{AVPacket}, Ptr{UInt8}, Cint), pkt, data, size)
end

function av_dup_packet(pkt)
    ccall((:av_dup_packet, libavcodec), Cint, (Ptr{AVPacket},), pkt)
end

function av_copy_packet(dst, src)
    ccall((:av_copy_packet, libavcodec), Cint, (Ptr{AVPacket}, Ptr{AVPacket}), dst, src)
end

function av_copy_packet_side_data(dst, src)
    ccall((:av_copy_packet_side_data, libavcodec), Cint, (Ptr{AVPacket}, Ptr{AVPacket}), dst, src)
end

function av_free_packet(pkt)
    ccall((:av_free_packet, libavcodec), Cvoid, (Ptr{AVPacket},), pkt)
end

function av_packet_new_side_data(pkt, _type::AVPacketSideDataType, size::Integer)
    ccall((:av_packet_new_side_data, libavcodec), Ptr{UInt8}, (Ptr{AVPacket}, AVPacketSideDataType, Cint), pkt, _type, size)
end

function av_packet_add_side_data(pkt, _type::AVPacketSideDataType, data, size::Csize_t)
    ccall((:av_packet_add_side_data, libavcodec), Cint, (Ptr{AVPacket}, AVPacketSideDataType, Ptr{UInt8}, Csize_t), pkt, _type, data, size)
end

function av_packet_shrink_side_data(pkt, _type::AVPacketSideDataType, size::Integer)
    ccall((:av_packet_shrink_side_data, libavcodec), Cint, (Ptr{AVPacket}, AVPacketSideDataType, Cint), pkt, _type, size)
end

function av_packet_get_side_data(pkt, _type::AVPacketSideDataType, size)
    ccall((:av_packet_get_side_data, libavcodec), Ptr{UInt8}, (Ptr{AVPacket}, AVPacketSideDataType, Ptr{Cint}), pkt, _type, size)
end

function av_packet_merge_side_data(pkt)
    ccall((:av_packet_merge_side_data, libavcodec), Cint, (Ptr{AVPacket},), pkt)
end

function av_packet_split_side_data(pkt)
    ccall((:av_packet_split_side_data, libavcodec), Cint, (Ptr{AVPacket},), pkt)
end

function av_packet_side_data_name(_type::AVPacketSideDataType)
    ccall((:av_packet_side_data_name, libavcodec), Cstring, (AVPacketSideDataType,), _type)
end

function av_packet_pack_dictionary(dict, size)
    ccall((:av_packet_pack_dictionary, libavcodec), Ptr{UInt8}, (Ptr{AVDictionary}, Ptr{Cint}), dict, size)
end

function av_packet_unpack_dictionary(data, size::Integer, dict)
    ccall((:av_packet_unpack_dictionary, libavcodec), Cint, (Ptr{UInt8}, Cint, Ref{Ptr{AVDictionary}}), data, size, dict)
end

function av_packet_free_side_data(pkt)
    ccall((:av_packet_free_side_data, libavcodec), Cvoid, (Ptr{AVPacket},), pkt)
end

function av_packet_ref(dst, src)
    ccall((:av_packet_ref, libavcodec), Cint, (Ptr{AVPacket}, Ptr{AVPacket}), dst, src)
end

function av_packet_unref(pkt)
    ccall((:av_packet_unref, libavcodec), Cvoid, (Ptr{AVPacket},), pkt)
end

function av_packet_move_ref(dst, src)
    ccall((:av_packet_move_ref, libavcodec), Cvoid, (Ptr{AVPacket}, Ptr{AVPacket}), dst, src)
end

function av_packet_copy_props(dst, src)
    ccall((:av_packet_copy_props, libavcodec), Cint, (Ptr{AVPacket}, Ptr{AVPacket}), dst, src)
end

function av_packet_make_refcounted(pkt)
    ccall((:av_packet_make_refcounted, libavcodec), Cint, (Ptr{AVPacket},), pkt)
end

function av_packet_make_writable(pkt)
    ccall((:av_packet_make_writable, libavcodec), Cint, (Ptr{AVPacket},), pkt)
end

function av_packet_rescale_ts(pkt, tb_src::AVRational, tb_dst::AVRational)
    ccall((:av_packet_rescale_ts, libavcodec), Cvoid, (Ptr{AVPacket}, AVRational, AVRational), pkt, tb_src, tb_dst)
end

function avcodec_find_decoder(id::AVCodecID)
    ccall((:avcodec_find_decoder, libavcodec), Ptr{AVCodec}, (AVCodecID,), id)
end

function avcodec_find_decoder_by_name(name)
    ccall((:avcodec_find_decoder_by_name, libavcodec), Ptr{AVCodec}, (Cstring,), name)
end

function avcodec_default_get_buffer2(s, frame, flags::Integer)
    ccall((:avcodec_default_get_buffer2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVFrame}, Cint), s, frame, flags)
end

function avcodec_align_dimensions(s, width, height)
    ccall((:avcodec_align_dimensions, libavcodec), Cvoid, (Ptr{AVCodecContext}, Ptr{Cint}, Ptr{Cint}), s, width, height)
end

function avcodec_align_dimensions2(s, width, height, linesize_align::NTuple{8, Cint})
    ccall((:avcodec_align_dimensions2, libavcodec), Cvoid, (Ptr{AVCodecContext}, Ptr{Cint}, Ptr{Cint}, NTuple{8, Cint}), s, width, height, linesize_align)
end

function avcodec_enum_to_chroma_pos(xpos, ypos, pos::AVChromaLocation)
    ccall((:avcodec_enum_to_chroma_pos, libavcodec), Cint, (Ptr{Cint}, Ptr{Cint}, AVChromaLocation), xpos, ypos, pos)
end

function avcodec_chroma_pos_to_enum(xpos::Integer, ypos::Integer)
    ccall((:avcodec_chroma_pos_to_enum, libavcodec), AVChromaLocation, (Cint, Cint), xpos, ypos)
end

function avcodec_decode_audio4(avctx, frame, got_frame_ptr, avpkt)
    ccall((:avcodec_decode_audio4, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVFrame}, Ptr{Cint}, Ptr{AVPacket}), avctx, frame, got_frame_ptr, avpkt)
end

function avcodec_decode_video2(avctx, picture, got_picture_ptr, avpkt)
    ccall((:avcodec_decode_video2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVFrame}, Ptr{Cint}, Ptr{AVPacket}), avctx, picture, got_picture_ptr, avpkt)
end

function avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, avpkt)
    ccall((:avcodec_decode_subtitle2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVSubtitle}, Ptr{Cint}, Ptr{AVPacket}), avctx, sub, got_sub_ptr, avpkt)
end

function avcodec_send_packet(avctx, avpkt)
    ccall((:avcodec_send_packet, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVPacket}), avctx, avpkt)
end

function avcodec_receive_frame(avctx, frame)
    ccall((:avcodec_receive_frame, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVFrame}), avctx, frame)
end

function avcodec_send_frame(avctx, frame)
    ccall((:avcodec_send_frame, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVFrame}), avctx, frame)
end

function avcodec_receive_packet(avctx, avpkt)
    ccall((:avcodec_receive_packet, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVPacket}), avctx, avpkt)
end

function avcodec_get_hw_frames_parameters(avctx, device_ref, hw_pix_fmt::AVPixelFormat, out_frames_ref)
    ccall((:avcodec_get_hw_frames_parameters, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVBufferRef}, AVPixelFormat, Ptr{Ptr{AVBufferRef}}), avctx, device_ref, hw_pix_fmt, out_frames_ref)
end

function av_parser_iterate(opaque)
    ccall((:av_parser_iterate, libavcodec), Ptr{AVCodecParser}, (Ptr{Ptr{Cvoid}},), opaque)
end

function av_parser_next(c)
    ccall((:av_parser_next, libavcodec), Ptr{AVCodecParser}, (Ptr{AVCodecParser},), c)
end

function av_register_codec_parser(parser)
    ccall((:av_register_codec_parser, libavcodec), Cvoid, (Ptr{AVCodecParser},), parser)
end

function av_parser_init(codec_id::Integer)
    ccall((:av_parser_init, libavcodec), Ptr{AVCodecParserContext}, (Cint,), codec_id)
end

function av_parser_parse2(s, avctx, poutbuf, poutbuf_size, buf, buf_size::Integer, pts::Int64, dts::Int64, pos::Int64)
    ccall((:av_parser_parse2, libavcodec), Cint, (Ptr{AVCodecParserContext}, Ptr{AVCodecContext}, Ptr{Ptr{UInt8}}, Ptr{Cint}, Ptr{UInt8}, Cint, Int64, Int64, Int64), s, avctx, poutbuf, poutbuf_size, buf, buf_size, pts, dts, pos)
end

function av_parser_change(s, avctx, poutbuf, poutbuf_size, buf, buf_size::Integer, keyframe::Integer)
    ccall((:av_parser_change, libavcodec), Cint, (Ptr{AVCodecParserContext}, Ptr{AVCodecContext}, Ptr{Ptr{UInt8}}, Ptr{Cint}, Ptr{UInt8}, Cint, Cint), s, avctx, poutbuf, poutbuf_size, buf, buf_size, keyframe)
end

function av_parser_close(s)
    ccall((:av_parser_close, libavcodec), Cvoid, (Ptr{AVCodecParserContext},), s)
end

function avcodec_find_encoder(id::AVCodecID)
    ccall((:avcodec_find_encoder, libavcodec), Ptr{AVCodec}, (AVCodecID,), id)
end

function avcodec_find_encoder_by_name(name)
    ccall((:avcodec_find_encoder_by_name, libavcodec), Ptr{AVCodec}, (Cstring,), name)
end

function avcodec_encode_audio2(avctx, avpkt, frame, got_packet_ptr)
    ccall((:avcodec_encode_audio2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVPacket}, Ptr{AVFrame}, Ptr{Cint}), avctx, avpkt, frame, got_packet_ptr)
end

function avcodec_encode_video2(avctx, avpkt, frame, got_packet_ptr)
    ccall((:avcodec_encode_video2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{AVPacket}, Ptr{AVFrame}, Ptr{Cint}), avctx, avpkt, frame, got_packet_ptr)
end

function avcodec_encode_subtitle(avctx, buf, buf_size::Integer, sub)
    ccall((:avcodec_encode_subtitle, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{UInt8}, Cint, Ptr{AVSubtitle}), avctx, buf, buf_size, sub)
end

function avpicture_alloc(picture, pix_fmt::AVPixelFormat, width::Integer, height::Integer)
    ccall((:avpicture_alloc, libavcodec), Cint, (Ptr{AVPicture}, AVPixelFormat, Cint, Cint), picture, pix_fmt, width, height)
end

function avpicture_free(picture)
    ccall((:avpicture_free, libavcodec), Cvoid, (Ptr{AVPicture},), picture)
end

function avpicture_fill(picture, ptr, pix_fmt::AVPixelFormat, width::Integer, height::Integer)
    ccall((:avpicture_fill, libavcodec), Cint, (Ptr{AVPicture}, Ptr{UInt8}, AVPixelFormat, Cint, Cint), picture, ptr, pix_fmt, width, height)
end

function avpicture_layout(src, pix_fmt::AVPixelFormat, width::Integer, height::Integer, dest, dest_size::Integer)
    ccall((:avpicture_layout, libavcodec), Cint, (Ptr{AVPicture}, AVPixelFormat, Cint, Cint, Ptr{Cuchar}, Cint), src, pix_fmt, width, height, dest, dest_size)
end

function avpicture_get_size(pix_fmt::AVPixelFormat, width::Integer, height::Integer)
    ccall((:avpicture_get_size, libavcodec), Cint, (AVPixelFormat, Cint, Cint), pix_fmt, width, height)
end

function av_picture_copy(dst, src, pix_fmt::AVPixelFormat, width::Integer, height::Integer)
    ccall((:av_picture_copy, libavcodec), Cvoid, (Ptr{AVPicture}, Ptr{AVPicture}, AVPixelFormat, Cint, Cint), dst, src, pix_fmt, width, height)
end

function av_picture_crop(dst, src, pix_fmt::AVPixelFormat, top_band::Integer, left_band::Integer)
    ccall((:av_picture_crop, libavcodec), Cint, (Ptr{AVPicture}, Ptr{AVPicture}, AVPixelFormat, Cint, Cint), dst, src, pix_fmt, top_band, left_band)
end

function av_picture_pad(dst, src, height::Integer, width::Integer, pix_fmt::AVPixelFormat, padtop::Integer, padbottom::Integer, padleft::Integer, padright::Integer, color)
    ccall((:av_picture_pad, libavcodec), Cint, (Ptr{AVPicture}, Ptr{AVPicture}, Cint, Cint, AVPixelFormat, Cint, Cint, Cint, Cint, Ptr{Cint}), dst, src, height, width, pix_fmt, padtop, padbottom, padleft, padright, color)
end

function avcodec_get_chroma_sub_sample(pix_fmt::AVPixelFormat, h_shift, v_shift)
    ccall((:avcodec_get_chroma_sub_sample, libavcodec), Cvoid, (AVPixelFormat, Ptr{Cint}, Ptr{Cint}), pix_fmt, h_shift, v_shift)
end

function avcodec_pix_fmt_to_codec_tag(pix_fmt::AVPixelFormat)
    ccall((:avcodec_pix_fmt_to_codec_tag, libavcodec), UInt32, (AVPixelFormat,), pix_fmt)
end

function avcodec_get_pix_fmt_loss(dst_pix_fmt::AVPixelFormat, src_pix_fmt::AVPixelFormat, has_alpha::Integer)
    ccall((:avcodec_get_pix_fmt_loss, libavcodec), Cint, (AVPixelFormat, AVPixelFormat, Cint), dst_pix_fmt, src_pix_fmt, has_alpha)
end

function avcodec_find_best_pix_fmt_of_list(pix_fmt_list, src_pix_fmt::AVPixelFormat, has_alpha::Integer, loss_ptr)
    ccall((:avcodec_find_best_pix_fmt_of_list, libavcodec), AVPixelFormat, (Ptr{AVPixelFormat}, AVPixelFormat, Cint, Ptr{Cint}), pix_fmt_list, src_pix_fmt, has_alpha, loss_ptr)
end

function avcodec_find_best_pix_fmt_of_2(dst_pix_fmt1::AVPixelFormat, dst_pix_fmt2::AVPixelFormat, src_pix_fmt::AVPixelFormat, has_alpha::Integer, loss_ptr)
    ccall((:avcodec_find_best_pix_fmt_of_2, libavcodec), AVPixelFormat, (AVPixelFormat, AVPixelFormat, AVPixelFormat, Cint, Ptr{Cint}), dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, has_alpha, loss_ptr)
end

function avcodec_find_best_pix_fmt2(dst_pix_fmt1::AVPixelFormat, dst_pix_fmt2::AVPixelFormat, src_pix_fmt::AVPixelFormat, has_alpha::Integer, loss_ptr)
    ccall((:avcodec_find_best_pix_fmt2, libavcodec), AVPixelFormat, (AVPixelFormat, AVPixelFormat, AVPixelFormat, Cint, Ptr{Cint}), dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, has_alpha, loss_ptr)
end

function avcodec_default_get_format(s, fmt)
    ccall((:avcodec_default_get_format, libavcodec), AVPixelFormat, (Ptr{AVCodecContext}, Ptr{AVPixelFormat}), s, fmt)
end

function av_get_codec_tag_string(buf, buf_size::Csize_t, codec_tag::Integer)
    ccall((:av_get_codec_tag_string, libavcodec), Csize_t, (Cstring, Csize_t, UInt32), buf, buf_size, codec_tag)
end

function avcodec_string(buf, buf_size::Integer, enc, encode::Integer)
    ccall((:avcodec_string, libavcodec), Cvoid, (Cstring, Cint, Ptr{AVCodecContext}, Cint), buf, buf_size, enc, encode)
end

function av_get_profile_name(codec, profile::Integer)
    ccall((:av_get_profile_name, libavcodec), Cstring, (Ptr{AVCodec}, Cint), codec, profile)
end

function avcodec_profile_name(codec_id::AVCodecID, profile::Integer)
    ccall((:avcodec_profile_name, libavcodec), Cstring, (AVCodecID, Cint), codec_id, profile)
end

function avcodec_default_execute(c, func, arg, ret, count::Integer, size::Integer)
    ccall((:avcodec_default_execute, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cint}, Cint, Cint), c, func, arg, ret, count, size)
end

function avcodec_default_execute2(c, func, arg, ret, count::Integer)
    ccall((:avcodec_default_execute2, libavcodec), Cint, (Ptr{AVCodecContext}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cint}, Cint), c, func, arg, ret, count)
end

function avcodec_fill_audio_frame(frame, nb_channels::Integer, sample_fmt::AVSampleFormat, buf, buf_size::Integer, align::Integer)
    ccall((:avcodec_fill_audio_frame, libavcodec), Cint, (Ptr{AVFrame}, Cint, AVSampleFormat, Ptr{UInt8}, Cint, Cint), frame, nb_channels, sample_fmt, buf, buf_size, align)
end

function avcodec_flush_buffers(avctx)
    ccall((:avcodec_flush_buffers, libavcodec), Cvoid, (Ptr{AVCodecContext},), avctx)
end

function av_get_bits_per_sample(codec_id::AVCodecID)
    ccall((:av_get_bits_per_sample, libavcodec), Cint, (AVCodecID,), codec_id)
end

function av_get_pcm_codec(fmt::AVSampleFormat, be::Integer)
    ccall((:av_get_pcm_codec, libavcodec), AVCodecID, (AVSampleFormat, Cint), fmt, be)
end

function av_get_exact_bits_per_sample(codec_id::AVCodecID)
    ccall((:av_get_exact_bits_per_sample, libavcodec), Cint, (AVCodecID,), codec_id)
end

function av_get_audio_frame_duration(avctx, frame_bytes::Integer)
    ccall((:av_get_audio_frame_duration, libavcodec), Cint, (Ptr{AVCodecContext}, Cint), avctx, frame_bytes)
end

function av_get_audio_frame_duration2(par, frame_bytes::Integer)
    ccall((:av_get_audio_frame_duration2, libavcodec), Cint, (Ptr{AVCodecParameters}, Cint), par, frame_bytes)
end

function av_register_bitstream_filter(bsf)
    ccall((:av_register_bitstream_filter, libavcodec), Cvoid, (Ptr{AVBitStreamFilter},), bsf)
end

function av_bitstream_filter_init(name)
    ccall((:av_bitstream_filter_init, libavcodec), Ptr{AVBitStreamFilterContext}, (Cstring,), name)
end

function av_bitstream_filter_filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size::Integer, keyframe::Integer)
    ccall((:av_bitstream_filter_filter, libavcodec), Cint, (Ptr{AVBitStreamFilterContext}, Ptr{AVCodecContext}, Cstring, Ptr{Ptr{UInt8}}, Ptr{Cint}, Ptr{UInt8}, Cint, Cint), bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe)
end

function av_bitstream_filter_close(bsf)
    ccall((:av_bitstream_filter_close, libavcodec), Cvoid, (Ptr{AVBitStreamFilterContext},), bsf)
end

function av_bitstream_filter_next(f)
    ccall((:av_bitstream_filter_next, libavcodec), Ptr{AVBitStreamFilter}, (Ptr{AVBitStreamFilter},), f)
end

function av_bsf_get_by_name(name)
    ccall((:av_bsf_get_by_name, libavcodec), Ptr{AVBitStreamFilter}, (Cstring,), name)
end

function av_bsf_iterate(opaque)
    ccall((:av_bsf_iterate, libavcodec), Ptr{AVBitStreamFilter}, (Ptr{Ptr{Cvoid}},), opaque)
end

function av_bsf_next(opaque)
    ccall((:av_bsf_next, libavcodec), Ptr{AVBitStreamFilter}, (Ptr{Ptr{Cvoid}},), opaque)
end

function av_bsf_alloc(filter, ctx)
    ccall((:av_bsf_alloc, libavcodec), Cint, (Ptr{AVBitStreamFilter}, Ptr{Ptr{AVBSFContext}}), filter, ctx)
end

function av_bsf_init(ctx)
    ccall((:av_bsf_init, libavcodec), Cint, (Ptr{AVBSFContext},), ctx)
end

function av_bsf_send_packet(ctx, pkt)
    ccall((:av_bsf_send_packet, libavcodec), Cint, (Ptr{AVBSFContext}, Ptr{AVPacket}), ctx, pkt)
end

function av_bsf_receive_packet(ctx, pkt)
    ccall((:av_bsf_receive_packet, libavcodec), Cint, (Ptr{AVBSFContext}, Ptr{AVPacket}), ctx, pkt)
end

function av_bsf_flush(ctx)
    ccall((:av_bsf_flush, libavcodec), Cvoid, (Ptr{AVBSFContext},), ctx)
end

function av_bsf_free(ctx)
    ccall((:av_bsf_free, libavcodec), Cvoid, (Ptr{Ptr{AVBSFContext}},), ctx)
end

function av_bsf_get_class()
    ccall((:av_bsf_get_class, libavcodec), Ptr{AVClass}, ())
end

function av_bsf_list_alloc()
    ccall((:av_bsf_list_alloc, libavcodec), Ptr{AVBSFList}, ())
end

function av_bsf_list_free(lst)
    ccall((:av_bsf_list_free, libavcodec), Cvoid, (Ptr{Ptr{AVBSFList}},), lst)
end

function av_bsf_list_append(lst, bsf)
    ccall((:av_bsf_list_append, libavcodec), Cint, (Ptr{AVBSFList}, Ptr{AVBSFContext}), lst, bsf)
end

function av_bsf_list_append2(lst, bsf_name, options)
    ccall((:av_bsf_list_append2, libavcodec), Cint, (Ptr{AVBSFList}, Cstring, Ref{Ptr{AVDictionary}}), lst, bsf_name, options)
end

function av_bsf_list_finalize(lst, bsf)
    ccall((:av_bsf_list_finalize, libavcodec), Cint, (Ptr{Ptr{AVBSFList}}, Ptr{Ptr{AVBSFContext}}), lst, bsf)
end

function av_bsf_list_parse_str(str, bsf)
    ccall((:av_bsf_list_parse_str, libavcodec), Cint, (Cstring, Ptr{Ptr{AVBSFContext}}), str, bsf)
end

function av_bsf_get_null_filter(bsf)
    ccall((:av_bsf_get_null_filter, libavcodec), Cint, (Ptr{Ptr{AVBSFContext}},), bsf)
end

function av_fast_padded_malloc(ptr, size, min_size::Csize_t)
    ccall((:av_fast_padded_malloc, libavcodec), Cvoid, (Ptr{Cvoid}, Ptr{UInt32}, Csize_t), ptr, size, min_size)
end

function av_fast_padded_mallocz(ptr, size, min_size::Csize_t)
    ccall((:av_fast_padded_mallocz, libavcodec), Cvoid, (Ptr{Cvoid}, Ptr{UInt32}, Csize_t), ptr, size, min_size)
end

function av_xiphlacing(s, v::Integer)
    ccall((:av_xiphlacing, libavcodec), UInt32, (Ptr{Cuchar}, UInt32), s, v)
end

function av_register_hwaccel(hwaccel)
    ccall((:av_register_hwaccel, libavcodec), Cvoid, (Ptr{AVHWAccel},), hwaccel)
end

function av_hwaccel_next(hwaccel)
    ccall((:av_hwaccel_next, libavcodec), Ptr{AVHWAccel}, (Ptr{AVHWAccel},), hwaccel)
end

function av_lockmgr_register(cb)
    ccall((:av_lockmgr_register, libavcodec), Cint, (Ptr{Cvoid},), cb)
end

function avcodec_get_type(codec_id::AVCodecID)
    ccall((:avcodec_get_type, libavcodec), AVMediaType, (AVCodecID,), codec_id)
end

function avcodec_get_name(id::AVCodecID)
    ccall((:avcodec_get_name, libavcodec), Cstring, (AVCodecID,), id)
end

function avcodec_is_open(s)
    ccall((:avcodec_is_open, libavcodec), Cint, (Ptr{AVCodecContext},), s)
end

function av_codec_is_encoder(codec)
    ccall((:av_codec_is_encoder, libavcodec), Cint, (Ptr{AVCodec},), codec)
end

function av_codec_is_decoder(codec)
    ccall((:av_codec_is_decoder, libavcodec), Cint, (Ptr{AVCodec},), codec)
end

function avcodec_descriptor_get(id::AVCodecID)
    ccall((:avcodec_descriptor_get, libavcodec), Ptr{AVCodecDescriptor}, (AVCodecID,), id)
end

function avcodec_descriptor_next(prev)
    ccall((:avcodec_descriptor_next, libavcodec), Ptr{AVCodecDescriptor}, (Ptr{AVCodecDescriptor},), prev)
end

function avcodec_descriptor_get_by_name(name)
    ccall((:avcodec_descriptor_get_by_name, libavcodec), Ptr{AVCodecDescriptor}, (Cstring,), name)
end

function av_cpb_properties_alloc(size)
    ccall((:av_cpb_properties_alloc, libavcodec), Ptr{AVCPBProperties}, (Ptr{Csize_t},), size)
end


text:
using Sugar, MacroTools, Base.Test
using Base.Test

srand()

function controlflow_1(a, b)
    if a == 10
        x = if b == 22
            7
        else
            8
        end
        for i = 1:100
            x += i
            x -= 77
            i == 77 && continue
            if i == 99 && (i % 2 == 0)
                break
            end
        end
        return x
    else
        return 77
    end
end

apply_vararg2(x...) = +(x...)

@testset "round trips" begin
    @testset "control flow" begin
        method = Sugar.LazyMethod(controlflow_1, (Int, Int))
        func_expr = Sugar.get_func_expr(method, gensym(:controlflow_1))
        try
            round_tripped = eval(func_expr)
            for i = 1:10
                x, y = rand(-5000:5000), rand(-5000:5000)
                @test round_tripped(x, y) == controlflow_1(x, y)
            end
        catch e
            warn(e)
            @test false
        end
    end
    @testset "complex exp" begin
        # exp was complex enough to break Matcha, so lets test it
        method = Sugar.LazyMethod(exp, Tuple{Complex64})
        func_expr = Sugar.get_func_expr(method, gensym(:exp_sugar))
        try
            round_tripped = eval(func_expr)
            for i = 1:10
                x = rand(Complex64)
                @test round_tripped(x) == exp(x)
            end
        catch e
            warn(e)
            @test false
        end
    end
    @testset "apply vararg" begin
        method = @lazymethod apply_vararg2(1, 2, 3)
        func_expr = Sugar.get_func_expr(method, gensym(:varargtest))
        try
            round_tripped = eval(func_expr)
            # note that you need to pass a tuple, since that's what it expects
            # TODO, move the construction of the tuple into function body?
            @test apply_vararg2(1, 2, 3) == round_tripped((1, 2, 3))
        catch e
            warn(e)
            @test false
        end
    end
end

decl = @lazymethod controlflow_1(1, 2)
ast = Sugar.getast!(decl)
needsnotype = (:block, :if, :(=), :while, :return, :continue, :break, :for, :(:))
@testset "ast rewriting and normalization" begin
    MacroTools.prewalk(ast) do expr
        if isa(expr, Expr)
            if !(expr.head in needsnotype)
                # there shouldn't be any untyped expressions in the AST
                if expr.typ == Any
                    show(expr.head)
                end
                @test expr.typ != Any
            end
            if expr.head == :call
                f = expr.args[1]
                # all function calls should get replaced by the real function
                @test isa(f, LazyMethod)
            end
        end
        expr
    end
end
# The dependencies and implementation on 0.6 have changed quite a bit...
# TODO add a `pure` example, which doesn't rely on implementations of base!
decl = @lazymethod controlflow_1(1, 2)
ast = Sugar.getast!(decl)

@testset "method dependencies" begin
    deps = Sugar.dependencies!(decl)
    deps_test = [
        typeof(controlflow_1),
        Bool,
        Int,
        (==, Tuple{Int64,Int64}),
        (+, Tuple{Int,Int}),
        (-, Tuple{Int,Int}),
        (rem, Tuple{Int,Int}),
    ]
    @test length(deps) == length(deps_test)
    @test all(x-> x.signature in deps_test, deps)
    funcs = [
        (==,Tuple{Int64,Int64}),
        (+,Tuple{Int, Int}),
        (-,Tuple{Int, Int}),
        (rem, Tuple{Int,Int}),
    ]
    funcdeps = filter(Sugar.isfunction, deps)
    @test length(funcdeps) == length(funcs)
    @test all(x-> x.signature in funcs, funcdeps)
    types = [
        typeof(controlflow_1),
        Int64,
        Bool
    ]
    typedeps = filter(Sugar.istype, deps)
    @test length(typedeps) == length(types)
    @test all(x-> x.signature in types, typedeps)
end

function fortest(x)
    acc = x
    for i = 1:5
        if i == 1
            acc += x
        elseif i == 2
            acc -= x
        else
            acc += x * x
        end
    end
    return acc
end

decl = Sugar.@lazymethod fortest(1f0)
ast = Sugar.getast!(decl)
function typed_expr(head, typ, args...)
    expr = Expr(head, args...)
    expr.typ = typ
    expr
end
ast_target = []
push!(ast_target, typed_expr(:(::), Float32, :acc, Float32))
push!(ast_target, typed_expr(:(::), Int, Symbol("#temp#"), Int))
push!(ast_target, typed_expr(:(::), Int, :i, Int))
sloti, slotx, slotacc = TypedSlot(3, Int), TypedSlot(2, Float32), TypedSlot(5, Float32)

push!(ast_target, :($slotacc = $slotx))
for_loop = Expr(:for)

push!(for_loop.args, :($sloti = 1:5))
forbody = Expr(:block)
push!(for_loop.args, forbody)
# if else
call = typed_expr(:call, Float32, +, slotacc, slotx)
firstif = Expr(:if,
    typed_expr(:call, Bool, ==, sloti, 1),
    Expr(:block,
        :($(slotacc) = $call),
        Expr(:continue)
    )
)
push!(forbody.args, firstif)
call = typed_expr(:call, Float32, -, slotacc, slotx)
secondif = Expr(:if,
    typed_expr(:call, Bool, ==, sloti, 2),
    Expr(:block,
        :($(slotacc) = $call),
        Expr(:continue)
    )
)
push!(forbody.args, secondif)
call1 = typed_expr(:call, Float32, *, slotx, slotx)
call = typed_expr(:call, Float32, +, slotacc, call1)
push!(forbody.args, :($(slotacc) = $call))

push!(ast_target, for_loop)
push!(ast_target, :(return $(slotacc)))
target_expr = typed_expr(:block, Float32, ast_target...)

function compare(x, y::LazyMethod)
    if Sugar.isfunction(y)
        Sugar.getfunction(y) == x || error("$x $y no match")
    else
        y.signature == x || error("$x $y no match")
    end
end
compare(x, y) = (x == y || error("$x $y no match"); true)
function compare(x::Expr, y::Expr)
    x.head == y.head || error("$x $y no match")
    x.typ == y.typ || error("$x $y no match")
    length(x.args) == length(y.args) || error("$x $y no match")
    for (a, b) in zip(x.args, y.args)
        compare(a, b)
    end
    true
end
@testset "for + ifelse" begin
    @test compare(target_expr, ast)
end

function test1(a, b)
    c = a + b
    a == c && (c = a)
    c
end
function test2(a, b)
    c = a + b
    if a == c
        c = a
    end
    c
end
ast1 = Sugar.sugared(test1, (Int, Int), code_lowered)
ast2 = Sugar.sugared(test2, (Int, Int), code_lowered)
@test ast1 == ast2

test3(b) = one(b)
lm = @lazymethod test3(Int)
deps = [LazyMethod(typeof(test3)), LazyMethod(Type{Int}), LazyMethod(Int), @lazymethod(one(Int))]
@test all(x-> x in deps, dependencies!(lm))

test4(b::T) where T = one(T)
lm = @lazymethod test4(1)
deps = [LazyMethod(typeof(test4)), LazyMethod(Int), LazyMethod(Type{Int}), @lazymethod(one(Int))]
@test all(x-> x in deps, dependencies!(lm))


text:
# This file is auto-generated by AWSMetadata.jl
using AWS
using AWS.AWSServices: kendra
using AWS.Compat
using AWS.UUIDs
"""
    BatchDeleteDocument()

Removes one or more documents from an index. The documents must have been added with the BatchPutDocument operation. The documents are deleted asynchronously. You can see the progress of the deletion by using AWS CloudWatch. Any error messages releated to the processing of the batch are sent to you CloudWatch log.

# Required Parameters
- `DocumentIdList`: One or more identifiers for documents to delete from the index.
- `IndexId`: The identifier of the index that contains the documents to delete.

# Optional Parameters
- `DataSourceSyncJobMetricTarget`:
"""

batch_delete_document(DocumentIdList, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("BatchDeleteDocument", Dict{String, Any}("DocumentIdList"=>DocumentIdList, "IndexId"=>IndexId); aws_config=aws_config)
batch_delete_document(DocumentIdList, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("BatchDeleteDocument", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("DocumentIdList"=>DocumentIdList, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    BatchPutDocument()

Adds one or more documents to an index. The BatchPutDocument operation enables you to ingest inline documents or a set of documents stored in an Amazon S3 bucket. Use this operation to ingest your text and unstructured text into an index, add custom attributes to the documents, and to attach an access control list to the documents added to the index. The documents are indexed asynchronously. You can see the progress of the batch using AWS CloudWatch. Any error messages related to processing the batch are sent to your AWS CloudWatch log.

# Required Parameters
- `Documents`: One or more documents to add to the index.  Documents have the following file size limits.   5 MB total size for inline documents   50 MB total size for files from an S3 bucket   5 MB extracted text for any file   For more information about file size and transaction per second quotas, see Quotas.
- `IndexId`: The identifier of the index to add the documents to. You need to create the index first using the CreateIndex operation.

# Optional Parameters
- `RoleArn`: The Amazon Resource Name (ARN) of a role that is allowed to run the BatchPutDocument operation. For more information, see IAM Roles for Amazon Kendra.
"""

batch_put_document(Documents, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("BatchPutDocument", Dict{String, Any}("Documents"=>Documents, "IndexId"=>IndexId); aws_config=aws_config)
batch_put_document(Documents, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("BatchPutDocument", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Documents"=>Documents, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    CreateDataSource()

Creates a data source that you use to with an Amazon Kendra index.  You specify a name, data source connector type and description for your data source. You also specify configuration information such as document metadata (author, source URI, and so on) and user context information.  CreateDataSource is a synchronous operation. The operation returns 200 if the data source was successfully created. Otherwise, an exception is raised.

# Required Parameters
- `IndexId`: The identifier of the index that should be associated with this data source.
- `Name`: A unique name for the data source. A data source name can't be changed without deleting and recreating the data source.
- `Type`: The type of repository that contains the data source.

# Optional Parameters
- `ClientToken`: A token that you provide to identify the request to create a data source. Multiple calls to the CreateDataSource operation with the same client token will create only one data source.
- `Configuration`: The connector configuration information that is required to access the repository. You can't specify the Configuration parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception. The Configuration parameter is required for all other data sources.
- `Description`: A description for the data source.
- `RoleArn`: The Amazon Resource Name (ARN) of a role with permission to access the data source. For more information, see IAM Roles for Amazon Kendra. You can't specify the RoleArn parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception. The RoleArn parameter is required for all other data sources.
- `Schedule`: Sets the frequency that Amazon Kendra will check the documents in your repository and update the index. If you don't set a schedule Amazon Kendra will not periodically update the index. You can call the StartDataSourceSyncJob operation to update the index. You can't specify the Schedule parameter when the Type parameter is set to CUSTOM. If you do, you receive a ValidationException exception.
- `Tags`: A list of key-value pairs that identify the data source. You can use the tags to identify and organize your resources and to control access to resources.
"""

create_data_source(IndexId, Name, Type; aws_config::AWSConfig=global_aws_config()) = kendra("CreateDataSource", Dict{String, Any}("IndexId"=>IndexId, "Name"=>Name, "Type"=>Type, "ClientToken"=>string(uuid4())); aws_config=aws_config)
create_data_source(IndexId, Name, Type, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("CreateDataSource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId, "Name"=>Name, "Type"=>Type, "ClientToken"=>string(uuid4())), args)); aws_config=aws_config)

"""
    CreateFaq()

Creates an new set of frequently asked question (FAQ) questions and answers.

# Required Parameters
- `IndexId`: The identifier of the index that contains the FAQ.
- `Name`: The name that should be associated with the FAQ.
- `RoleArn`: The Amazon Resource Name (ARN) of a role with permission to access the S3 bucket that contains the FAQs. For more information, see IAM Roles for Amazon Kendra.
- `S3Path`: The S3 location of the FAQ input data.

# Optional Parameters
- `ClientToken`: A token that you provide to identify the request to create a FAQ. Multiple calls to the CreateFaqRequest operation with the same client token will create only one FAQ.
- `Description`: A description of the FAQ.
- `FileFormat`: The format of the input file. You can choose between a basic CSV format, a CSV format that includes customs attributes in a header, and a JSON format that includes custom attributes. The format must match the format of the file stored in the S3 bucket identified in the S3Path parameter. For more information, see Adding questions and answers.
- `Tags`: A list of key-value pairs that identify the FAQ. You can use the tags to identify and organize your resources and to control access to resources.
"""

create_faq(IndexId, Name, RoleArn, S3Path; aws_config::AWSConfig=global_aws_config()) = kendra("CreateFaq", Dict{String, Any}("IndexId"=>IndexId, "Name"=>Name, "RoleArn"=>RoleArn, "S3Path"=>S3Path, "ClientToken"=>string(uuid4())); aws_config=aws_config)
create_faq(IndexId, Name, RoleArn, S3Path, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("CreateFaq", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId, "Name"=>Name, "RoleArn"=>RoleArn, "S3Path"=>S3Path, "ClientToken"=>string(uuid4())), args)); aws_config=aws_config)

"""
    CreateIndex()

Creates a new Amazon Kendra index. Index creation is an asynchronous operation. To determine if index creation has completed, check the Status field returned from a call to . The Status field is set to ACTIVE when the index is ready to use. Once the index is active you can index your documents using the operation or using one of the supported data sources.

# Required Parameters
- `Name`: The name for the new index.
- `RoleArn`: An AWS Identity and Access Management (IAM) role that gives Amazon Kendra permissions to access your Amazon CloudWatch logs and metrics. This is also the role used when you use the BatchPutDocument operation to index documents from an Amazon S3 bucket.

# Optional Parameters
- `ClientToken`: A token that you provide to identify the request to create an index. Multiple calls to the CreateIndex operation with the same client token will create only one index.
- `Description`: A description for the index.
- `Edition`: The Amazon Kendra edition to use for the index. Choose DEVELOPER_EDITION for indexes intended for development, testing, or proof of concept. Use ENTERPRISE_EDITION for your production databases. Once you set the edition for an index, it can't be changed.  The Edition parameter is optional. If you don't supply a value, the default is ENTERPRISE_EDITION.
- `ServerSideEncryptionConfiguration`: The identifier of the AWS KMS customer managed key (CMK) to use to encrypt data indexed by Amazon Kendra. Amazon Kendra doesn't support asymmetric CMKs.
- `Tags`: A list of key-value pairs that identify the index. You can use the tags to identify and organize your resources and to control access to resources.
"""

create_index(Name, RoleArn; aws_config::AWSConfig=global_aws_config()) = kendra("CreateIndex", Dict{String, Any}("Name"=>Name, "RoleArn"=>RoleArn, "ClientToken"=>string(uuid4())); aws_config=aws_config)
create_index(Name, RoleArn, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("CreateIndex", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Name"=>Name, "RoleArn"=>RoleArn, "ClientToken"=>string(uuid4())), args)); aws_config=aws_config)

"""
    DeleteDataSource()

Deletes an Amazon Kendra data source. An exception is not thrown if the data source is already being deleted. While the data source is being deleted, the Status field returned by a call to the operation is set to DELETING. For more information, see Deleting Data Sources.

# Required Parameters
- `Id`: The unique identifier of the data source to delete.
- `IndexId`: The unique identifier of the index associated with the data source.

"""

delete_data_source(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteDataSource", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
delete_data_source(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteDataSource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    DeleteFaq()

Removes an FAQ from an index.

# Required Parameters
- `Id`: The identifier of the FAQ to remove.
- `IndexId`: The index to remove the FAQ from.

"""

delete_faq(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteFaq", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
delete_faq(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteFaq", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    DeleteIndex()

Deletes an existing Amazon Kendra index. An exception is not thrown if the index is already being deleted. While the index is being deleted, the Status field returned by a call to the DescribeIndex operation is set to DELETING.

# Required Parameters
- `Id`: The identifier of the index to delete.

"""

delete_index(Id; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteIndex", Dict{String, Any}("Id"=>Id); aws_config=aws_config)
delete_index(Id, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DeleteIndex", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id), args)); aws_config=aws_config)

"""
    DescribeDataSource()

Gets information about a Amazon Kendra data source.

# Required Parameters
- `Id`: The unique identifier of the data source to describe.
- `IndexId`: The identifier of the index that contains the data source.

"""

describe_data_source(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeDataSource", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
describe_data_source(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeDataSource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    DescribeFaq()

Gets information about an FAQ list.

# Required Parameters
- `Id`: The unique identifier of the FAQ.
- `IndexId`: The identifier of the index that contains the FAQ.

"""

describe_faq(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeFaq", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
describe_faq(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeFaq", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    DescribeIndex()

Describes an existing Amazon Kendra index

# Required Parameters
- `Id`: The name of the index to describe.

"""

describe_index(Id; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeIndex", Dict{String, Any}("Id"=>Id); aws_config=aws_config)
describe_index(Id, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("DescribeIndex", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id), args)); aws_config=aws_config)

"""
    ListDataSourceSyncJobs()

Gets statistics about synchronizing Amazon Kendra with a data source.

# Required Parameters
- `Id`: The identifier of the data source.
- `IndexId`: The identifier of the index that contains the data source.

# Optional Parameters
- `MaxResults`: The maximum number of synchronization jobs to return in the response. If there are fewer results in the list, this response contains only the actual results.
- `NextToken`: If the result of the previous request to GetDataSourceSyncJobHistory was truncated, include the NextToken to fetch the next set of jobs.
- `StartTimeFilter`: When specified, the synchronization jobs returned in the list are limited to jobs between the specified dates.
- `StatusFilter`: When specified, only returns synchronization jobs with the Status field equal to the specified status.
"""

list_data_source_sync_jobs(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("ListDataSourceSyncJobs", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
list_data_source_sync_jobs(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("ListDataSourceSyncJobs", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    ListDataSources()

Lists the data sources that you have created.

# Required Parameters
- `IndexId`: The identifier of the index that contains the data source.

# Optional Parameters
- `MaxResults`: The maximum number of data sources to return.
- `NextToken`: If the previous response was incomplete (because there is more data to retrieve), Amazon Kendra returns a pagination token in the response. You can use this pagination token to retrieve the next set of data sources (DataSourceSummaryItems).
"""

list_data_sources(IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("ListDataSources", Dict{String, Any}("IndexId"=>IndexId); aws_config=aws_config)
list_data_sources(IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("ListDataSources", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    ListFaqs()

Gets a list of FAQ lists associated with an index.

# Required Parameters
- `IndexId`: The index that contains the FAQ lists.

# Optional Parameters
- `MaxResults`: The maximum number of FAQs to return in the response. If there are fewer results in the list, this response contains only the actual results.
- `NextToken`: If the result of the previous request to ListFaqs was truncated, include the NextToken to fetch the next set of FAQs.
"""

list_faqs(IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("ListFaqs", Dict{String, Any}("IndexId"=>IndexId); aws_config=aws_config)
list_faqs(IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("ListFaqs", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    ListIndices()

Lists the Amazon Kendra indexes that you have created.

# Optional Parameters
- `MaxResults`: The maximum number of data sources to return.
- `NextToken`: If the previous response was incomplete (because there is more data to retrieve), Amazon Kendra returns a pagination token in the response. You can use this pagination token to retrieve the next set of indexes (DataSourceSummaryItems).
"""

list_indices(; aws_config::AWSConfig=global_aws_config()) = kendra("ListIndices"; aws_config=aws_config)
list_indices(args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("ListIndices", args; aws_config=aws_config)

"""
    ListTagsForResource()

Gets a list of tags associated with a specified resource. Indexes, FAQs, and data sources can have tags associated with them.

# Required Parameters
- `ResourceARN`: The Amazon Resource Name (ARN) of the index, FAQ, or data source to get a list of tags for.

"""

list_tags_for_resource(ResourceARN; aws_config::AWSConfig=global_aws_config()) = kendra("ListTagsForResource", Dict{String, Any}("ResourceARN"=>ResourceARN); aws_config=aws_config)
list_tags_for_resource(ResourceARN, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("ListTagsForResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN), args)); aws_config=aws_config)

"""
    Query()

Searches an active index. Use this API to search your documents using query. The Query operation enables to do faceted search and to filter results based on document attributes. It also enables you to provide user context that Amazon Kendra uses to enforce document access control in the search results.  Amazon Kendra searches your index for text content and question and answer (FAQ) content. By default the response contains three types of results.   Relevant passages   Matching FAQs   Relevant documents   You can specify that the query return only one type of result using the QueryResultTypeConfig parameter. Each query returns the 100 most relevant results.

# Required Parameters
- `IndexId`: The unique identifier of the index to search. The identifier is returned in the response from the operation.
- `QueryText`: The text to search for.

# Optional Parameters
- `AttributeFilter`: Enables filtered searches based on document attributes. You can only provide one attribute filter; however, the AndAllFilters, NotFilter, and OrAllFilters parameters contain a list of other filters. The AttributeFilter parameter enables you to create a set of filtering rules that a document must satisfy to be included in the query results.
- `Facets`: An array of documents attributes. Amazon Kendra returns a count for each attribute key specified. You can use this information to help narrow the search for your user.
- `PageNumber`: Query results are returned in pages the size of the PageSize parameter. By default, Amazon Kendra returns the first page of results. Use this parameter to get result pages after the first one.
- `PageSize`: Sets the number of results that are returned in each page of results. The default page size is 10. The maximum number of results returned is 100. If you ask for more than 100 results, only 100 are returned.
- `QueryResultTypeFilter`: Sets the type of query. Only results for the specified query type are returned.
- `RequestedDocumentAttributes`: An array of document attributes to include in the response. No other document attributes are included in the response. By default all document attributes are included in the response.
- `SortingConfiguration`: Provides information that determines how the results of the query are sorted. You can set the field that Amazon Kendra should sort the results on, and specify whether the results should be sorted in ascending or descending order. In the case of ties in sorting the results, the results are sorted by relevance. If you don't provide sorting configuration, the results are sorted by the relevance that Amazon Kendra determines for the result.
"""

query(IndexId, QueryText; aws_config::AWSConfig=global_aws_config()) = kendra("Query", Dict{String, Any}("IndexId"=>IndexId, "QueryText"=>QueryText); aws_config=aws_config)
query(IndexId, QueryText, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("Query", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId, "QueryText"=>QueryText), args)); aws_config=aws_config)

"""
    StartDataSourceSyncJob()

Starts a synchronization job for a data source. If a synchronization job is already in progress, Amazon Kendra returns a ResourceInUseException exception.

# Required Parameters
- `Id`: The identifier of the data source to synchronize.
- `IndexId`: The identifier of the index that contains the data source.

"""

start_data_source_sync_job(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("StartDataSourceSyncJob", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
start_data_source_sync_job(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("StartDataSourceSyncJob", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    StopDataSourceSyncJob()

Stops a running synchronization job. You can't stop a scheduled synchronization job.

# Required Parameters
- `Id`: The identifier of the data source for which to stop the synchronization jobs.
- `IndexId`: The identifier of the index that contains the data source.

"""

stop_data_source_sync_job(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("StopDataSourceSyncJob", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
stop_data_source_sync_job(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("StopDataSourceSyncJob", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    SubmitFeedback()

Enables you to provide feedback to Amazon Kendra to improve the performance of the service.

# Required Parameters
- `IndexId`: The identifier of the index that was queried.
- `QueryId`: The identifier of the specific query for which you are submitting feedback. The query ID is returned in the response to the operation.

# Optional Parameters
- `ClickFeedbackItems`: Tells Amazon Kendra that a particular search result link was chosen by the user.
- `RelevanceFeedbackItems`: Provides Amazon Kendra with relevant or not relevant feedback for whether a particular item was relevant to the search.
"""

submit_feedback(IndexId, QueryId; aws_config::AWSConfig=global_aws_config()) = kendra("SubmitFeedback", Dict{String, Any}("IndexId"=>IndexId, "QueryId"=>QueryId); aws_config=aws_config)
submit_feedback(IndexId, QueryId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("SubmitFeedback", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("IndexId"=>IndexId, "QueryId"=>QueryId), args)); aws_config=aws_config)

"""
    TagResource()

Adds the specified tag to the specified index, FAQ, or data source resource. If the tag already exists, the existing value is replaced with the new value.

# Required Parameters
- `ResourceARN`: The Amazon Resource Name (ARN) of the index, FAQ, or data source to tag.
- `Tags`: A list of tag keys to add to the index, FAQ, or data source. If a tag already exists, the existing value is replaced with the new value.

"""

tag_resource(ResourceARN, Tags; aws_config::AWSConfig=global_aws_config()) = kendra("TagResource", Dict{String, Any}("ResourceARN"=>ResourceARN, "Tags"=>Tags); aws_config=aws_config)
tag_resource(ResourceARN, Tags, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("TagResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN, "Tags"=>Tags), args)); aws_config=aws_config)

"""
    UntagResource()

Removes a tag from an index, FAQ, or a data source.

# Required Parameters
- `ResourceARN`: The Amazon Resource Name (ARN) of the index, FAQ, or data source to remove the tag from.
- `TagKeys`: A list of tag keys to remove from the index, FAQ, or data source. If a tag key does not exist on the resource, it is ignored.

"""

untag_resource(ResourceARN, TagKeys; aws_config::AWSConfig=global_aws_config()) = kendra("UntagResource", Dict{String, Any}("ResourceARN"=>ResourceARN, "TagKeys"=>TagKeys); aws_config=aws_config)
untag_resource(ResourceARN, TagKeys, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("UntagResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN, "TagKeys"=>TagKeys), args)); aws_config=aws_config)

"""
    UpdateDataSource()

Updates an existing Amazon Kendra data source.

# Required Parameters
- `Id`: The unique identifier of the data source to update.
- `IndexId`: The identifier of the index that contains the data source to update.

# Optional Parameters
- `Configuration`:
- `Description`: The new description for the data source.
- `Name`: The name of the data source to update. The name of the data source can't be updated. To rename a data source you must delete the data source and re-create it.
- `RoleArn`: The Amazon Resource Name (ARN) of the new role to use when the data source is accessing resources on your behalf.
- `Schedule`: The new update schedule for the data source.
"""

update_data_source(Id, IndexId; aws_config::AWSConfig=global_aws_config()) = kendra("UpdateDataSource", Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId); aws_config=aws_config)
update_data_source(Id, IndexId, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("UpdateDataSource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id, "IndexId"=>IndexId), args)); aws_config=aws_config)

"""
    UpdateIndex()

Updates an existing Amazon Kendra index.

# Required Parameters
- `Id`: The identifier of the index to update.

# Optional Parameters
- `CapacityUnits`: Sets the number of addtional storage and query capacity units that should be used by the index. You can change the capacity of the index up to 5 times per day. If you are using extra storage units, you can't reduce the storage capacity below that required to meet the storage needs for your index.
- `Description`: A new description for the index.
- `DocumentMetadataConfigurationUpdates`: The document metadata to update.
- `Name`: The name of the index to update.
- `RoleArn`: A new IAM role that gives Amazon Kendra permission to access your Amazon CloudWatch logs.
"""

update_index(Id; aws_config::AWSConfig=global_aws_config()) = kendra("UpdateIndex", Dict{String, Any}("Id"=>Id); aws_config=aws_config)
update_index(Id, args::AbstractDict{String, <:Any}; aws_config::AWSConfig=global_aws_config()) = kendra("UpdateIndex", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("Id"=>Id), args)); aws_config=aws_config)


text:
using UPPE
using Test

using PhysicalConstants.CODATA2018
const C0 = SpeedOfLightInVacuum.val

cd(@__DIR__)

@testset "UPPE.jl" begin
    include("test_t.jl")
    include("test_rt.jl")
end

rm("results", recursive=true)


text:
function Predict(θ;μ=0,σ=1)
   P=function (X)
      m=size(X,1)
      X=(X.-μ)./σ
      X=[ones(m) X]
      p=X*θ
        return p
    end

        return P
end


text:
import Gadfly

Gadfly.set_default_plot_format(:svg)

function Base.display(report::Report, m::MIME"image/png", p::Gadfly.Plot)
    display(report, MIME("image/svg+xml"), p)
end

#Gadfly doesn't call the default display methods, this catches
#all Gadfly plots
function Base.display(report::Report, m::MIME"image/svg+xml", p::Gadfly.Plot)

    chunk = report.cur_chunk
    full_name, rel_name = get_figname(report, chunk)

    docformat = formats[report.formatdict[:doctype]]
    push!(report.figures, rel_name)

    report.fignum += 1

    w = chunk.options[:fig_width]Gadfly.inch
    h = chunk.options[:fig_height]Gadfly.inch
    format = chunk.options[:fig_ext]
    dpi = chunk.options[:dpi]

    #This is probably not the correct way to handle different formats, but it works.
    if format == ".png"
        try
            Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi=dpi), p)
        catch
            Gadfly.draw(Gadfly.PNG(full_name, w, h), p) #Compose < 0.3.1, Gadfly < 0.3.1
        end
    elseif format == ".pdf"
        Gadfly.draw(Gadfly.PDF(full_name, w, h), p)
    elseif format == ".ps"
        Gadfly.draw(Gadfly.PS(full_name, w, h), p)
    elseif format == ".svg"
        Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
    elseif format == ".js.svg"
        Gadfly.draw(Gadfly.SVGJS(full_name, w, h), p)
    elseif format == ".tex"
        Gadfly.draw(Gadfly.PGF(full_name, w, h, true ), p)
    else
        @warn("Can't save figure. Unsupported format")
    end
end