text:
# Subtypes of Stationary must define the following functions:
# cov(k::Stationary, r::Float64) = ::Float64
# grad_kern!

abstract type Stationary{D} <: Kernel where D <: Distances.SemiMetric end
abstract type StationaryData <: KernelData end

function metric(kernel::Stationary{D}) where D <: Distances.SemiMetric
    return D()
end
function metric(kernel::Stationary{WeightedSqEuclidean})
    return WeightedSqEuclidean(ard_weights(kernel))
end
function metric(kernel::Stationary{WeightedEuclidean})
    return WeightedEuclidean(ard_weights(kernel))
end
ard_weights(kernel::Stationary{WeightedSqEuclidean}) = kernel.iℓ2
ard_weights(kernel::Stationary{WeightedEuclidean}) = kernel.iℓ2

Statistics.cov(k::Stationary, x::VecF64, y::VecF64) = cov(k, distance(k, x, y))
@inline function cov_ij(k::Stationary, X::MatF64, i::Int, j::Int, dim::Int)
    cov(k, distij(metric(k), X, i, j, dim))
end
@inline function cov_ij(k::Stationary, X::MatF64, data::KernelData, i::Int, j::Int, dim::Int)
    cov(k, distij(metric(k), X, i, j, dim))
end
function cov!(cK::MatF64, k::Stationary, X1::MatF64, X2::MatF64)
    dim1, nobsv1 = size(X1)
    dim2, nobsv2 = size(X2)
    dim1==dim2 || throw(ArgumentError("X1 and X2 must have same dimension"))
    nobsv1==size(cK,1) || throw(ArgumentError("X1 and cK incompatible nobsv"))
    nobsv2==size(cK,2) || throw(ArgumentError("X2 and cK incompatible nobsv"))
    dim = dim1
    met = metric(k)
    for i in 1:nobsv1
        for j in 1:nobsv2
            cK[i,j] = cov(k, distij(met, X1, X2, i, j, dim))
        end
    end
    return cK
end
function Statistics.cov(k::Stationary, X1::MatF64, X2::MatF64)
    nobsv1 = size(X1, 2)
    nobsv2 = size(X2, 2)
    cK = Array{Float64}(undef, nobsv1, nobsv2)
    cov!(cK, k, X1, X2)
    return cK
end

function cov!(cK::MatF64, k::Stationary, X::MatF64)
    dim, nobsv = size(X)
    nobsv==size(cK,1) || throw(ArgumentError("X and cK incompatible nobsv"))
    nobsv==size(cK,2) || throw(ArgumentError("X and cK incompatible nobsv"))
    met = metric(k)
    @inbounds for i in 1:nobsv
        for j in 1:i
            cK[i,j] = cov(k, distij(met, X, i, j, dim))
            cK[j,i] = cK[i,j]
        end
    end
    return cK
end
function cov!(cK::MatF64, k::Stationary, X::MatF64, data::StationaryData)
    cov!(cK, k, X)
end
function Statistics.cov(k::Stationary, X::MatF64, data::StationaryData)
    nobsv = size(X, 2)
    cK = Matrix{Float64}(undef, nobsv, nobsv)
    cov!(cK, k, X, data)
end
function Statistics.cov(k::Stationary, X::MatF64)
    nobsv = size(X, 2)
    cK = Matrix{Float64}(undef, nobsv, nobsv)
    cov!(cK, k, X)
end
dk_dlσ(k::Stationary, r::Float64) = 2 * cov(k,r)

# Isotropic Kernels

abstract type Isotropic{D} <: Stationary{D} end

struct IsotropicData{D} <: StationaryData
    R::D
end

function KernelData(k::Isotropic, X::MatF64)
     IsotropicData(distance(k, X))
end
function kernel_data_key(k::Isotropic, X::MatF64)
    return @sprintf("%s_%s", "IsotropicData", metric(k))
end

@inline @inbounds function cov_ij(kern::Isotropic, X::MatF64, data::IsotropicData, i::Int, j::Int, dim::Int)
    return cov(kern, data.R[i,j])
end
@inline function dKij_dθp(kern::Isotropic,X::MatF64,i::Int,j::Int,p::Int,dim::Int)
    return dk_dθp(kern, distij(metric(kern),X,i,j,dim), p)
end
@inline @inbounds function dKij_dθp(kern::Isotropic,X::MatF64,data::IsotropicData,i::Int,j::Int,p::Int,dim::Int)
    return dk_dθp(kern, data.R[i,j], p)
end
@inline @inbounds function dKij_dθ!(dK::VecF64, kern::Isotropic, X::MatF64, i::Int, j::Int, dim::Int, npars::Int)
    r = distij(metric(kern),X,i,j,dim)
    for p in 1:npars
        dK[p] = dk_dθp(kern, r, p)
    end
end
@inline @inbounds function dKij_dθ!(dK::VecF64, kern::Isotropic, X::MatF64, data::IsotropicData,
                                    i::Int, j::Int, dim::Int, npars::Int)
    r = data.R[i,j]
    for iparam in 1:npars
        dK[iparam] = dk_dθp(kern, r, iparam)
    end
end

# StationaryARD Kernels

abstract type StationaryARD{D} <: Stationary{D} end

struct StationaryARDData{D} <: StationaryData
    dist_stack::D
end

# May need to customized in subtypes
function KernelData(k::StationaryARD, X::MatF64)
    dim, nobsv = size(X)
    dist_stack = Array{Float64}(undef, nobsv, nobsv, dim)
    for d in 1:dim
        grad_ls = view(dist_stack, :, :, d)
        distance!(grad_ls, SqEuclidean(), view(X, d:d,:))
    end
    StationaryARDData(dist_stack)
end
kernel_data_key(k::StationaryARD, X::MatF64) = @sprintf("%s_%s", "StationaryARDData", metric(k))


text:
"""
    operation(mg::Microgrid)

Simulate the annual operation of the microgrid `mg` and return the
hourly operation variables `OperVarsTraj`.
"""
function operation(mg::Microgrid)
    # photovoltaic production over one year
    # photovoltaic_production = production(mg.photovoltaic)
    renewables_production = hcat(collect(production(nd) for nd in mg.nondispatchables)...)

    # wind turbine production over one year
    # windpower_production = production(mg.windpower)

    # power balance before battery+generator
    # renewable_production = photovoltaic_production + windpower_production
    total_renewables_production = sum(renewables_production; dims=2)
    power_net_load_requested = mg.power_load - total_renewables_production

    # variables initialization
    stepsnumber = length(mg.power_load)
    power_net_load = zeros(Real,stepsnumber)   # TODO - change Real to typeof(...)
    Pgen = zeros(Real,stepsnumber)
    Ebatt = zeros(Real,stepsnumber+1)
    Ebatt[1] = mg.battery.energy_initial
    Pbatt = zeros(Real,stepsnumber)
    Pbatt_dmax = zeros(Real,stepsnumber)
    Pbatt_cmax = zeros(Real,stepsnumber)
    Pcurt = zeros(Real,stepsnumber)
    Pshed = zeros(Real,stepsnumber)

    for i=1:stepsnumber
        # battery limits
        Pb_emin = - (mg.battery.energy_max - Ebatt[i]) / ((1 - mg.battery.loss) * mg.project.timestep)
        Pb_emax = (Ebatt[i] - mg.battery.energy_min) / ((1 + mg.battery.loss) * mg.project.timestep)
        Pbatt_dmax[i] = min(Pb_emax,mg.battery.power_max)
        Pbatt_cmax[i] = max(Pb_emin,mg.battery.power_min)

        # dispatch
        power_net_load[i], Pgen[i], Pbatt[i], Pcurt[i], Pshed[i] = dispatch(power_net_load_requested[i], Pbatt_cmax[i], Pbatt_dmax[i], mg.dieselgenerator.power_rated)

        # next battery energy level
        if i < stepsnumber
            Ebatt[i+1] = Ebatt[i] - (Pbatt[i] + mg.battery.loss * abs(Pbatt[i])) * mg.project.timestep
            # if Ebatt[i+1] < 0
            #     Ebatt[i+1] = 0
            # end
        end
    end

    opervarstraj = OperVarsTraj(power_net_load, Pshed, Pgen, Ebatt, Pbatt, Pbatt_dmax, Pbatt_cmax, Pcurt)
    return opervarstraj
end

"""
    aggregation(mg::Microgrid, opervarstraj::OperVarsTraj)

Return the aggregated operation variables `OperVarsAggr` for the microgrid `mg` and
the hourly operation variables `OperVarsTraj`.
"""
function aggregation(mg::Microgrid, opervarstraj::OperVarsTraj)
    # variables initialization
    nHours = 0
    vFuel  = 0
    Eserv = 0
    delestTimeCurrent = 0
    delestTimeMax = 0
    annualThrpt = 0.0
    for i = 1 : length(opervarstraj.Pgen)
        # diesel generator
        if opervarstraj.Pgen[i] > 0 #DG on
            nHours = nHours + 1 # incremention of the number of hours
            fuelConsump = mg.dieselgenerator.F0 * mg.dieselgenerator.power_rated + mg.dieselgenerator.F1 * opervarstraj.Pgen[i] #[L.h-1]  F = F0*Ygen + F1*Pgen
        else
            fuelConsump = 0 # DG off [L.h-1]
        end
        vFuel = vFuel + fuelConsump*mg.project.timestep # [L]

        # battery
        annualThrpt = annualThrpt + abs(opervarstraj.Pbatt[i])*mg.project.timestep #battery throughtput (charging & dicharging)

        # load - energy served - energy provided (served in one year) [kWh]
        Eserv = Eserv + (mg.power_load[i] - opervarstraj.power_shedding[i]) * mg.project.timestep

        # load - calculation of the Max shedding duration
        if opervarstraj.power_shedding[i] > 0 && i!=length(opervarstraj.Pgen)
            delestTimeCurrent = delestTimeCurrent + 1
        else
            if delestTimeCurrent > delestTimeMax
                delestTimeMax = delestTimeCurrent
            end
            delestTimeCurrent = 0 # Ré-initialisation de la durée de délestage
        end
    end

    # load
    Pshed_max = maximum(opervarstraj.power_shedding)    # max shedding
    shed_time_max = delestTimeMax
    shed_total_kwh = sum(opervarstraj.power_shedding) * mg.project.timestep # [kWh]
    shed_rate =  (sum(opervarstraj.power_shedding) * mg.project.timestep) / (sum(mg.power_load)*mg.project.timestep) # [0,1]
    # battery
    annualThrpt = annualThrpt/2    # (charging and discharging cycle)
    # renewables sources
    Pcurt_max = maximum(opervarstraj.power_curtailment)    # max curtailment
    renew_rate = (1 - sum(opervarstraj.Pgen)/Eserv) * 100 # d'insertion ENR insertion Rate
    # outputs
    opervarsaggr = OperVarsAggr(Eserv, Pshed_max, shed_time_max, shed_total_kwh, shed_rate, nHours, vFuel, annualThrpt, Pcurt_max, renew_rate)

    # TODO - parei aqui
    # load
    # operVars.delestSumHours = sum(operVars.loaddelestRealHours); #[h]
    # operVars.delestRateHours =  100*sum(operVars.loaddelestRealHours) / length(mgDef.load); # [%]
    # operVars.serviceRate = 100 - operVars.load.delestRate; # service rate in term of Energy (%)
    # operVars.serviceRateHours = 100 - operVars.load.delestRateHours; #  service rate in term of duration[%]

    return opervarsaggr
end

"""
    aggregation(mg::Microgrid, opervarstraj::OperVarsTraj, ε)

When a relaxation factor `ε` is given, return the aggregated operation variables
`OperVarsAggr` with a linear relaxation of the diesel generator annual operation
hours `OperVarsAggr.nHours`.
"""
function aggregation(mg::Microgrid, opervarstraj::OperVarsTraj, ε)
    # variables initialization
    nHours = 0.
    vFuel  = 0
    Eserv = 0
    delestTimeCurrent = 0
    delestTimeMax = 0
    annualThrpt = 0
    for i = 1 : length(opervarstraj.Pgen)
        x = opervarstraj.Pgen[i]/mg.dieselgenerator.power_rated
        # diesel generator
        if opervarstraj.Pgen[i] > 0 && x <= ε   #DG on
            nHours = nHours + x/ε # incremention of the number of hours
            fuelConsump = mg.dieselgenerator.F0 * mg.dieselgenerator.power_rated + mg.dieselgenerator.F1 * opervarstraj.Pgen[i] #[L.h-1]  F = F0*Ygen + F1*Pgen
        elseif opervarstraj.Pgen[i] > 0 && x > ε   #DG on
            nHours = nHours + 1 # incremention of the number of hours
            fuelConsump = mg.dieselgenerator.F0 * mg.dieselgenerator.power_rated + mg.dieselgenerator.F1 * opervarstraj.Pgen[i] #[L.h-1]  F = F0*Ygen + F1*Pgen
        else
            fuelConsump = 0 # DG off [L.h-1]
        end
        vFuel = vFuel + fuelConsump*mg.project.timestep # [L]

        # battery
        annualThrpt = annualThrpt + abs(opervarstraj.Pbatt[i])*mg.project.timestep #battery throughtput (charging & dicharging)

        # load - energy served - energy provided (served in one year) [kWh]
        Eserv = Eserv + (mg.power_load[i] - opervarstraj.power_shedding[i]) * mg.project.timestep

        # load - calculation of the Max shedding duration
        if opervarstraj.power_shedding[i] > 0 && i!=length(opervarstraj.Pgen)
            delestTimeCurrent = delestTimeCurrent + 1
        else
            if delestTimeCurrent > delestTimeMax
                delestTimeMax = delestTimeCurrent
            end
            delestTimeCurrent = 0 # Ré-initialisation de la durée de délestage
        end
    end

    # load
    Pshed_max = maximum(opervarstraj.power_shedding)    # max shedding
    shed_time_max = delestTimeMax
    shed_total_kwh = sum(opervarstraj.power_shedding) * mg.project.timestep # [kWh]
    shed_rate =  (sum(opervarstraj.power_shedding) * mg.project.timestep) / (sum(mg.power_load)*mg.project.timestep) * 100 # (%)
    # battery
    annualThrpt = annualThrpt/2    # (charging and discharging cycle)
    # renewables sources
    Pcurt_max = maximum(opervarstraj.power_curtailment)    # max curtailment
    renew_rate = (1 - sum(opervarstraj.Pgen .* mg.project.timestep)/Eserv) * 100 # d'insertion ENR insertion Rate
    # outputs
    opervarsaggr = OperVarsAggr(Eserv, Pshed_max, shed_time_max, shed_total_kwh, shed_rate, nHours, vFuel, annualThrpt, Pcurt_max, renew_rate)

    # TODO - parei aqui
    # load
    # operVars.delestSumHours = sum(operVars.loaddelestRealHours); #[h]
    # operVars.delestRateHours =  100*sum(operVars.loaddelestRealHours) / length(mgDef.load); # [%]
    # operVars.serviceRate = 100 - operVars.load.delestRate; # service rate in term of Energy (%)
    # operVars.serviceRateHours = 100 - operVars.load.delestRateHours; #  service rate in term of duration[%]

    return opervarsaggr
