text:
# This file is part of IntegerSequences.
# Copyright Peter Luschny. License is MIT.
# This file includes parts from Combinatorics.jl in modified form.

# Version of: UTC 2020-01-30 22:26:36
# 3239f540-43a7-11ea-3681-7159542018ed

# Do not edit this file, it is generated from the modules and will be overwritten!
# Edit the modules in the src directory and build this file with BuildSequences.jl!

module runtests
using Nemo, Test, IntegerSequences, IterTools, DataStructures
tstdir = realpath(joinpath(dirname(@__FILE__)))
srcdir = joinpath(dirname(tstdir), "src")
tstdir ∉ LOAD_PATH && push!(LOAD_PATH, tstdir)
srcdir ∉ LOAD_PATH && push!(LOAD_PATH, srcdir)
tstidx = joinpath(tstdir, "TESTINDEX.jl")
include(tstidx)
# *** Abundant.jl *********
@testset "Abundant" begin
@test isAbundant(100800) == true
@test isAbundant(2402400) == true
@test isAbundant(49008960) == true
if data_installed()
SeqTest([L005101], 'L')
end
end
# *** AltPartitions.jl *********
@testset "AltIntParts" begin
@test length(V026791(6)) == 11
end
V080577(6)
# *** AndreNumbers.jl *********
@testset "André" begin
@test isa(André(2, 10), fmpz)
@test André(2, 10) == fmpz(-50521)
@test André(2, 50) == fmpz(-6053285248188621896314383785111649088103498225146815121)
@test V178963(30) == fmpz(2716778010767155313771539)
@test V178964(40) == fmpz(11289082167259099068433198467575829)
if data_installed()
V = [V000111, V178963, V178964, V181936, V250283]
for v ∈ V
SeqTest(v, 'V')
end
end
V = [1, 1, 1, 2, 5, 16, 61, 272, 1385, 7936, 50521]
generator = C000111()
for n ∈ 1:10
v = take!(generator)
@test V[n] == v
end
v = take!(generator)
close(generator)
@test isa(v, fmpz)
end
# *** BellNumbers.jl *********
@testset "Bell" begin
seq = fmpz[1, 1, 2, 5, 15, 52]
a = [BellTrans(6, k, seq) for k ∈ 0:5]
b = [0, 52, 205, 210, 85, 15]
@test all(a .== b)
seq = [1, 1, 1, 1, 1, 1]
a = BellTriangle(6, seq)
b = fmpz[1, 0, 1, 0, 1, 1, 0, 1, 3, 1, 0, 1, 7, 6, 1, 0, 1, 15, 25]
@test all(a[1:5] .== b[1:5])
a = fmpz[1, 1, 2, 5, 15, 52, 203]
b = [BellNumber(n) for n ∈ 0:6]
@test all(a .== b)
if data_installed()
SeqTest(V000110, 'V')
SeqTest([L000110], 'L')
T = [T264428, T137452, T132062, T265606]
SeqTest(T, 'T')
P = [T104556, T001497, T039683, T203412, T004747,
T051141, T119274, T000369, T051142, T137513]
SeqTest(P, 'P')
end
end
# *** BernoulliNumbers.jl *********
@testset "BernoulliNum" begin
@test BernoulliInt(2, 10) == fmpz(79360)
@test BernoulliInt(3, 30) == fmpz(-7708110416280010548302670)
@test BernoulliInt(4, 40) == fmpz(-44494882577309421077208834962882560)
@test isa(BernoulliInt(3, 30), fmpz)
@test isa(BernoulliIntList(2, 20)[end], fmpz)
@test isa(Bernoulli(0), Nemo.fmpq)
@test isa(V027641(10), fmpz)
@test isa(V195441(10), fmpz)
for m ∈ 1:20
@test BernoulliInt(m, 200) == BernoulliIntList(m, 200 + 1)[end]
end
for n ∈ 0:20
@test denominator(Rational(Bernoulli(2 * n))) == ClausenNumber(n)
end
t = fmpz(8622529719094842064796322984685715031642180319435676189471082876882585178647210)
@test V195441(10000) == t
l = fmpz[0, 1, 2, 3, 8, 25, 96, 427, 2176]
@test all(L065619(9) .== l)
if data_installed()
V = [V195441, V281586, V281588, V027641]
for v ∈ V SeqTest(v, 'V') end
end
end
# *** BinaryInteger.jl *********
@testset "BinaryInteger" begin
@test V295513(0) == -1
@test V295513(1) == -1
@test V295513(2) == 0
@test V295513(3) == 2
if data_installed()
V = [V001855, V003314, V033156, V054248, V061168, V097383]
for v ∈ V
SeqTest(v, 'V', 1)
end
V = [V083652, V123753]
for v ∈ V
SeqTest(v, 'V', 0)
end
end
end
# *** BinaryQF.jl *********
Data = Dict{Int,Array{fmpz}}(
002476 => [7, 13, 19, 31, 37, 43, 61, 67, 73, 79, 97, 103],
008784 => [1, 2, 5, 10, 13, 17, 25, 26, 29, 34, 37, 41],
031363 => [1, 4, 5, 9, 11, 16, 19, 20, 25, 29, 31, 36],
034017 => [1, 3, 7, 13, 19, 21, 31, 37, 39, 43, 49, 57],
035251 => [1, 2, 4, 7, 8, 9, 14, 16, 17, 18, 23, 25],
038872 => [5, 11, 19, 29, 31, 41, 59, 61, 71, 79, 89, 101],
038873 => [2, 7, 17, 23, 31, 41, 47, 71, 73, 79, 89, 97],
042965 => [1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16],
057126 => [1, 2, 7, 14, 17, 23, 31, 34, 41, 46, 47, 49],
057127 => [1, 2, 3, 6, 9, 11, 17, 18, 19, 22, 27, 33],
068228 => [13, 37, 61, 73, 97, 109, 157, 181, 193, 229, 241, 277],
084916 => [1, 4, 6, 9, 13, 16, 22, 24, 25, 33, 36, 37],
089270 => [1, 5, 11, 19, 29, 31, 41, 55, 59, 61, 71, 79],
141158 => [5, 11, 19, 29, 31, 41, 59, 61, 71, 79, 89, 101],
242660 => [1, 4, 7, 9, 10, 13, 16, 18, 19, 22, 25, 27],
243655 => [1, 6, 13, 22, 33, 37, 46, 61, 69, 73, 78, 94],
244779 => [1, 2, 4, 7, 8, 11, 14, 16, 22, 23, 28, 29],
244780 => [1, 3, 5, 9, 11, 15, 23, 25, 27, 31, 33, 37],
244819 => [1, 3, 4, 7, 12, 13, 19, 21, 28, 31, 37, 39],
243168 => [1, 4, 9, 13, 16, 24, 25, 33, 36, 37, 49, 52],
244291 => [1, 4, 13, 24, 33, 37, 52, 61, 69, 73, 88, 97],
007522 => [7, 23, 31, 47, 71, 79, 103, 127, 151, 167, 191, 199]
)
L = [
L002476,
L008784,
L031363,
L034017,
L035251,
L038872,
L038873,
L042965,
L057126,
L057127,
L068228,
L084916,
L089270,
L141158,
L242660,
L243655,
L244779,
L244780,
L244819,
L243168,
L244291,
L007522
]
SeqNum(seq) = parse(Int, string(seq)[end-5:end])
@testset "BinaryQF" begin
for seq ∈ L
S = seq(300)
anum = SeqNum(seq)
data = Data[anum]
@test all(S[1:11] .== data[1:11])
end
end
# *** BooleanOperations.jl *********
@testset "BoolOps" begin
A = [1, 1, 0, 0]
B = [1, 0, 1, 0]
S(R) = sum(r << (i-1)  for (i, r) ∈ enumerate(R))
for n ∈ 0:15
@test n == S([Bits(n, A[k], B[k]) for k ∈ 1:4])
end
for n ∈ 0:15
@test n == S([Bits(BoolOps[n+1], A[k], B[k]) for k ∈ 1:4])
end
@test BinDigits(12, 17) == ([0, 0, 1, 1, 0], [1, 0, 0, 0, 1])
@test [V163617(n) for n ∈ 0:8] == [0, 3, 6, 7, 12, 15, 14, 15, 24]
@test [V035327(n) for n ∈ 0:8] == [1, 0, 1, 0, 3, 2, 1, 0, 7]
@test [V129760(n) for n ∈ 0:8] == [0, 0, 2, 0, 4, 4, 6, 0, 8]
@test [V142151(n) for n ∈ 0:8] == [0, 1, 2, 3, 6, 5, 6, 7, 14]
@test [V003817(n) for n ∈ 0:8] == [1, 1, 3, 3, 7, 7, 7, 7, 15]
@test [V080079(n) for n ∈ 0:8] == [1, 2, 1, 4, 3, 2, 1, 8, 7]
@test [V086799(n) for n ∈ 0:8] == [1, 3, 3, 7, 5, 7, 7, 15, 9]
@test [V038712(n) for n ∈ 0:8] == [1, 3, 1, 7, 1, 3, 1, 15, 1]
@test [V006257(n) for n ∈ 0:8] == [0, 1, 1, 3, 1, 3, 5, 7, 1]
@test [V080940(n) for n ∈ 0:8] == [1, 0, 1, 0, 1, 2, 1, 0, 1]
@test [V135521(n) for n ∈ 0:8] == [1, 1, 1, 3, 1, 3, 1, 7, 1]
@test [V048724(n) for n ∈ 0:8] == [0, 3, 6, 5, 12, 15, 10, 9, 24]
@test [V003188(n) for n ∈ 0:8] == [0, 1, 3, 2, 6, 7, 5, 4, 12]
@test [V038554(n) for n ∈ 0:8] == [0, 1, 1, 0, 2, 3, 1, 0, 4]
@test [V048735(n) for n ∈ 0:8] == [0, 0, 0, 1, 0, 0, 2, 3, 0]
@test [V213370(n) for n ∈ 0:8] == [0, 0, 0, 2, 0, 0, 4, 6, 0]
@test [V135481(n) for n ∈ 0:8] == [0, 1, 0, 3, 0, 1, 0, 7, 0]
@test [V327987(n) for n ∈ 0:8] == [0, 1, 0, 2, 2, 2, 4, 2, 0]
@test L327988(99) == [0, 2, 8, 10, 26, 32, 34, 40, 50, 58, 74, 82]
@test is327988(121) == false
@test is327988(122) == true
end
# *** CantorMachines.jl *********
@testset "CantorMachines" begin
len = 64
println()
println("Running CantorMachine")
x, y, state = 0, 0, false
for n ∈ 0:len
p = CantorPairing(x, y)
@test n == p
x, y, state = CantorMachine(x, y, state)
end
println("Running CantorBoustrophedonicMachine")
x, y = 0, 0
for n ∈ 0:len
p = CantorBoustrophedonicPairing(x, y)
@test n == p
x, y = CantorBoustrophedonicMachine(x, y)
end
println("Running RosenbergStrongBoustrophedonicMachine")
x, y, state = 0, 0, 0
for n ∈ 0:len
p = RosenbergStrongBoustrophedonicPairing(x, y)
@test n == p
x, y, state = RosenbergStrongBoustrophedonicMachine(x, y, state)
end
println()
end
# *** CarmichaelNumbers.jl *********
@testset "Carmichael" begin
@test !isCarmichael(560)
@test isCarmichael(561)
@test !isCarmichael(563)
@test isweakCarmichael(561)
@test !isweakCarmichael(563)
@test isweakCarmichael(625)
if data_installed()
L = [L002997, L225498]
SeqTest(L, 'L')
end
end
# *** ClausenNumbers.jl *********
∈
@testset "Clausen" begin
C = ClausenNumberList(800)
@test C[125] == 30
@test C[781] == 32695402455500348373810
@test C[794] == 6
@test isa(C[781], fmpz)
@test isa(ClausenNumber(10), fmpz)
end
if data_installed()
SeqTest([L002445], 'L')
SeqTest(V002445, 'V', 0)
SeqTest(V027642, 'V', 0)
end
# *** CombinationsIterator.jl *********
C = collect(Combinations([2, 3, 5]))
@testset "Combinations" begin
@test C == [[2], [3], [5], [2, 3], [2, 5], [3, 5], [2, 3, 5]]
end
# *** Compositions.jl *********
# *** Counts.jl *********
indicators = [isPositive, isEven, isSquare, isPrime]
indicatorNames = ["isPositive", "isEven", "isSquare", "isPrime"]
len = 14
@testset "Counts" begin
@test Nth(96, isPrime) == 503
@test Nth(97, isPrime) == 509
@test Nth(98, isPrime) == 521
@test Count(96, isPrime) == 24
@test Count(97, isPrime) == 25
@test Count(98, isPrime) == 25
@test List(24, isPrime)[end] == 89
@test List(25, isPrime)[end] == 97
for (i, isA) ∈ enumerate(indicators)
for n ∈ 1:len
@test isA(n) == (Nth(Count(n, isA), isA) == n)
@test n == Count(Nth(n, isA), isA)
end
end
a = [V257993(n) for n ∈ 1:10]
b = [1, 2, 1, 2, 1, 3, 1, 2, 1, 2]
@test all(a .== b)
if data_installed()
L = [L000961, L002808, L005117, L013928, L246547, L246655]
SeqTest(L, 'L')
end
end
# *** CyclotomicBinaryForms.jl *********
@testset "CyclotomicForms" begin
if data_installed()
L = [
L206942,
L206864,
L299498,
L299928,
L299929,
L299930,
L299214,
L296095,
L293654
]
SeqTest(L, 'L')
end
end
# *** DedekindEta.jl *********
@testset "DedekindEta" begin
@test DedekindEtaPowers(0, 1) == fmpz[]
@test isa(DedekindEtaPowers(30, 1)[10], fmpz)
@test isa(DedekindEtaPowers(30, -1)[10], fmpz)
@test RamanujanTau(20) == -7109760
P0 = [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101]
P1 = PartitionNumberList(14)
@test all(P0 .== P1)
if data_installed()
L = [
L010815,
L002107,
L010816,
L000727,
L000728,
L000729,
L000730,
L000731,
L010817,
L010819,
L000735,
L010820,
L010821,
L010822,
L000739,
L010823,
L010824,
L010825,
L010826,
L010827,
L010828,
L010829,
L000594,
L010830,
L010831,
L010832,
L010833,
L010834,
L010835,
L010836,
L010837,
L010840,
L010838,
L010839,
L010841,
L000041,
L000712,
L000716,
L023003,
L023004,
L023005,
L023006,
L023007,
L023008,
L023009,
L023010,
L005758,
L023011,
L023012,
L023013,
L023014,
L023015,
L023016,
L023017,
L023018,
L023019,
L023020,
L023021,
L006922,
L082556,
L082557,
L082558,
L082559
]
SeqTest(L, 'L')
end
end
# *** DelehamDelta.jl *********
Data = Dict{Int, Array{fmpz}}(
084938 => [1, 0, 1, 0, 1, 1, 0, 2, 2, 1],
060693 => [1, 1, 1, 2, 3, 1, 5, 10, 6, 1],
106566 => [1, 0, 1, 0, 1, 1, 0, 2, 2, 1],
094665 => [1, 0, 1, 0, 1, 3, 0, 4, 15, 15],
090238 => [1, 0, 1, 0, 2, 1, 0, 6, 4, 1],
225478 => [1, 3, 4, 21, 40, 16, 231, 524, 336, 64],
055883 => [1, 1, 1, 2, 4, 2, 5, 15, 15, 5],
184962 => [1, 0, 1, 0, 1, 1, 0, 3, 3, 1],
088969 => [1, 0, 1, 0, 1, 3, 0, 5, 20, 21],
090981 => [1, 1, 0, 1, 1, 0, 1, 4, 1, 0],
011117 => [1, 1, 0, 1, 1, 0, 1, 2, 3, 0]
)
@testset "Deléham" begin
n = 7
B = [bell(n) * binomial(n, j) for j ∈ 0:n]
R = Row(T055883(n + 1), n)
@test all(B .== R)
a = fmpz[0, 5040, 2208, 828, 272, 70, 12, 1]
b = Row(T090238(8), 7)
@test all(a .== b)
SeqNum(seq) = parse(Int, string(seq)[end-5:end])
Seq = [
T084938,
T060693,
T106566,
T094665,
T090238,
T225478,
T055883,
T184962,
T088969
]
for seq ∈ Seq
S = seq(20)
anum = SeqNum(seq)
data = Data[anum]
@test all(S[1:9] .== data[1:9])
end
end
# *** EulerTransforms.jl *********
@testset "EulerTransform" begin
if data_installed()
L = [L107895, L190905, L061256, L275585, L006171, L290351, L052847]
SeqTest(L, 'L')
V = [V107895, V190905, V061256, V275585, V006171]
for v ∈ V
SeqTest(v, 'V', 0)
end
end
end
# *** Fibonacci.jl *********
@testset "Fibonacci" begin
@test isa(V000045(30), fmpz)
end
# *** FigurativeNumbers.jl *********
@testset "Figurative" begin
@test V002411(1000) == 500500000
if data_installed()
V = [
V014107,
V067998,
V001477,
V000217,
V000290,
V000326,
V000384,
V000566,
V000567,
V001106,
V001107,
V000292,
V000330,
V002411,
V002412,
V002413,
V007584,
V007585
]
for v ∈ V
SeqTest(v, 'V')
end
end
end
# *** GaussFactorials.jl *********
@testset "GaussFactorial" begin
if data_installed()
V = [V001783, V124441, V124442, V066570]
for v ∈ V
SeqTest(v, 'V', 1)
end
W = [V055634, V232980, V232981, V232982]
for w ∈ W
SeqTest(w, 'V', 0)
end
end
end
# *** GeneralizedBinomial.jl *********
@testset "Binomial" begin
for n ∈ 0:10, k ∈ 0:n
@test Binomial(n, k) == div(factorial(n), (factorial(n - k) * factorial(k)))
@test Binomial(n, k) == Pascal(n, k)
end
end
# *** GeneralizedFibonacci.jl *********
@testset "Multinacci" begin
@test Multinacci(0, 0) == 1
@test [Multinacci(2, n) for n ∈ 0:9] == [1, 1, 2, 3, 5,  8, 13, 21, 34,  55]
@test [V006053(n) for n ∈ 0:9] == [1, 1, 3, 4, 9, 14, 28, 47, 89, 155]
@test [V188021(n) for n ∈ 0:9] == [1, 1, 4, 5, 14, 20, 48, 75, 165, 274]
@test [V231181(n) for n ∈ 0:9] == [1, 1, 5, 6, 20, 27, 75, 110, 275,429]
@test [Multinacci(6, n) for n ∈ 0:9] == [1, 1, 6, 7, 27, 35, 110, 154,429,637]
@test [Multinacci(7, n) for n ∈ 0:9] == [1, 1, 7, 8, 35, 44, 154, 208,637,910]
@test [Multinacci(8, n) for n ∈ 0:9] == [1, 1, 8, 9, 44, 54,208,273,910, 1260]
end
# *** HighlyAbundant.jl *********
# *** Hyper1F1.jl *********
@testset "Hyper1F1" begin
@test V000255(10) == fmpz(16019531)
@test V000262(10) == fmpz(58941091)
@test V001339(10) == fmpz(98641011)
@test V007060(10) == fmpz(871804170613555200)
@test V033815(10) == fmpz(1465957162768492800)
@test V099022(10) == fmpz(3984884716852972800)
@test V251568(10) == fmpz(123320412181)
if data_installed()
V = [V000255, V000262, V001339, V007060, V033815, V099022, V251568]
for v ∈ V
SeqTest(v, 'V')
end
end
end
# *** IntPartitions.jl *********
@testset "IntegerPartitions" begin
@test IntegerPartitions(0) == [[]]
@test collect(IntegerPartitions(0, 0)) == [[]]
@test collect(IntegerPartitions(0, 1)) == []
@test collect(IntegerPartitions(1, 0)) == []
@test collect(IntegerPartitions(1, 1)) == [[1]]
@test collect(IntegerPartitions(1, 2)) == []
@test collect(IntegerPartitions(2, 0)) == []
@test collect(IntegerPartitions(2, 1)) == [[2]]
@test collect(IntegerPartitions(2, 2)) == [[1, 1]]
@test collect(IntegerPartitions(2, 3)) == []
@test [length(b) for b ∈ IntegerPartitions(0)] == [0]
@test [length(b) for b ∈ IntegerPartitions(1)] == [1]
@test length(IntegerPartitions(0)) == 1
@test length(collect(IntegerPartitions(1))) == 1
@test_throws DomainError IntegerPartitions(-1)
@test collect(IntegerPartitions(5)) == reverse(Any[[1, 1, 1, 1, 1],
[2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]])
for n ∈ 0:7
pn = PartitionNumber(n)
@test length(collect(IntegerPartitions(n, byMaxPart))) == pn
@test length(collect(IntegerPartitions(n, byNumPart))) == pn
end
for n ∈ 0:7, k ∈ 0:n
pn = PartitionNumber(n, k)
@test length(collect(IntegerPartitions(n, k))) == pn
end
@test L005651(10) == [1, 1, 3, 10, 47, 246, 1602, 11481, 95503, 871030]
@test [V000041(n) for n ∈ 0:8] == [1, 1, 2, 3, 5, 7, 11, 15, 22]
@test L072233(7) == [0, 1, 3, 4, 3, 2, 1, 1]
@test L036038(6) == [1, 6, 15, 20, 30, 60, 90, 120, 180, 360, 720]
@test L078760(6) == [1, 6, 15, 30, 20, 60, 120, 90, 180, 360, 720]
@test L005651(10) == [1, 1, 3, 10, 47, 246, 1602, 11481, 95503, 871030]
@test L262071(6) == [0, 720, 630, 200, 45, 6, 1]
@test L292222(6) == [1, 41, 180, 300, 360, 720]
end
# *** JacobiTheta.jl *********
@testset "JacobiTheta" begin
@test JacobiTheta3Powers(0, 1) == fmpz[]
@test isa(JacobiTheta3Powers(30, 1)[end], fmpz)
@test isa(JacobiTheta4Powers(30, 1)[end], fmpz)
@test L035016(999 + 1)[end] == fmpz(-16565884160)
@test L035016(1000 + 1)[end] == fmpz(18365675328)
if data_installed()
L = [
L000122,
L002448,
L004018,
L104794,
L005875,
L213384,
L000118,
L035016,
L008452,
L096727,
L000132,
L000141,
L008451,
L000143,
L000144,
L008453,
L000145,
L276285,
L276286,
L276287,
L004402,
L004406,
L004407,
L015128,
L004403,
L001934,
L004404,
L004405,
L004408,
L004409,
L004410,
L004411,
L004412,
L004413,
L004414,
L004420,
L004421,
L004415,
L004416,
L004417,
L004418,
L004419,
L004422,
L004423,
L004424,
L004425
]
SeqTest(L, 'L')
end
end
# *** Kolakoski.jl *********
@testset "Kolakoski" begin
K = KolakoskiList(100)
@test K[1] == 1
@test K[33] == 2
@test K[72] == 2
generator = C000002()
for n ∈ [1, 33, 72]
k = take!(generator)
@test K[n] == k
end
close(generator)
end
# *** LahNumbers.jl *********
@testset "Lah" begin
@test Lah(7) == [0, 5040, 15120, 12600, 4200, 630, 42, 1]
end
# *** LandauConstants.jl *********
@testset "Landau" begin
@test V006519(0) == 1
@test V000265(0) == 0
@test V327494(0) == 1
@test V001803(0) == 1
@test V007814(0) == 0
@test V327491(0) == 0
@test V327493(0) == 1
@test V000120(0) == 0
@test V102376(0) == 1
@test V011371(0) == 0
@test V120738(0) == 0
@test V060818(0) == 1
@test V124399(0) == 1
@test V056982(0) == 1
@test V001511(0) == 0
@test V046161(0) == 1
@test V001316(0) == 1
@test V163590(0) == 1
@test V327492(0) == 0
@test V005187(0) == 0
@test V001790(0) == 1
@test V277233(0) == 1
@test V327495(0) == 1
@test V006519(10) == 2
@test V000265(10) == 5
@test V327494(10) == 403341
@test V001803(10) == 969969
@test V007814(10) == 1
@test V327491(10) == 1
@test V327493(10) == 262144
@test V000120(10) == 2
@test V102376(10) == 16
@test V011371(10) == 8
@test V120738(10) == 38
@test V060818(10) == 256
@test V124399(10) == 65536
@test V056982(10) == 68719476736
@test V001511(10) == 2
@test V046161(10) == 262144
@test V001316(10) == 4
@test V001511(10) == 2
@test V163590(10) == 63
@test V327492(10) == 18
@test V005187(10) == 18
@test V001790(10) == 46189
@test V277233(10) == 125233642041
@test V327495(10) == 74796032037
end
# *** NarayanaCows.jl *********
@testset "Narayana" begin
@test IterTools.nth(NarayanasCows(12), 12) == 5
end
# *** NodesAndEdges.jl *********
@testset "Nodes" begin
@test V000055(10) == 106
@test V000081(10) == 719
@test V000106(10) == 1235
@test V095350(10) == 6471
@test V209397(10) == 7238
@test V217420(10) == 239
@test V055544(10) == 7190
@test V055543(10) == 1060
@test V055542(10) == 120051680
@test V000088(10) == 12005168
@test V002494(10) == 11730500
@test L087803(5)  == BigInt[0, 1, 2, 4, 8, 17]
@test L036039(5)  == BigInt[24, 30, 20, 20, 15, 10, 1]
end
# *** NumberTheory.jl *********
Data = Dict{Int,Array{fmpz}}(
034386 => [1, 1, 2, 6, 6, 30, 30, 210, 210, 210],
061142 => [1, 1, 2, 2, 4, 2, 4, 2, 8, 4],
002110 => [1, 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870],
000005 => [0, 1, 2, 2, 3, 2, 4, 2, 4, 3],
000010 => [0, 1, 1, 2, 2, 4, 2, 6, 4, 6],
000203 => [0, 1, 3, 4, 7, 6, 12, 8, 15, 13],
001222 => [0, 0, 1, 1, 2, 1, 2, 1, 3, 2],
001221 => [0, 0, 1, 1, 1, 1, 2, 1, 1, 1],
008683 => [0, 1, -1, -1, 0, -1, 1, -1, 0, 0],
181830 => [0, 1, 0, 0, 0, 1, 0, 2, 2, 2],
034444 => [1, 1, 2, 2, 2, 2, 4, 2, 2, 2]
)
@testset "NumTheory" begin
@test τ(7560) == 64
@test τ(46080) == 66
@test τ(25920) == 70
@test σ(7560) == 28800
@test σ(46080) == 159666
@test σ(25919) == 25920
@test σ(25920) == 92202
@test ω(7560) == 4
@test ω(46080) == 3
@test ω(25919) == 1
@test ω(25920) == 3
@test Ω(7560) == 8
@test Ω(46080) == 13
@test Ω(25919) == 1
@test Ω(25920) == 11
@test Radical(58564) == 22
@test Radical(58565) == 58565
FB(n::Int) = (r = 1; for k ∈ 1:n
⊥(n, k) && (r = mods(r * k, n))
end; r)
FA(n::Int) = mods(∏([j for j ∈ 1:n if ⊥(j, n)]), n)
for n ∈ 1:20
@test FA(n) == FB(n)
end
if data_installed()
V = [V061142, V000005, V000010, V000203, V001222, V001221, V008683]
W = [V034386, V002110, V181830, V034444]
for v ∈ V
SeqTest(v, 'V', 1)
end
L = [L003277]
SeqTest(L, 'L')
end
end
composita = [false, false, false, false, true, false, true, false]
@testset "Queries" begin
for n ∈ 0:7
@test isComposite(n) == composita[n+1]
end
end
# *** OEISUtils.jl *********
if is_oeis_installed()
@info("OEIS data is installed as: " * oeis_path())
end
# *** OrthoPolynomials.jl *********
@testset "OrthoPoly" begin
@test isa(OrthoPoly(10, n -> 1, n -> n + 1)[end], fmpz)
@test isa(InvOrthoPoly(10, n -> 1, n -> n + 1)[end], fmpz)
@test RowSums(T217537(8)) == L217924(8)
if data_installed()
T = [
T066325,
T049310,
T137338,
T104562,
T037027,
T049218,
T159834,
T137286,
T053120,
T053117,
T053121,
T216916,
T217537,
T064189,
T202327,
T111062,
T099174,
T111593,
T064189
]
SeqTest(T, 'T')
L = [L217924, L005425, L000085, L001464, L003723, L108624, L006229]
SeqTest(L, 'L')
end
end
# *** Polynomials.jl *********
@testset "Polynomials" begin
T, x = PolynomialRing(ZZ, "x")
p = 63063000 * x^4 + 2702700 * x^3 + 16510 * x^2 + x
@test Coeffs(p) == [0, 1, 16510, 2702700, 63063000]
@test CoeffSum(p) == 65782211
@test CoeffAltSum(p) == 60376809
@test CoeffConst(p) == T(0)
@test CoeffLeading(p) == 63063000
q = x^2 - x - 1
p = 1 - x - x^2
r = ReflectPoly(p)
@test r == q
end
# *** PrimesIterator.jl *********
@testset "Primes" begin
@test PrimePi(2^14) == 1900
@test PrimePi(10^6) == 78498
end
# *** PrimeSwingFactorial.jl *********
@testset "PrimeSwingF" begin
for n ∈ 0:999
S = PSfactorial(n)
B = Base.factorial(BigInt(n))
@test all(S .== B)
end
end
# *** Products.jl *********
@testset "FallingFact" begin
@test FallingFactorial(100, 100) == factorial(BigInt(100))
@test (100↓100) == factorial(BigInt(100))
@test FallingFactorial(333, 333) == factorial(BigInt(333))
@test FallingFactorial(111, 0) == 1
end
@testset "RisingFact" begin
@test RisingFactorial(11, 11) == 14079294028800
@test (11↑11) == 14079294028800
@test RisingFactorial(
33,
33
) == 31344295059422473624824839739793024055460338073600000000
@test RisingFactorial(111, 0) == 1
end
@testset "MultiFact" begin
a = [MultiFactorial(2, 1)(n) for n ∈ 0:6]
b = [1, 1, 3, 15, 105, 945, 10395]
@test all(a .== b)
end
if data_installed()
V = [
V000142,
V000165,
V007696,
V001813,
V047053,
V001147,
V008545,
V081125,
V000407,
V032031,
V007559,
V008544
]
@testset "Products" begin
for v ∈ V
SeqTest(v, 'V')
end
end
end
# *** QueensProblems.jl *********
@testset "QueensProblem" begin
levels = [1, 10, 72, 364, 1400, 3916, 7552, 9632, 7828, 4040, 724]
@test all(L319284(10) .== levels)
end
# *** RationalTrees.jl *********
@testset "EuclidTree" begin
S = [numerator(sum(r for r ∈ EuclidTree(n))) for n ∈ 1:9]
L = fmpz[1, 5, 11, 23, 47, 95, 191, 383, 767] # A052940
@test all(S[1:9] .== L[1:9])
end
# *** RecordSearch.jl *********
# *** RiordanSquares.jl *********
@testset "RiordanSqr" begin
a = T039599(5)
b = [1, 1, 1, 2, 3, 1, 5, 9, 5, 1, 14, 28, 20, 7, 1]
@test all(a .== b)
a = T116392(5)
b = [1, 1, 1, 3, 4, 1, 7, 13, 7, 1, 19, 42, 32, 10, 1]
@test all(a .== b)
a = T172094(5)
b = [1, 1, 1, 3, 4, 1, 11, 17, 7, 1, 45, 76, 40, 10, 1]
@test all(a .== b)
a = T321620(5)
b = [1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1]
@test all(a .== b)
a = T321621(5)
b = [1, 1, 1, 2, 3, 1, 4, 8, 5, 1, 9, 21, 18, 7, 1]
@test all(a .== b)
a = T321623(5)
b = T321623(5)
@test all(a .== b)
a = T321624(5)
b = [1, 1, 1, 3, 4, 1, 4, 10, 7, 1, 7, 24, 26, 10, 1]
@test all(a .== b)
a = T322942(5)
b = [1, 1, 1, 1, 2, 1, 3, 5, 3, 1, 5, 12, 10, 4, 1]
@test all(a .== b)
end
# *** SelfConvolutive.jl *********
@testset "SelfConvRec" begin
if data_installed()
L = [
L005411,
L005412,
L006012,
L006318,
L047891,
L062980,
L082298,
L082301,
L082302,
L105523,
L107716,
L111529,
L111530,
L111531,
L111532,
L111533,
L146559,
L167872
]
SeqTest(L, 'L')
end
end
# *** SeqTests.jl *********
@testset "GenerateAll" begin
end
# *** SeqUtils.jl *********
# *** SeriesExpansion.jl *********
@testset "SeriesCoefficients" begin
a = L000032(14)
b = [1, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521]
@test all(a .== b)
a = L000073(15)
b = [1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136]
@test all(a .== b)
a = L000108(13)
b = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012]
@test all(a .== b)
a = L000257(12)
b = [1, 1, 3, 12, 56, 288, 1584, 9152, 54912, 339456, 2149888, 13891584]
@test all(a .== b)
a = L000957(13)
b = [1, 1, 0, 1, 2, 6, 18, 57, 186, 622, 2120, 7338, 25724]
@test all(a .== b)
a = L001003(12)
b = [1, 1, 3, 11, 45, 197, 903, 4279, 20793, 103049, 518859, 2646723]
@test all(a .== b)
a = L001006(14)
b = [1, 1, 2, 4, 9, 21, 51, 127, 323, 835, 2188, 5798, 15511, 41835]
@test all(a .== b)
a = L001045(13)
b = [1, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365]
@test all(a .== b)
a = L002426(12)
b = [1, 1, 3, 7, 19, 51, 141, 393, 1107, 3139, 8953, 25653]
@test all(a .== b)
a = L005043(12)
b = [1, 1, 0, 1, 1, 3, 6, 15, 36, 91, 232, 603]
@test all(a .== b)
xL006318(n) = Coefficients(G006318, n)
a = xL006318(12)
b = [1, 2, 6, 22, 90, 394, 1806, 8558, 41586, 206098, 1037718, 5293446]
@test all(a .== b)
a = L068875(10)
b = [1, 2, 4, 10, 28, 84, 264, 858, 2860, 9724]
@test all(a .== b)
end
# *** SetPartitions.jl *********
@testset "SetPartitions" begin
@test collect(SetPartitions([])) == [[]]
@test collect(SetPartitions([], 0)) == [[]]
@test collect(SetPartitions([], 1)) == []
@test collect(SetPartitions([1])) == [[[1]]]
@test collect(SetPartitions([1], 0)) == []
@test collect(SetPartitions([1], 1)) == [[[1]]]
@test collect(SetPartitions([1], 2)) == []
@test collect(SetPartitions([1,2])) == [[[1,2]],[[1],[2]]]
@test collect(SetPartitions([1,2], 0)) == []
@test collect(SetPartitions([1,2], 1)) == [[[1, 2]]]
@test collect(SetPartitions([1,2], 2)) == [[[1], [2]]]
@test collect(SetPartitions([1,2], 3)) == []
@test collect(SetPartitions(0)) == [[]]
@test collect(SetPartitions(0, 0)) == [[]]
@test collect(SetPartitions(0, 1)) == []
@test collect(SetPartitions(1)) == [[[1]]]
@test collect(SetPartitions(1, 0)) == []
@test collect(SetPartitions(1, 1)) == [[[1]]]
@test collect(SetPartitions(1, 2)) == []
@test collect(SetPartitions(2)) == [[[1,2]],[[1],[2]]]
@test collect(SetPartitions(2, 0)) == []
@test collect(SetPartitions(2, 1)) == [[[1, 2]]]
@test collect(SetPartitions(2, 2)) == [[[1], [2]]]
@test collect(SetPartitions(2, 3)) == []
SP = [ [[1,2,3]], [[1,2], [3]], [[1,3], [2]], [[1], [2,3]], [[1], [2], [3]] ]
CP = collect(SetPartitions([1, 2, 3]))
@test SP == CP
RP = reduce(vcat, [collect(SetPartitions([1, 2, 3], k)) for k ∈ 1:3])
@test SP == RP
for n ∈ 1:7
s = collect(0:n-1)
@test length(collect(SetPartitions(s))) == SetNumber(length(s))
end
for n ∈ 1:7, k ∈ 1:n
sn = SetNumber(n, k)
@test length(collect(SetPartitions(1:n, k))) == sn
end
@test_throws DomainError SetPartitions([ ], -1)
@test_throws DomainError SetPartitions([1], -1)
end
# *** SpigotPi.jl *********
@testset "Pi" begin
@test Pi(12) == "314159265358"
@test Pi(100)[100] == '7'
end
# *** StirlingLahNumbers.jl *********
# *** SwingFactorial.jl *********
@testset "SwingFactorial" begin
for n ∈ 0:999
S = Sfactorial(n)
B = Base.factorial(BigInt(n))
@test S == B
end
end
# *** Triangles.jl *********
BinTri(n) = [binomial(k, j) for k ∈ 0:n-1 for j ∈ 0:k]
X(n, k) =
((k > n || k < 0) && return 0;
(n == 0 && k == 0) && return 1;
4 * X(n - 1, k - 1) + (4 * n - 1) * X(n - 1, k))
T(n) = [X(j, k) for j ∈ 0:n for k ∈ 0:j]
@testset "Triangles" begin
t = T(6)
a = [3465, 8784, 7136, 2304, 256]
b = Row(t, 4)
@test all(a .== b)
t = BinTri(8)
a = [1, 2, 4, 8, 16, 32, 64, 128]
b = RowSums(t)
@test all(a .== b)
a = [1, 0, 0, 0, 0, 0, 0, 0]
b = RowSums(t, true)  # alternating sum
@test all(a .== b)
end
# *** UlamNumbers.jl *********
@testset "UlamNumbers" begin
@test UlamList(6)[end] == 8
end
# *** ZumkellerNumbers.jl *********
@testset "Zumkeller" begin
@test isZumkeller(17000) == true
@test isZumkeller(27472) == true
@test isZumkeller(29062) == false
@test isZumkeller(43464) == true
end
end # module

