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

struct PolicyV1beta1Api <: SwaggerApi
    client::Swagger.Client
end

"""

create a PodDisruptionBudget
Param: namespace::String (required)
Param: body::IoK8sApiPolicyV1beta1PodDisruptionBudget (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function createPolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, namespace::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "POST", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

create a PodSecurityPolicy
Param: body::IoK8sApiPolicyV1beta1PodSecurityPolicy (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Return: IoK8sApiPolicyV1beta1PodSecurityPolicy
"""
function createPolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "POST", IoK8sApiPolicyV1beta1PodSecurityPolicy, "/apis/policy/v1beta1/podsecuritypolicies", ["BearerToken"], body)
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

delete collection of PodDisruptionBudget
Param: namespace::String (required)
Param: pretty::String
Param: allowWatchBookmarks::Bool
Param: body::IoK8sApimachineryPkgApisMetaV1DeleteOptions
Param: __continue__::String
Param: dryRun::String
Param: fieldSelector::String
Param: gracePeriodSeconds::Int32
Param: labelSelector::String
Param: limit::Int32
Param: orphanDependents::Bool
Param: propagationPolicy::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1Status
"""
function deletePolicyV1beta1CollectionNamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, namespace::String; pretty=nothing, allowWatchBookmarks=nothing, body=nothing, __continue__=nothing, dryRun=nothing, fieldSelector=nothing, gracePeriodSeconds=nothing, labelSelector=nothing, limit=nothing, orphanDependents=nothing, propagationPolicy=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "DELETE", IoK8sApimachineryPkgApisMetaV1Status, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "gracePeriodSeconds", gracePeriodSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "orphanDependents", orphanDependents)  # type Bool
    Swagger.set_param(_ctx.query, "propagationPolicy", propagationPolicy)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

delete collection of PodSecurityPolicy
Param: pretty::String
Param: allowWatchBookmarks::Bool
Param: body::IoK8sApimachineryPkgApisMetaV1DeleteOptions
Param: __continue__::String
Param: dryRun::String
Param: fieldSelector::String
Param: gracePeriodSeconds::Int32
Param: labelSelector::String
Param: limit::Int32
Param: orphanDependents::Bool
Param: propagationPolicy::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1Status
"""
function deletePolicyV1beta1CollectionPodSecurityPolicy(_api::PolicyV1beta1Api; pretty=nothing, allowWatchBookmarks=nothing, body=nothing, __continue__=nothing, dryRun=nothing, fieldSelector=nothing, gracePeriodSeconds=nothing, labelSelector=nothing, limit=nothing, orphanDependents=nothing, propagationPolicy=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "DELETE", IoK8sApimachineryPkgApisMetaV1Status, "/apis/policy/v1beta1/podsecuritypolicies", ["BearerToken"], body)
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "gracePeriodSeconds", gracePeriodSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "orphanDependents", orphanDependents)  # type Bool
    Swagger.set_param(_ctx.query, "propagationPolicy", propagationPolicy)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

delete a PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: pretty::String
Param: body::IoK8sApimachineryPkgApisMetaV1DeleteOptions
Param: dryRun::String
Param: gracePeriodSeconds::Int32
Param: orphanDependents::Bool
Param: propagationPolicy::String
Return: IoK8sApimachineryPkgApisMetaV1Status
"""
function deletePolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, name::String, namespace::String; pretty=nothing, body=nothing, dryRun=nothing, gracePeriodSeconds=nothing, orphanDependents=nothing, propagationPolicy=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "DELETE", IoK8sApimachineryPkgApisMetaV1Status, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "gracePeriodSeconds", gracePeriodSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "orphanDependents", orphanDependents)  # type Bool
    Swagger.set_param(_ctx.query, "propagationPolicy", propagationPolicy)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

delete a PodSecurityPolicy
Param: name::String (required)
Param: pretty::String
Param: body::IoK8sApimachineryPkgApisMetaV1DeleteOptions
Param: dryRun::String
Param: gracePeriodSeconds::Int32
Param: orphanDependents::Bool
Param: propagationPolicy::String
Return: IoK8sApimachineryPkgApisMetaV1Status
"""
function deletePolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, name::String; pretty=nothing, body=nothing, dryRun=nothing, gracePeriodSeconds=nothing, orphanDependents=nothing, propagationPolicy=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "DELETE", IoK8sApimachineryPkgApisMetaV1Status, "/apis/policy/v1beta1/podsecuritypolicies/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "gracePeriodSeconds", gracePeriodSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "orphanDependents", orphanDependents)  # type Bool
    Swagger.set_param(_ctx.query, "propagationPolicy", propagationPolicy)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

get available resources
Return: IoK8sApimachineryPkgApisMetaV1APIResourceList
"""
function getPolicyV1beta1APIResources(_api::PolicyV1beta1Api; _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1APIResourceList, "/apis/policy/v1beta1/", ["BearerToken"])
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

list or watch objects of kind PodDisruptionBudget
Param: namespace::String (required)
Param: pretty::String
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApiPolicyV1beta1PodDisruptionBudgetList
"""
function listPolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, namespace::String; pretty=nothing, allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodDisruptionBudgetList, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets", ["BearerToken"])
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

list or watch objects of kind PodDisruptionBudget
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApiPolicyV1beta1PodDisruptionBudgetList
"""
function listPolicyV1beta1PodDisruptionBudgetForAllNamespaces(_api::PolicyV1beta1Api; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodDisruptionBudgetList, "/apis/policy/v1beta1/poddisruptionbudgets", ["BearerToken"])
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

list or watch objects of kind PodSecurityPolicy
Param: pretty::String
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApiPolicyV1beta1PodSecurityPolicyList
"""
function listPolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api; pretty=nothing, allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodSecurityPolicyList, "/apis/policy/v1beta1/podsecuritypolicies", ["BearerToken"])
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