end

# # With the number of DG operation hours relaxed - exponential
# function aggregation(mg::Microgrid, opervarstraj::OperVarsTraj, ε)
#     # variables initialization
#     nHours = 0.
#     vFuel  = 0
#     Eserv = 0
#     delestTimeCurrent = 0
#     delestTimeMax = 0
#     annualThrpt = 0
#     for i = 1 : length(opervarstraj.Pgen)
#         x = opervarstraj.Pgen[i]/mg.dieselgenerator.power_rated
#         # diesel generator
#         if opervarstraj.Pgen[i] > 0   #DG on
#             nHours = nHours + exp(-ε * x) # incremention of the number of hours
#             fuelConsump = mg.dieselgenerator.F0 * mg.dieselgenerator.power_rated + mg.dieselgenerator.F1 * opervarstraj.Pgen[i] #[L.h-1]  F = F0*Ygen + F1*Pgen
#         else
#             fuelConsump = 0 # DG off [L.h-1]
#         end
#         vFuel = vFuel + fuelConsump*mg.project.timestep # [L]

#         # battery
#         annualThrpt = annualThrpt + abs(opervarstraj.Pbatt[i])*mg.project.timestep #battery throughtput (charging & dicharging)

#         # load - energy served - energy provided (served in one year) [kWh]
#         Eserv = Eserv + (mg.load[i] - opervarstraj.Pshed[i]) * mg.project.timestep

#         # load - calculation of the Max shedding duration
#         if opervarstraj.Pshed[i] > 0 && i!=length(opervarstraj.Pgen)
#             delestTimeCurrent = delestTimeCurrent + 1
#         else
#             if delestTimeCurrent > delestTimeMax
#                 delestTimeMax = delestTimeCurrent
#             end
#             delestTimeCurrent = 0 # Ré-initialisation de la durée de délestage
#         end
#     end

#     # load
#     Pshed_max = maximum(opervarstraj.Pshed)    # max shedding
#     shed_time_max = delestTimeMax
#     shed_total_kwh = sum(opervarstraj.Pshed) * mg.project.timestep # [kWh]
#     shed_rate =  (sum(opervarstraj.Pshed) * mg.project.timestep) / (sum(mg.load)*mg.project.timestep) # [0,1]
#     # battery
#     annualThrpt = annualThrpt/2    # (charging and discharging cycle)
#     # renewables sources
#     Pcurt_max = maximum(opervarstraj.Pcurt)    # max curtailment
#     renew_rate = (1 - sum(opervarstraj.Pgen)/Eserv) * 100 # d'insertion ENR insertion Rate
#     # outputs
#     opervarsaggr = OperVarsAggr(Eserv, Pshed_max, shed_time_max, shed_total_kwh, shed_rate, nHours, vFuel, annualThrpt, Pcurt_max, renew_rate)

#     # TODO - parei aqui
#     # load
#     # operVars.delestSumHours = sum(operVars.loaddelestRealHours); #[h]
#     # operVars.delestRateHours =  100*sum(operVars.loaddelestRealHours) / length(mgDef.load); # [%]
#     # operVars.serviceRate = 100 - operVars.load.delestRate; # service rate in term of Energy (%)
#     # operVars.serviceRateHours = 100 - operVars.load.delestRateHours; #  service rate in term of duration[%]

#     return opervarsaggr
# end

ext: jl


text:
@testset "Math" begin

    @testset "Math: abs.jl(Absolute Value) " begin
        @test abs_val(-100) == 100
        @test abs_val(0) == 0
        @test abs(123.1) == 123.1
        @test (-1000 == abs_val(-1000)) == false
        @test (1000 == abs_val(1000)) == true

        @test abs_max([1,3,4]) == 4
        @test abs_max([-3,1,2]) == -3
        @test abs_max([-7,-3,6]) == -7

        @test abs_min([1,3,4]) == 1
        @test abs_min([-3,1,2]) == 1
        @test abs_min([-7,-3,6]) == -3
    end

    @testset "Math: Area Under Curve" begin
        # Area by Trapazoid rule
        @test trapazoidal_area(x -> 5, 12, 14, 1000) == 10.00000000000334
        @test trapazoidal_area(x -> 9 * x^2, -4, 0, 1000) == 192.0000960000001
        @test trapazoidal_area(x -> 9 * x^2, -4, 4, 1000) == 384.0007680000011
    end

    @testset "Math: Area" begin
        @test surfarea_cube(1) == 6
        @test surfarea_cube(3) == 54
        @test_throws DomainError surfarea_cube(-1)

        @test surfarea_sphere(5) == 314.1592653589793
        @test surfarea_sphere(1) == 12.566370614359172
        @test_throws DomainError surfarea_sphere(-1)

        @test area_rectangle(10, 20) == 200
        @test_throws DomainError area_rectangle(-1, -2)
        @test_throws DomainError area_rectangle(1, -2)
        @test_throws DomainError area_rectangle(-1, 2)

        @test area_square(10) == 100
        @test_throws DomainError area_square(-1)

        @test area_triangle(10, 10) == 50.0
        @test_throws DomainError area_triangle(-1, -2)
        @test_throws DomainError area_triangle(1, -2)
        @test_throws DomainError area_triangle(-1, 2)

        @test area_heron_triangle(5, 12, 13) == 30.0
        @test_throws DomainError area_heron_triangle(-1, -2, 1)
        @test_throws DomainError area_heron_triangle(1, -2, 1)
        @test_throws DomainError area_heron_triangle(-1, 2, 1)

        @test area_parallelogram(10, 20) == 200
        @test_throws DomainError area_parallelogram(-1, -2)
        @test_throws DomainError area_parallelogram(1, -2)
        @test_throws DomainError area_parallelogram(-1, 2)

        @test area_trapezium(10, 20, 30) == 450.0
        @test_throws DomainError area_trapezium(-1, -2, -3)
        @test_throws DomainError area_trapezium(-1, 2, 3)
        @test_throws DomainError area_trapezium(1, -2, 3)

        @test area_circle(20) == 1256.6370614359173
        @test_throws DomainError area_circle(-1)

        @test area_ellipse(10, 10) == 314.1592653589793
        @test area_ellipse(10, 20) == 628.3185307179587
        @test_throws DomainError area_ellipse(1, -2)
        @test_throws DomainError area_ellipse(-1, 2)
        @test_throws DomainError area_ellipse(-1, -2)

        @test area_rhombus(10, 20) == 100.0
        @test_throws DomainError area_rhombus(-1, -2)
        @test_throws DomainError area_rhombus(1, -2)
        @test_throws DomainError area_rhombus(-1, 2)
    end

    @testset "Math: Armstrong Number" begin
        x = 370     # an armstrong number
        @test is_armstrong(x) == true
        x = 225     # Not an armstrong number
        @test is_armstrong(x) == false
        x = -23     # Not an armstrong number
        @test is_armstrong(x) == false
        x = 153     # an armstrong number
        @test is_armstrong(x) == true
        x = 0       # an armstrong number
        @test is_armstrong(x) == true
        x = 12      # Not an armstrong number
        @test is_armstrong(x) == false
        end

    @testset "Math: Average Mean" begin
        @test mean([3, 6, 9, 12, 15, 18, 21]) == 12.0
        @test mean([5, 10, 15, 20, 25, 30, 35]) == 20.0
        @test mean([1, 2, 3, 4, 5, 6, 7, 8])  == 4.5
    end

    @testset "Math: Average Mode" begin
        @test mode([2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2]) == [2]
        @test mode([3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 4, 2, 2, 2]) == [2]
        @test mode([3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 4, 4, 2, 2, 4, 2]) == [4, 2]
        @test mode(["x", "y", "y", "z"]) == ["y"]
        @test mode(["x", "x" , "y", "y", "z"]) == ["x", "y"]
    end

    @testset "Math: Average Median" begin
        @test median([2,1,3,4]) == 2.5
        @test median([2, 70, 6, 50, 20, 8, 4]) == 8
        @test median([0]) == 0
    end

    @testset "Math: ceil_floor" begin
        @test ceil_val(1.3) == 2.0
        @test ceil_val(2.0) == 2.0
        @test ceil_val(-1.5) == -1.0

        @test floor_val(1.3) == 1
        @test floor_val(2.0) == 2.0
        @test floor_val(-1.7) == -2.0
    end

    @testset "Math: Collatz Sequence" begin
        @test collatz_sequence(3) == [3,10,5,16,8,4,2,1]
        @test collatz_sequence(42) == [42,21,64,32,16,8,4,2,1]
        @test collatz_sequence(5) == [5,16,8,4,2,1]
    end

    @testset "Math: Line Length" begin
        # Arc Lengths
        @test line_length(x -> x, 0, 1, 10) == 1.4142135623730947
        @test line_length(x -> 1, -5.5, 4.5) == 9.999999999999977
        @test line_length(x -> sin(5 * x) + cos(10 * x) + 0.1 * x^2, 0, 10, 10000) == 69.53493003183544
    end

    @testset "Math: Euler Method" begin
        @test euler_method((x, t) -> x, 1, (0, 5))[1][end] == 143.33937864611195
    end

    @testset "Math: Factorial Related" begin
        @test factorial_iterative(5) == 120
        @test factorial_iterative(0) == 1
        @test_throws ErrorException  factorial_iterative(-1)
        @test factorial_recursive(5) == 120
        @test factorial_recursive(0) == 1
        @test_throws ErrorException  factorial_recursive(-1)
    end

    @testset "Math: Krishnamurthy Number" begin
        @test krishnamurthy(145) == true
        @test krishnamurthy(240) == false
        @test krishnamurthy(1) == true
        @test_throws ErrorException krishnamurthy(0.1)
        @test_throws ErrorException krishnamurthy(-1)
    end

	  @testset "Math: Monte Carlo Integration" begin
		    @test isapprox(monte_carlo_integration(x->3*x^2,100000,(0,1)),1,atol = 0.01)
		    @test isapprox(monte_carlo_integration(x->sin(x),1000,(0,pi)),2,atol = 0.1)
	  end

    @testset "Math: Prime Check" begin
        @test prime_check(2) == true
        @test prime_check(3) == true
        @test prime_check(5) == true
        @test prime_check(7) == true
        @test prime_check(11) == true
        @test prime_check(13) == true
        @test prime_check(17) == true
        @test prime_check(19) == true
        @test prime_check(23) == true
        @test prime_check(29) == true
        @test prime_check(112) == false
        @test prime_check(172) == false
        @test prime_check(1231) == true
        @test prime_check(2332) == false
        @test prime_check(2932) == false
    end

    @testset "Math: Prime Factors" begin
        @test prime_factors(50) == [2,5,5]
        @test prime_factors(0) == []
        @test prime_factors(100) == [2, 2, 5, 5]
        @test prime_factors(2560) == [2, 2, 2, 2, 2, 2, 2, 2, 2, 5]
    end

    @testset "Math: Perfect Cube" begin
        @test perfect_cube(27) == true
        @test perfect_cube(4) == false
    end

    @testset "Math: Perfect Number" begin
        @test perfect_number(27)  == false
        @test perfect_number(28)  == true
        @test perfect_number(496) == true
        @test perfect_number(8128)== true
        @test perfect_number(123) == false
    end

    @testset "Math: Perfect Square" begin
        @test perfect_square(9) == true
        @test perfect_square(16)== true
        @test perfect_square(1) == true
        @test perfect_square(0) == true
        @test perfect_square(10)== false
    end

    @testset "Math: SIR Model" begin
        # TODO: implement tests

        #initian conditions
        p = [0.5/7900000.0,0.33]
        u0 = [7900000.0,10.0,0.0]
        tspan = (0.0,140.0)

        #solve
        sir = ODEProblem(SIR,u0,tspan,p)
        sol = solve(sir)

        #plot
        plot(sol)
    end

    @testset "Math: Sum of Arithmetic progression" begin
        @test sum_ap(1, 1, 10) == 55.0
        @test sum_ap(1, 10, 100) == 49600.0
    end

    @testset "Math: Sum of Geometric Progrssion" begin
        @test sum_gp(1, 2, 10) == 1023.0
        @test sum_gp(1, 10, 5) == 11111.0
        @test sum_gp(0, 2, 10) == 0.0
        @test sum_gp(1, 0, 10) == 1.0
        @test sum_gp(1, 2, 0) == -0.0
        @test sum_gp(-1, 2, 10) == -1023.0
        @test sum_gp(1, -2, 10) == -341.0
    end

    @testset "Math: Sieve of Eratosthenes" begin
        @test eratosthenes(20) ==   [2,3,5,7,11,13,17,19]
        @test eratosthenes(2) == [2]
        @test eratosthenes(1) == Int64[] # No prime number less that 1, so it should return empty array.
    end

    @testset "Math: Volume of Various Shapes" begin
        @test vol_cube(1) == 1
        @test vol_cube(3) == 27
        @test vol_cuboid(1, 1, 1) == 1
        @test vol_cuboid(1, 2, 3) == 6
        @test vol_cone(10, 3) == 10.0
        @test vol_cone(1, 1) == 0.3333333333333333
        @test vol_right_circ_cone(2, 3) == 12.566370614359172
        @test vol_prism(10, 2) == 20.0
        @test vol_prism(11, 1) == 11.0
        @test vol_pyramid(10, 3) == 10.0
        @test vol_pyramid(1.5, 3) == 1.5
        @test vol_sphere(5) == 523.5987755982989
        @test vol_sphere(1) == 4.1887902047863905
        @test vol_circular_cylinder(1, 1) == 3.141592653589793
        @test vol_circular_cylinder(4, 3) == 150.79644737231007

        @test_throws DomainError vol_cube(-1)
        @test_throws DomainError vol_cuboid(-1, 2, 2)
        @test_throws DomainError vol_cone(-1, 3)
        @test_throws DomainError vol_right_circ_cone(-1, 3)
        @test_throws DomainError vol_prism(-1, 2)
        @test_throws DomainError vol_pyramid(-1, 3)
        @test_throws DomainError vol_sphere(-1)
        @test_throws DomainError vol_circular_cylinder(-1, 3)
    end

   @testset "Math: Verlet scheme" begin
        @test verlet_integration(x->-x,[0.0,0.1],(1,10))[end][end] == 9.999
   end