max_stars_repo_name: OpenLibMathSeq/Sequences

max_issues_repo_name: OpenLibMathSeq/Sequences


text:
@inline function parse_trigger_issue_title(issue_title::AbstractString)
    _issue_title = strip(issue_title)
    data = Dict{Symbol, String}()
    words = strip.(split(_issue_title))
    if length(words) < 2
        throw(IssueTitleError("Could not parse issue title", _issue_title))
    end
    if lowercase(words[1]) != "register"
        throw(IssueTitleError("Could not parse issue title", _issue_title))
    end
    data[:repo] = words[2]
    accepted_parameters = ["branch", "subdir"]
    parameter_regex = r"^([\w]*?)=([\w\-\/\_]*?)$"
    for word in words[3:end]
        m = match(parameter_regex, word)
        if m === nothing
            throw(IssueTitleError("Could not parse issue title", _issue_title))
        else
            param_name = m[1]
            param_value = m[2]
            if param_name in accepted_parameters
                data[Symbol(param_name)] = param_value
            else
                throw(IssueTitleError("The \"\" parameter is not allowed", _issue_title))
            end
        end
    end
    return data
end

@inline function parse_trigger_issue_title!(kwargs_dict::Dict, issue_title::AbstractString)
    for (k, v) in pairs(parse_trigger_issue_title(issue_title))
        if !haskey(kwargs_dict, k)
            kwargs_dict[k] = v
        end
    end
    return nothing