partially update the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: body::IoK8sApimachineryPkgApisMetaV1Patch (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Param: force::Bool
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function patchPolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, name::String, namespace::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, force=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PATCH", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_param(_ctx.query, "force", force)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json-patch+json", "application/merge-patch+json", "application/strategic-merge-patch+json", "application/apply-patch+yaml"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

partially update status of the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: body::IoK8sApimachineryPkgApisMetaV1Patch (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Param: force::Bool
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function patchPolicyV1beta1NamespacedPodDisruptionBudgetStatus(_api::PolicyV1beta1Api, name::String, namespace::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, force=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PATCH", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}/status", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_param(_ctx.query, "force", force)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json-patch+json", "application/merge-patch+json", "application/strategic-merge-patch+json", "application/apply-patch+yaml"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

partially update the specified PodSecurityPolicy
Param: name::String (required)
Param: body::IoK8sApimachineryPkgApisMetaV1Patch (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Param: force::Bool
Return: IoK8sApiPolicyV1beta1PodSecurityPolicy
"""
function patchPolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, name::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, force=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PATCH", IoK8sApiPolicyV1beta1PodSecurityPolicy, "/apis/policy/v1beta1/podsecuritypolicies/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_param(_ctx.query, "force", force)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json-patch+json", "application/merge-patch+json", "application/strategic-merge-patch+json", "application/apply-patch+yaml"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

read the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: pretty::String
Param: exact::Bool
Param: __export__::Bool
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function readPolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, name::String, namespace::String; pretty=nothing, exact=nothing, __export__=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}", ["BearerToken"])
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "exact", exact)  # type Bool
    Swagger.set_param(_ctx.query, "export", __export__)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

read status of the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: pretty::String
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function readPolicyV1beta1NamespacedPodDisruptionBudgetStatus(_api::PolicyV1beta1Api, name::String, namespace::String; pretty=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}/status", ["BearerToken"])
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

read the specified PodSecurityPolicy
Param: name::String (required)
Param: pretty::String
Param: exact::Bool
Param: __export__::Bool
Return: IoK8sApiPolicyV1beta1PodSecurityPolicy
"""
function readPolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, name::String; pretty=nothing, exact=nothing, __export__=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApiPolicyV1beta1PodSecurityPolicy, "/apis/policy/v1beta1/podsecuritypolicies/{name}", ["BearerToken"])
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "exact", exact)  # type Bool
    Swagger.set_param(_ctx.query, "export", __export__)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

replace the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: body::IoK8sApiPolicyV1beta1PodDisruptionBudget (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function replacePolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, name::String, namespace::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PUT", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

replace status of the specified PodDisruptionBudget
Param: name::String (required)
Param: namespace::String (required)
Param: body::IoK8sApiPolicyV1beta1PodDisruptionBudget (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Return: IoK8sApiPolicyV1beta1PodDisruptionBudget
"""
function replacePolicyV1beta1NamespacedPodDisruptionBudgetStatus(_api::PolicyV1beta1Api, name::String, namespace::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PUT", IoK8sApiPolicyV1beta1PodDisruptionBudget, "/apis/policy/v1beta1/namespaces/{namespace}/poddisruptionbudgets/{name}/status", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

replace the specified PodSecurityPolicy
Param: name::String (required)
Param: body::IoK8sApiPolicyV1beta1PodSecurityPolicy (required)
Param: pretty::String
Param: dryRun::String
Param: fieldManager::String
Return: IoK8sApiPolicyV1beta1PodSecurityPolicy
"""
function replacePolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, name::String, body; pretty=nothing, dryRun=nothing, fieldManager=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "PUT", IoK8sApiPolicyV1beta1PodSecurityPolicy, "/apis/policy/v1beta1/podsecuritypolicies/{name}", ["BearerToken"], body)
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "dryRun", dryRun)  # type String
    Swagger.set_param(_ctx.query, "fieldManager", fieldManager)  # type String
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

watch changes to an object of kind PodDisruptionBudget. deprecated: use the 'watch' parameter with a list operation instead, filtered to a single item with the 'fieldSelector' parameter.
Param: name::String (required)
Param: namespace::String (required)
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1WatchEvent
"""
function watchPolicyV1beta1NamespacedPodDisruptionBudget(_api::PolicyV1beta1Api, name::String, namespace::String; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1WatchEvent, "/apis/policy/v1beta1/watch/namespaces/{namespace}/poddisruptionbudgets/{name}", ["BearerToken"])
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

watch individual changes to a list of PodDisruptionBudget. deprecated: use the 'watch' parameter with a list operation instead.
Param: namespace::String (required)
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1WatchEvent
"""
function watchPolicyV1beta1NamespacedPodDisruptionBudgetList(_api::PolicyV1beta1Api, namespace::String; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1WatchEvent, "/apis/policy/v1beta1/watch/namespaces/{namespace}/poddisruptionbudgets", ["BearerToken"])
    Swagger.set_param(_ctx.path, "namespace", namespace)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

watch individual changes to a list of PodDisruptionBudget. deprecated: use the 'watch' parameter with a list operation instead.
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1WatchEvent
"""
function watchPolicyV1beta1PodDisruptionBudgetListForAllNamespaces(_api::PolicyV1beta1Api; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1WatchEvent, "/apis/policy/v1beta1/watch/poddisruptionbudgets", ["BearerToken"])
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

watch changes to an object of kind PodSecurityPolicy. deprecated: use the 'watch' parameter with a list operation instead, filtered to a single item with the 'fieldSelector' parameter.
Param: name::String (required)
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1WatchEvent
"""
function watchPolicyV1beta1PodSecurityPolicy(_api::PolicyV1beta1Api, name::String; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1WatchEvent, "/apis/policy/v1beta1/watch/podsecuritypolicies/{name}", ["BearerToken"])
    Swagger.set_param(_ctx.path, "name", name)  # type String
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

"""

watch individual changes to a list of PodSecurityPolicy. deprecated: use the 'watch' parameter with a list operation instead.
Param: allowWatchBookmarks::Bool
Param: __continue__::String
Param: fieldSelector::String
Param: labelSelector::String
Param: limit::Int32
Param: pretty::String
Param: resourceVersion::String
Param: timeoutSeconds::Int32
Param: watch::Bool
Return: IoK8sApimachineryPkgApisMetaV1WatchEvent
"""
function watchPolicyV1beta1PodSecurityPolicyList(_api::PolicyV1beta1Api; allowWatchBookmarks=nothing, __continue__=nothing, fieldSelector=nothing, labelSelector=nothing, limit=nothing, pretty=nothing, resourceVersion=nothing, timeoutSeconds=nothing, watch=nothing, _mediaType=nothing)
    _ctx = Swagger.Ctx(_api.client, "GET", IoK8sApimachineryPkgApisMetaV1WatchEvent, "/apis/policy/v1beta1/watch/podsecuritypolicies", ["BearerToken"])
    Swagger.set_param(_ctx.query, "allowWatchBookmarks", allowWatchBookmarks)  # type Bool
    Swagger.set_param(_ctx.query, "continue", __continue__)  # type String
    Swagger.set_param(_ctx.query, "fieldSelector", fieldSelector)  # type String
    Swagger.set_param(_ctx.query, "labelSelector", labelSelector)  # type String
    Swagger.set_param(_ctx.query, "limit", limit)  # type Int32
    Swagger.set_param(_ctx.query, "pretty", pretty)  # type String
    Swagger.set_param(_ctx.query, "resourceVersion", resourceVersion)  # type String
    Swagger.set_param(_ctx.query, "timeoutSeconds", timeoutSeconds)  # type Int32
    Swagger.set_param(_ctx.query, "watch", watch)  # type Bool
    Swagger.set_header_accept(_ctx, ["application/json", "application/yaml", "application/vnd.kubernetes.protobuf", "application/json;stream=watch", "application/vnd.kubernetes.protobuf;stream=watch"])
    Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["*/*"] : [_mediaType])
    Swagger.exec(_ctx)
end

export createPolicyV1beta1NamespacedPodDisruptionBudget, createPolicyV1beta1PodSecurityPolicy, deletePolicyV1beta1CollectionNamespacedPodDisruptionBudget, deletePolicyV1beta1CollectionPodSecurityPolicy, deletePolicyV1beta1NamespacedPodDisruptionBudget, deletePolicyV1beta1PodSecurityPolicy, getPolicyV1beta1APIResources, listPolicyV1beta1NamespacedPodDisruptionBudget, listPolicyV1beta1PodDisruptionBudgetForAllNamespaces, listPolicyV1beta1PodSecurityPolicy, patchPolicyV1beta1NamespacedPodDisruptionBudget, patchPolicyV1beta1NamespacedPodDisruptionBudgetStatus, patchPolicyV1beta1PodSecurityPolicy, readPolicyV1beta1NamespacedPodDisruptionBudget, readPolicyV1beta1NamespacedPodDisruptionBudgetStatus, readPolicyV1beta1PodSecurityPolicy, replacePolicyV1beta1NamespacedPodDisruptionBudget, replacePolicyV1beta1NamespacedPodDisruptionBudgetStatus, replacePolicyV1beta1PodSecurityPolicy, watchPolicyV1beta1NamespacedPodDisruptionBudget, watchPolicyV1beta1NamespacedPodDisruptionBudgetList, watchPolicyV1beta1PodDisruptionBudgetListForAllNamespaces, watchPolicyV1beta1PodSecurityPolicy, watchPolicyV1beta1PodSecurityPolicyList


text:
module PolygenicRiskScores

## CSV parsing

using CSV
using DataFrames, DataFramesMeta
using Dates, Distributions, Statistics, Random, LinearAlgebra, Printf
using HDF5

include("parse_genet.jl")
include("gigrnd.jl")
include("mcmc_gtb.jl")

## argument parsing

using ArgParse

settings = ArgParseSettings()

@add_arg_table! settings begin
    "--ref_dir"
        help = "Path to the reference panel directory"
        required = true
    "--bim_prefix"
        help = "Directory and prefix of the bim file for the validation set"
        required = true
    "--sst_file"
        help = "Path to summary statistics file"
        required = true
    "--sst_missing"
        help = "Indicator for missing data in sumstats file (eg 'NA')"
        default = ""
    "--a"
        arg_type = Float64
        default = 1.0
    "--b"
        arg_type = Float64
        default = 0.5
    "--phi"
        arg_type = Float64
    "--n_gwas"
        help = "Sample size of the GWAS"
        arg_type = Int
        required = true
    "--n_iter"
        help = "Number of MCMC iterations to perform"
        arg_type = Int
        default = 1000
    "--n_burnin"
        help = "Number of MCMC burn-in iterations"
        arg_type = Int
        default = 500
    "--thin"
        arg_type = Int
        default = 5
    "--out_dir"
        help = "Output file directory and prefix"
        required = true
    "--out_header"
        help = "Write header to output file"
        action = :store_true
    "--out_delim"
        help = "Output file delimiter"
        default = '\t'
    "--out_path"
        help = "Output file path (overrides --out_dir)"
    "--chrom"
        help = "Chromosomes to process"
        default = "1:22"
    "--beta_std"
        action = :store_true
    "--seed"
        help = "RNG seed for MCMC"
        arg_type = Int
    "--quiet"
        help = "Disable all unnecessary printing"
        action = :store_true
    "--hostsfile"
        help = "Hostsfile to use for parallel processing"
        default = nothing
end

function main()
    opts = parse_args(ARGS, settings)
    verbose = !opts["quiet"]

    chroms = eval(Meta.parse(opts["chrom"]))
    verbose && @info "Selecting chromosomes $chroms"

    ref_dir = opts["ref_dir"]
    verbose && @info "Parsing reference file: $ref_dir/snpinfo_1kg_hm3"
    t = now()
    ref_df = parse_ref(ref_dir * "/snpinfo_1kg_hm3", chroms)
    verbose && @info "$(nrow(ref_df)) SNPs in reference file ($(round(now()-t, Dates.Second)))"

    bim_prefix = opts["bim_prefix"]
    verbose && @info "Parsing BIM file: $(bim_prefix*".bim")"
    t = now()
    vld_df = parse_bim(bim_prefix, chroms)
    verbose && @info "$(nrow(vld_df)) SNPs in BIM file ($(round(now()-t, Dates.Second)))"

    for chrom in chroms
        _main(chrom, ref_df, vld_df, opts; verbose=verbose)
    end
end
function _main(chrom, ref_df, vld_df, opts; verbose=false)
    sst_file = opts["sst_file"]
    verbose && @info "(Chromosome $chrom) Parsing summary statistics file: $sst_file"
    t = now()
    sst_df = parse_sumstats(ref_df[ref_df.CHR .== chrom,:], vld_df[vld_df.CHR .== chrom,:], sst_file, opts["n_gwas"]; verbose=verbose, missingstring=opts["sst_missing"])
    verbose && @info "(Chromosome $chrom) $(nrow(sst_df)) SNPs in summary statistics file ($(round(now()-t, Dates.Second)))"

    verbose && @info "(Chromosome $chrom) Parsing reference LD"
    t = now()
    ld_blk, blk_size = parse_ldblk(opts["ref_dir"], sst_df, chrom)
    verbose && @info "(Chromosome $chrom) Completed parsing reference LD ($(round(now()-t, Dates.Second)))"

    verbose && @info "(Chromosome $chrom) Initiating MCMC"
    t = now()
    beta_est = mcmc(opts["a"], opts["b"], opts["phi"], sst_df, opts["n_gwas"], ld_blk, blk_size, opts["n_iter"], opts["n_burnin"], opts["thin"], chrom, opts["beta_std"], opts["seed"]; verbose=verbose)
    verbose && @info "(Chromosome $chrom) Completed MCMC ($(round(now()-t, Dates.Second)))"

    verbose && @info "(Chromosome $chrom) Writing posterior effect sizes"
    eff_file = if opts["out_path"] === nothing
        out_path = opts["out_dir"]
        phi = opts["phi"]
        phi_str = phi === nothing ? "auto" : @sprintf("%1.0e", phi)
        out_path * @sprintf("_pst_eff_a%d_b%.1f_phi%s_chr%d.txt", opts["a"], opts["b"], phi_str, chrom)
    else
        opts["out_path"]
    end
    t = now()
    out_df = sst_df[:, [:SNP, :BP, :A1, :A2]]
    out_df[!, :CHR] .= chrom
    out_df.BETA = map(b->@sprintf("%.6e", b), beta_est)
    out_df = select(out_df, [:CHR, :SNP, :BP, :A1, :A2, :BETA])
    CSV.write(eff_file, out_df; header=opts["out_header"], delim=opts["out_delim"])
    verbose && @info "(Chromosome $chrom) finished writing posterior effect sizes ($(round(now()-t, Dates.Second)))"
end

end # module

ext: jl


text:
using JuMP, Gurobi

function tcm_estimateRanking(N, assortments, transaction_counts, time_limit_overall, perTol)
    M = size(assortments, 1)

	m_sub = Model(solver = GurobiSolver(OutputFlag = 0))
	@variable(m_sub, x[1:N,1:N], Bin)
	@variable(m_sub, a[1:M,1:N], Bin)

	# VVM - constraint below is not in van Ryzin and Vulcano, but maybe its needed?
	for m in 1:M
        @constraint(m_sub,sum( a[m,p1] for p1 in 1:N) == 1)
    end

	for m in 1:M
        for p1 in 1:N
            @constraint(m_sub,a[m,p1] <= assortments[m,p1])
            for p2 in 1:N
                if ( (p1 != p2) & (assortments[m,p1] == 1) & (assortments[m,p2] == 1) )
    	            @constraint(m_sub, a[m,p1] <= x[p1,p2])
                end
           end
        end
    end

    for p1 in 1:N
        for p2 in 1:N
            if p1 != p2
                @constraint(m_sub, x[p1,p2] + x[p2,p1] == 1)
            end
        end
    end

    for p1 in 1:N
        for p2 in 1:N
            for p3 in 1:N
                if ( (p1 != p2) & (p2 != p3) & (p1 != p3) )
                    @constraint(m_sub, x[p1,p2] + x[p2,p3] + x[p3,p1] <= 2)
                end
            end
        end
    end

    function solve_subproblem(u)
    	@objective(m_sub, Max, sum(u[m,p] * a[m,p] for m in 1:M, p in 1:N))
    	solve(m_sub)

    	x_val = getvalue(x)
    	objval = getobjectivevalue(m_sub)

    	single_ranking = sum(x_val, 2)
        single_ranking = single_ranking[:]
    	single_ordering = sortperm(single_ranking, rev = true)

    	return single_ordering, objval
    end

    time_limit_EM = 60.0

    start_time = time()

    K = N
    orderings = zeros(Int64, K, N)
    for k in 1:(N-1)
    	single_ordering = [k; N; collect(1:(k-1)); collect( (k+1):(N-1) )]
    	orderings[k,:] = single_ordering
    end
    orderings[N,:] = [N; collect(1:(N-1))]

    #
    initial_lambda = 1/K * ones(K)
    lambda, v, loglik, elapsed_time = tcm_ranking_EM(N, K, orderings, assortments, transaction_counts, time_limit_EM, initial_lambda)
	u = transaction_counts ./ v
    # if (any(isinf.(u)) | any(isnan.(u)))
    #     @show u
    #     @show lambda
    #     @show orderings
    #     error("Stop here - pre loop")
    # end
	u[ isinf.(u)] = 0.0
	u[ isnan.(u)] = 0.0

	#perTol = 1e-7
    iter = 0;

    #@show loglik
    println("CG iter ", iter, " -- time elapsed = ", 0.0, " log likelihood = ",loglik)

	while (time() - start_time < time_limit_overall)
        iter += 1

		u = transaction_counts ./ v
        # if (any(isinf.(u)) | any(isnan.(u)))
        #     @show u
        #     error("Stop here")
        # end
		u[ isinf.(u)] = 0.0
		u[ isnan.(u)] = 0.0
		single_ordering, objval = solve_subproblem(u)

		orderings = [orderings; single_ordering']
		K += 1

        initial_fudge = 0.999
        initial_lambda = [ initial_fudge*lambda; (1-initial_fudge)]
		lambda, v, new_loglik, elapsed_time = tcm_ranking_EM(N, K, orderings, assortments, transaction_counts, time_limit_EM, initial_lambda)

        println("CG iter ", iter, " -- time elapsed = ", time() - start_time, " log likelihood = ",new_loglik)

        if ( (new_loglik - loglik) / abs(loglik) < perTol )
        	temp = (new_loglik - loglik) / abs(loglik)
        	@show temp
        	@show new_loglik
        	@show loglik

        	loglik = new_loglik
			break
		end

        loglik = new_loglik
	end

	end_time = time()

	elapsed_time = end_time - start_time

	return lambda, orderings, loglik, elapsed_time
end

function tcm_ranking_EM(N, K, orderings, assortments, transaction_counts, time_limit_EM, initial_lambda)
	lambda = copy(initial_lambda); #1/K * ones(K)
    v, v_by_class = tcm_predictRanking(N, K, lambda, orderings, assortments)
    logv = log.(v)
    logv[ isinf.(logv)] = 0.0;
    loglik = dot( convert(Array{Float64,}, transaction_counts), logv)

    # @show v
    # @show loglik

	v = zeros(size(transaction_counts))

	perTol_EM = 1e-5
    iter = 0;

	start_time = time()

	while (time() - start_time < time_limit_EM)
		iter += 1;
		h, v, v_by_class = tcm_ranking_E(N, K, lambda, orderings, assortments)
        # @show lambda
		lambda = tcm_ranking_M_update_lambda(K, h, transaction_counts)

        # @show lambda

        # error("Stop here - EM loop")

		v, v_by_class = tcm_predictRanking(N, K, lambda, orderings, assortments)
		logv = log.(v)
		logv[ isinf.(logv)] = 0.0;
		new_loglik = dot( convert(Array{Float64,}, transaction_counts), logv)

		# println("\t Ranking EM: iter ", iter, " -- time elapsed = ", time() - start_time, " log likelihood = ", new_loglik)

	    if ( (new_loglik - loglik) / abs(loglik) < perTol_EM )
	    	temp = (new_loglik - loglik) / abs(loglik)
	    	# @show temp
	    	# @show new_loglik
	    	# @show loglik

	    	loglik = new_loglik
			break
		end

        # if (iter > 100)
        #     error("Stop here")
        # end

		loglik = new_loglik
	end

	elapsed_time = time() - start_time

	return lambda, v, loglik, elapsed_time

end

function tcm_ranking_M_update_lambda(K, h, transaction_counts)
	sum_of_h = zeros(K)

	for k in 1:K
		sum_of_h[k] = dot( h[k], convert(Array{Float64}, transaction_counts))
	end

	lambda = sum_of_h ./ sum(sum_of_h)

	return lambda
end

function tcm_ranking_E(N, K, lambda, orderings, assortments)
	v, v_by_class = tcm_predictRanking(N, K, lambda, orderings, assortments)

	h = Array{ Array{Float64,2}, 1}(K)
	for k in 1:K
		single_h = lambda[k] * v_by_class[k] ./ v
		single_h[ isnan.(single_h)] = 0.0;

		h[k] = single_h
	end

	return h, v, v_by_class
end

max_stars_repo_licenses: MIT Unlicense

max_issues_repo_licenses: MIT Unlicense

max_forks_repo_licenses: MIT Unlicense


text:
# The resulting polymer isn't nearly strong enough to reinforce the submarine.
# You'll need to run more steps of the pair insertion process; a total of 40
# steps should do it.
#
# In the above example, the most common element is B (occurring 2192039569602
# times) and the least common element is H (occurring 3849876073 times);
# subtracting these produces 2188189693529.
#
# Apply 40 steps of pair insertion to the polymer template and find the most
# and least common elements in the result. What do you get if you take the
# quantity of the most common element and subtract the quantity of the least
# common element?

const steps = 40

# read input
iter = eachline("input.txt")
(template, _) = iterate(iter)
iterate(iter) # blank line
rules = Dict([split(l, " -> ") for l in iter])

# Recursing will take forever. Instead, we're going to build from the bottom up
# - there are only 10 characters, so only 100 two letter combos. We can build a
# 100x10 matrix representing how many of each character will be added per two
# letter combo and build that up 40 times.
chars = unique(values(rules))
charidx = Dict([(c,i) for (i,c) in enumerate(chars)])
pairidx = Dict{String, Int}()
cnts = zeros(Int128, length(rules), length(chars))
for (i,(k,v)) in enumerate(rules)
  pairidx[k] = i
  cnts[i, charidx[v]] = 1
end

# for each step, take the two letter pair with the element it creates and find
# the sum of the characters from the two new pairs in the previous steps
temp = similar(cnts)
for _ in 2:steps
  global (cnts,temp) = (temp,cnts)
  for (k,v) in rules
    l = k[1] * v
    r = v * k[2]
    i = pairidx[k]
    cnts[i,:] = temp[pairidx[l],:] .+ temp[pairidx[r],:]
    cnts[i,charidx[v]] += 1
  end
end

# build final counts - iterate over (1,2), (2,3), ..., (len-1, len)
finalcnts = zeros(Int128, length(chars))
foreach(zip(1:(length(template)-1), 2:length(template))) do (i,j)
  finalcnts .+= cnts[pairidx[template[i:j]],:]
  finalcnts[charidx[template[i:i]]] += 1
end
finalcnts[charidx[template[end:end]]] += 1

println("Result: ", abs(-(extrema(finalcnts)...)))


text:
using Stheno, Plots, Random
using Stheno: @model

###########################  Define and inspect our model  ###########################

#=

=#
@model function model()
    g1, g2 = x::Real->sin(x), x::Real->x
    w1, w2 = GP(EQ()), GP(EQ())
    f = g1 * w1 + g2 * w2
    y = f + GP(Noise(0.001))
    return w1, w2, f, y
end

# Sample from the prior from plotting and for conditioning.
rng, N, Nplot, S = MersenneTwister(123456), 250, 500, 100;
X, Xp = sort(rand(rng, N) * 10), range(-2.5, stop=12.5, length=Nplot);
w1, w2, f, y = model();
w1s, w2s, fs, ŷ = rand(rng, [w1(Xp), w2(Xp), f(Xp), y(X)]);

# Compute posterior distribution over f′.
w1′, w2′, f′, y′ = (w1, w2, f, y) | (y(X) ← ŷ);

# Sample from the posterior and write to file.
# w1′s, w2′s, f′s = rand(rng, [w1′(Xp), w2′(Xp), f′(Xp)], S);
w1′s, w2′s, y′s = rand(rng, [w1′(Xp), w2′(Xp), y′(Xp)], S);

# Get posterior mean and marginals f′ and y′ and write them for plotting.
μw1′, σw1′ = marginals(w1′(Xp));
μw2′, σw2′ = marginals(w2′(Xp));
# μf′, σf′ = marginals(f′(Xp));
μy′, σy′ = marginals(y′(Xp));

###########################  Plot results - USE ONLY Julia-0.6!  ###########################

posterior_plot = plot();

# Plot samples against which we're regressing.
plot!(posterior_plot, X, ŷ;
    markercolor=:red,
    markershape=:circle,
    markerstrokewidth=0.0,
    markersize=4,
    markeralpha=0.7,
    label="");

# # Plot posterior over `f`.
# plot!(posterior_plot, Xp, μf′;
#     linecolor=:blue,
#     linewidth=2.0,
#     label="f");
# plot!(posterior_plot, Xp, [μf′ μf′];
#     linewidth=0.0,
#     fillrange=[μf′ .- 3 .* σf′, μf′ .+ 3 * σf′],
#     fillalpha=0.3,
#     fillcolor=:blue,
#     label="");
# plot!(posterior_plot, Xp, f′s;
#     linecolor=:blue,
#     linealpha=0.2,
#     label="");

# Plot posterior over `y`.
plot!(posterior_plot, Xp, μy′;
    linecolor=:blue,
    linewidth=2.0,
    label="y");
plot!(posterior_plot, Xp, [μy′ μy′];
    linewidth=0.0,
    fillrange=[μy′ .- 3 .* σy′, μy′ .+ 3 * σy′],
    fillalpha=0.3,
    fillcolor=:blue,
    label="");
plot!(posterior_plot, Xp, y′s;
    linecolor=:blue,
    linealpha=0.2,
    label="");

# Plot posterior over w1.
plot!(posterior_plot, Xp, μw1′;
    linecolor=:green,
    linewidth=2.0,
    label="w1");
plot!(posterior_plot, Xp, [μw1′ μw1′];
    linewidth=0.0,
    fillrange=[μw1′ .- 3 .* σw1′, μw1′ .+ 3 * σw1′],
    fillalpha=0.3,
    fillcolor=:green,
    label="");
plot!(posterior_plot, Xp, w1′s;
    linecolor=:green,
    linealpha=0.2,
    label="");

# Plot posterior over w2.
plot!(posterior_plot, Xp, μw2′;
    linecolor=:magenta,
    linewidth=2.0,
    label="w2");
plot!(posterior_plot, Xp, [μw2′ μw2′];
    linewidth=0.0,
    fillrange=[μw2′ .- 3 .* σw2′, μw2′ .+ 3 * σw2′],
    fillalpha=0.3,
    fillcolor=:magenta,
    label="");
plot!(posterior_plot, Xp, w2′s;
    linecolor=:magenta,
    linealpha=0.2,
    label="");

display(posterior_plot);


text:
module Iteration
    include("readinputfile.jl")
    include("shoot.jl")
    include("solve_tf.jl")
    using Printf
    using .Readinputfile
    using .Shoot
    using .Solve_TF

    function construct(opt)
        rif_val = Readinputfile.construct(opt.inpname, opt.usethread)
        data = Readinputfile.readfile(rif_val)

        dx = data.xmax / float(data.grid_num)

        shoot_val = Shoot.construct(dx, data)
        xarray, yarray = Shoot.shootf!(shoot_val)
        solve_tf_param, solve_tf_val = Solve_TF.construct(data, xarray, yarray)
        return data, solve_tf_param, solve_tf_val, yarray
    end

    getNormRD(newarray, oldarray, x) = let
        tmp = newarray .- oldarray
        return sqrt(sum(tmp .* tmp))
    end

    function iteration!(data, solve_tf_param, solve_tf_val, yarray)
        convergence_flag = false

        for iter in 0:data.iteration_maxiter - 1
            newyarray = Solve_TF.solvetf!(solve_tf_param, solve_tf_val, yarray)
            normrd = getNormRD(newyarray, yarray, solve_tf_val.node_x_glo)

            @printf("Iteration # %d: NormRD = %.15f\n", iter + 1, normrd)
            if normrd <= data.iteration_criterion
                convergence_flag = true
                break
            end

            yarray = simple_mixing(data, newyarray, yarray)
        end

        if convergence_flag
            @printf("計算が収束しました．\n")
        else
            @printf("計算が収束しませんでした．プログラムを終了します．\n")
            exit(1)
        end

        return solve_tf_val.node_x_glo
    end

    simple_mixing(data, newarray, oldarray) = let
        return data.iteration_mixing_weight .* newarray .+ (1.0 - data.iteration_mixing_weight) .* oldarray
    end
end


text:
@cache struct EulerCache{uType,rateType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  tmp::uType
  k::rateType
  fsalfirst::rateType
end

@cache struct SplitEulerCache{uType,rateType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  tmp::uType
  k::rateType
  fsalfirst::rateType
end

function alg_cache(alg::SplitEuler,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  SplitEulerCache(u,uprev,zero(u),zero(rate_prototype),zero(rate_prototype))
end

struct SplitEulerConstantCache <: OrdinaryDiffEqConstantCache end

alg_cache(alg::SplitEuler,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = SplitEulerConstantCache()

function alg_cache(alg::Euler,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  EulerCache(u,uprev,zero(u),zero(rate_prototype),zero(rate_prototype))
end

struct EulerConstantCache <: OrdinaryDiffEqConstantCache end

alg_cache(alg::Euler,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = EulerConstantCache()

@cache struct HeunCache{uType,rateType,uNoUnitsType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  tmp::uType
  atmp::uNoUnitsType
  k::rateType
  fsalfirst::rateType
end

@cache struct RalstonCache{uType,rateType,uNoUnitsType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  tmp::uType
  atmp::uNoUnitsType
  k::rateType
  fsalfirst::rateType
end

function alg_cache(alg::Heun,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  atmp = similar(u, uEltypeNoUnits); recursivefill!(atmp,false)
  HeunCache(u,uprev,zero(u),atmp,zero(rate_prototype),
            zero(rate_prototype))
end

function alg_cache(alg::Ralston,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  atmp = similar(u, uEltypeNoUnits); recursivefill!(atmp,false)
  RalstonCache(u,uprev,zero(u),atmp,zero(rate_prototype),
               zero(rate_prototype))
end

struct HeunConstantCache <: OrdinaryDiffEqConstantCache end

alg_cache(alg::Heun,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = HeunConstantCache()

struct RalstonConstantCache <: OrdinaryDiffEqConstantCache end

alg_cache(alg::Ralston,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = RalstonConstantCache()

@cache struct MidpointCache{uType,rateType,uNoUnitsType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k::rateType
  tmp::uType
  atmp::uNoUnitsType
  fsalfirst::rateType
end

struct MidpointConstantCache <: OrdinaryDiffEqConstantCache end

function alg_cache(alg::Midpoint,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tmp = zero(u); atmp = similar(u, uEltypeNoUnits); recursivefill!(atmp,false)
  k = zero(rate_prototype)
  fsalfirst = zero(rate_prototype)
  MidpointCache(u,uprev,k,tmp,atmp,fsalfirst)
end

alg_cache(alg::Midpoint,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = MidpointConstantCache()

@cache struct RK4Cache{uType,rateType,uNoUnitsType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  fsalfirst::rateType
  k₂::rateType
  k₃::rateType
  k₄::rateType
  k::rateType
  tmp::uType
  atmp::uNoUnitsType
end

struct RK4ConstantCache <: OrdinaryDiffEqConstantCache end

function alg_cache(alg::RK4,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  k₁ = zero(rate_prototype)
  k₂ = zero(rate_prototype)
  k₃ = zero(rate_prototype)
  k₄ = zero(rate_prototype)
  k  = zero(rate_prototype)
  tmp = zero(u); atmp = similar(u, uEltypeNoUnits); recursivefill!(atmp,false)
  RK4Cache(u,uprev,k₁,k₂,k₃,k₄,k,tmp,atmp)
end

alg_cache(alg::RK4,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = RK4ConstantCache()

@cache struct BS3Cache{uType,rateType,uNoUnitsType,TabType,StageLimiter,StepLimiter,Thread} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  fsalfirst::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
  stage_limiter!::StageLimiter
  step_limiter!::StepLimiter
  thread::Thread
end

function alg_cache(alg::BS3,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = BS3ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  BS3Cache(u,uprev,k1,k2,k3,k4,utilde,tmp,atmp,tab,alg.stage_limiter!,alg.step_limiter!,alg.thread)
end

alg_cache(alg::BS3,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = BS3ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct OwrenZen3Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::OwrenZen3,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = OwrenZen3ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  OwrenZen3Cache(u,uprev,k1,k2,k3,k4,utilde,tmp,atmp,tab)
end

alg_cache(alg::OwrenZen3,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = OwrenZen3ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct OwrenZen4Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::OwrenZen4,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = OwrenZen4ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  OwrenZen4Cache(u,uprev,k1,k2,k3,k4,k5,k6,utilde,tmp,atmp,tab)
end

alg_cache(alg::OwrenZen4,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = OwrenZen4ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct OwrenZen5Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  k8::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::OwrenZen5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = OwrenZen5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  k8 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  OwrenZen5Cache(u,uprev,k1,k2,k3,k4,k5,k6,k7,k8,utilde,tmp,atmp,tab)
end

alg_cache(alg::OwrenZen5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = OwrenZen5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct BS5Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  k8::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::BS5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = BS5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  k8 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  BS5Cache(u,uprev,k1,k2,k3,k4,k5,k6,k7,k8,utilde,tmp,atmp,tab)
end

alg_cache(alg::BS5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = BS5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct Tsit5Cache{uType,rateType,uNoUnitsType,TabType,StageLimiter,StepLimiter,Thread} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
  stage_limiter!::StageLimiter
  step_limiter!::StepLimiter
  thread::Thread
end

@cache struct RK46NLCache{uType,rateType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k::rateType
  tmp::uType
  fsalfirst::rateType
  tab::TabType
end

struct RK46NLConstantCache{T,T2} <: OrdinaryDiffEqConstantCache
  α2::T
  α3::T
  α4::T
  α5::T
  α6::T
  β1::T
  β2::T
  β3::T
  β4::T
  β5::T
  β6::T
  c2::T2
  c3::T2
  c4::T2
  c5::T2
  c6::T2

  function RK46NLConstantCache(T, T2)
    α2 = T(-0.737101392796)
    α3 = T(-1.634740794343)
    α4 = T(-0.744739003780)
    α5 = T(-1.469897351522)
    α6 = T(-2.813971388035)
    β1 = T(0.032918605146)
    β2 = T(0.823256998200)
    β3 = T(0.381530948900)
    β4 = T(0.200092213184)
    β5 = T(1.718581042715)
    β6 = T(0.27)
    c2 = T2(0.032918605146)
    c3 = T2(0.249351723343)
    c4 = T2(0.466911705055)
    c5 = T2(0.582030414044)
    c6 = T2(0.847252983783)
    new{T,T2}(α2, α3, α4, α5, α6, β1, β2, β3, β4, β5, β6, c2, c3, c4, c5, c6)
  end
end

function alg_cache(alg::RK46NL,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tmp = zero(u)
  k = zero(rate_prototype)
  fsalfirst = zero(rate_prototype)
  tab = RK46NLConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits))
  RK46NLCache(u,uprev,k,tmp,fsalfirst,tab)
end

function alg_cache(alg::RK46NL,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  RK46NLConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits))
end

function alg_cache(alg::Tsit5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = Tsit5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  Tsit5Cache(u,uprev,k1,k2,k3,k4,k5,k6,k7,utilde,tmp,atmp,tab,alg.stage_limiter!,alg.step_limiter!,alg.thread)
end

alg_cache(alg::Tsit5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = Tsit5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct DP5Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  dense_tmp3::rateType
  dense_tmp4::rateType
  update::rateType
  bspl::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::DP5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = k2
  k7 = zero(rate_prototype) # This is FSAL'd to k1
  dense_tmp3 = k2
  dense_tmp4 = k5
  bspl = k3

  tmp = zero(u) # has to be separate for FSAL
  utilde = tmp

  if eltype(u) != uEltypeNoUnits || calck
    update = zero(rate_prototype)
    atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  else
    update = k7
    atmp = k3
  end

  tab = DP5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  cache = DP5Cache(u,uprev,k1,k2,k3,k4,k5,k6,k7,dense_tmp3,dense_tmp4,update,bspl,utilde,tmp,atmp,tab)
  cache
end

alg_cache(alg::DP5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = DP5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct Anas5Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  utilde::uType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

function alg_cache(alg::Anas5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = Anas5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  Anas5Cache(u,uprev,k1,k2,k3,k4,k5,k6,k7,utilde,tmp,atmp,tab)
end

alg_cache(alg::Anas5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = Anas5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

@cache struct KYK2014DGSSPRK_3S2_Cache{uType,rateType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k::rateType
  fsalfirst::rateType
  tab::TabType
  #temporary values for Shu-Osher
  u_1::uType
  u_2::uType
  kk_1::rateType
  kk_2::rateType
end

struct KYK2014DGSSPRK_3S2_ConstantCache{T,T2} <: OrdinaryDiffEqConstantCache
  #These are not α and β for RK but for Shu-Osher
  #see top of page 317 in
  #Optimal Strong-Stability-Preserving Runge–Kutta Time Discretizations for
  #Discontinuous Garlekin Methods, Kubatko, Yaeger, Ketcheson 2014
  α_10::T
  α_20::T
  α_21::T
  α_30::T
  α_32::T
  β_10::T
  β_21::T
  β_30::T
  β_32::T
  #Shu-Osher is normally stated for autonomous systems, the times
  #are calculated by hand for this scheme
  c_1::T
  c_2::T

  function KYK2014DGSSPRK_3S2_ConstantCache(T, T2)
    α_10 = T(1.0)
    α_20 = T(0.087353119859156)
    α_21 = T(0.912646880140844)
    α_30 = T(0.344956917166841)
    α_32 = T(0.655043082833159)
    β_10 = T(0.528005024856522)
    β_21 = T(0.481882138633993)
    β_30 = T(0.022826837460491)
    β_32 = T(0.345866039233415)
    c_1 = β_10
    c_2 = α_21 * β_10 + β_21 # ==0.96376427726
    new{T,T2}(α_10, α_20, α_21, α_30, α_32, β_10, β_21, β_30, β_32, c_1, c_2)
  end
end

function alg_cache(alg::KYK2014DGSSPRK_3S2,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  u_1 = zero(u)
  u_2 = zero(u)
  kk_1 = zero(rate_prototype)
  kk_2 = zero(rate_prototype)
  k = zero(rate_prototype)
  fsalfirst = zero(rate_prototype)
  tab = KYK2014DGSSPRK_3S2_ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits))
  KYK2014DGSSPRK_3S2_Cache(u,uprev,k,fsalfirst,tab, u_1, u_2, kk_1, kk_2)
end

function alg_cache(alg::KYK2014DGSSPRK_3S2,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  KYK2014DGSSPRK_3S2_ConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits))
end

@cache struct RKO65Cache{uType,rateType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k::rateType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  tmp::uType
  fsalfirst::rateType
  tab::TabType
end

u_cache(c::RKO65Cache) = ()
du_cache(c::RKO65Cache) = (c.k,c.du,c.fsalfirst)

struct RKO65ConstantCache{T1,T2} <: OrdinaryDiffEqConstantCache
  α21::T1
  α31::T1
  α41::T1
  α51::T1

  α32::T1
  α42::T1
  α52::T1
  α62::T1

  α43::T1
  α53::T1
  α63::T1

  α54::T1
  α64::T1

  α65::T1

  β2::T1
  β3::T1
  β4::T1
  β5::T1
  β6::T1

  c1::T2
  c2::T2
  c3::T2
  c4::T2
  c5::T2
  c6::T2

  function RKO65ConstantCache(T1,T2)
    # elements of Butcher Table
    α21 = T1(1//6)
    α31 = T1(-15//8)
    α41 = T1(-9//1)
    α51 = T1(-3//1)

    α32 = T1(21//8)
    α42 = T1(75//7)
    α52 = T1(34257//8750)
    α62 = T1(123//380)

    α43 = T1(-5//7)
    α53 = T1(-114//875)
    α63 = T1(5//2)

    α54 = T1(19//1250)
    α64 = T1(3//20)

    α65 = T1(-75//38)

    β2 = T1(54//133)
    β3 = T1(32//21)
    β4 = T1(1//18)
    β5 = T1(-125//114)
    β6 = T1(1//9)

    c1 = T2(2//3)
    c2 = T2(1//6)
    c3 = T2(3//4)
    c4 = T2(1//1)
    c5 = T2(4//5)
    c6 = T2(1//1)
    new{T1,T2}(α21, α31, α41, α51, α32, α42, α52, α62, α43, α53, α63, α54, α64, α65, β2, β3, β4, β5, β6, c1, c2, c3, c4, c5, c6)
  end
end

function alg_cache(alg::RKO65,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  RKO65ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits)) # why not real(tTypeNoUnits)?
end

function alg_cache(alg::RKO65,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}

  tmp = zero(u)

  k = zero(rate_prototype)
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)

  fsalfirst = zero(rate_prototype)

  tab = RKO65ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  RKO65Cache(u,uprev,k, k1,k2,k3,k4,k5,k6, tmp, fsalfirst, tab)
end

@cache struct FRK65Cache{uType,rateType,uNoUnitsType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  utilde::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  k8::rateType
  k9::rateType
  tmp::uType
  atmp::uNoUnitsType
  tab::TabType
end

struct FRK65ConstantCache{T1,T2} <: OrdinaryDiffEqConstantCache

  α21::T1
  α31::T1
  α41::T1
  α51::T1
  α61::T1
  α71::T1
  α81::T1
  α91::T1

  α32::T1

  α43::T1
  α53::T1
  α63::T1
  α73::T1
  α83::T1

  α54::T1
  α64::T1
  α74::T1
  α84::T1
  α94::T1

  α65::T1
  α75::T1
  α85::T1
  α95::T1

  α76::T1
  α86::T1
  α96::T1

  α87::T1
  α97::T1

  α98::T1

  β1::T1
  # β4::T1
  # β5::T1
  # β6::T1
  β7::T1
  β8::T1

  β1tilde::T1
  β4tilde::T1
  β5tilde::T1
  β6tilde::T1
  β7tilde::T1
  β8tilde::T1
  β9tilde::T1

  c2::T2
  c3::T2
  c4::T2
  c5::T2
  c6::T2
  c7::T2
  c8::T2
  c9::T2

  d1::T1
  d2::T1
  d3::T1
  d4::T1
  d5::T1
  d6::T1
  d7::T1
  d8::T1
  d9::T1
  d10::T1
  d11::T1
  d12::T1
  d13::T1

  e1::T1
  e2::T1
  e3::T1
  e4::T1
  e5::T1
  e6::T1
  e7::T1
  e8::T1
  e9::T1
  e10::T1
  e11::T1

  f1::T1
  f2::T1
  f3::T1
  f4::T1
  f5::T1
  f6::T1
  f7::T1
  f8::T1
  f9::T1
  f10::T1
  f11::T1

  function FRK65ConstantCache(T1,T2)

    # elements of Butcher Table
    α21 = T1(1//89)
    α31 = T1(-38624//142129)
    α41 = T1(51//1508)
    α51 = T1(3259284578//3517556363)
    α61 = T1(-108363632681//45875676369)
    α71 = T1(7137368591//11299833148)
    α81 = T1(8898824396//9828950919)
    α91 = T1(1026331676//33222204855)

    α32 = T1(51442//142129)

    α43 = T1(153//1508)
    α53 = T1(-69727055112//19553806387)
    α63 = T1(80902506271//8700424616)
    α73 = T1(-33088067061//10572251159)
    α83 = T1(25673454973//11497947835)

    α54 = T1(36230363390//11788838981)
    α64 = T1(-120088218786//17139312481)
    α74 = T1(11481363823//3650030081)
    α84 = T1(-74239028301//15737704666)
    α94 = T1(1450675392//5936579813)

    α65 = T1(4533285649//6676940598)
    α75 = T1(-4096673444//7349814937)
    α85 = T1(222688842816//44196813415)
    α95 = T1(4617877550//16762182457)

    α76 = T1(9911918171//12847192605)
    α86 = T1(-105204445705//30575217706)
    α96 = T1(1144867463//6520294355)

    α87 = T1(8799291910//8966990271)
    α97 = T1(1822809703//7599996644)

    α98 = T1(79524953//2351253316)

    β1 = T1(1026331676//33222204855)
    #β4 = T1(1450675392//5936579813)
    #β5 = T1(4617877550//16762182457)
    #β6 = T1(1144867463//6520294355)
    β7 = T1(1822809703//7599996644)
    β8 = T1(79524953//2351253316)

    β1tilde = T1(413034411//13925408836)
    β4tilde = T1(1865954212//7538591735)
    β5tilde = T1(4451980162//16576017119)
    β6tilde = T1(1157843020//6320223511)
    β7tilde = T1(802708729//3404369569)
    β8tilde = T1(-251398161//17050111121)
    β9tilde = T1(1//20)

    c2 = T2(1//89)
    c3 = T2(34//377)
    c4 = T2(51//377)
    c5 = T2(14497158//33407747)
    c6 = T2(9744566553//16002998914)
    c7 = T2(330//383)
    c8 = T2(1//1)
    c9 = T2(1//1)

    d1 = T1(140209127//573775965)
    d2 = T1(-8530039//263747097)
    d3 = T1(-308551//104235790)
    d4 = T1(233511//333733259)
    d5 = T1(9126//184950985)
    d6 = T1(22//50434083)
    d7 = T1(19//424427471)
    d8 = T1(-28711//583216934059)
    d9 = T1(-3831531//316297807)
    d10 = T1(551767//187698280)
    d11 = T1(9205//210998423)
    d12 = T1(-250//519462673)
    d13 = T1(67//327513887)

    e1=T1(437217689//1587032700)
    e2=T1(-15824413//592362279)
    e3=T1(-1563775//341846569)
    e4=T1(270497//369611210)
    e5=T1(-26623//453099487)
    e6=T1(-616297487849)
    e7=T1(-47682337//491732789)
    e8=T1(-4778275//287766311)
    e9=T1(641177//265376522)
    e10=T1(44633//291742143)
    e11=T1(611//223639880)

    f1=T1(44861261//255495624)
    f2=T1(-11270940//352635157)
    f3=T1(-182222//232874507)
    f4=T1(164263//307215200)
    f5=T1(32184//652060417)
    f6=T1(-352//171021903)
    f7=T1(-18395427//101056291)
    f8=T1(-621686//139501937)
    f9=T1(2030024//612171255)
    f10=T1(-711049//7105160932)
    f11=T1(267//333462710)

    new{T1,T2}(α21, α31, α41, α51, α61, α71, α81, α91, α32, α43, α53, α63, α73, α83, α54, α64, α74, α84, α94, α65, α75, α85, α95, α76, α86, α96, α87, α97, α98, β1, β7, β8, β1tilde, β4tilde, β5tilde, β6tilde, β7tilde, β8tilde, β9tilde, c2, c3, c4, c5, c6, c7, c8, c9, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11)
  end
end

alg_cache(alg::FRK65,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = FRK65ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

function alg_cache(alg::FRK65,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = FRK65ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  k8 = zero(rate_prototype)
  k9 = zero(rate_prototype)
  utilde = zero(u)
  atmp = similar(u,uEltypeNoUnits); recursivefill!(atmp,false)
  tmp = zero(u)
  FRK65Cache(u, uprev, utilde, k1, k2, k3, k4, k5, k6, k7, k8, k9, tmp, atmp, tab)
end

@cache struct RKMCache{uType,rateType,TabType} <: OrdinaryDiffEqMutableCache
  u::uType
  uprev::uType
  k::rateType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  tmp::uType
  fsalfirst::rateType
  tab::TabType
end

struct RKMConstantCache{T,T2} <: OrdinaryDiffEqConstantCache
  α2::T
  α3::T
  α4::T
  α5::T
  α6::T
  β1::T
  β2::T
  β3::T
  β4::T
  β6::T
  c2::T2
  c3::T2
  c4::T2
  c5::T2
  c6::T2

  function RKMConstantCache(::Type{T}, ::Type{T2}) where {T,T2}
    # α2 = T(0.16791846623918)
    # α3 = T(0.48298439719700)
    # α4 = T(0.70546072965982)
    # α5 = T(0.09295870406537)
    # α6 = T(0.76210081248836)
    # β1 = T(-0.15108370762927)
    # β2 = T(0.75384683913851)
    # β3 = T(-0.36016595357907)
    # β4 = T(0.52696773139913)
    # β6 = T(0.23043509067071)
    # c2 = T2(0.16791846623918)
    # c3 = T2(0.48298439719700)
    # c4 = T2(0.70546072965982)
    # c5 = T2(0.09295870406537)
    # c6 = T2(0.76210081248836)

    α2 = T(0.167266187050662)
    α3 = T(0.484574582244783)
    α4 = T(0.536909403373491)
    α5 = T(0.082069535961948)
    α6 = T(0.853923000035347)
    β1 = T(-0.028289441132839)
    β2 = T(0.463968918564710)
    β3 = T(-0.434414348751899)
    β4 = T(0.693796229087598)
    β6 = T(0.304938642232430)
    c2 = T2(0.167266187050662)
    c3 = T2(0.484574582244783)
    c4 = T2(0.536909403373491)
    c5 = T2(0.082069535961948)
    c6 = T2(0.853923000035347)

    new{T,T2}(α2, α3, α4, α5, α6, β1, β2, β3, β4, β6, c2, c3, c4, c5, c6)
  end
end

alg_cache(alg::RKM,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} = RKMConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))

function alg_cache(alg::RKM,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  tab = RKMConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  k = zero(rate_prototype)
  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  tmp = zero(u)
  fsalfirst = zero(rate_prototype)
  RKMCache(u, uprev, k, k1, k2, k3, k4, k5, k6, tmp, fsalfirst, tab)
end

@cache struct MSRK5Cache{uType, rateType, TabType} <: OrdinaryDiffEqCache
  u::uType
  uprev::uType
  tmp::uType
  fsalfirst::uType
  k1::rateType
  k2::rateType
  k3::rateType
  k4::rateType
  k5::rateType
  k6::rateType
  k7::rateType
  k8::rateType
  k9::rateType
  k::rateType
  tab::TabType
end

function alg_cache(alg::MSRK5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{false}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
  return MSRK5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
end

function alg_cache(alg::MSRK5,u,rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,uprev2,f,t,dt,reltol,p,calck,::Val{true}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}

  k1 = zero(rate_prototype)
  k2 = zero(rate_prototype)
  k3 = zero(rate_prototype)
  k4 = zero(rate_prototype)
  k5 = zero(rate_prototype)
  k6 = zero(rate_prototype)
  k7 = zero(rate_prototype)
  k8 = zero(rate_prototype)
  k9 = zero(rate_prototype)
  k = zero(rate_prototype)
  tmp = zero(u)
  fsalfirst = zero(u)
  tab = MSRK5ConstantCache(constvalue(uBottomEltypeNoUnits),constvalue(tTypeNoUnits))
  MSRK5Cache(u,uprev,tmp,fsalfirst,k1,k2,k3,k4,k5,k6,k7,k8,k9,k,tab)
end


text:
# Isso é um comentário que não será exibido no Julia

a = 321;

function msg(n)
    println("Você entrou com o número ",n);
end

function soma(a,b)
    println("A soma é ",a+b);
end

max_stars_repo_name: leonardosecchin/temp

max_issues_repo_name: leonardosecchin/temp

max_forks_repo_name: leonardosecchin/temp


text:
using BenchmarkTools
using GeoPhyInv
using Test

# some mem tests
mod=randn(1000); mod0=2.0 #src
@btime GeoPhyInv.χ!(mod,mod0,1) #src
@btime GeoPhyInv.χ!(mod,mod0,-1) #src
@btime GeoPhyInv.χg!(mod,mod0,1) #src
@btime GeoPhyInv.χg!(mod,mod0,-1) #src

# some model
mgrid = [range(0.0, stop=10.,step=0.05), range(0.0, stop=10.,step=0.05)];
model = Medium(mgrid);

vpb=[2100.,2200.];vsb=[1500, 1700]; rhob=[2100., 2300.]
update!(model, [:vp,:vs,:rho], [vpb, vsb, rhob]);
fill!(model)

update!(model, [:vp,:rho], randn_perc=1e-3)

nznx=prod(length.(model.mgrid))

# test copyto!
model0=similar(model);
fill!(model0)
update!(model0, [:vp,:rho], randn_perc=1e-3)

@btime copyto!(model0, model)
@test isequal(model0, model)

# allocation of model0

# reparameterize twice to see conversion formulae are correct
for fields in [[:χKI,:χrhoI,:null], [:χKI,:null,:null], [:null,:χrho,:null], [:null,:χrho,:null], [:χvp,:χrho,:null]]
	x=zeros(nznx*count(fields.≠:null));
        copyto!(x, model, fields);
	@time copyto!(model0, x, fields);
	@test model[:vp] ≈ model0[:vp]
	@test model[:rho] ≈ model0[:rho]
end

nznx=prod(length.(model.mgrid))
G1 = randn(nznx); G2 = randn(nznx);
g1 = similar(G1); g2 = similar(G2);

gmodel = Medium(model.mgrid, [:χvp,:χrho]);

for fields in [[:χKI,:χrhoI,:null], [:χKI,:null,:null], [:χvp,:χrho,:null] , [:null,:χrho,:null], [:χvp,:null,:null]]
	G=randn(nznx*count(fields.≠:null));
	g=zeros(nznx*count(fields.≠:null));
	@time GeoPhyInv.chainrule!(gmodel, model, G, fields,1);
	@time GeoPhyInv.chainrule!(gmodel, model, g, fields, -1);
	@test G ≈ g
end


text:
#module CryingBabies

using POMDPs
using Distributions
using POMDPToolbox

import POMDPs.states
import POMDPs.actions!
import POMDPs.create_action
import POMDPs.create_state
import POMDPs.create_transition
import POMDPs.create_observation
import POMDPs.transition!
import POMDPs.observation!
import POMDPs.reward
import POMDPs.n_states
import POMDPs.n_actions
import POMDPs.n_observations
import POMDPs.rand!

import POMDPs: create_interpolants, interpolants!, weight, index
import POMDPs: dimensions

#=
export
    BabyPOMDP,
    BabyState,
    BabyAction,
    BabyObservation,
    TransitionDistribution,
    ObservationDistribution,
    create_state,
    create_action,
    create_transition,
    create_observation,
    n_states,
    n_actions,
    n_observations,
    states,
    actions!,
    transition!
    observation!,
    reward,
    rand!,
    interpolants!
=#

mutable struct BabyPOMDP <: POMDP
    r_feed::Float64
    r_hungry::Float64
end

mutable struct BabyState
    hungry::Bool
end

mutable struct BabyObservation
    crying::Bool
end

mutable struct BabyAction
    feed::Bool
end

mutable struct TransitionDistribution <: AbstractDistribution
    ishungry::Bernoulli

    TransitionDistribution() = new(Bernoulli(0.2))
end

mutable struct ObservationDistribution <: AbstractDistribution
    iscrying::Bernoulli

    ObservationDistribution() = new(Bernoulli(0.1))
end

create_state(::BabyPOMDP) = BabyState(false)
create_action(::BabyPOMDP) = BabyAction(false)
create_transition(::BabyPOMDP) = TransitionDistribution()
create_observation(::BabyPOMDP) = ObservationDistribution()

n_states(::BabyPOMDP) = 2
n_actions(::BabyPOMDP) = 2
n_observations(::BabyPOMDP) = 2

function transition!(d::TransitionDistribution, pomdp::BabyPOMDP, s::BabyState, a::BabyAction)
    if !a.feed && s.hungry
        d.ishungry = Bernoulli(1.0)
    elseif a.feed
        d.ishungry = Bernoulli(0.0)
    else
        d.ishungry = Bernoulli(0.1)
    end
    d
end

function observation!(d::ObservationDistribution, pomdp::BabyPOMDP, s::BabyState, a::BabyAction)
    if s.hungry
        d.iscrying = Bernoulli(0.8)
    else
        d.iscrying = Bernoulli(0.1)
    end
    d
end

function reward(pomdp::BabyPOMDP, s::BabyState, a::BabyAction)
    r = 0.0
    if s.hungry
        r += pomdp.r_hungry
    end
    if a.feed
        r += pomdp.r_feed
    end
    return r
end

function rand!(s::BabyState, d::TransitionDistribution)
    s.hungry = rand(d.ishungry)
    s
end

function rand!(s::BabyState, d::ObservationDistribution)
    s.hungry = rand(d.crying)
    s
end

dimensions(::ObservationDistribution) = 1
dimensions(::TransitionDistribution) = 1

function states(::BabyPOMDP)
    [BabyState(i) for i = 0:1]
end

const ACTION_SET = [BabyAction(i) for i = 0:1]

function actions!(acts::Vector{BabyAction}, ::BabyPOMDP, s::BabyState)
    acts[1:end] = ACTION_SET[1:end]
end

create_interpolants(::BabyPOMDP) = Interpolants()

function interpolants!(interpolants::Interpolants, d::TransitionDistribution)
    empty!(interpolants)
    ph = params(d.ishungry)[1]
    push!(interpolants, 1, (1-ph)) # hungry
    push!(interpolants, 2, (ph)) # not hungry
    interpolants
end

function interpolants!(interpolants::Interpolants, d::ObservationDistribution)
    empty!(interpolants)
    ph = params(d.iscrying)[1]
    push!(interpolants, 1, (1-ph)) # crying
    push!(interpolants, 2, (ph)) # not crying
    interpolants
end

length(interps::Interpolants) = interps.length

weight(interps::Interpolants, i::Int64) = interps.weights[i]

index(interps::Interpolants, i::Int64) = interps.indices[i]

function convert!(x::Vector{Float64}, state::BabyState)
    x[1] = float(state.hungry)
    x
end

#end #mdoule


text:
__precompile__(false)

using Pkg

function install_packages()
    return
    # install packages
    println("Update OLD Packages...")
    Pkg.update()
    list=Pkg.installed()
    open(joinpath(@__DIR__, "../REQUIRE")) do file
        line = readline(file)
        if !haskey(list, line) Pkg.add(line); println("Package $line added."); end
    end
    println("Install Packages...")
    Pkg.update()
    println("Packages done.")
end

install_packages()

module JuliaOpenGL

const USE_PROCESSES = false
const USE_THREADS = false

using Distributed

if USE_PROCESSES addprocs(1) end

@everywhere println("=== Process started ===")
@everywhere push!(LOAD_PATH, @__DIR__)
@everywhere push!(LOAD_PATH,joinpath(@__DIR__,"GL")) # add path
if USE_PROCESSES
  #@everywhere include(joinpath(@__DIR__,"process.jl"))
  using Main.Process
end

using App

"""
TODO
"""
function main()
  if USE_PROCESSES
    Process.start(App.run)
  elseif USE_THREADS
    #start_threads()
    error("Does not work with OpenGL, because OpenGL has to be on main thread...")
  else
    App.run()
  end
end

export main

end #JuliaOpenGL

max_stars_repo_name: Gilga/JuliaOpenGL

max_issues_repo_name: Gilga/JuliaOpenGL

max_forks_repo_name: Gilga/JuliaOpenGL


text:
dataset(example::AbstractString, datafile::AbstractString, suffix::AbstractString="csv", header::Bool=true) =
  readcsv(joinpath(dirname(@__FILE__), "..", "data", example, join([datafile, suffix], '.')), header=header)

function datasets(example::AbstractString)
  fnames = readcsv(joinpath(dirname(@__FILE__), "..", "doc", "datasets.csv"), header=false)
  fnames[fnames[:, 2] .== example, 4]
end

function datasets(example::AbstractString, header::Vector{Bool})
  fnames = datasets(example)
  Any[readcsv(joinpath(dirname(@__FILE__), "..", "data", example, fnames[i]), header=header[i]) for i in 1:length(fnames)]
end

function datasets(example::AbstractString, header::Bool)
  fnames = datasets(example)
  Any[readcsv(joinpath(dirname(@__FILE__), "..", "data", example, f), header=header) for f in fnames]
end

datasets(header::Bool=true) = readcsv(joinpath(dirname(@__FILE__), "..", "doc", "datasets.csv"), header=header)

examples(header::Bool=true) = readcsv(joinpath(dirname(@__FILE__), "..", "doc", "examples", "examples.csv"), header=header)


text:
using HypothesisTests, Test

mutable struct TestTest <: HypothesisTests.HypothesisTest end

@testset "Common" begin
@test_throws DimensionMismatch HypothesisTests.check_same_length([1], [])
@test_throws ArgumentError HypothesisTests.check_alpha(0.0)

result = HypothesisTests.population_param_of_interest(TestTest())
@test result[1] == "not implemented yet"
@test isnan(result[2])
end


text:
inpt = """11
30
47
31
32
36
3
1
5
3
32
36
15
11
46
26
28
1
19
3"""
buckets = Int64[parse(Int, i) for i in split(inpt)]

nFit = 0
fridge = 150

# solution stolen from the subreddit
# the point is that computing all permutations takes too long
# all we do here is compute the distinct combinations of n sub-elements of the input array
# where 1<= n <= length(input)
for i in 1:length(buckets)
	for j in combinations(buckets, i)
		if sum(j) == fridge
			nFit += 1
		end
	end
	if nFit > 0
		break
	end
end

println(nFit)

max_stars_repo_name: jstrube/adventofcode

max_issues_repo_name: jstrube/adventofcode

max_forks_repo_name: jstrube/adventofcode


text:
## load in the data
using PowerSpectra
using Healpix
using PyCall, PyPlot
using CSV, DataFrames, LinearAlgebra
using BenchmarkTools
ENV["OMP_NUM_THREADS"] = 16
hp = pyimport("healpy")
nmt = pyimport("pymaster")

data_dir = "/home/zequnl/.julia/dev/PowerSpectra/notebooks/data/"
# mask = readMapFromFITS(data_dir * "mask.fits", 1, Float64)
nside = 256
lmax = 3 * nside - 1

##
mask_arr = zeros(hp.nside2npix(nside))
θ, ϕ = hp.pix2ang(nside, 0:(hp.nside2npix(nside)-1))
ϕ[ϕ .> π] .-= 2π
mask_arr[
    (θ .* (1 .+ 0.1 .* sin.(ϕ .* 3.1 .+ 0.1)) .> 1.7) .|
    (θ .* (1 .+ 0.1 .* sin.(ϕ .* 2.0 .+ 0.1)) .< 1.25)
] .= 1.0
mask_arr = nmt.mask_apodization(mask_arr, 20.0, apotype="C2")

ps_mask = ones(hp.nside2npix(nside))
ps_mask[ rand(length(mask_arr)) .> 0.9999 ] .= 0.0
ps_mask = nmt.mask_apodization(ps_mask, 4.0, apotype="C2")

mask = HealpixMap{Float64, RingOrder}(mask_arr)
saveToFITS(mask, "test/mask1_P.fits")
mask.pixels .= mask_arr .* ps_mask
saveToFITS(mask, "test/mask1_T.fits")

##
mask_arr = zeros(hp.nside2npix(nside))
θ, ϕ = hp.pix2ang(nside, 0:(hp.nside2npix(nside)-1))
ϕ[ϕ .> π] .-= 2π
mask_arr[
    (θ .* (1 .+ 0.1 .* sin.(ϕ .* (2.1+rand()) .+ 0.1 .+ (rand()*0.1) )) .> 1.7) .|
    (θ .* (1 .+ 0.1 .* sin.(ϕ .* (1 + rand()) .+ 0.1 .+ (rand()*0.1) )) .< 1.25)
] .= 1.0
mask_arr = nmt.mask_apodization(mask_arr, 20.0, apotype="C2")

ps_mask = ones(hp.nside2npix(nside))
ps_mask[ rand(length(mask_arr)) .> 0.9999 ] .= 0.0
ps_mask = nmt.mask_apodization(ps_mask, 4.0, apotype="C2")

mask = HealpixMap{Float64, RingOrder}(mask_arr)
saveToFITS(mask, "test/mask2_P.fits")
mask.pixels .= mask_arr .* ps_mask
saveToFITS(mask, "test/mask2_T.fits")

clf(); hp.mollview(mask.pixels); gcf()

##

using CSV
using DataFrames

data_dir = "/home/zequnl/.julia/dev/PowerSpectra/notebooks/data/"
theory = CSV.File(data_dir * "theory.csv") |> DataFrame
m0 = hp.synfast(theory.cltt, nside=nside, verbose=false, pixwin=true, new=true)
saveToFITS(HealpixMap{Float64, RingOrder}(m0), "test/example_map.fits")

##

max_stars_repo_name: xzackli/PlanckCov

max_issues_repo_name: xzackli/PlanckCov