end

max_stars_repo_name: ErikQQY/Julia

max_issues_repo_name: ErikQQY/Julia

max_forks_repo_name: ErikQQY/Julia


text:
__precompile__()
module eps_gold
export epsgold
@inline function epsgold(e_photon::Float64)::ComplexF64
   # eVtoOmega = eV/hbar_eV
    eps_0 = 9.84
    wp = 9.010 #eV
    gamma = 0.072 #eV
    eps_di = eps_0 - wp^2/(e_photon^2 + gamma^2) + im*(wp^2*gamma/(e_photon*(e_photon^2 + gamma^2)))
    wc =2.4#eV (the second energy gap of the interbad transitions).
    A = 5.6#eV
    delta = 0.17 #eV
    delta_eps = A/(1  + exp(-(e_photon-wc)/delta))

    if(e_photon>1.8)
        eps = eps_di + 1j*delta_eps
    else
        eps =eps_di
    end
   # if imag(eps)<0
   #     return real(eps)-im*imag(eps)
   # else
    return eps
end
precompile(epsgold,(Float64, ))
end


text:
abstract type CrossmapEmbedding end

struct CCMEmbedding end
struct PAIEmbedding end

function crossmapembed(x, d, τ, method::CCMEmbedding)
    τs = 0:-τ:d*-τ+1
    Mₓ = genembed(x, τs);
    return Mₓ
end

function crossmapembed(x, y, d, τ, method::PAIEmbedding)
    τs = [collect(0:-τ:d*-τ+1); 0]
    js = [repeat([1], d); 2]
    Mₓy = genembed(Dataset(x, y), τs, js);
    return Mₓy
end

function crossmap_basic(Mₓ, y, d, τ; correspondence_measure = Statistics.cor, r = 0)
    theiler = Theiler(r);
    tree = KDTree(Mₓ)
    idxs = bulkisearch(tree, Mₓ, NeighborNumber(d+1), theiler)
    ỹ = copy(y)

    for i in 1:length(Mₓ)
        J = idxs[i]
        xᵢ = Mₓ[i]
        n1 = norm(xᵢ - Mₓ[J[1]])

        # If distance to nearest neighor is zero, then we get division by zero.
        # If that is the case, set all weights all to zero (or just skip
        # computing ỹᵢ, because it is already set to 0).
        n1 > 0.0 || continue
        w = [exp(-norm(xᵢ - Mₓ[j])/n1) for j in J]
        w ./= sum(w)
        ỹ[i] = sum(w[k]*y[j] for (k, j) in enumerate(J))
    end

    return correspondence_measure(y, ỹ)
end

function crossmap_bootstrap(Mₓ, y, d, τ, bootstrap_method::Symbol;
    L = ceil(Int, (length(y) - d * τ) * 0.2), nreps = 100,
    r = 0, correspondence_measure = Statistics.cor)

    theiler = Theiler(r);

    # Compute correlations between out-of-sample target and embedding for `nreps`
    # different training sets
    cors = zeros(nreps)

    # These arrays are re-used.
    u = zeros(d + 1)
    w = zeros(d + 1)
    ỹs = zeros(L)

    for n = 1:nreps
        # Select training set and keep track of corresponding y-values
        if bootstrap_method == :random
            # Training set is a random embedding vectors. This is method 3 in
            # Luo et al. (2015)
            idxs = StatsBase.sample(1:length(Mₓ), L)
        elseif bootstrap_method == :segment
            # Training set is a random set of L embedding vectors in Mₓ
            # This is method 2 in Luo et al. (2015), but with added exclusion of
            # the predictee from the libraries.
            startidx = rand(1:length(Mₓ) - L)
            idxs = startidx:startidx + L - 1
        else
            error("$bootstrap_method is not a valid bootstrap method")
        end
        training_set = Mₓ[idxs]
        ys = y[idxs]

        # Find the nearest neighbors of points in the training set
        tree = KDTree(training_set)
        idxs_nns = bulkisearch(tree, training_set, NeighborNumber(d+1), theiler)

        # Reset predictions
        ỹs .= 0.0

        @inbounds for i in 1:length(training_set)
            # For every point xᵢ ∈ training_set
            xᵢ = training_set[i]

            # Get the indices of its nearest neighbors (in the training set, not the entire Mx)
            nns_idxs = idxs_nns[i]
            nns = training_set[nns_idxs]

            # Depending on the input data, we might encounter a case where the distance from xᵢ
            # to its closest neighbor is indistinguishable from zero. In that case, we encounter
            # division by zero when computing weights. In that case, set weights to zero (but in
            # practice, just continue to the next step, because ỹᵢ will is already initialized to 0)
            dist₁ = norm(xᵢ - nns[1])
            dist₁ > 0.0 || continue

            for j = 1:d+1
                distⱼ = norm(xᵢ - nns[j])
                u[j] = exp(-distⱼ / dist₁)
            end
            s = sum(u)
            for j = 1:d+1
                w[j] = u[j] / s
            end

            # For each weight
            for j = 1:d+1
                # Find the scalar value corresponding to this weight
                idx_nnⱼ = nns_idxs[j]
                y_scalar = ys[idx_nnⱼ]
                ỹs[i] += w[j] * y_scalar
            end
        end
        cors[n] = correspondence_measure(ys, ỹs)
    end

    return cors
end


text:
# TODO: replace this with a bitstype that uses reinterpret to copy data in and out, and generated functions to convert

# FixedLengthSymbol types... Symbol6 and Symbol8 are fixed width types used for reading in symbols from a binary feed handler

abstract FixedLengthSymbol
# @createIOMethods FixedLengthSymbol
isvalidchar(c::UInt8) = (c != 0x00 && c != 0x20)

@packedStruct immutable Symbol6 <: FixedLengthSymbol
  s1::UInt8
  s2::UInt8
  s3::UInt8
  s4::UInt8
  s5::UInt8
  s6::UInt8
end
Base.sizeof(::Type{Symbol6}) = 6
function Base.String(s::Symbol6)
  buf = IOBuffer(6)
  isvalidchar(s.s1) && write(buf, s.s1)
  isvalidchar(s.s2) && write(buf, s.s2)
  isvalidchar(s.s3) && write(buf, s.s3)
  isvalidchar(s.s4) && write(buf, s.s4)
  isvalidchar(s.s5) && write(buf, s.s5)
  isvalidchar(s.s6) && write(buf, s.s6)
  String(buf)
end

@packedStruct immutable Symbol8 <: FixedLengthSymbol
  s1::UInt8
  s2::UInt8
  s3::UInt8
  s4::UInt8
  s5::UInt8
  s6::UInt8
  s7::UInt8
  s8::UInt8
end
Base.sizeof(::Type{Symbol8}) = 8
function Base.String(s::Symbol8)
  buf = IOBuffer(8)
  isvalidchar(s.s1) && write(buf, s.s1)
  isvalidchar(s.s2) && write(buf, s.s2)
  isvalidchar(s.s3) && write(buf, s.s3)
  isvalidchar(s.s4) && write(buf, s.s4)
  isvalidchar(s.s5) && write(buf, s.s5)
  isvalidchar(s.s6) && write(buf, s.s6)
  isvalidchar(s.s7) && write(buf, s.s7)
  isvalidchar(s.s8) && write(buf, s.s8)
  String(buf)
end


text:
using Gadfly
using RDatasets

plot(data("ggplot2", "diamonds"),
     x="price", color="cut",
     Geom.bar)


text:
# Survey types

"""
`SurveyType`: Type of a survey record, currently defined:\n
  `HoleSurvey`
"""
abstract type SurveyType end

mutable struct HoleSurvey <: SurveyType
  depth::Float64                 # [ft]
  inclination::Float64          # [degrees]
  diameter::Float64            # [in]
end

# Trajectory type

"""
`Trajectory(depth, inclination, diameter)`: Definition of well trajectory record.

where:\n
  `depth`         ::Float64                 # Distance from surface, along bore hole, in [ft]
  `inclination`  ::Float64                 # Inclination from vertical, in [radians]\n
  `diameter`    ::Float74                 # Hole diameter, in [inch]\n
"""
mutable struct TrajectoryRecord
  depth::Float64
  inclination::Float64
  diameter::Float64
end
TrajectoryRecord() = TrajectoryRecord(0.0, 0.0)

"""
# MeshRecord object

Nodal mesh data generated from segments, etc

This structure is used to generate the PtFEM input data

###
```julia
MeshRecord()      : Created an initialized MeshRecord

A mesh consistst of an Array{MeshRecord, 1}

The properties matrix is an Array{Floet64, 2}(no of collar/pipe segments, 4)

Each row in the properties matrix contains ea, eiy, eiz and gj.
```
### Fields
```julia
* `x::Float64`                   : x coordinate (along borehole)
* `y::Float64`                   : y coordinate
* `clearance::Float64`     : Clearance between od bha & bore hole wall
* `npType::Int`                 : Index into properties for element
* `seg::Int`                       : Element is part of segment `seg`
* `fx::Float64`                  : External force in x direction
* `fy::Float64`                  : External force in y direction
* `mx::Float64`                : External moment in x direction
* `my::Float64`                : External moment in y direction
* `eqfx::Float64`              : External equivalent force in x direction
* `eqfy::Float64`              : External equivalent force in y direction
* `eqmx::Float64`            : External equivalent moment in x direction
* `eqmy::Float64`            : External equivalent moment in y direction

The equivalent forces and moments correct the actions for distributed loads and moment (see figure 4.21 in PtFEM)
```
"""
mutable struct MeshRecord
  x::Float64
  y::Float64
  clearance::Float64                 #
  nptype::Int
  segment::Int

  # Nodal loads

  fx::Float64
  fy::Float64
  mx::Float64
  my::Float64

  # Equivalent nodal forces and moments
  eqfx::Float64
  eqfy::Float64
  eqmx::Float64
  eqmy::Float64