end

@inline function parse_trigger_issue_title!(kwargs_dict::Dict, issue_title::Nothing)
    return nothing
end

ext: jl


text:
const DO_NOT_PUSH_TO_THESE_DESTINATIONS = String[
    "MirrorUpdater",
    "MirrorUpdater.jl",
    "UnofficialJuliaMirrorSnapshots/MirrorUpdater",
    "UnofficialJuliaMirrorSnapshots/MirrorUpdater.jl",
    "UnofficialJuliaMirrorBot/MirrorUpdater",
    "UnofficialJuliaMirrorBot/MirrorUpdater.jl",
    #
    "Snapshots",
    "Snapshots.jl",
    "UnofficialJuliaMirrorSnapshots/Snapshots",
    "UnofficialJuliaMirrorSnapshots/Snapshots.jl",
    "UnofficialJuliaMirrorBot/Snapshots",
    "UnofficialJuliaMirrorBot/Snapshots.jl",
    ]


text:
# ENV["JULIA_DEBUG"] = "all"
print("> Connecting to debugger... ")

pushfirst!(LOAD_PATH, joinpath(@__DIR__, "..", "packages"))
import VSCodeDebugger
popfirst!(LOAD_PATH)

Base.load_julia_startup()

VSCodeDebugger.startdebugger()

max_stars_repo_name: JaapHaitsma/julia-vscode

max_issues_repo_name: JaapHaitsma/julia-vscode

max_forks_repo_name: JaapHaitsma/julia-vscode


text:
export change_input_to_row_major
export change_output_to_row_major

function change_input_to_row_major(x)
    return permutedims(reshape(x, reverse(size(x))), length(size(x)):-1:1)
end

function change_output_to_row_major(x)
    return reshape(permutedims(x, length(size(x)):-1:1), size(x))
end


text:
#=

N-Queens problem in ConstraintSolver.jl

Performance (timeout 60s):
n:8
  0.004049 seconds (23.04 k allocations: 1.663 MiB)

n:12
  0.018140 seconds (113.31 k allocations: 8.275 MiB)

n:50
  0.102909 seconds (531.49 k allocations: 43.128 MiB)

n:100
  0.297124 seconds (637.23 k allocations: 69.590 MiB, 34.21% gc time)

n:200
  1.427308 seconds (2.57 M allocations: 341.693 MiB, 7.26% gc time)

n:300
  4.453372 seconds (5.99 M allocations: 878.029 MiB, 6.68% gc time)

n:400
 10.641826 seconds (11.54 M allocations: 1.767 GiB, 9.06% gc time)

n:500
status:TIME_LIMIT
 60.136410 seconds (110.37 M allocations: 8.428 GiB, 10.85% gc time)

 77.461974 seconds (132.85 M allocations: 11.574 GiB, 10.32% gc time, 0.21% compilation time)

Model created by Hakan Kjellerstrand, hakank@gmail.com
See also my Julia page: http://www.hakank.org/julia/

=#

using ConstraintSolver, JuMP
using Cbc, GLPK, Ipopt
const CS = ConstraintSolver
include("constraints_utils.jl")

function nqueens(n=8,print_solutions=true,all_solutions=true,timeout=6)

    cbc_optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
    glpk_optimizer = optimizer_with_attributes(GLPK.Optimizer)
    ipopt_optimizer = optimizer_with_attributes(Ipopt.Optimizer)

    model = Model(optimizer_with_attributes(CS.Optimizer,   "all_solutions"=> all_solutions,
                                                            # "all_optimal_solutions"=>all_solutions,
                                                            "logging"=>[],

                                                            "traverse_strategy"=>:BFS,
                                                            # "traverse_strategy"=>:DFS,
                                                            # "traverse_strategy"=>:DBFS,

                                                            # "branch_split"=>:Smallest,
                                                            "branch_split"=>:Biggest,
                                                            # "branch_split"=>:InHalf,

                                                            # https://wikunia.github.io/ConstraintSolver.jl/stable/options/#branch_strategy-(:Auto)
                                                            "branch_strategy" => :IMPS, # default
                                                            # "branch_strategy" => :ABS, # Activity Based Search
                                                            # "activity.decay" => 0.999, # default 0.999
                                                            # "activity.max_probes" => 10, # default, 10
                                                            # "activity.max_confidence_deviation" => 20, # default 20

                                                            # "simplify"=>false,
                                                            # "simplify"=>true, # default

                                                            "time_limit"=>timeout,

                                                            # "backtrack" => false, # default true
                                                            # "backtrack_sorting" => false, # default true

                                                            # "lp_optimizer" => cbc_optimizer,
                                                            # "lp_optimizer" => glpk_optimizer,
                                                            # "lp_optimizer" => ipopt_optimizer,
                                        ))

    @variable(model, 1 <= x[1:n] <= n, Int)
    @variable(model, 0 <= t1[1:n] <= n*2, Int)
    @variable(model, -n <= t2[1:n] <= n, Int)

    @constraint(model, x in CS.AllDifferent())
    for i in 1:n
        @constraint(model, x[i] + i == t1[i])
        @constraint(model, x[i] - i == t2[i])
    end
    @constraint(model, t1 in CS.AllDifferent())
    @constraint(model, t2 in CS.AllDifferent())

    # This don't work:
    # """
    # Each variable must be an integer and bounded.
    # Currently the variable index 9 doesn't fulfill this requirements.
    # """
    # @constraint(model, [t1[i] + i for i in 1:n] in CS.AllDifferent())
    # @constraint(model, [x[i] - i for i in 1:n] in CS.AllDifferent())

    #=
    # This is another approach, but slower.
    for i in 1:n, j in i+1:n
        @constraint(model, x[i] != x[j])
        @constraint(model, x[i] + i != x[j] + j)
        @constraint(model, x[i] - i != x[j] - j)
    end
    =#

    # Solve the problem
    optimize!(model)

    status = JuMP.termination_status(model)
    # println("status:$status")
    num_sols = 0
    if status == MOI.OPTIMAL
        num_sols = MOI.get(model, MOI.ResultCount())
        # println("num_sols:$num_sols\n")
        if print_solutions
            for sol in 1:num_sols
                # println("solution #$sol")
                x_val = convert.(Integer,JuMP.value.(x; result=sol))
                # t1_val = convert.(Integer,JuMP.value.(t1; result=sol))
                # t2_val = convert.(Integer,JuMP.value.(t2; result=sol))
                println("x:$x_val")
                # println("t1:$t1_val")
                # println("t2:$t2_val")
                # println()

            end
        end
    else
        println("status:$status")
    end
    println("num_sols: $num_sols")
    return status, num_sols
end

@time nqueens(8)

for n in [8,12,50,100,200,300,400,500]
    println("\nn:$n")
    @time status, num_sols = nqueens(n,false,false,60)
    if status == MOI.TIME_LIMIT
        break
    end
end

max_stars_repo_name: tias/hakank

max_issues_repo_name: tias/hakank

max_forks_repo_name: tias/hakank


text:
# Julia wrapper for header: sunlinsol_band.h
# Automatically generated using Clang.jl