end
MeshRecord() = MeshRecord(0.0, 0.0, 0.0, 1, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

"""
# BHA element object

BHA element object

### Type
```julia
Element(length, id, od, npind)
```
### Arguments
```julia
* `length`      : Length of element
* `id`             : Inside diameter
* `od`            : Outside diameter
* `npind`       : Index (row no) in property array
```
"""
mutable struct Element
  length::Float64
  id::Float64                 # Inside diameter
  od::Float64                 # Outside diameter
  npind::Int
end
Element() = Element(0.0, 0.0, 0.0, 0)

"""
# Node object

Node: Node object

### Constructor
```julia
Node(z, x, y, tvd, xvert, inclination, deltainclination, dip,
   holeradius, stringradius, fc, clearance, weight)

* dip  : Angle [Radians] from horizon
* inclination : Angle [Radians] from vertical
```
### Fields
```julia
* `bharadius`         : String radius
* `weight`              : Weight (force)
* `fc`                      : Friction coefficient
```
"""
mutable struct Node
  bharadius::Float64
  weight::Float64
  fc::Float64
end
Node() = Node(0.0, 0.0, 0.0)


text:
#=
KTrussTest:
- Julia version: 1.6.2
- Author: samuel
- Date: 2021-09-11
=#

using SuiteSparseGraphBLAS
using SparseArrays
using LinearAlgebra
using Test

include("/Users/samuel/Documents/Jupyter/GraphBlasAlgorithmsFinal/src/KTruss.jl")
matrix =  GBMatrix([[0, 1, 1, 0, 0] [1, 0, 1, 1, 1] [1, 1, 0, 0, 1] [0, 1, 0, 0, 1] [0, 1, 1, 1, 0]])
@test ktruss(matrix, 3, 5) == [[nothing, 1, 1, nothing, nothing]  [1, nothing, 2, 1, 2] [1, 2, nothing, nothing, 1] [nothing, 1, nothing, nothing, 1] [nothing, 2, 1, 1, nothing]]


text:
module advanced_timer

export start_advanced_timer, pause_advanced_timer, print_timer_stats, get_elapsed_time, class_advanced_timer, merge_timers

mutable struct class_timing_info
    start::Float64
    total::Float64
    active::Bool
    num_calls::Int64

    function class_timing_info()
        return new(0.0,0.0,false,0)
    end
end

mutable struct class_advanced_timer
  grand_total::class_timing_info
	times::Dict{String,class_timing_info}

	function class_advanced_timer()
		this = new();
    this.grand_total = class_timing_info();
		this.times = Dict{String,class_timing_info}();
		return this;
	end
end

function elapsed_time(time_this::class_timing_info)
    return time_this.total + ((Base.time_ns)() * 10^(-9.0) - time_this.start)
end

function start(time_this::class_timing_info)
    time_this.start = (Base.time_ns)() * 10^(-9.0);
    time_this.active = true;
    time_this.num_calls += 1
end

function pause(time_this::class_timing_info)
    if time_this.active
      time_this.total = elapsed_time(time_this) #+= (time() - time_this.start)
      time_this.active = false;
    else
        error("cannot pause inactive timer")
    end
end

function start_advanced_timer(timer::class_advanced_timer)
    start(timer.grand_total)
end

function start_advanced_timer(timer::class_advanced_timer, str::String)
    timer::class_advanced_timer
    if (timer.grand_total.active)
        if ~(str in keys(timer.times))
          timer.times[str] = class_timing_info();
        end
        start(timer.times[str])
    else
        error("timer not active")
    end
end

function pause_advanced_timer(timer::class_advanced_timer,str::String)
  if (timer.grand_total.active)
    if ~(str in keys(timer.times))
        error(str * " is not included in timer dictionary")
    end
    pause(timer.times[str])
  else
      error("timer not active")
  end
end

function pause_advanced_timer(timer::class_advanced_timer)
    pause(timer.grand_total)
end

#function reset_advanced_timer(timer::class_advanced_timer)
#  timer::class_advanced_timer
#  timer.grand_total = class_timing_info()
#  timer.times = Dict{String,class_timing_info}();
#end

function round_num(num,k=1)
  return round(num*10^k)/10^k
end

function show_percent(val,total)
  return string(round_num(100*val/total)) * "%"
end

function print_timer_stats(stream, timer::class_advanced_timer)
    heading = "========= Time statistics =========\n";
    write(stream, heading)
    max_string_length = 0;
    for label in keys(timer.times)
        max_string_length = max(length(label),max_string_length)
    end

    padsize =  max_string_length + 3;

    # percentage time, number of calls
    write(stream, rpad("Label",padsize), rpad("Time",8), "#calls", "\n")
    total = timer.grand_total.total

    sorted_labels = sort(collect(keys(timer.times)))
    for label in sorted_labels
        this_time = timer.times[label];
        if(this_time.active)
          error("$label is active, should be inactive!")
        end
        write(stream, rpad(label, padsize), rpad(show_percent(this_time.total,total), 8), "$(this_time.num_calls)", "\n")
    end

    # total time
    rounded_num = round_num(total, 3)
    write(stream, "Total time (seconds): $rounded_num \n" )

    println(stream, repeat("=",length(heading)), "\n")
end

function print_timer_stats(timer::class_advanced_timer)
    print_timer_stats(stdout, timer)
end

function get_elapsed_time(timer::class_advanced_timer)
    return elapsed_time(timer.grand_total)
end

function get_elapsed_time(timer::class_advanced_timer, str::String)
    return elapsed_time(timer.times[str])
end

function merge_timers(timing_info1::class_timing_info, timing_info2::class_timing_info)
    merged_info = class_timing_info()
    if timing_info1.active || timing_info2.active
        error("cannot merge if any timer is active")
    end
    merged_info.total = timing_info1.total + timing_info2.total
    merged_info.num_calls = timing_info1.num_calls + timing_info2.num_calls
    merged_info.active = false
    merged_info.start = NaN

    return merged_info
end

function merge_timers(timer1::class_advanced_timer, timer2::class_advanced_timer)
    merged_timer = class_advanced_timer()
    merged_timer.grand_total = merge_timers(timer1.grand_total, timer2.grand_total)

    for label in keys(timer1.times)
        if label in keys(timer2.times)
          merged_timer.times[label] = merge_timers(timer1.times[label], timer2.times[label])
        else
          merged_timer.times[label] = timer1.times[label]
        end
    end

    for label in keys(timer2.times)
        if !(label in keys(timer1.times))
          merged_timer.times[label] = timer2.times[label]
        end
    end

    return merged_timer
end

########################
## GLOBAL TIMER FUNCTIONS
#########################

#=
GLOBAL_timer = class_advanced_timer();

function start_advanced_timer()
    start_advanced_timer(GLOBAL_timer)
end
function start_advanced_timer(str::String)
    start_advanced_timer(GLOBAL_timer, str)
end

function pause_advanced_timer()
    pause_advanced_timer(GLOBAL_timer)
end

function pause_advanced_timer(str::String)
    pause_advanced_timer(GLOBAL_timer, str)
end

function reset_advanced_timer()
    GLOBAL_timer = class_advanced_timer()
end

function print_timer_stats()
    print_timer_stats(GLOBAL_timer)
end

function get_advanced_timer()
    return GLOBAL_timer
end

function get_elapsed_time()
    return get_elapsed_time(GLOBAL_timer)
end

function get_elapsed_time(str::String)
    return get_elapsed_time(GLOBAL_timer,str)
end=#

end # module


text:
using PowerModels
using Ipopt
import JSON

function run_powermodels(json_path)
    pm_net = Dict()
    open(json_path, "r") do f
        dicttxt = JSON.readstring(f)  # file information to string
        pm_net=JSON.parse(dicttxt)  # parse and transform data
    end
    result = PowerModels.run_ac_opf(pm_net, Ipopt.IpoptSolver())
    return result
end


text:
using MathUtils
using Base.Test

# Test log_sum_exp()
original = log(sum(exp([1, 2])))
ours = log_sum_exp([1, 2])
@test abs(ours - original) <= eps(original)

original = log(sum(exp([1, 2, 3, 4, 5, 6])))
ours = log_sum_exp([1, 2, 3, 4, 5, 6])
@test abs(ours - original) <= eps(original)

original = log(sum(exp([1, 1, 1, 1, 1])))
ours = log_sum_exp([1, 1, 1, 1, 1])
@test abs(ours - original) <= eps(original)

# Test sample_discrete_logspace() by comparing with a simpler sampler
# (given the same random input they should behave identically)
dist = [0.1, 0.7, 0.2]
log_dist = log(dist)
num_test = 1000
vals1 = zeros(num_test)
# run sample_discrete_logspace
srand(1)
for i in 1:num_test
  vals1[i] = sample_discrete_logspace(log_dist)
end
# run sample_discrete
srand(1)
vals2 = zeros(num_test)
for i in 1:num_test
  vals2[i] = sample_discrete(dist)
end
@test vals1 == vals2

max_stars_repo_name: BelhalK/Julia

max_issues_repo_name: BelhalK/Julia

max_forks_repo_name: BelhalK/Julia


text:
# distance(k::Stationary, X::MatF64, Y::MatF64) = pairwise(metric(k), X, Y)
distance(k::Stationary, x::VecF64, y::VecF64) = evaluate(metric(k), x, y)

distance(k::Isotropic, X::MatF64, data::IsotropicData) = data.R
function distance(k::Stationary, X::MatF64)
    nobsv = size(X, 2)
    return distance!(Matrix{Float64}(undef, nobsv, nobsv), metric(k), X)
end
distance!(dist::MatF64, k::Stationary, X::MatF64) = distance!(dist, metric(k), X)
function distance!(dist::MatF64, m::PreMetric, X::MatF64)
    dim, nobsv = size(X)
    for i in 1:nobsv
        dist[i,i] = 0.0
        for j in 1:i-1
            dist[i,j] = dist[j,i] = distij(m, X, i, j, dim)
        end
    end
    return dist
end
function distance(k::Stationary, X::MatF64, Y::MatF64)
    nobsx = size(X, 2)
    nobsy = size(Y, 2)
    return distance!(Matrix{Float64}(undef, nobsx, nobsy), metric(k), X, Y)
end
distance!(dist::MatF64, k::Stationary, X::MatF64, Y::MatF64) = distance!(dist, metric(k), X, Y)
function distance!(dist::MatF64, m::PreMetric, X::MatF64, Y::MatF64)
    dimx, nobsx = size(X)
    dimy, nobsy = size(Y)
    dimx == dimy || error("size(X, 1) != size(Y, 1)")
    for i in 1:nobsx
        for j in 1:nobsy
            dist[i,j] = distij(m, X, Y, i, j, dimx)
        end
    end
    return dist
end
function distance(k::StationaryARD, X::MatF64, data::StationaryARDData)
    distance(k, X)
end
@inline _SqEuclidean_ijk(X::MatF64,i::Int,j::Int,k::Int)=(X[k,i]-X[k,j])^2
@inline _SqEuclidean_ijk(X1::MatF64,X2::MatF64,i::Int,j::Int,k::Int)=(X1[k,i]-X2[k,j])^2
@inline function _SqEuclidean_ij(X::MatF64,i::Int,j::Int,dim::Int)
    s = 0.0
    @inbounds @simd for k in 1:dim
        s += _SqEuclidean_ijk(X,i,j,k)
    end
    return s
end
@inline function _SqEuclidean_ij(X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)
    s = 0.0
    @inbounds @simd for k in 1:dim
        s += _SqEuclidean_ijk(X1,X2,i,j,k)
    end
    return s
end
# Squared Euclidean
# @inline distijk(dist::SqEuclidean,X::MatF64,i::Int,j::Int,k::Int)=_SqEuclidean_ijk(X,i,j,k)
# @inline distijk(dist::SqEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,k::Int)=_SqEuclidean_ijk(X1,X2,i,j,k)
@inline distij(dist::SqEuclidean,X::MatF64,i::Int,j::Int,dim::Int)=_SqEuclidean_ij(X,i,j,dim)
@inline distij(dist::SqEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)=_SqEuclidean_ij(X1,X2,i,j,dim)

# Euclidean
@inline distij(dist::Euclidean,X::MatF64,i::Int,j::Int,dim::Int)=√_SqEuclidean_ij(X,i,j,dim)
@inline distij(dist::Euclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)=√_SqEuclidean_ij(X1,X2,i,j,dim)

@inline _WeightedSqEuclidean_ijk(weights::VecF64,X::MatF64,i::Int,j::Int,k::Int)=(X[k,i]-X[k,j])^2*weights[k]
@inline _WeightedSqEuclidean_ijk(weights::VecF64,X1::MatF64,X2::MatF64,i::Int,j::Int,k::Int)=(X1[k,i]-X2[k,j])^2*weights[k]
@inline function _WeightedSqEuclidean_ij(weights::VecF64,X::MatF64,i::Int,j::Int,dim::Int)
    s = 0.0
    @inbounds @simd for k in 1:dim
        s += _WeightedSqEuclidean_ijk(weights,X,i,j,k)
    end
    return s
end
@inline function _WeightedSqEuclidean_ij(weights::VecF64,X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)
    s = 0.0
    @inbounds @simd for k in 1:dim
        s += _WeightedSqEuclidean_ijk(weights,X1,X2,i,j,k)
    end
    return s
end

# Weighted Squared Euclidean
@inline distijk(dist::WeightedSqEuclidean,X::MatF64,i::Int,j::Int,k::Int)=_WeightedSqEuclidean_ijk(dist.weights,X,i,j,k)
@inline distijk(dist::WeightedSqEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,k::Int)=_WeightedSqEuclidean_ijk(dist.weights,X1,X2,i,j,k)
@inline distij(dist::WeightedSqEuclidean,X::MatF64,i::Int,j::Int,dim::Int)=_WeightedSqEuclidean_ij(dist.weights,X,i,j,dim)
@inline distij(dist::WeightedSqEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)=_WeightedSqEuclidean_ij(dist.weights,X1,X2,i,j,dim)

# Weighted Euclidean
@inline dist2ijk(dist::WeightedEuclidean,X::MatF64,i::Int,j::Int,k::Int)=_WeightedSqEuclidean_ijk(dist.weights,X,i,j,k)
@inline dist2ijk(dist::WeightedEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,k::Int)=_WeightedSqEuclidean_ijk(dist.weights,X1,X2,i,j,k)
@inline distij(dist::WeightedEuclidean,X::MatF64,i::Int,j::Int,dim::Int)=√_WeightedSqEuclidean_ij(dist.weights,X,i,j,dim)
@inline distij(dist::WeightedEuclidean,X1::MatF64,X2::MatF64,i::Int,j::Int,dim::Int)=√_WeightedSqEuclidean_ij(dist.weights,X1,X2,i,j,dim)


text:
module WGL

import GetC.@getCFun

const libGL = @windows? "opengl32" : "libGL"

typealias GLenum Cuint
typealias GLboolean Cuchar
typealias GLbitfield Cuint
typealias GLvoid Void
typealias GLbyte Cuchar
typealias GLshort Cshort
typealias GLint Cint
typealias GLubyte Cuchar
typealias GLushort Cushort
typealias GLuint Cuint
typealias GLsizei Csize_t
typealias GLfloat Cfloat
typealias GLclampf Cfloat
typealias GLdouble Cdouble
typealias GLclampd Cdouble
typealias GLchar Cchar
typealias GLint64 Clonglong
typealias GLuint64 Culonglong
typealias GLhalf Cushort
typealias GLhalfARB Cushort
typealias GLhalfNV Cushort
typealias GLsync Ptr{Void}
typealias Pointer Ptr{Void}
typealias GLsizeiptr Cint
typealias GLintptr Cptrdiff_t
const WGL_SAMPLES_3DFX = 0x2061
export WGL_SAMPLES_3DFX
const WGL_SAMPLE_BUFFERS_3DFX = 0x2060
export WGL_SAMPLE_BUFFERS_3DFX
const WGL_STEREO_EMITTER_DISABLE_3DL = 0x2056
export WGL_STEREO_EMITTER_DISABLE_3DL
const WGL_STEREO_EMITTER_ENABLE_3DL = 0x2055
export WGL_STEREO_EMITTER_ENABLE_3DL
const WGL_STEREO_POLARITY_INVERT_3DL = 0x2058
export WGL_STEREO_POLARITY_INVERT_3DL
const WGL_STEREO_POLARITY_NORMAL_3DL = 0x2057
export WGL_STEREO_POLARITY_NORMAL_3DL
const WGL_GPU_CLOCK_AMD = 0x21A4
export WGL_GPU_CLOCK_AMD
const WGL_GPU_FASTEST_TARGET_GPUS_AMD = 0x21A2
export WGL_GPU_FASTEST_TARGET_GPUS_AMD
const WGL_GPU_NUM_PIPES_AMD = 0x21A5
export WGL_GPU_NUM_PIPES_AMD
const WGL_GPU_NUM_RB_AMD = 0x21A7
export WGL_GPU_NUM_RB_AMD
const WGL_GPU_NUM_SIMD_AMD = 0x21A6
export WGL_GPU_NUM_SIMD_AMD
const WGL_GPU_NUM_SPI_AMD = 0x21A8
export WGL_GPU_NUM_SPI_AMD
const WGL_GPU_OPENGL_VERSION_STRING_AMD = 0x1F02
export WGL_GPU_OPENGL_VERSION_STRING_AMD
const WGL_GPU_RAM_AMD = 0x21A3
export WGL_GPU_RAM_AMD
const WGL_GPU_RENDERER_STRING_AMD = 0x1F01
export WGL_GPU_RENDERER_STRING_AMD
const WGL_GPU_VENDOR_AMD = 0x1F00
export WGL_GPU_VENDOR_AMD
const WGL_BACK_COLOR_BUFFER_BIT_ARB = 0x00000002
export WGL_BACK_COLOR_BUFFER_BIT_ARB
const WGL_DEPTH_BUFFER_BIT_ARB = 0x00000004
export WGL_DEPTH_BUFFER_BIT_ARB
const WGL_FRONT_COLOR_BUFFER_BIT_ARB = 0x00000001
export WGL_FRONT_COLOR_BUFFER_BIT_ARB
const WGL_STENCIL_BUFFER_BIT_ARB = 0x00000008
export WGL_STENCIL_BUFFER_BIT_ARB
const ERROR_INVALID_VERSION_ARB = 0x2095
export ERROR_INVALID_VERSION_ARB
const WGL_CONTEXT_DEBUG_BIT_ARB = 0x00000001
export WGL_CONTEXT_DEBUG_BIT_ARB
const WGL_CONTEXT_FLAGS_ARB = 0x2094
export WGL_CONTEXT_FLAGS_ARB
const WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x00000002
export WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
const WGL_CONTEXT_LAYER_PLANE_ARB = 0x2093
export WGL_CONTEXT_LAYER_PLANE_ARB
const WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091
export WGL_CONTEXT_MAJOR_VERSION_ARB
const WGL_CONTEXT_MINOR_VERSION_ARB = 0x2092
export WGL_CONTEXT_MINOR_VERSION_ARB
const ERROR_INVALID_PROFILE_ARB = 0x2096
export ERROR_INVALID_PROFILE_ARB
const WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002
export WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
const WGL_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001
export WGL_CONTEXT_CORE_PROFILE_BIT_ARB
const WGL_CONTEXT_PROFILE_MASK_ARB = 0x9126
export WGL_CONTEXT_PROFILE_MASK_ARB
const WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256
export WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
const WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004
export WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB
const WGL_LOSE_CONTEXT_ON_RESET_ARB = 0x8252
export WGL_LOSE_CONTEXT_ON_RESET_ARB
const WGL_NO_RESET_NOTIFICATION_ARB = 0x8261
export WGL_NO_RESET_NOTIFICATION_ARB
const WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB = 0x20A9
export WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB
const ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB = 0x2054
export ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB
const ERROR_INVALID_PIXEL_TYPE_ARB = 0x2043
export ERROR_INVALID_PIXEL_TYPE_ARB
const WGL_SAMPLES_ARB = 0x2042
export WGL_SAMPLES_ARB
const WGL_SAMPLE_BUFFERS_ARB = 0x2041
export WGL_SAMPLE_BUFFERS_ARB
const WGL_DRAW_TO_PBUFFER_ARB = 0x202D
export WGL_DRAW_TO_PBUFFER_ARB
const WGL_MAX_PBUFFER_HEIGHT_ARB = 0x2030
export WGL_MAX_PBUFFER_HEIGHT_ARB
const WGL_MAX_PBUFFER_PIXELS_ARB = 0x202E
export WGL_MAX_PBUFFER_PIXELS_ARB
const WGL_MAX_PBUFFER_WIDTH_ARB = 0x202F
export WGL_MAX_PBUFFER_WIDTH_ARB
const WGL_PBUFFER_HEIGHT_ARB = 0x2035
export WGL_PBUFFER_HEIGHT_ARB
const WGL_PBUFFER_LARGEST_ARB = 0x2033
export WGL_PBUFFER_LARGEST_ARB
const WGL_PBUFFER_LOST_ARB = 0x2036
export WGL_PBUFFER_LOST_ARB
const WGL_PBUFFER_WIDTH_ARB = 0x2034
export WGL_PBUFFER_WIDTH_ARB
const WGL_ACCELERATION_ARB = 0x2003
export WGL_ACCELERATION_ARB
const WGL_ACCUM_ALPHA_BITS_ARB = 0x2021
export WGL_ACCUM_ALPHA_BITS_ARB
const WGL_ACCUM_BITS_ARB = 0x201D
export WGL_ACCUM_BITS_ARB
const WGL_ACCUM_BLUE_BITS_ARB = 0x2020
export WGL_ACCUM_BLUE_BITS_ARB
const WGL_ACCUM_GREEN_BITS_ARB = 0x201F
export WGL_ACCUM_GREEN_BITS_ARB
const WGL_ACCUM_RED_BITS_ARB = 0x201E
export WGL_ACCUM_RED_BITS_ARB
const WGL_ALPHA_BITS_ARB = 0x201B
export WGL_ALPHA_BITS_ARB
const WGL_ALPHA_SHIFT_ARB = 0x201C
export WGL_ALPHA_SHIFT_ARB
const WGL_AUX_BUFFERS_ARB = 0x2024
export WGL_AUX_BUFFERS_ARB
const WGL_BLUE_BITS_ARB = 0x2019
export WGL_BLUE_BITS_ARB
const WGL_BLUE_SHIFT_ARB = 0x201A
export WGL_BLUE_SHIFT_ARB
const WGL_COLOR_BITS_ARB = 0x2014
export WGL_COLOR_BITS_ARB
const WGL_DEPTH_BITS_ARB = 0x2022
export WGL_DEPTH_BITS_ARB
const WGL_DOUBLE_BUFFER_ARB = 0x2011
export WGL_DOUBLE_BUFFER_ARB
const WGL_DRAW_TO_BITMAP_ARB = 0x2002
export WGL_DRAW_TO_BITMAP_ARB
const WGL_DRAW_TO_WINDOW_ARB = 0x2001
export WGL_DRAW_TO_WINDOW_ARB
const WGL_FULL_ACCELERATION_ARB = 0x2027
export WGL_FULL_ACCELERATION_ARB
const WGL_GENERIC_ACCELERATION_ARB = 0x2026
export WGL_GENERIC_ACCELERATION_ARB
const WGL_GREEN_BITS_ARB = 0x2017
export WGL_GREEN_BITS_ARB
const WGL_GREEN_SHIFT_ARB = 0x2018
export WGL_GREEN_SHIFT_ARB
const WGL_NEED_PALETTE_ARB = 0x2004
export WGL_NEED_PALETTE_ARB
const WGL_NEED_SYSTEM_PALETTE_ARB = 0x2005
export WGL_NEED_SYSTEM_PALETTE_ARB
const WGL_NO_ACCELERATION_ARB = 0x2025
export WGL_NO_ACCELERATION_ARB
const WGL_NUMBER_OVERLAYS_ARB = 0x2008
export WGL_NUMBER_OVERLAYS_ARB
const WGL_NUMBER_PIXEL_FORMATS_ARB = 0x2000
export WGL_NUMBER_PIXEL_FORMATS_ARB
const WGL_NUMBER_UNDERLAYS_ARB = 0x2009
export WGL_NUMBER_UNDERLAYS_ARB
const WGL_PIXEL_TYPE_ARB = 0x2013
export WGL_PIXEL_TYPE_ARB
const WGL_RED_BITS_ARB = 0x2015
export WGL_RED_BITS_ARB
const WGL_RED_SHIFT_ARB = 0x2016
export WGL_RED_SHIFT_ARB
const WGL_SHARE_ACCUM_ARB = 0x200E
export WGL_SHARE_ACCUM_ARB
const WGL_SHARE_DEPTH_ARB = 0x200C
export WGL_SHARE_DEPTH_ARB
const WGL_SHARE_STENCIL_ARB = 0x200D
export WGL_SHARE_STENCIL_ARB
const WGL_STENCIL_BITS_ARB = 0x2023
export WGL_STENCIL_BITS_ARB
const WGL_STEREO_ARB = 0x2012
export WGL_STEREO_ARB
const WGL_SUPPORT_GDI_ARB = 0x200F
export WGL_SUPPORT_GDI_ARB
const WGL_SUPPORT_OPENGL_ARB = 0x2010
export WGL_SUPPORT_OPENGL_ARB
const WGL_SWAP_COPY_ARB = 0x2029
export WGL_SWAP_COPY_ARB
const WGL_SWAP_EXCHANGE_ARB = 0x2028
export WGL_SWAP_EXCHANGE_ARB
const WGL_SWAP_LAYER_BUFFERS_ARB = 0x2006
export WGL_SWAP_LAYER_BUFFERS_ARB
const WGL_SWAP_METHOD_ARB = 0x2007
export WGL_SWAP_METHOD_ARB
const WGL_SWAP_UNDEFINED_ARB = 0x202A
export WGL_SWAP_UNDEFINED_ARB
const WGL_TRANSPARENT_ARB = 0x200A
export WGL_TRANSPARENT_ARB
const WGL_TYPE_COLORINDEX_ARB = 0x202C
export WGL_TYPE_COLORINDEX_ARB
const WGL_TYPE_RGBA_ARB = 0x202B
export WGL_TYPE_RGBA_ARB
const WGL_TYPE_RGBA_FLOAT_ARB = 0x21A0
export WGL_TYPE_RGBA_FLOAT_ARB
const WGL_AUX0_ARB = 0x2087
export WGL_AUX0_ARB
const WGL_AUX1_ARB = 0x2088
export WGL_AUX1_ARB
const WGL_AUX2_ARB = 0x2089
export WGL_AUX2_ARB
const WGL_AUX3_ARB = 0x208A
export WGL_AUX3_ARB
const WGL_AUX4_ARB = 0x208B
export WGL_AUX4_ARB
const WGL_AUX5_ARB = 0x208C
export WGL_AUX5_ARB
const WGL_AUX6_ARB = 0x208D
export WGL_AUX6_ARB
const WGL_AUX7_ARB = 0x208E
export WGL_AUX7_ARB
const WGL_AUX8_ARB = 0x208F
export WGL_AUX8_ARB
const WGL_AUX9_ARB = 0x2090
export WGL_AUX9_ARB
const WGL_BACK_LEFT_ARB = 0x2085
export WGL_BACK_LEFT_ARB
const WGL_BACK_RIGHT_ARB = 0x2086
export WGL_BACK_RIGHT_ARB
const WGL_BIND_TO_TEXTURE_RGBA_ARB = 0x2071
export WGL_BIND_TO_TEXTURE_RGBA_ARB
const WGL_BIND_TO_TEXTURE_RGB_ARB = 0x2070
export WGL_BIND_TO_TEXTURE_RGB_ARB
const WGL_CUBE_MAP_FACE_ARB = 0x207C
export WGL_CUBE_MAP_FACE_ARB
const WGL_FRONT_LEFT_ARB = 0x2083
export WGL_FRONT_LEFT_ARB
const WGL_FRONT_RIGHT_ARB = 0x2084
export WGL_FRONT_RIGHT_ARB
const WGL_MIPMAP_LEVEL_ARB = 0x207B
export WGL_MIPMAP_LEVEL_ARB
const WGL_MIPMAP_TEXTURE_ARB = 0x2074
export WGL_MIPMAP_TEXTURE_ARB
const WGL_NO_TEXTURE_ARB = 0x2077
export WGL_NO_TEXTURE_ARB
const WGL_TEXTURE_1D_ARB = 0x2079
export WGL_TEXTURE_1D_ARB
const WGL_TEXTURE_2D_ARB = 0x207A
export WGL_TEXTURE_2D_ARB
const WGL_TEXTURE_CUBE_MAP_ARB = 0x2078
export WGL_TEXTURE_CUBE_MAP_ARB
const WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB = 0x207E
export WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
const WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB = 0x2080
export WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
const WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB = 0x2082
export WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
const WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB = 0x207D
export WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
const WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB = 0x207F
export WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
const WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB = 0x2081
export WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
const WGL_TEXTURE_FORMAT_ARB = 0x2072
export WGL_TEXTURE_FORMAT_ARB
const WGL_TEXTURE_RGBA_ARB = 0x2076
export WGL_TEXTURE_RGBA_ARB
const WGL_TEXTURE_RGB_ARB = 0x2075
export WGL_TEXTURE_RGB_ARB
const WGL_TEXTURE_TARGET_ARB = 0x2073
export WGL_TEXTURE_TARGET_ARB
const WGL_TYPE_RGBA_FLOAT_ATI = 0x21A0
export WGL_TYPE_RGBA_FLOAT_ATI
const WGL_CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004
export WGL_CONTEXT_ES2_PROFILE_BIT_EXT
const WGL_DEPTH_FLOAT_EXT = 0x2040
export WGL_DEPTH_FLOAT_EXT
const WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT = 0x20A9
export WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT
const ERROR_INVALID_PIXEL_TYPE_EXT = 0x2043
export ERROR_INVALID_PIXEL_TYPE_EXT
const WGL_SAMPLES_EXT = 0x2042
export WGL_SAMPLES_EXT
const WGL_SAMPLE_BUFFERS_EXT = 0x2041
export WGL_SAMPLE_BUFFERS_EXT
const WGL_DRAW_TO_PBUFFER_EXT = 0x202D
export WGL_DRAW_TO_PBUFFER_EXT
const WGL_MAX_PBUFFER_HEIGHT_EXT = 0x2030
export WGL_MAX_PBUFFER_HEIGHT_EXT
const WGL_MAX_PBUFFER_PIXELS_EXT = 0x202E
export WGL_MAX_PBUFFER_PIXELS_EXT
const WGL_MAX_PBUFFER_WIDTH_EXT = 0x202F
export WGL_MAX_PBUFFER_WIDTH_EXT
const WGL_OPTIMAL_PBUFFER_HEIGHT_EXT = 0x2032
export WGL_OPTIMAL_PBUFFER_HEIGHT_EXT
const WGL_OPTIMAL_PBUFFER_WIDTH_EXT = 0x2031
export WGL_OPTIMAL_PBUFFER_WIDTH_EXT
const WGL_PBUFFER_HEIGHT_EXT = 0x2035
export WGL_PBUFFER_HEIGHT_EXT
const WGL_PBUFFER_LARGEST_EXT = 0x2033
export WGL_PBUFFER_LARGEST_EXT
const WGL_PBUFFER_WIDTH_EXT = 0x2034
export WGL_PBUFFER_WIDTH_EXT
const WGL_ACCELERATION_EXT = 0x2003
export WGL_ACCELERATION_EXT
const WGL_ACCUM_ALPHA_BITS_EXT = 0x2021
export WGL_ACCUM_ALPHA_BITS_EXT
const WGL_ACCUM_BITS_EXT = 0x201D
export WGL_ACCUM_BITS_EXT
const WGL_ACCUM_BLUE_BITS_EXT = 0x2020
export WGL_ACCUM_BLUE_BITS_EXT
const WGL_ACCUM_GREEN_BITS_EXT = 0x201F
export WGL_ACCUM_GREEN_BITS_EXT
const WGL_ACCUM_RED_BITS_EXT = 0x201E
export WGL_ACCUM_RED_BITS_EXT
const WGL_ALPHA_BITS_EXT = 0x201B
export WGL_ALPHA_BITS_EXT
const WGL_ALPHA_SHIFT_EXT = 0x201C
export WGL_ALPHA_SHIFT_EXT
const WGL_AUX_BUFFERS_EXT = 0x2024
export WGL_AUX_BUFFERS_EXT
const WGL_BLUE_BITS_EXT = 0x2019
export WGL_BLUE_BITS_EXT
const WGL_BLUE_SHIFT_EXT = 0x201A
export WGL_BLUE_SHIFT_EXT
const WGL_COLOR_BITS_EXT = 0x2014
export WGL_COLOR_BITS_EXT
const WGL_DEPTH_BITS_EXT = 0x2022
export WGL_DEPTH_BITS_EXT
const WGL_DOUBLE_BUFFER_EXT = 0x2011
export WGL_DOUBLE_BUFFER_EXT
const WGL_DRAW_TO_BITMAP_EXT = 0x2002
export WGL_DRAW_TO_BITMAP_EXT
const WGL_DRAW_TO_WINDOW_EXT = 0x2001
export WGL_DRAW_TO_WINDOW_EXT
const WGL_FULL_ACCELERATION_EXT = 0x2027
export WGL_FULL_ACCELERATION_EXT
const WGL_GENERIC_ACCELERATION_EXT = 0x2026
export WGL_GENERIC_ACCELERATION_EXT
const WGL_GREEN_BITS_EXT = 0x2017
export WGL_GREEN_BITS_EXT
const WGL_GREEN_SHIFT_EXT = 0x2018
export WGL_GREEN_SHIFT_EXT
const WGL_NEED_PALETTE_EXT = 0x2004
export WGL_NEED_PALETTE_EXT
const WGL_NEED_SYSTEM_PALETTE_EXT = 0x2005
export WGL_NEED_SYSTEM_PALETTE_EXT
const WGL_NO_ACCELERATION_EXT = 0x2025
export WGL_NO_ACCELERATION_EXT
const WGL_NUMBER_OVERLAYS_EXT = 0x2008
export WGL_NUMBER_OVERLAYS_EXT
const WGL_NUMBER_PIXEL_FORMATS_EXT = 0x2000
export WGL_NUMBER_PIXEL_FORMATS_EXT
const WGL_NUMBER_UNDERLAYS_EXT = 0x2009
export WGL_NUMBER_UNDERLAYS_EXT
const WGL_PIXEL_TYPE_EXT = 0x2013
export WGL_PIXEL_TYPE_EXT
const WGL_RED_BITS_EXT = 0x2015
export WGL_RED_BITS_EXT
const WGL_RED_SHIFT_EXT = 0x2016
export WGL_RED_SHIFT_EXT
const WGL_SHARE_ACCUM_EXT = 0x200E
export WGL_SHARE_ACCUM_EXT
const WGL_SHARE_DEPTH_EXT = 0x200C
export WGL_SHARE_DEPTH_EXT
const WGL_SHARE_STENCIL_EXT = 0x200D
export WGL_SHARE_STENCIL_EXT
const WGL_STENCIL_BITS_EXT = 0x2023
export WGL_STENCIL_BITS_EXT
const WGL_STEREO_EXT = 0x2012
export WGL_STEREO_EXT
const WGL_SUPPORT_GDI_EXT = 0x200F
export WGL_SUPPORT_GDI_EXT
const WGL_SUPPORT_OPENGL_EXT = 0x2010
export WGL_SUPPORT_OPENGL_EXT
const WGL_SWAP_COPY_EXT = 0x2029
export WGL_SWAP_COPY_EXT
const WGL_SWAP_EXCHANGE_EXT = 0x2028
export WGL_SWAP_EXCHANGE_EXT
const WGL_SWAP_LAYER_BUFFERS_EXT = 0x2006
export WGL_SWAP_LAYER_BUFFERS_EXT
const WGL_SWAP_METHOD_EXT = 0x2007
export WGL_SWAP_METHOD_EXT
const WGL_SWAP_UNDEFINED_EXT = 0x202A
export WGL_SWAP_UNDEFINED_EXT
const WGL_TRANSPARENT_EXT = 0x200A
export WGL_TRANSPARENT_EXT
const WGL_TRANSPARENT_VALUE_EXT = 0x200B
export WGL_TRANSPARENT_VALUE_EXT
const WGL_TYPE_COLORINDEX_EXT = 0x202C
export WGL_TYPE_COLORINDEX_EXT
const WGL_TYPE_RGBA_EXT = 0x202B
export WGL_TYPE_RGBA_EXT
const WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT = 0x20A8
export WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
const WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D = 0x2050
export WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D
const WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D = 0x2051
export WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D
const WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D = 0x2052
export WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D
const WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D = 0x2053
export WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D
const WGL_GAMMA_EXCLUDE_DESKTOP_I3D = 0x204F
export WGL_GAMMA_EXCLUDE_DESKTOP_I3D
const WGL_GAMMA_TABLE_SIZE_I3D = 0x204E
export WGL_GAMMA_TABLE_SIZE_I3D
const WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D = 0x2049
export WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D
const WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D = 0x2048
export WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D
const WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D = 0x204C
export WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D
const WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D = 0x204A
export WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D
const WGL_GENLOCK_SOURCE_EDGE_RISING_I3D = 0x204B
export WGL_GENLOCK_SOURCE_EDGE_RISING_I3D
const WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D = 0x2046
export WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D
const WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D = 0x2045
export WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D
const WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D = 0x2047
export WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D
const WGL_GENLOCK_SOURCE_MULTIVIEW_I3D = 0x2044
export WGL_GENLOCK_SOURCE_MULTIVIEW_I3D
const WGL_IMAGE_BUFFER_LOCK_I3D = 0x00000002
export WGL_IMAGE_BUFFER_LOCK_I3D
const WGL_IMAGE_BUFFER_MIN_ACCESS_I3D = 0x00000001
export WGL_IMAGE_BUFFER_MIN_ACCESS_I3D
const WGL_ACCESS_READ_ONLY_NV = 0x00000000
export WGL_ACCESS_READ_ONLY_NV
const WGL_ACCESS_READ_WRITE_NV = 0x00000001
export WGL_ACCESS_READ_WRITE_NV
const WGL_ACCESS_WRITE_DISCARD_NV = 0x00000002
export WGL_ACCESS_WRITE_DISCARD_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV = 0x20B4
export WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV = 0x20B3
export WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV = 0x20B2
export WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV = 0x20B1
export WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV
const WGL_FLOAT_COMPONENTS_NV = 0x20B0
export WGL_FLOAT_COMPONENTS_NV
const WGL_TEXTURE_FLOAT_RGBA_NV = 0x20B8
export WGL_TEXTURE_FLOAT_RGBA_NV
const WGL_TEXTURE_FLOAT_RGB_NV = 0x20B7
export WGL_TEXTURE_FLOAT_RGB_NV
const WGL_TEXTURE_FLOAT_RG_NV = 0x20B6
export WGL_TEXTURE_FLOAT_RG_NV
const WGL_TEXTURE_FLOAT_R_NV = 0x20B5
export WGL_TEXTURE_FLOAT_R_NV
const WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV = 0x20D0
export WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV
const WGL_ERROR_MISSING_AFFINITY_MASK_NV = 0x20D1
export WGL_ERROR_MISSING_AFFINITY_MASK_NV
const WGL_COLOR_SAMPLES_NV = 0x20B9
export WGL_COLOR_SAMPLES_NV
const WGL_COVERAGE_SAMPLES_NV = 0x2042
export WGL_COVERAGE_SAMPLES_NV
const WGL_NUM_VIDEO_SLOTS_NV = 0x20F0
export WGL_NUM_VIDEO_SLOTS_NV
const WGL_BIND_TO_TEXTURE_DEPTH_NV = 0x20A3
export WGL_BIND_TO_TEXTURE_DEPTH_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV = 0x20A4
export WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV
const WGL_DEPTH_COMPONENT_NV = 0x20A7
export WGL_DEPTH_COMPONENT_NV
const WGL_DEPTH_TEXTURE_FORMAT_NV = 0x20A5
export WGL_DEPTH_TEXTURE_FORMAT_NV
const WGL_TEXTURE_DEPTH_COMPONENT_NV = 0x20A6
export WGL_TEXTURE_DEPTH_COMPONENT_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV = 0x20A1
export WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV
const WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV = 0x20A0
export WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV
const WGL_TEXTURE_RECTANGLE_NV = 0x20A2
export WGL_TEXTURE_RECTANGLE_NV
const WGL_NUM_VIDEO_CAPTURE_SLOTS_NV = 0x20CF
export WGL_NUM_VIDEO_CAPTURE_SLOTS_NV
const WGL_UNIQUE_ID_NV = 0x20CE
export WGL_UNIQUE_ID_NV
const WGL_BIND_TO_VIDEO_RGBA_NV = 0x20C1
export WGL_BIND_TO_VIDEO_RGBA_NV
const WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV = 0x20C2
export WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV
const WGL_BIND_TO_VIDEO_RGB_NV = 0x20C0
export WGL_BIND_TO_VIDEO_RGB_NV
const WGL_VIDEO_OUT_ALPHA_NV = 0x20C4
export WGL_VIDEO_OUT_ALPHA_NV
const WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV = 0x20C6
export WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV
const WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV = 0x20C7
export WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV
const WGL_VIDEO_OUT_COLOR_NV = 0x20C3
export WGL_VIDEO_OUT_COLOR_NV
const WGL_VIDEO_OUT_DEPTH_NV = 0x20C5
export WGL_VIDEO_OUT_DEPTH_NV
const WGL_VIDEO_OUT_FIELD_1 = 0x20C9
export WGL_VIDEO_OUT_FIELD_1
const WGL_VIDEO_OUT_FIELD_2 = 0x20CA
export WGL_VIDEO_OUT_FIELD_2
const WGL_VIDEO_OUT_FRAME = 0x20C8
export WGL_VIDEO_OUT_FRAME
const WGL_VIDEO_OUT_STACKED_FIELDS_1_2 = 0x20CB
export WGL_VIDEO_OUT_STACKED_FIELDS_1_2
const WGL_VIDEO_OUT_STACKED_FIELDS_2_1 = 0x20CC
export WGL_VIDEO_OUT_STACKED_FIELDS_2_1
@getCFun libGL wglSetStereoEmitterState3DL wglSetStereoEmitterState3DL(hDC::HDC, uState::Cuint)::Cint
export wglSetStereoEmitterState3DL
@getCFun libGL wglGetGPUIDsAMD wglGetGPUIDsAMD(maxCount::Cuint, ids::Ptr{Cuint})::Cuint
export wglGetGPUIDsAMD
@getCFun libGL wglGetGPUInfoAMD wglGetGPUInfoAMD(id::Cuint, property::Cint, dataType::GLenum, size::Cuint, data::Ptr{Void})::Cint
export wglGetGPUInfoAMD
@getCFun libGL wglGetContextGPUIDAMD wglGetContextGPUIDAMD(hglrc::HGLRC)::Cuint
export wglGetContextGPUIDAMD
@getCFun libGL wglCreateAssociatedContextAMD wglCreateAssociatedContextAMD(id::Cuint)::Ptr{Void}
export wglCreateAssociatedContextAMD
@getCFun libGL wglCreateAssociatedContextAttribsAMD wglCreateAssociatedContextAttribsAMD(id::Cuint, hShareContext::HGLRC, attribList::Ptr{Cint})::Ptr{Void}
export wglCreateAssociatedContextAttribsAMD
@getCFun libGL wglDeleteAssociatedContextAMD wglDeleteAssociatedContextAMD(hglrc::HGLRC)::Cint
export wglDeleteAssociatedContextAMD
@getCFun libGL wglMakeAssociatedContextCurrentAMD wglMakeAssociatedContextCurrentAMD(hglrc::HGLRC)::Cint
export wglMakeAssociatedContextCurrentAMD
@getCFun libGL wglGetCurrentAssociatedContextAMD wglGetCurrentAssociatedContextAMD()::Ptr{Void}
export wglGetCurrentAssociatedContextAMD
@getCFun libGL wglCreateBufferRegionARB wglCreateBufferRegionARB(hDC::HDC, iLayerPlane::Cint, uType::Cuint)::Ptr{Void}
export wglCreateBufferRegionARB
@getCFun libGL wglSaveBufferRegionARB wglSaveBufferRegionARB(hRegion::HANDLE, x::Cint, y::Cint, width::Cint, height::Cint)::Cint
export wglSaveBufferRegionARB
@getCFun libGL wglRestoreBufferRegionARB wglRestoreBufferRegionARB(hRegion::HANDLE, x::Cint, y::Cint, width::Cint, height::Cint, xSrc::Cint, ySrc::Cint)::Cint
export wglRestoreBufferRegionARB
@getCFun libGL wglCreateContextAttribsARB wglCreateContextAttribsARB(hDC::HDC, hShareContext::HGLRC, attribList::Ptr{Cint})::Ptr{Void}
export wglCreateContextAttribsARB
@getCFun libGL wglGetExtensionsStringARB wglGetExtensionsStringARB(hdc::HDC)::Ptr{Cchar}
export wglGetExtensionsStringARB
@getCFun libGL wglMakeContextCurrentARB wglMakeContextCurrentARB(hDrawDC::HDC, hReadDC::HDC, hglrc::HGLRC)::Cint
export wglMakeContextCurrentARB
@getCFun libGL wglGetCurrentReadDCARB wglGetCurrentReadDCARB()::Ptr{Void}
export wglGetCurrentReadDCARB
@getCFun libGL wglCreatePbufferARB wglCreatePbufferARB(hDC::HDC, iPixelFormat::Cint, iWidth::Cint, iHeight::Cint, piAttribList::Ptr{Cint})::Ptr{Void}
export wglCreatePbufferARB
@getCFun libGL wglGetPbufferDCARB wglGetPbufferDCARB(hPbuffer::HPBUFFERARB)::Ptr{Void}
export wglGetPbufferDCARB
@getCFun libGL wglReleasePbufferDCARB wglReleasePbufferDCARB(hPbuffer::HPBUFFERARB, hDC::HDC)::Cint
export wglReleasePbufferDCARB
@getCFun libGL wglDestroyPbufferARB wglDestroyPbufferARB(hPbuffer::HPBUFFERARB)::Cint
export wglDestroyPbufferARB
@getCFun libGL wglQueryPbufferARB wglQueryPbufferARB(hPbuffer::HPBUFFERARB, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglQueryPbufferARB
@getCFun libGL wglGetPixelFormatAttribivARB wglGetPixelFormatAttribivARB(hdc::HDC, iPixelFormat::Cint, iLayerPlane::Cint, nAttributes::Cuint, piAttributes::Ptr{Cint}, piValues::Ptr{Cint})::Cint
export wglGetPixelFormatAttribivARB
@getCFun libGL wglGetPixelFormatAttribfvARB wglGetPixelFormatAttribfvARB(hdc::HDC, iPixelFormat::Cint, iLayerPlane::Cint, nAttributes::Cuint, piAttributes::Ptr{Cint}, pfValues::Ptr{Cfloat})::Cint
export wglGetPixelFormatAttribfvARB
@getCFun libGL wglChoosePixelFormatARB wglChoosePixelFormatARB(hdc::HDC, piAttribIList::Ptr{Cint}, pfAttribFList::Ptr{Cfloat}, nMaxFormats::Cuint, piFormats::Ptr{Cint}, nNumFormats::Ptr{Cuint})::Cint
export wglChoosePixelFormatARB
@getCFun libGL wglBindTexImageARB wglBindTexImageARB(hPbuffer::HPBUFFERARB, iBuffer::Cint)::Cint
export wglBindTexImageARB
@getCFun libGL wglReleaseTexImageARB wglReleaseTexImageARB(hPbuffer::HPBUFFERARB, iBuffer::Cint)::Cint
export wglReleaseTexImageARB
@getCFun libGL wglSetPbufferAttribARB wglSetPbufferAttribARB(hPbuffer::HPBUFFERARB, piAttribList::Ptr{Cint})::Cint
export wglSetPbufferAttribARB
@getCFun libGL wglCreateDisplayColorTableEXT wglCreateDisplayColorTableEXT(id::GLushort)::Bool
export wglCreateDisplayColorTableEXT
@getCFun libGL wglLoadDisplayColorTableEXT wglLoadDisplayColorTableEXT(table::Ptr{GLushort}, length::GLuint)::Bool
export wglLoadDisplayColorTableEXT
@getCFun libGL wglBindDisplayColorTableEXT wglBindDisplayColorTableEXT(id::GLushort)::Bool
export wglBindDisplayColorTableEXT
@getCFun libGL wglGetExtensionsStringEXT wglGetExtensionsStringEXT()::Ptr{Cchar}
export wglGetExtensionsStringEXT
@getCFun libGL wglMakeContextCurrentEXT wglMakeContextCurrentEXT(hDrawDC::HDC, hReadDC::HDC, hglrc::HGLRC)::Cint
export wglMakeContextCurrentEXT
@getCFun libGL wglGetCurrentReadDCEXT wglGetCurrentReadDCEXT()::Ptr{Void}
export wglGetCurrentReadDCEXT
@getCFun libGL wglCreatePbufferEXT wglCreatePbufferEXT(hDC::HDC, iPixelFormat::Cint, iWidth::Cint, iHeight::Cint, piAttribList::Ptr{Cint})::Ptr{Void}
export wglCreatePbufferEXT
@getCFun libGL wglGetPbufferDCEXT wglGetPbufferDCEXT(hPbuffer::HPBUFFEREXT)::Ptr{Void}
export wglGetPbufferDCEXT
@getCFun libGL wglReleasePbufferDCEXT wglReleasePbufferDCEXT(hPbuffer::HPBUFFEREXT, hDC::HDC)::Cint
export wglReleasePbufferDCEXT
@getCFun libGL wglDestroyPbufferEXT wglDestroyPbufferEXT(hPbuffer::HPBUFFEREXT)::Cint
export wglDestroyPbufferEXT
@getCFun libGL wglQueryPbufferEXT wglQueryPbufferEXT(hPbuffer::HPBUFFEREXT, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglQueryPbufferEXT
@getCFun libGL wglGetPixelFormatAttribivEXT wglGetPixelFormatAttribivEXT(hdc::HDC, iPixelFormat::Cint, iLayerPlane::Cint, nAttributes::Cuint, piAttributes::Ptr{Cint}, piValues::Ptr{Cint})::Cint
export wglGetPixelFormatAttribivEXT
@getCFun libGL wglGetPixelFormatAttribfvEXT wglGetPixelFormatAttribfvEXT(hdc::HDC, iPixelFormat::Cint, iLayerPlane::Cint, nAttributes::Cuint, piAttributes::Ptr{Cint}, pfValues::Ptr{Cfloat})::Cint
export wglGetPixelFormatAttribfvEXT
@getCFun libGL wglChoosePixelFormatEXT wglChoosePixelFormatEXT(hdc::HDC, piAttribIList::Ptr{Cint}, pfAttribFList::Ptr{Cfloat}, nMaxFormats::Cuint, piFormats::Ptr{Cint}, nNumFormats::Ptr{Cuint})::Cint
export wglChoosePixelFormatEXT
@getCFun libGL wglSwapIntervalEXT wglSwapIntervalEXT(interval::Cint)::Cint
export wglSwapIntervalEXT
@getCFun libGL wglGetSwapIntervalEXT wglGetSwapIntervalEXT()::Cint
export wglGetSwapIntervalEXT
@getCFun libGL wglGetDigitalVideoParametersI3D wglGetDigitalVideoParametersI3D(hDC::HDC, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglGetDigitalVideoParametersI3D
@getCFun libGL wglSetDigitalVideoParametersI3D wglSetDigitalVideoParametersI3D(hDC::HDC, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglSetDigitalVideoParametersI3D
@getCFun libGL wglGetGammaTableParametersI3D wglGetGammaTableParametersI3D(hDC::HDC, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglGetGammaTableParametersI3D
@getCFun libGL wglSetGammaTableParametersI3D wglSetGammaTableParametersI3D(hDC::HDC, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglSetGammaTableParametersI3D
@getCFun libGL wglGetGammaTableI3D wglGetGammaTableI3D(hDC::HDC, iEntries::Cint, puRed::Ptr{Cushort}, puGreen::Ptr{Cushort}, puBlue::Ptr{Cushort})::Cint
export wglGetGammaTableI3D
@getCFun libGL wglSetGammaTableI3D wglSetGammaTableI3D(hDC::HDC, iEntries::Cint, puRed::Ptr{Cushort}, puGreen::Ptr{Cushort}, puBlue::Ptr{Cushort})::Cint
export wglSetGammaTableI3D
@getCFun libGL wglEnableGenlockI3D wglEnableGenlockI3D(hDC::HDC)::Cint
export wglEnableGenlockI3D
@getCFun libGL wglDisableGenlockI3D wglDisableGenlockI3D(hDC::HDC)::Cint
export wglDisableGenlockI3D
@getCFun libGL wglIsEnabledGenlockI3D wglIsEnabledGenlockI3D(hDC::HDC, pFlag::Ptr{Bool})::Cint
export wglIsEnabledGenlockI3D
@getCFun libGL wglGenlockSourceI3D wglGenlockSourceI3D(hDC::HDC, uSource::Cuint)::Cint
export wglGenlockSourceI3D
@getCFun libGL wglGetGenlockSourceI3D wglGetGenlockSourceI3D(hDC::HDC, uSource::Ptr{Cuint})::Cint
export wglGetGenlockSourceI3D
@getCFun libGL wglGenlockSourceEdgeI3D wglGenlockSourceEdgeI3D(hDC::HDC, uEdge::Cuint)::Cint
export wglGenlockSourceEdgeI3D
@getCFun libGL wglGetGenlockSourceEdgeI3D wglGetGenlockSourceEdgeI3D(hDC::HDC, uEdge::Ptr{Cuint})::Cint
export wglGetGenlockSourceEdgeI3D
@getCFun libGL wglGenlockSampleRateI3D wglGenlockSampleRateI3D(hDC::HDC, uRate::Cuint)::Cint
export wglGenlockSampleRateI3D
@getCFun libGL wglGetGenlockSampleRateI3D wglGetGenlockSampleRateI3D(hDC::HDC, uRate::Ptr{Cuint})::Cint
export wglGetGenlockSampleRateI3D
@getCFun libGL wglGenlockSourceDelayI3D wglGenlockSourceDelayI3D(hDC::HDC, uDelay::Cuint)::Cint
export wglGenlockSourceDelayI3D
@getCFun libGL wglGetGenlockSourceDelayI3D wglGetGenlockSourceDelayI3D(hDC::HDC, uDelay::Ptr{Cuint})::Cint
export wglGetGenlockSourceDelayI3D
@getCFun libGL wglQueryGenlockMaxSourceDelayI3D wglQueryGenlockMaxSourceDelayI3D(hDC::HDC, uMaxLineDelay::Ptr{Cuint}, uMaxPixelDelay::Ptr{Cuint})::Cint
export wglQueryGenlockMaxSourceDelayI3D
@getCFun libGL wglCreateImageBufferI3D wglCreateImageBufferI3D(hDC::HDC, dwSize::DWORD, uFlags::Cuint)::Ptr{Void}
export wglCreateImageBufferI3D
@getCFun libGL wglDestroyImageBufferI3D wglDestroyImageBufferI3D(hDC::HDC, pAddress::LPVOID)::Cint
export wglDestroyImageBufferI3D
@getCFun libGL wglAssociateImageBufferEventsI3D wglAssociateImageBufferEventsI3D(hDC::HDC, pEvent::HANDLE, pAddress::LPVOID, pSize::Ptr{DWORD}, count::Cuint)::Cint
export wglAssociateImageBufferEventsI3D
@getCFun libGL wglReleaseImageBufferEventsI3D wglReleaseImageBufferEventsI3D(hDC::HDC, pAddress::LPVOID, count::Cuint)::Cint
export wglReleaseImageBufferEventsI3D
@getCFun libGL wglEnableFrameLockI3D wglEnableFrameLockI3D()::Cint
export wglEnableFrameLockI3D
@getCFun libGL wglDisableFrameLockI3D wglDisableFrameLockI3D()::Cint
export wglDisableFrameLockI3D
@getCFun libGL wglIsEnabledFrameLockI3D wglIsEnabledFrameLockI3D(pFlag::Ptr{Bool})::Cint
export wglIsEnabledFrameLockI3D
@getCFun libGL wglQueryFrameLockMasterI3D wglQueryFrameLockMasterI3D(pFlag::Ptr{Bool})::Cint
export wglQueryFrameLockMasterI3D
@getCFun libGL wglGetFrameUsageI3D wglGetFrameUsageI3D(pUsage::Ptr{Cfloat})::Cint
export wglGetFrameUsageI3D
@getCFun libGL wglBeginFrameTrackingI3D wglBeginFrameTrackingI3D()::Cint
export wglBeginFrameTrackingI3D
@getCFun libGL wglEndFrameTrackingI3D wglEndFrameTrackingI3D()::Cint
export wglEndFrameTrackingI3D
@getCFun libGL wglQueryFrameTrackingI3D wglQueryFrameTrackingI3D(pFrameCount::Ptr{DWORD}, pMissedFrames::Ptr{DWORD}, pLastMissedUsage::Ptr{Cfloat})::Cint
export wglQueryFrameTrackingI3D
@getCFun libGL wglDXSetResourceShareHandleNV wglDXSetResourceShareHandleNV(dxObject::Ptr{Void}, shareHandle::HANDLE)::Cint
export wglDXSetResourceShareHandleNV
@getCFun libGL wglDXOpenDeviceNV wglDXOpenDeviceNV(dxDevice::Ptr{Void})::Ptr{Void}
export wglDXOpenDeviceNV
@getCFun libGL wglDXCloseDeviceNV wglDXCloseDeviceNV(hDevice::HANDLE)::Cint
export wglDXCloseDeviceNV
@getCFun libGL wglDXRegisterObjectNV wglDXRegisterObjectNV(hDevice::HANDLE, dxObject::Ptr{Void}, name::GLuint, type_::GLenum, access::GLenum)::Ptr{Void}
export wglDXRegisterObjectNV
@getCFun libGL wglDXUnregisterObjectNV wglDXUnregisterObjectNV(hDevice::HANDLE, hObject::HANDLE)::Cint
export wglDXUnregisterObjectNV
@getCFun libGL wglDXObjectAccessNV wglDXObjectAccessNV(hObject::HANDLE, access::GLenum)::Cint
export wglDXObjectAccessNV
@getCFun libGL wglDXLockObjectsNV wglDXLockObjectsNV(hDevice::HANDLE, count::GLint, hObjects::HANDLE)::Cint
export wglDXLockObjectsNV
@getCFun libGL wglDXUnlockObjectsNV wglDXUnlockObjectsNV(hDevice::HANDLE, count::GLint, hObjects::HANDLE)::Cint
export wglDXUnlockObjectsNV
@getCFun libGL wglCopyImageSubDataNV wglCopyImageSubDataNV(hSrcRC::HGLRC, srcName::GLuint, srcTarget::GLenum, srcLevel::GLint, srcX::GLint, srcY::GLint, srcZ::GLint, hDstRC::HGLRC, dstName::GLuint, dstTarget::GLenum, dstLevel::GLint, dstX::GLint, dstY::GLint, dstZ::GLint, width::GLsizei, height::GLsizei, depth::GLsizei)::Cint
export wglCopyImageSubDataNV
@getCFun libGL wglEnumGpusNV wglEnumGpusNV(iGpuIndex::Cuint, phGpu::HGPUNV)::Cint
export wglEnumGpusNV
@getCFun libGL wglEnumGpuDevicesNV wglEnumGpuDevicesNV(hGpu::HGPUNV, iDeviceIndex::Cuint, lpGpuDevice::PGPU_DEVICE)::Cint
export wglEnumGpuDevicesNV
@getCFun libGL wglCreateAffinityDCNV wglCreateAffinityDCNV(phGpuList::HGPUNV)::Ptr{Void}
export wglCreateAffinityDCNV
@getCFun libGL wglEnumGpusFromAffinityDCNV wglEnumGpusFromAffinityDCNV(hAffinityDC::HDC, iGpuIndex::Cuint, hGpu::HGPUNV)::Cint
export wglEnumGpusFromAffinityDCNV
@getCFun libGL wglDeleteDCNV wglDeleteDCNV(hdc::HDC)::Cint
export wglDeleteDCNV
@getCFun libGL wglEnumerateVideoDevicesNV wglEnumerateVideoDevicesNV(hDC::HDC, phDeviceList::HVIDEOOUTPUTDEVICENV)::Cint
export wglEnumerateVideoDevicesNV
@getCFun libGL wglBindVideoDeviceNV wglBindVideoDeviceNV(hDC::HDC, uVideoSlot::Cuint, hVideoDevice::HVIDEOOUTPUTDEVICENV, piAttribList::Ptr{Cint})::Cint
export wglBindVideoDeviceNV
@getCFun libGL wglQueryCurrentContextNV wglQueryCurrentContextNV(iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglQueryCurrentContextNV
@getCFun libGL wglJoinSwapGroupNV wglJoinSwapGroupNV(hDC::HDC, group::GLuint)::Cint
export wglJoinSwapGroupNV
@getCFun libGL wglBindSwapBarrierNV wglBindSwapBarrierNV(group::GLuint, barrier::GLuint)::Cint
export wglBindSwapBarrierNV
@getCFun libGL wglQuerySwapGroupNV wglQuerySwapGroupNV(hDC::HDC, group::Ptr{GLuint}, barrier::Ptr{GLuint})::Cint
export wglQuerySwapGroupNV
@getCFun libGL wglQueryMaxSwapGroupsNV wglQueryMaxSwapGroupsNV(hDC::HDC, maxGroups::Ptr{GLuint}, maxBarriers::Ptr{GLuint})::Cint
export wglQueryMaxSwapGroupsNV
@getCFun libGL wglQueryFrameCountNV wglQueryFrameCountNV(hDC::HDC, count::Ptr{GLuint})::Cint
export wglQueryFrameCountNV
@getCFun libGL wglResetFrameCountNV wglResetFrameCountNV(hDC::HDC)::Cint
export wglResetFrameCountNV
@getCFun libGL wglAllocateMemoryNV wglAllocateMemoryNV(size::GLsizei, readfreq::GLfloat, writefreq::GLfloat, priority::GLfloat)::Ptr{Void}
export wglAllocateMemoryNV
@getCFun libGL wglBindVideoCaptureDeviceNV wglBindVideoCaptureDeviceNV(uVideoSlot::Cuint, hDevice::HVIDEOINPUTDEVICENV)::Cint
export wglBindVideoCaptureDeviceNV
@getCFun libGL wglEnumerateVideoCaptureDevicesNV wglEnumerateVideoCaptureDevicesNV(hDc::HDC, phDeviceList::HVIDEOINPUTDEVICENV)::Cuint
export wglEnumerateVideoCaptureDevicesNV
@getCFun libGL wglLockVideoCaptureDeviceNV wglLockVideoCaptureDeviceNV(hDc::HDC, hDevice::HVIDEOINPUTDEVICENV)::Cint
export wglLockVideoCaptureDeviceNV
@getCFun libGL wglQueryVideoCaptureDeviceNV wglQueryVideoCaptureDeviceNV(hDc::HDC, hDevice::HVIDEOINPUTDEVICENV, iAttribute::Cint, piValue::Ptr{Cint})::Cint
export wglQueryVideoCaptureDeviceNV
@getCFun libGL wglReleaseVideoCaptureDeviceNV wglReleaseVideoCaptureDeviceNV(hDc::HDC, hDevice::HVIDEOINPUTDEVICENV)::Cint
export wglReleaseVideoCaptureDeviceNV
@getCFun libGL wglGetVideoDeviceNV wglGetVideoDeviceNV(hDC::HDC, numDevices::Cint, hVideoDevice::HPVIDEODEV)::Cint
export wglGetVideoDeviceNV
@getCFun libGL wglReleaseVideoDeviceNV wglReleaseVideoDeviceNV(hVideoDevice::HPVIDEODEV)::Cint
export wglReleaseVideoDeviceNV
@getCFun libGL wglBindVideoImageNV wglBindVideoImageNV(hVideoDevice::HPVIDEODEV, hPbuffer::HPBUFFERARB, iVideoBuffer::Cint)::Cint
export wglBindVideoImageNV
@getCFun libGL wglReleaseVideoImageNV wglReleaseVideoImageNV(hPbuffer::HPBUFFERARB, iVideoBuffer::Cint)::Cint
export wglReleaseVideoImageNV
@getCFun libGL wglSendPbufferToVideoNV wglSendPbufferToVideoNV(hPbuffer::HPBUFFERARB, iBufferType::Cint, pulCounterPbuffer::Ptr{Culong}, bBlock::Bool)::Cint
export wglSendPbufferToVideoNV
@getCFun libGL wglGetVideoInfoNV wglGetVideoInfoNV(hpVideoDevice::HPVIDEODEV, pulCounterOutputPbuffer::Ptr{Culong}, pulCounterOutputVideo::Ptr{Culong})::Cint
export wglGetVideoInfoNV
@getCFun libGL wglGetSyncValuesOML wglGetSyncValuesOML(hdc::HDC, ust::Ptr{Clonglong}, msc::Ptr{Clonglong}, sbc::Ptr{Clonglong})::Cint
export wglGetSyncValuesOML
@getCFun libGL wglGetMscRateOML wglGetMscRateOML(hdc::HDC, numerator::Ptr{Cint}, denominator::Ptr{Cint})::Cint
export wglGetMscRateOML
@getCFun libGL wglSwapBuffersMscOML wglSwapBuffersMscOML(hdc::HDC, target_msc::Clonglong, divisor::Clonglong, remainder::Clonglong)::CClonglong
export wglSwapBuffersMscOML
@getCFun libGL wglSwapLayerBuffersMscOML wglSwapLayerBuffersMscOML(hdc::HDC, fuPlanes::Cint, target_msc::Clonglong, divisor::Clonglong, remainder::Clonglong)::CClonglong
export wglSwapLayerBuffersMscOML
@getCFun libGL wglWaitForMscOML wglWaitForMscOML(hdc::HDC, target_msc::Clonglong, divisor::Clonglong, remainder::Clonglong, ust::Ptr{Clonglong}, msc::Ptr{Clonglong}, sbc::Ptr{Clonglong})::Cint
export wglWaitForMscOML
@getCFun libGL wglWaitForSbcOML wglWaitForSbcOML(hdc::HDC, target_sbc::Clonglong, ust::Ptr{Clonglong}, msc::Ptr{Clonglong}, sbc::Ptr{Clonglong})::Cint
export wglWaitForSbcOML
@getCFun libGL wglCreateContext wglCreateContext(hDc::HDC)::Ptr{Void}
export wglCreateContext
@getCFun libGL wglDeleteContext wglDeleteContext(oldContext::HGLRC)::Cint
export wglDeleteContext
@getCFun libGL wglGetCurrentContext wglGetCurrentContext()::Ptr{Void}
export wglGetCurrentContext
@getCFun libGL wglMakeCurrent wglMakeCurrent(hDc::HDC, newContext::HGLRC)::Cint
export wglMakeCurrent
@getCFun libGL wglCopyContext wglCopyContext(hglrcSrc::HGLRC, hglrcDst::HGLRC, mask::Cuint)::Cint
export wglCopyContext
@getCFun libGL wglChoosePixelFormat wglChoosePixelFormat(hDc::HDC, pPfd::PIXELFORMATDESCRIPTOR)::Cint
export wglChoosePixelFormat
@getCFun libGL wglGetCurrentDC wglGetCurrentDC()::Ptr{Void}
export wglGetCurrentDC
@getCFun libGL wglGetDefaultProcAddress wglGetDefaultProcAddress(lpszProc::LPCSTR)::Ptr{Void}
export wglGetDefaultProcAddress
@getCFun libGL wglGetProcAddress wglGetProcAddress(lpszProc::LPCSTR)::Ptr{Void}
export wglGetProcAddress
@getCFun libGL wglGetPixelFormat wglGetPixelFormat(hdc::HDC)::Cint
export wglGetPixelFormat
@getCFun libGL wglSetPixelFormat wglSetPixelFormat(hdc::HDC, ipfd::Cint, ppfd::PIXELFORMATDESCRIPTOR)::Cint
export wglSetPixelFormat
@getCFun libGL wglSwapBuffers wglSwapBuffers(hdc::HDC)::Cint
export wglSwapBuffers
@getCFun libGL wglShareLists wglShareLists(hrcSrvShare::HGLRC, hrcSrvSource::HGLRC)::Cint
export wglShareLists
@getCFun libGL wglCreateLayerContext wglCreateLayerContext(hDc::HDC, level::Cint)::Ptr{Void}
export wglCreateLayerContext
@getCFun libGL wglDescribeLayerPlane wglDescribeLayerPlane(hDc::HDC, pixelFormat::Cint, layerPlane::Cint, nBytes::Cuint, plpd::LAYERPLANEDESCRIPTOR)::Cint
export wglDescribeLayerPlane
@getCFun libGL wglSetLayerPaletteEntries wglSetLayerPaletteEntries(hdc::HDC, iLayerPlane::Cint, iStart::Cint, cEntries::Cint, pcr::COLORREF)::Cint
export wglSetLayerPaletteEntries
@getCFun libGL wglGetLayerPaletteEntries wglGetLayerPaletteEntries(hdc::HDC, iLayerPlane::Cint, iStart::Cint, cEntries::Cint, pcr::COLORREF)::Cint
export wglGetLayerPaletteEntries
@getCFun libGL wglRealizeLayerPalette wglRealizeLayerPalette(hdc::HDC, iLayerPlane::Cint, bRealize::Bool)::Cint
export wglRealizeLayerPalette
@getCFun libGL wglSwapLayerBuffers wglSwapLayerBuffers(hdc::HDC, fuFlags::Cuint)::Cint
export wglSwapLayerBuffers
@getCFun libGL wglUseFontBitmapsA wglUseFontBitmapsA(hDC::HDC, first::DWORD, count::DWORD, listBase::DWORD)::Cint
export wglUseFontBitmapsA
@getCFun libGL wglUseFontBitmapsW wglUseFontBitmapsW(hDC::HDC, first::DWORD, count::DWORD, listBase::DWORD)::Cint
export wglUseFontBitmapsW

end