function SUNLinSol_Band(y::N_Vector, A::SUNMatrix)
    ccall((:SUNLinSol_Band, libsundials_sunlinsolband), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNLinSol_Band(y, A)
    __y = convert(NVector, y)
    SUNLinSol_Band(convert(N_Vector, __y), A)
end

function SUNBandLinearSolver(y::N_Vector, A::SUNMatrix)
    ccall((:SUNBandLinearSolver, libsundials_sunlinsolband), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNBandLinearSolver(y, A)
    __y = convert(NVector, y)
    SUNBandLinearSolver(convert(N_Vector, __y), A)
end

function SUNLinSolGetType_Band(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_Band, libsundials_sunlinsolband), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_Band(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_Band, libsundials_sunlinsolband), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_Band(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_Band, libsundials_sunlinsolband), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetup_Band(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_Band, libsundials_sunlinsolband), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_Band(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_Band, libsundials_sunlinsolband), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_Band(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_Band(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolLastFlag_Band(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_Band, libsundials_sunlinsolband), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_Band(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_Band, libsundials_sunlinsolband), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_Band(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_Band, libsundials_sunlinsolband), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_dense.h
# Automatically generated using Clang.jl

function SUNLinSol_Dense(y::N_Vector, A::SUNMatrix)
    ccall((:SUNLinSol_Dense, libsundials_sunlinsoldense), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNLinSol_Dense(y, A)
    __y = convert(NVector, y)
    SUNLinSol_Dense(convert(N_Vector,  __y), A)
end

function SUNDenseLinearSolver(y::N_Vector, A::SUNMatrix)
    ccall((:SUNDenseLinearSolver, libsundials_sunlinsoldense), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNDenseLinearSolver(y, A)
    __y = convert(NVector, y)
    SUNDenseLinearSolver(convert(N_Vector, __y), A)
end

function SUNLinSolGetType_Dense(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_Dense, libsundials_sunlinsoldense), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_Dense(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_Dense, libsundials_sunlinsoldense), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_Dense(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_Dense, libsundials_sunlinsoldense), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetup_Dense(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_Dense, libsundials_sunlinsoldense), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_Dense(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_Dense, libsundials_sunlinsoldense), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_Dense(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_Dense(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolLastFlag_Dense(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_Dense, libsundials_sunlinsoldense), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_Dense(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_Dense, libsundials_sunlinsoldense), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_Dense(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_Dense, libsundials_sunlinsoldense), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_klu.h
# Automatically generated using Clang.jl

function SUNLinSol_KLU(y::N_Vector, A::SUNMatrix)
    ccall((:SUNLinSol_KLU, libsundials_sunlinsolklu), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNLinSol_KLU(y, A)
    __y = convert(NVector, y)
    SUNLinSol_KLU(convert(N_Vector, __y), A)
end

function SUNLinSol_KLUReInit(S::SUNLinearSolver, A::SUNMatrix, nnz::sunindextype, reinit_type::Cint)
    ccall((:SUNLinSol_KLUReInit, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, SUNMatrix, sunindextype, Cint), S, A, nnz, reinit_type)
end

function SUNLinSol_KLUReInit(S, A, nnz, reinit_type)
    SUNLinSol_KLUReInit(S, A, nnz, convert(Cint, reinit_type))
end

function SUNLinSol_KLUSetOrdering(S::SUNLinearSolver, ordering_choice::Cint)
    ccall((:SUNLinSol_KLUSetOrdering, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, Cint), S, ordering_choice)
end

function SUNLinSol_KLUSetOrdering(S, ordering_choice)
    SUNLinSol_KLUSetOrdering(S, convert(Cint, ordering_choice))
end

function SUNKLU(y::N_Vector, A::SUNMatrix)
    ccall((:SUNKLU, libsundials_sunlinsolklu), SUNLinearSolver, (N_Vector, SUNMatrix), y, A)
end

function SUNKLU(y, A)
    __y = convert(NVector, y)
    SUNKLU(convert(N_Vector, y), A)
end

function SUNKLUReInit(S::SUNLinearSolver, A::SUNMatrix, nnz::sunindextype, reinit_type::Cint)
    ccall((:SUNKLUReInit, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, SUNMatrix, sunindextype, Cint), S, A, nnz, reinit_type)
end

function SUNKLUReInit(S, A, nnz, reinit_type)
    SUNKLUReInit(S, A, nnz, convert(Cint, reinit_type))
end

function SUNKLUSetOrdering(S::SUNLinearSolver, ordering_choice::Cint)
    ccall((:SUNKLUSetOrdering, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, Cint), S, ordering_choice)
end

function SUNKLUSetOrdering(S, ordering_choice)
    SUNKLUSetOrdering(S, convert(Cint, ordering_choice))
end

function SUNLinSol_KLUGetSymbolic(S::SUNLinearSolver)
    ccall((:SUNLinSol_KLUGetSymbolic, libsundials_sunlinsolklu), Ptr{klu_l_symbolic}, (SUNLinearSolver,), S)
end

function SUNLinSol_KLUGetNumeric(S::SUNLinearSolver)
    ccall((:SUNLinSol_KLUGetNumeric, libsundials_sunlinsolklu), Ptr{klu_l_numeric}, (SUNLinearSolver,), S)
end

function SUNLinSol_KLUGetCommon(S::SUNLinearSolver)
    ccall((:SUNLinSol_KLUGetCommon, libsundials_sunlinsolklu), Ptr{klu_l_common}, (SUNLinearSolver,), S)
end

function SUNLinSolGetType_KLU(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_KLU, libsundials_sunlinsolklu), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_KLU(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_KLU, libsundials_sunlinsolklu), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_KLU(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_KLU, libsundials_sunlinsolklu), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetup_KLU(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_KLU, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_KLU(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_KLU, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_KLU(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_KLU(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolLastFlag_KLU(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_KLU, libsundials_sunlinsolklu), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_KLU(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_KLU, libsundials_sunlinsolklu), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_KLU(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_KLU, libsundials_sunlinsolklu), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_pcg.h
# Automatically generated using Clang.jl

function SUNLinSol_PCG(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNLinSol_PCG, libsundials_sunlinsolpcg), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNLinSol_PCG(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNLinSol_PCG(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNLinSol_PCGSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNLinSol_PCGSetPrecType, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNLinSol_PCGSetPrecType(S, pretype)
    SUNLinSol_PCGSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSol_PCGSetMaxl(S::SUNLinearSolver, maxl::Cint)
    ccall((:SUNLinSol_PCGSetMaxl, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Cint), S, maxl)
end

function SUNLinSol_PCGSetMaxl(S, maxl)
    SUNLinSol_PCGSetMaxl(S, convert(Cint, maxl))
end

function SUNPCG(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNPCG, libsundials_sunlinsolpcg), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNPCG(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNPCG(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNPCGSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNPCGSetPrecType, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNPCGSetPrecType(S, pretype)
    SUNPCGSetPrecType(S, convert(Cint, pretype))
end

function SUNPCGSetMaxl(S::SUNLinearSolver, maxl::Cint)
    ccall((:SUNPCGSetMaxl, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Cint), S, maxl)
end

function SUNPCGSetMaxl(S, maxl)
    SUNPCGSetMaxl(S, convert(Cint, maxl))
end

function SUNLinSolGetType_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_PCG, libsundials_sunlinsolpcg), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_PCG, libsundials_sunlinsolpcg), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetATimes_PCG(S::SUNLinearSolver, A_data, ATimes::ATimesFn)
    ccall((:SUNLinSolSetATimes_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Ptr{Cvoid}, ATimesFn), S, A_data, ATimes)
end

function SUNLinSolSetPreconditioner_PCG(S::SUNLinearSolver, P_data, Pset::PSetupFn, Psol::PSolveFn)
    ccall((:SUNLinSolSetPreconditioner_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Ptr{Cvoid}, PSetupFn, PSolveFn), S, P_data, Pset, Psol)
end

function SUNLinSolSetScalingVectors_PCG(S::SUNLinearSolver, s::N_Vector, nul::N_Vector)
    ccall((:SUNLinSolSetScalingVectors_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, N_Vector, N_Vector), S, s, nul)
end

function SUNLinSolSetScalingVectors_PCG(S, s, nul)
    __s = convert(NVector, s)
    __nul = convert(NVector, nul)
    SUNLinSolSetScalingVectors_PCG(S, convert(N_Vector, __s), convert(N_Vector, __nul))
end

function SUNLinSolSetup_PCG(S::SUNLinearSolver, nul::SUNMatrix)
    ccall((:SUNLinSolSetup_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, SUNMatrix), S, nul)
end

function SUNLinSolSolve_PCG(S::SUNLinearSolver, nul::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, nul, x, b, tol)
end

function SUNLinSolSolve_PCG(S, nul, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_PCG(S, nul, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolNumIters_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolNumIters_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolResNorm_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolResNorm_PCG, libsundials_sunlinsolpcg), realtype, (SUNLinearSolver,), S)
end

function SUNLinSolResid_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolResid_PCG, libsundials_sunlinsolpcg), N_Vector, (SUNLinearSolver,), S)
end

function SUNLinSolLastFlag_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_PCG, libsundials_sunlinsolpcg), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_PCG(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_PCG(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_PCG, libsundials_sunlinsolpcg), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_spbcgs.h
# Automatically generated using Clang.jl

function SUNLinSol_SPBCGS(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNLinSol_SPBCGS, libsundials_sunlinsolspbcgs), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNLinSol_SPBCGS(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNLinSol_SPBCGS(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNLinSol_SPBCGSSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNLinSol_SPBCGSSetPrecType, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNLinSol_SPBCGSSetPrecType(S::SUNLinearSolver, pretype)
    SUNLinSol_SPBCGSSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSol_SPBCGSSetMaxl(S::SUNLinearSolver, maxl::Cint)
    ccall((:SUNLinSol_SPBCGSSetMaxl, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Cint), S, maxl)
end

function SUNLinSol_SPBCGSSetMaxl(S::SUNLinearSolver, maxl)
    SUNLinSol_SPBCGSSetMaxl(S, convert(Cint, maxl))
end

function SUNSPBCGS(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNSPBCGS, libsundials_sunlinsolspbcgs), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNSPBCGS(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNSPBCGS(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNSPBCGSSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNSPBCGSSetPrecType, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNSPBCGSSetPrecType(S, pretype)
    SUNSPBCGSSetPrecType(S, convert(Cint, pretype))
end

function SUNSPBCGSSetMaxl(S::SUNLinearSolver, maxl::Cint)
    ccall((:SUNSPBCGSSetMaxl, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Cint), S, maxl)
end

function SUNSPBCGSSetMaxl(S, maxl)
    SUNSPBCGSSetMaxl(S, convert(Cint, maxl))
end

function SUNLinSolGetType_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_SPBCGS, libsundials_sunlinsolspbcgs), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_SPBCGS, libsundials_sunlinsolspbcgs), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetATimes_SPBCGS(S::SUNLinearSolver, A_data, ATimes::ATimesFn)
    ccall((:SUNLinSolSetATimes_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Ptr{Cvoid}, ATimesFn), S, A_data, ATimes)
end

function SUNLinSolSetPreconditioner_SPBCGS(S::SUNLinearSolver, P_data, Pset::PSetupFn, Psol::PSolveFn)
    ccall((:SUNLinSolSetPreconditioner_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Ptr{Cvoid}, PSetupFn, PSolveFn), S, P_data, Pset, Psol)
end

function SUNLinSolSetScalingVectors_SPBCGS(S::SUNLinearSolver, s1::N_Vector, s2::N_Vector)
    ccall((:SUNLinSolSetScalingVectors_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, N_Vector, N_Vector), S, s1, s2)
end

function SUNLinSolSetScalingVectors_SPBCGS(S, s1, s2)
    __s1 = convert(NVector, s1)
    __s2 = convert(NVector, s2)
    SUNLinSolSetScalingVectors_SPBCGS(S, convert(N_Vector, __s1), convert(N_Vector, __s2))
end

function SUNLinSolSetup_SPBCGS(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_SPBCGS(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_SPBCGS(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_SPBCGS(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolNumIters_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolNumIters_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolResNorm_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolResNorm_SPBCGS, libsundials_sunlinsolspbcgs), realtype, (SUNLinearSolver,), S)
end

function SUNLinSolResid_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolResid_SPBCGS, libsundials_sunlinsolspbcgs), N_Vector, (SUNLinearSolver,), S)
end

function SUNLinSolLastFlag_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_SPBCGS, libsundials_sunlinsolspbcgs), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_SPBCGS(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_SPBCGS(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_SPBCGS, libsundials_sunlinsolspbcgs), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_spfgmr.h
# Automatically generated using Clang.jl

function SUNLinSol_SPFGMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNLinSol_SPFGMR, libsundials_sunlinsolspfgmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNLinSol_SPFGMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNLinSol_SPFGMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNLinSol_SPFGMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNLinSol_SPFGMRSetPrecType, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNLinSol_SPFGMRSetPrecType(S, pretype)
    SUNLinSol_SPFGMRSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSol_SPFGMRSetGSType(S::SUNLinearSolver, gstype::Cint)
    ccall((:SUNLinSol_SPFGMRSetGSType, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, gstype)
end

function SUNLinSol_SPFGMRSetGSType(S, gstype)
    SUNLinSol_SPFGMRSetGSType(S, convert(Cint, gstype))
end

function SUNLinSol_SPFGMRSetMaxRestarts(S::SUNLinearSolver, maxrs::Cint)
    ccall((:SUNLinSol_SPFGMRSetMaxRestarts, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, maxrs)
end

function SUNLinSol_SPFGMRSetMaxRestarts(S, maxrs)
    SUNLinSol_SPFGMRSetMaxRestarts(S, convert(Cint, maxrs))
end

function SUNSPFGMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNSPFGMR, libsundials_sunlinsolspfgmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNSPFGMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNSPFGMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNSPFGMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNSPFGMRSetPrecType, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNSPFGMRSetPrecType(S, pretype)
    SUNSPFGMRSetPrecType(S, convert(Cint, pretype))
end

function SUNSPFGMRSetGSType(S::SUNLinearSolver, gstype::Cint)
    ccall((:SUNSPFGMRSetGSType, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, gstype)
end

function SUNSPFGMRSetGSType(S, gstype)
    SUNSPFGMRSetGSType(S, convert(Cint, gstype))
end

function SUNSPFGMRSetMaxRestarts(S::SUNLinearSolver, maxrs::Cint)
    ccall((:SUNSPFGMRSetMaxRestarts, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Cint), S, maxrs)
end

function SUNSPFGMRSetMaxRestarts(S, maxrs)
    SUNSPFGMRSetMaxRestarts(S, convert(Cint, maxrs))
end

function SUNLinSolGetType_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_SPFGMR, libsundials_sunlinsolspfgmr), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_SPFGMR, libsundials_sunlinsolspfgmr), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetATimes_SPFGMR(S::SUNLinearSolver, A_data, ATimes::ATimesFn)
    ccall((:SUNLinSolSetATimes_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, ATimesFn), S, A_data, ATimes)
end

function SUNLinSolSetPreconditioner_SPFGMR(S::SUNLinearSolver, P_data, Pset::PSetupFn, Psol::PSolveFn)
    ccall((:SUNLinSolSetPreconditioner_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, PSetupFn, PSolveFn), S, P_data, Pset, Psol)
end

function SUNLinSolSetScalingVectors_SPFGMR(S::SUNLinearSolver, s1::N_Vector, s2::N_Vector)
    ccall((:SUNLinSolSetScalingVectors_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, N_Vector, N_Vector), S, s1, s2)
end

function SUNLinSolSetScalingVectors_SPFGMR(S, s1, s2)
    __s1 = convert(NVector, s1)
    __s2 = convert(NVector, s2)
    SUNLinSolSetScalingVectors_SPFGMR(S, convert(N_Vector, __s1), convert(N_Vector, __s2))
end

function SUNLinSolSetup_SPFGMR(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_SPFGMR(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_SPFGMR(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_SPFGMR(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolNumIters_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolNumIters_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolResNorm_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResNorm_SPFGMR, libsundials_sunlinsolspfgmr), realtype, (SUNLinearSolver,), S)
end

function SUNLinSolResid_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResid_SPFGMR, libsundials_sunlinsolspfgmr), N_Vector, (SUNLinearSolver,), S)
end

function SUNLinSolLastFlag_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_SPFGMR, libsundials_sunlinsolspfgmr), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_SPFGMR(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_SPFGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_SPFGMR, libsundials_sunlinsolspfgmr), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_spgmr.h
# Automatically generated using Clang.jl

function SUNLinSol_SPGMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNLinSol_SPGMR, libsundials_sunlinsolspgmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNLinSol_SPGMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNLinSol_SPGMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNLinSol_SPGMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNLinSol_SPGMRSetPrecType, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNLinSol_SPGMRSetPrecType(S, pretype)
    SUNLinSol_SPGMRSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSol_SPGMRSetGSType(S::SUNLinearSolver, gstype::Cint)
    ccall((:SUNLinSol_SPGMRSetGSType, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, gstype)
end

function SUNLinSol_SPGMRSetGSType(S, gstype)
    SUNLinSol_SPGMRSetGSType(S, convert(Cint, gstype))
end

function SUNLinSol_SPGMRSetMaxRestarts(S::SUNLinearSolver, maxrs::Cint)
    ccall((:SUNLinSol_SPGMRSetMaxRestarts, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, maxrs)
end

function SUNLinSol_SPGMRSetMaxRestarts(S::SUNLinearSolver, maxrs)
    SUNLinSol_SPGMRSetMaxRestarts(S, convert(Cint, maxrs))
end

function SUNSPGMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNSPGMR, libsundials_sunlinsolspgmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNSPGMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNSPGMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNSPGMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNSPGMRSetPrecType, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNSPGMRSetPrecType(S, pretype)
    SUNSPGMRSetPrecType(S, convert(Cint, pretype))
end

function SUNSPGMRSetGSType(S::SUNLinearSolver, gstype::Cint)
    ccall((:SUNSPGMRSetGSType, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, gstype)
end

function SUNSPGMRSetGSType(S, gstype)
    SUNSPGMRSetGSType(S, convert(Cint, gstype))
end

function SUNSPGMRSetMaxRestarts(S::SUNLinearSolver, maxrs::Cint)
    ccall((:SUNSPGMRSetMaxRestarts, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Cint), S, maxrs)
end

function SUNSPGMRSetMaxRestarts(S, maxrs)
    SUNSPGMRSetMaxRestarts(S, convert(Cint, maxrs))
end

function SUNLinSolGetType_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_SPGMR, libsundials_sunlinsolspgmr), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_SPGMR, libsundials_sunlinsolspgmr), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetATimes_SPGMR(S::SUNLinearSolver, A_data, ATimes::ATimesFn)
    ccall((:SUNLinSolSetATimes_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, ATimesFn), S, A_data, ATimes)
end

function SUNLinSolSetPreconditioner_SPGMR(S::SUNLinearSolver, P_data, Pset::PSetupFn, Psol::PSolveFn)
    ccall((:SUNLinSolSetPreconditioner_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, PSetupFn, PSolveFn), S, P_data, Pset, Psol)
end

function SUNLinSolSetScalingVectors_SPGMR(S::SUNLinearSolver, s1::N_Vector, s2::N_Vector)
    ccall((:SUNLinSolSetScalingVectors_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, N_Vector, N_Vector), S, s1, s2)
end

function SUNLinSolSetScalingVectors_SPGMR(S, s1, s2)
    __s1 = convert(NVector, s1)
    __s2 = convert(NVector, s2)
    SUNLinSolSetScalingVectors_SPGMR(S, convert(N_Vector, __s1), convert(N_Vector, __s2))
end

function SUNLinSolSetup_SPGMR(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_SPGMR(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_SPGMR(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_SPGMR(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolNumIters_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolNumIters_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolResNorm_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResNorm_SPGMR, libsundials_sunlinsolspgmr), realtype, (SUNLinearSolver,), S)
end

function SUNLinSolResid_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResid_SPGMR, libsundials_sunlinsolspgmr), N_Vector, (SUNLinearSolver,), S)
end

function SUNLinSolLastFlag_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_SPGMR, libsundials_sunlinsolspgmr), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_SPGMR(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_SPGMR(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_SPGMR, libsundials_sunlinsolspgmr), Cint, (SUNLinearSolver,), S)
end
# Julia wrapper for header: sunlinsol_sptfqmr.h
# Automatically generated using Clang.jl

function SUNLinSol_SPTFQMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNLinSol_SPTFQMR, libsundials_sunlinsolsptfqmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNLinSol_SPTFQMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNLinSol_SPTFQMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNLinSol_SPTFQMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNLinSol_SPTFQMRSetPrecType, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNLinSol_SPTFQMRSetPrecType(S, pretype)
    SUNLinSol_SPTFQMRSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSol_SPTFQMRSetMaxl(S::SUNLinearSolver, maxl::Cint)
    ccall((:SUNLinSol_SPTFQMRSetMaxl, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Cint), S, maxl)
end

function SUNLinSol_SPTFQMRSetMaxl(S, maxl)
    SUNLinSol_SPTFQMRSetMaxl(S, convert(Cint, maxl))
end

function SUNSPTFQMR(y::N_Vector, pretype::Cint, maxl::Cint)
    ccall((:SUNSPTFQMR, libsundials_sunlinsolsptfqmr), SUNLinearSolver, (N_Vector, Cint, Cint), y, pretype, maxl)
end

function SUNSPTFQMR(y, pretype, maxl)
    __y = convert(NVector, y)
    SUNSPTFQMR(convert(N_Vector, __y), convert(Cint, pretype), convert(Cint, maxl))
end

function SUNSPTFQMRSetPrecType(S::SUNLinearSolver, pretype::Cint)
    ccall((:SUNSPTFQMRSetPrecType, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Cint), S, pretype)
end

function SUNSPTFQMRSetPrecType(S, pretype)
    SUNSPTFQMRSetPrecType(S, convert(Cint, pretype))
end

function SUNLinSolGetType_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetType_SPTFQMR, libsundials_sunlinsolsptfqmr), SUNLinearSolver_Type, (SUNLinearSolver,), S)
end

function SUNLinSolGetID_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolGetID_SPTFQMR, libsundials_sunlinsolsptfqmr), SUNLinearSolver_ID, (SUNLinearSolver,), S)
end

function SUNLinSolInitialize_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolInitialize_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolSetATimes_SPTFQMR(S::SUNLinearSolver, A_data, ATimes::ATimesFn)
    ccall((:SUNLinSolSetATimes_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, ATimesFn), S, A_data, ATimes)
end

function SUNLinSolSetPreconditioner_SPTFQMR(S::SUNLinearSolver, P_data, Pset::PSetupFn, Psol::PSolveFn)
    ccall((:SUNLinSolSetPreconditioner_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Ptr{Cvoid}, PSetupFn, PSolveFn), S, P_data, Pset, Psol)
end

function SUNLinSolSetScalingVectors_SPTFQMR(S::SUNLinearSolver, s1::N_Vector, s2::N_Vector)
    ccall((:SUNLinSolSetScalingVectors_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, N_Vector, N_Vector), S, s1, s2)
end

function SUNLinSolSetScalingVectors_SPTFQMR(S, s1, s2)
    __s1 = convert(NVector, s1)
    __s2 = convert(NVector, s2)
    SUNLinSolSetScalingVectors_SPTFQMR(S, convert(N_Vector, __s1), convert(N_Vector, __s2))
end

function SUNLinSolSetup_SPTFQMR(S::SUNLinearSolver, A::SUNMatrix)
    ccall((:SUNLinSolSetup_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, SUNMatrix), S, A)
end

function SUNLinSolSolve_SPTFQMR(S::SUNLinearSolver, A::SUNMatrix, x::N_Vector, b::N_Vector, tol::realtype)
    ccall((:SUNLinSolSolve_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, SUNMatrix, N_Vector, N_Vector, realtype), S, A, x, b, tol)
end

function SUNLinSolSolve_SPTFQMR(S, A, x, b, tol)
    __x = convert(NVector, x)
    __b = convert(NVector, b)
    SUNLinSolSolve_SPTFQMR(S, A, convert(N_Vector, __x), convert(N_Vector, __b), tol)
end

function SUNLinSolNumIters_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolNumIters_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver,), S)
end

function SUNLinSolResNorm_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResNorm_SPTFQMR, libsundials_sunlinsolsptfqmr), realtype, (SUNLinearSolver,), S)
end

function SUNLinSolResid_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolResid_SPTFQMR, libsundials_sunlinsolsptfqmr), N_Vector, (SUNLinearSolver,), S)
end

function SUNLinSolLastFlag_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolLastFlag_SPTFQMR, libsundials_sunlinsolsptfqmr), sunindextype, (SUNLinearSolver,), S)
end

function SUNLinSolSpace_SPTFQMR(S::SUNLinearSolver, lenrwLS, leniwLS)
    ccall((:SUNLinSolSpace_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver, Ptr{Clong}, Ptr{Clong}), S, lenrwLS, leniwLS)
end

function SUNLinSolFree_SPTFQMR(S::SUNLinearSolver)
    ccall((:SUNLinSolFree_SPTFQMR, libsundials_sunlinsolsptfqmr), Cint, (SUNLinearSolver,), S)
end


text:
const DEFAULT_FITTING_RELTOL = 1e-6
const DEFAULT_FITTING_ABSTOL = 1e-8

### general interface

"""
    fit(scenario_pairs::AbstractVector{Pair{Symbol, C}},
      params::Vector{Pair{Symbol,Float64}};
      alg=DEFAULT_ALG,
      reltol=DEFAULT_FITTING_RELTOL,
      abstol=DEFAULT_FITTING_ABSTOL,
      parallel_type=EnsembleSerial(),
      ftol_abs = 0.0,
      ftol_rel = 1e-4,
      xtol_rel = 0.0,
      xtol_abs = 0.0,
      fit_alg = :LN_NELDERMEAD,
      maxeval = 10000,
      maxtime = 0.0,
      lbounds = fill(0.0, length(params)),
      ubounds = fill(Inf, length(params)),
      kwargs...
    ) where C<:AbstractScenario

Fit parameters to experimental measurements. Returns `FitResult` type.

Example: `fit([:x=>scn2, :y=>scn3, :z=>scn4], [:k1=>0.1,:k2=>0.2,:k3=>0.3])`

Arguments:

- `scenario_pairs` : vector of pairs containing names and scenarios of type [`Scenario`](@ref)
- `params` : optimization parameters and their initial values
- `parameters_upd` : constants, which overwrite both `Model` and `Scenario` constants. Default is `nothing`
- `alg` : ODE solver. See SciML docs for details. Default is AutoTsit5(Rosenbrock23())
- `reltol` : relative tolerance. Default is 1e-6
- `abstol` : relative tolerance. Default is 1e-8
- `parallel_type` : parallel setup. See SciML docs for details. Default is no parallelism: EnsembleSerial()
- `ftol_abs` : absolute tolerance on function value. See `NLopt.jl` docs for details. Default is `0.0`
- `ftol_rel` : relative tolerance on function value. See `NLopt.jl` docs for details. Default is `1e-4`
- `xtol_rel` : relative tolerance on optimization parameters. See `NLopt.jl` docs for details. Default is `0.0`
- `xtol_rel` : absolute tolerance on optimization parameters. See `NLopt.jl` docs for details. Default is `0.0`
- `fit_alg` : fitting algorithm. See `NLopt.jl` docs for details. Default is `:LN_NELDERMEAD`
- `maxeval` : maximum number of function evaluations. See `NLopt.jl` docs for details. Default is `1e4`
- `maxtime` : maximum optimization time (in seconds). See `NLopt.jl` docs for details. Default is `0`
- `lbounds` : lower parameters bounds. See `NLopt.jl` docs for details. Default is `fill(0.0, length(params))`
- `ubounds` : upper parameters bounds. See `NLopt.jl` docs for details. Default is `fill(Inf, length(params))`
- `scale`   : scale of the parameters (supports `:lin, :log, :log10`) to be used during fitting. Default is `fill(:lin, length(params))`
- kwargs : other solver related arguments supported by DiffEqBase.solve. See SciML docs for details
"""
function fit(
  scenario_pairs::AbstractVector{Pair{Symbol, C}},
  params::Vector{Pair{Symbol,Float64}};
  parameters_upd::Union{Nothing, Vector{P}}=nothing,
  alg=DEFAULT_ALG,
  reltol=DEFAULT_FITTING_RELTOL,
  abstol=DEFAULT_FITTING_ABSTOL,
  parallel_type=EnsembleSerial(),
  ftol_abs = 0.0,
  ftol_rel = 1e-4,
  xtol_rel = 0.0,
  xtol_abs = 0.0,
  fit_alg = :LN_NELDERMEAD,
  maxeval = 10000,
  maxtime = 0.0,
  lbounds = fill(0.0, length(params)),
  ubounds = fill(Inf, length(params)),
  scale = fill(:lin, length(params)),
  kwargs... # other arguments to sim()
) where {C<:AbstractScenario, P<:Pair}

  # names of parameters used in fitting and saved in params field of solution
  params_names = first.(params)

  selected_scenario_pairs = Pair{Symbol,Scenario}[]
  for scenario_pair in scenario_pairs # iterate through scenarios names
    if isempty(last(scenario_pair).measurements)
      @warn "Scenario \":$(first(scenario_pair))\" has no measurements. It will be excluded from fitting."
    else
      push!(selected_scenario_pairs, scenario_pair)
    end
  end

  isempty(selected_scenario_pairs) && throw("No measurements points included in scenarios.")

  # update saveat and initial values
  selected_prob = []
  for scn in selected_scenario_pairs
    prob_i = remake_saveat(last(scn).prob, last(scn).measurements)
    prob_i = !isnothing(parameters_upd) ? update_init_values(prob_i, last(scn).init_func, NamedTuple(parameters_upd)) : prob_i
    push!(selected_prob, prob_i)
  end

  function prob_func(x)
    function internal_prob_func(prob,i,repeat)
      update_init_values(selected_prob[i],last(selected_scenario_pairs[i]).init_func,x)
    end
  end

  function _output(sol, i)
    sol.retcode != :Success && error("Simulated scenario $i returned $(sol.retcode) status")
    sim = build_results(sol,last(selected_scenario_pairs[i]), params_names)
    loss_val = loss(sim, sim.scenario.measurements)
    (loss_val, false)
  end

  function _reduction(u, batch, I)
    (sum(batch),false)
  end

  prob(x) = EnsembleProblem(EMPTY_PROBLEM;
    prob_func = prob_func(x),
    output_func = _output,
    reduction = _reduction
  )

  function obj_func(x, grad)
    # try - catch is a tmp solution for NLopt
    x_nt = NamedTuple{Tuple(params_names)}(unscale_params.(x, scale))
    prob_i = prob(x_nt)
    sol = try
      solve(prob_i, alg, parallel_type;
        trajectories = length(selected_scenario_pairs),
        reltol,
        abstol,
        save_start = false,
        save_end = false,
        save_everystep = false,
        kwargs...
    )
    catch e
        @warn "Error when calling loss_func($x): $e"
    end
    #println(x_pairs)
    return sol.u
  end

  opt = Opt(fit_alg, length(params))
  opt.min_objective = obj_func

  opt.ftol_rel = ftol_rel
  opt.ftol_abs = ftol_abs

  opt.xtol_rel = xtol_rel
  opt.xtol_abs = xtol_abs

  opt.maxeval = maxeval
  opt.maxtime = maxtime

  lower_bounds!(opt, scale_params.(lbounds, scale))
  upper_bounds!(opt, scale_params.(ubounds, scale))

  params0 = scale_params.(last.(params), scale)
  (minf, minx, ret) = NLopt.optimize(opt, params0)

  # to create pairs from Float64
  minx_pairs = [key=>value for (key, value) in zip(first.(params), unscale_params.(minx, scale))]

  return FitResult(minf, minx_pairs, ret, opt.numevals)

end

"""
    fit(scenario_pairs::AbstractVector{Pair{Symbol, C}},
      params_df::DataFrame;
      kwargs...
    ) where C<:AbstractScenario

Fit parameters to experimental measurements. Returns `FitResult` type.

Arguments:

- `scenario_pairs` : vector of pairs containing names and scenarios of type [`Scenario`](@ref)
- `params` : DataFrame with optimization parameters setup and their initial values
- kwargs : other solver related arguments supported by `fit(scenario_pairs::Vector{<:Pair}, params::Vector{<:Pair}`
"""
function fit(
  scenario_pairs::AbstractVector{Pair{Symbol, C}},
  params_df::DataFrame;
  kwargs...
) where C<:AbstractScenario

  gdf = groupby(params_df, :estimate)
  @assert haskey(gdf, (true,)) "No parameters to estimate."

  params = gdf[(true,)].parameter .=> gdf[(true,)].nominal
  lbounds = gdf[(true,)].lower
  ubounds = gdf[(true,)].upper
  scale = gdf[(true,)].scale
  parameters_upd = haskey(gdf, (false,)) ? gdf[(false,)].parameter .=> gdf[(false,)].nominal : nothing

  fit(scenario_pairs, params; parameters_upd, lbounds, ubounds, scale, kwargs...)
end

### fit many scenarios
"""
    fit(scenarios::AbstractVector{C},
      params;
      kwargs...
    ) where C<:AbstractScenario

Fit parameters to experimental measurements. Returns `FitResult` type.

Example: `fit([scn2, scn3, scn4], [:k1=>0.1,:k2=>0.2,:k3=>0.3])`

Arguments:

- `scenarios` : vector of scenarios of type [`Scenario`](@ref)
- `params` : optimization parameters and their initial values
- kwargs : other solver related arguments supported by `fit(scenario_pairs::Vector{<:Pair}, params::Vector{<:Pair}`
"""
function fit(
  scenarios::AbstractVector{C},
  params;
  kwargs... # other arguments to sim(::Vector{Pair})
) where {C<:AbstractScenario}
  scenario_pairs = Pair{Symbol,AbstractScenario}[Symbol("_$i") => scn for (i, scn) in pairs(scenarios)]
  return fit(scenario_pairs, params; kwargs...)
end

### fit platform
"""
    fit(platform::Platform,
      params;
      scenarios::Union{AbstractVector{Symbol}, Nothing} = nothing,
      kwargs...
    ) where C<:AbstractScenario

Fit parameters to experimental measurements. Returns `FitResult` type.

Example: `fit(platform, [:k1=>0.1,:k2=>0.2,:k3=>0.3];scenarios=[:scn2,:scn3])`

Arguments:

- `platform` : platform of [`Platform`](@ref) type
- `params` : optimization parameters and their initial values
- `scenarios` : vector of scenarios of type [`Scenario`](@ref) or `nothing` to fit all scenarios. Default is `nothing`
- kwargs : other solver related arguments supported by `fit(scenario_pairs::Vector{<:Pair}, params::Vector{<:Pair}`
"""
function fit(
  platform::Platform,
  params;
  scenarios::Union{AbstractVector{Symbol}, Nothing} = nothing, # all if nothing
  kwargs... # other arguments to fit()
)
  if isnothing(scenarios)
    scenario_pairs = [platform.scenarios...]
  else
    scenario_pairs = Pair{Symbol,AbstractScenario}[]
    for scn_name in scenarios
      @assert haskey(platform.scenarios, scn_name) "No scenario :$scn_name found in the platform."
      push!(scenario_pairs, scn_name=>platform.scenarios[scn_name])
    end
  end

  return fit(scenario_pairs, params; kwargs...)
end

function scale_params(x, scale::Symbol)
  if scale == :lin
    return x
  elseif scale == :log
    return log(x)
  elseif scale == :log10
    return log10(x)
  else
    throw("Scale \"$scale\" is not supported.")
  end
end

function unscale_params(x, scale::Symbol)
  if scale == :lin
    return x
  elseif scale == :log
    return exp(x)
  elseif scale == :log10
    return exp10(x)
  else
    throw("Scale \"$scale\" is not supported.")
  end
end


text:
function li_ikegami(grid, vals)
    n = length(grid)
    m = length(vals)

    if n != m
        print("grid size and value siza is not equal")
    end

    mat = [grid vals]
    mat = sortrows(mat, by = x->(x[1]))
    mat = transpose(mat)

    grid = mat[1, :]
    vals = mat[2, :]

    slope = Array(Float64, n-1)
    for i in 1: (n-1)
        temp_slope = (vals[i] - vals[i+1]) / (grid[i] - grid[i+1])
        slope[i] = temp_slope
    end
    function approx(x_val)

        if x_val > maximum(grid)
            return print("too big value ...")
        end

        if x_val < minimum(grid)
            return print("too small value ...")
        end

        interval = 1
        for j in 1:(n-1)
            if x_val > grid[j+1]
                interval += 1
            else break
            end
        end
        return slope[interval] * (x_val - grid[interval]) + vals[interval]
    end

    function approx{T<:Real}(x::AbstractVector{T})
        n = length(x)
        out = Array(Float64, n)
        for i in 1:n
            out[i] = approx(x[i])
        end
        return out
    end

    return approx
end

max_stars_repo_name: keiikegami/Linear---Interpolation-

max_issues_repo_name: keiikegami/Linear---Interpolation-

max_forks_repo_name: keiikegami/Linear---Interpolation-


text:
"""
    InvWarpedView(img, tinv, [indices]) -> wv

Create a view of `img` that lazily transforms any given index `I`
passed to `wv[I]` to correspond to `img[inv(tinv)(I)]`. While
technically this approach is known as backward mode warping, note
that `InvWarpedView` is created by supplying the forward
transformation

The conceptual difference to [`WarpedView`](@ref) is that
`InvWarpedView` is intended to be used when reasoning about the
image is more convenient that reasoning about the indices.
Furthermore, `InvWarpedView` allows simple nesting of
transformations, in which case the transformations will be
composed into a single one.

The optional parameter `indices` can be used to specify the
domain of the resulting `wv`. By default the indices are computed
in such a way that `wv` contains all the original pixels in
`img`.

see [`invwarpedview`](@ref) for more information.
"""
struct InvWarpedView{T,N,A,F,I,FI<:Transformation,E} <: AbstractArray{T,N}
    inner::WarpedView{T,N,A,F,I,E}
    inverse::FI
end

function InvWarpedView(inner::WarpedView{T,N,TA,F,I,E}) where {T,N,TA,F,I,E}
    tinv = inv(inner.transform)
    InvWarpedView{T,N,TA,F,I,typeof(tinv),E}(inner, tinv)
end

function InvWarpedView(A::AbstractArray, tinv::Transformation, inds::Tuple = autorange(A, tinv))
    InvWarpedView(WarpedView(A, inv(tinv), inds), tinv)
end

function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation)
    tinv = compose(outer_tinv, inner.inverse)
    InvWarpedView(parent(inner), tinv)
end

function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation, inds::Tuple)
    tinv = compose(outer_tinv, inner.inverse)
    InvWarpedView(parent(inner), tinv, inds)
end

Base.parent(A::InvWarpedView) = parent(A.inner)
@inline Base.axes(A::InvWarpedView) = axes(A.inner)

IndexStyle(::Type{T}) where {T<:InvWarpedView} = IndexCartesian()
@inline Base.getindex(A::InvWarpedView{T,N}, I::Vararg{Int,N}) where {T,N} = A.inner[I...]

Base.size(A::InvWarpedView)    = size(A.inner)
Base.size(A::InvWarpedView, d) = size(A.inner, d)

function Base.showarg(io::IO, A::InvWarpedView, toplevel)
    print(io, "InvWarpedView(")
    Base.showarg(io, parent(A), false)
    print(io, ", ")
    print(io, A.inverse)
    if toplevel
        print(io, ") with eltype ", eltype(parent(A)))
    else
        print(io, ')')
    end
end

"""
    invwarpedview(img, tinv, [indices], [degree = Linear()], [fill = NaN]) -> wv

Create a view of `img` that lazily transforms any given index `I`
passed to `wv[I]` to correspond to `img[inv(tinv)(I)]`. While
technically this approach is known as backward mode warping, note
that `InvWarpedView` is created by supplying the forward
transformation. The given transformation `tinv` must accept a
`SVector` as input and support `inv(tinv)`. A useful package to
create a wide variety of such transformations is
[CoordinateTransformations.jl](https://github.com/FugroRoames/CoordinateTransformations.jl).

When invoking `wv[I]`, values for `img` must be reconstructed at
arbitrary locations `inv(tinv)(I)`. `InvWarpedView` serves as a
wrapper around [`WarpedView`](@ref) which takes care of
interpolation and extrapolation. The parameters `degree` and
`fill` can be used to specify the b-spline degree and the
extrapolation scheme respectively.

The optional parameter `indices` can be used to specify the
domain of the resulting `wv`. By default the indices are computed
in such a way that `wv` contains all the original pixels in
`img`.
"""
@inline invwarpedview(A::AbstractArray, tinv::Transformation, args...) =
    InvWarpedView(A, tinv, args...)

function invwarpedview(
        A::AbstractArray{T},
        tinv::Transformation,
        degree::Union{Linear,Constant},
        fill::FillType = _default_fill(T)) where T
    invwarpedview(box_extrapolation(A, degree, fill), tinv)
end

function invwarpedview(
        A::AbstractArray{T},
        tinv::Transformation,
        indices::Tuple,
        degree::Union{Linear,Constant},
        fill::FillType = _default_fill(T)) where T
    invwarpedview(box_extrapolation(A, degree, fill), tinv, indices)
end

function invwarpedview(
        A::AbstractArray,
        tinv::Transformation,
        fill::FillType)
    invwarpedview(A, tinv, Linear(), fill)
end

function invwarpedview(
        A::AbstractArray,
        tinv::Transformation,
        indices::Tuple,
        fill::FillType)
    invwarpedview(A, tinv, indices, Linear(), fill)
end

function invwarpedview(
        inner_view::SubArray{T,N,W,I},
        tinv::Transformation) where {T,N,W<:InvWarpedView,I<:Tuple{Vararg{AbstractUnitRange}}}
    inner = parent(inner_view)
    new_inner = InvWarpedView(inner, tinv, autorange(inner, tinv))
    inds = autorange(CartesianIndices(inner_view.indices), tinv)
    view(new_inner, map(x->IdentityRange(first(x),last(x)), inds)...)
end

function invwarpedview(
        inner_view::SubArray{T,N,W,I},
        tinv::Transformation,
        indices::Tuple) where {T,N,W<:InvWarpedView,I<:Tuple{Vararg{AbstractUnitRange}}}
    inner = parent(inner_view)
    new_inner = InvWarpedView(inner, tinv, autorange(inner, tinv))
    view(new_inner, indices...)
end


text:
import DataFrames

"""
"""
function transform(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame,
        labels_df::DataFrames.AbstractDataFrame;
        kwargs...
        )
    transformedlabels_df = DataFrames.DataFrame()
    label = transformer.label
    positive_class = transformer.positive_class
    originallabelcolumn = labels_df[label]
    transformedlabelcolumn = Int.(originallabelcolumn .== positive_class)
    transformedlabels_df[label] = transformedlabelcolumn
    return features_df, transformedlabels_df
end

"""
"""
function transform(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame;
        kwargs...
        )
    return features_df
end

"""
"""
function fit!(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame,
        labels_df::DataFrames.AbstractDataFrame;
        kwargs...
        )
    return transform(transformer, features_df, labels_df)
end

"""
"""
function predict(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame;
        kwargs...
        )
    return transform(transformer, features_df)
end

"""
"""
function predict(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame,
        my_class::AbstractString,
        varargs...;
        kwargs...
        )
    result = (transform(transformer, features_df),
              transform(transformer, my_class),
              varargs...)
    return result
end

"""
"""
function transform(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        my_class::AbstractString;
        kwargs...
        )
    transformed_my_class = Int(my_class == transformer.positive_class)
    return transformed_my_class
end

"""
"""
function predict_proba(
        transformer::ImmutableDataFrame2GLMSingleLabelBinaryClassTransformer,
        features_df::DataFrames.AbstractDataFrame;
        kwargs...
        )
    return transform(transformer, features_df)
end


text:
using Luxor

using Test

using Random
Random.seed!(42)

function text_path_clip(fname)
    currentwidth = 1250 # pts
    currentheight = 800 # pts
    Drawing(currentwidth, currentheight, fname)

    origin()
    background("darkslategray3")

    fontsize(600) # big text to use for clipping
    fontface("Agenda-Black")
    str = "julia" # string to be clipped
    w, h = textextents(str)[3:4] # get width and height

    translate(-(currentwidth/2) + 50, -(currentheight/2) + h)

    textpath(str) # make text into a path
    setline(3)
    setcolor("black")
    fillpreserve() # fill but keep
    clip()  # clip

    fontface("Monaco")
    fontsize(10)
    namelist = map(x->string(x), names(Base)) # list of names in Base.

    x = -20
    y = -h
    while y < currentheight
        sethue(rand(7:10)/10, rand(7:10)/10, rand(7:10)/10)
        s = namelist[rand(1:end)]
        text(s, x, y)
        se = textextents(s)
        x += se[5] # move to the right
        if x > w
           x = -20 # next row
           y += 10
        end
    end

    @test finish() == true
end

fname = "text-path-clipping.png"
text_path_clip(fname)
println("...finished test: output in $(fname)")


text:
sc## tests of the plotting functions
using DThree
using DataFrames
using RDatasets
using Base.Dates

## plot
plot(sin, 0, pi) |> browse
plot([sin, cos], 0, pi) |> browse
plot([sin, u -> cos(u) > 0 ? 0 : NaN], 0, 2pi) |> browse

## scatter
iris = dataset("datasets", "iris")
scatterChart(iris) |> browse     # no grouping
scatterChart(iris, :Species) |> browse #  group by species
scatterChart(iris[3:5], :Species) |> browse

## bar
barChart([1,2,3], ["2007", "2010", "2012"]) |> browse

## stackedAreaChart
five_days = [Dates.Day(k) for k in 1:5]
d = DataFrame(x= vcat(now() + five_days, now() + five_days), y = rand(10), f=vcat(rep("a",5), rep("b", 5)))
stackedAreaChart(d, :f)  |> browse


text:
using BoardGames

mutable struct MCTSStrategy{G <: Game} <: Strategy
    nsteps::Int
    c::Float64
end

mutable struct TreeNode{Board}
    board::Board

    n::Float64
    w::Float64

    expanded::Bool
    children::Vector{TreeNode{Board}}
    parent::TreeNode{Board}

    function TreeNode(board::Board) where {Board}
        new{Board}(board, 0, 0, false, TreeNode{Board}[])
     end
end

function TreeNode(board::B, parent::TreeNode{B}) where {B}
    tn = TreeNode(board)
    tn.parent = parent
    return tn
end

struct MCTSTree{Board}
    root::TreeNode{Board}
end

MCTSTree(board::Board) where {Board} = MCTSTree(TreeNode(board))

function MCTSStrategy{G}(nsteps::Int) where {G <: Game}
    MCTSStrategy{G}(nsteps, √2)
end

function BoardGames.getmove(board, s::MCTSStrategy; verbose=false)
    tree = MCTSTree(board)
    player = playerturn(board)

    for i in 1:s.nsteps
        step(tree.root, player, s.c)
    end
    if verbose
        results = [(m, c.w, c.n) for (m,c) in zip(getmoves(board), tree.root.children)]
        @show results
    end
    move_idx = select(tree.root, player, 0)

    verbose && println("selected $move_idx")

    getmoves(board)[move_idx]
end

function expand(node::TreeNode)
    moves = getmoves(node.board)

    for move in moves
        push!(node.children, TreeNode(play(node.board, move), node))
    end
    node.expanded = true
    nothing
end

function select(node::TreeNode, player::Int, c=√2)
    params = zeros(Float64, size(node.children))

    for (i,child) in enumerate(node.children)
        if child.n == 0
            params[i] = Inf
        else
            if player == playerturn(node.board)
                params[i] =  child.w / child.n + c*sqrt(log(node.n)/child.n)
            else
                params[i] = -child.w / child.n + c*sqrt(log(node.n)/child.n)
            end
        end
    end
    return random_argmax(params)
end

function backpropagate(node::TreeNode, w::Float64)
    while(isdefined(node, :parent))
        node.w += w
        node.n += 1
        node = node.parent
    end
    node.w += w
    node.n += 1
    nothing
end

function step(node::TreeNode, player::Int, c::Float64)
    if !node.expanded
        expand(node)
    end
    if isempty(node.children)
        w = 0.
        if winner(node.board) == 0
            w = .5
        else
            w = Float64(winner(node.board) == player)
        end
        backpropagate(node, w)
    else
        i = select(node, player, c)
        step(node.children[i], player, c)
    end
    nothing
end

function random_argmax(v)
    @assert(length(v) > 0)
    best = v[1]
    best_idx = 1
    best_count = 1

    for i in 2:length(v)
        if v[i] > best
            best = v[i]
            best_idx = i
            best_count = 1
        elseif v[i] == best
            best_count += 1
            if rand() < 1/best_count
                best_idx = i
            end
        end
    end
    return best_idx
end

function Base.copy(s::MCTSStrategy{T}) where T
    MCTSStrategy{T}(s.nsteps, s.c)
end

function BoardGames.getvarsnames(s::MCTSStrategy)
    return ["iterations", "c"]
end

function BoardGames.getvalues(s::MCTSStrategy)
    (s.nsteps, s.c)
end

function BoardGames.setvalue!(s::MCTSStrategy, name::AbstractString, value)
    if name == "iterations"
        s.nsteps = parse(Int, value)
    elseif name == "c"
        s.c = parse(Float64, value)
    else
        error("invalid set for parameter $name for strategy $s")
    end
    nothing
end

BoardGames.name(::MCTSStrategy) = "MCTS"