text:
# generated by misc/make_tz_map.py

function get_timezone_id_by_name_dict()::Dict{String, UInt16}
    Dict(
        "GMT"=> 65535,
        "ACT"=> 65534,
        "AET"=> 65533,
        "AGT"=> 65532,
        "ART"=> 65531,
        "AST"=> 65530,
        "Africa/Abidjan"=> 65529,
        "Africa/Accra"=> 65528,
        "Africa/Addis_Ababa"=> 65527,
        "Africa/Algiers"=> 65526,
        "Africa/Asmara"=> 65525,
        "Africa/Asmera"=> 65524,
        "Africa/Bamako"=> 65523,
        "Africa/Bangui"=> 65522,
        "Africa/Banjul"=> 65521,
        "Africa/Bissau"=> 65520,
        "Africa/Blantyre"=> 65519,
        "Africa/Brazzaville"=> 65518,
        "Africa/Bujumbura"=> 65517,
        "Africa/Cairo"=> 65516,
        "Africa/Casablanca"=> 65515,
        "Africa/Ceuta"=> 65514,
        "Africa/Conakry"=> 65513,
        "Africa/Dakar"=> 65512,
        "Africa/Dar_es_Salaam"=> 65511,
        "Africa/Djibouti"=> 65510,
        "Africa/Douala"=> 65509,
        "Africa/El_Aaiun"=> 65508,
        "Africa/Freetown"=> 65507,
        "Africa/Gaborone"=> 65506,
        "Africa/Harare"=> 65505,
        "Africa/Johannesburg"=> 65504,
        "Africa/Juba"=> 65503,
        "Africa/Kampala"=> 65502,
        "Africa/Khartoum"=> 65501,
        "Africa/Kigali"=> 65500,
        "Africa/Kinshasa"=> 65499,
        "Africa/Lagos"=> 65498,
        "Africa/Libreville"=> 65497,
        "Africa/Lome"=> 65496,
        "Africa/Luanda"=> 65495,
        "Africa/Lubumbashi"=> 65494,
        "Africa/Lusaka"=> 65493,
        "Africa/Malabo"=> 65492,
        "Africa/Maputo"=> 65491,
        "Africa/Maseru"=> 65490,
        "Africa/Mbabane"=> 65489,
        "Africa/Mogadishu"=> 65488,
        "Africa/Monrovia"=> 65487,
        "Africa/Nairobi"=> 65486,
        "Africa/Ndjamena"=> 65485,
        "Africa/Niamey"=> 65484,
        "Africa/Nouakchott"=> 65483,
        "Africa/Ouagadougou"=> 65482,
        "Africa/Porto-Novo"=> 65481,
        "Africa/Sao_Tome"=> 65480,
        "Africa/Timbuktu"=> 65479,
        "Africa/Tripoli"=> 65478,
        "Africa/Tunis"=> 65477,
        "Africa/Windhoek"=> 65476,
        "America/Adak"=> 65475,
        "America/Anchorage"=> 65474,
        "America/Anguilla"=> 65473,
        "America/Antigua"=> 65472,
        "America/Araguaina"=> 65471,
        "America/Argentina/Buenos_Aires"=> 65470,
        "America/Argentina/Catamarca"=> 65469,
        "America/Argentina/ComodRivadavia"=> 65468,
        "America/Argentina/Cordoba"=> 65467,
        "America/Argentina/Jujuy"=> 65466,
        "America/Argentina/La_Rioja"=> 65465,
        "America/Argentina/Mendoza"=> 65464,
        "America/Argentina/Rio_Gallegos"=> 65463,
        "America/Argentina/Salta"=> 65462,
        "America/Argentina/San_Juan"=> 65461,
        "America/Argentina/San_Luis"=> 65460,
        "America/Argentina/Tucuman"=> 65459,
        "America/Argentina/Ushuaia"=> 65458,
        "America/Aruba"=> 65457,
        "America/Asuncion"=> 65456,
        "America/Atikokan"=> 65455,
        "America/Atka"=> 65454,
        "America/Bahia"=> 65453,
        "America/Bahia_Banderas"=> 65452,
        "America/Barbados"=> 65451,
        "America/Belem"=> 65450,
        "America/Belize"=> 65449,
        "America/Blanc-Sablon"=> 65448,
        "America/Boa_Vista"=> 65447,
        "America/Bogota"=> 65446,
        "America/Boise"=> 65445,
        "America/Buenos_Aires"=> 65444,
        "America/Cambridge_Bay"=> 65443,
        "America/Campo_Grande"=> 65442,
        "America/Cancun"=> 65441,
        "America/Caracas"=> 65440,
        "America/Catamarca"=> 65439,
        "America/Cayenne"=> 65438,
        "America/Cayman"=> 65437,
        "America/Chicago"=> 65436,
        "America/Chihuahua"=> 65435,
        "America/Coral_Harbour"=> 65434,
        "America/Cordoba"=> 65433,
        "America/Costa_Rica"=> 65432,
        "America/Creston"=> 65431,
        "America/Cuiaba"=> 65430,
        "America/Curacao"=> 65429,
        "America/Danmarkshavn"=> 65428,
        "America/Dawson"=> 65427,
        "America/Dawson_Creek"=> 65426,
        "America/Denver"=> 65425,
        "America/Detroit"=> 65424,
        "America/Dominica"=> 65423,
        "America/Edmonton"=> 65422,
        "America/Eirunepe"=> 65421,
        "America/El_Salvador"=> 65420,
        "America/Ensenada"=> 65419,
        "America/Fort_Nelson"=> 65418,
        "America/Fort_Wayne"=> 65417,
        "America/Fortaleza"=> 65416,
        "America/Glace_Bay"=> 65415,
        "America/Godthab"=> 65414,
        "America/Goose_Bay"=> 65413,
        "America/Grand_Turk"=> 65412,
        "America/Grenada"=> 65411,
        "America/Guadeloupe"=> 65410,
        "America/Guatemala"=> 65409,
        "America/Guayaquil"=> 65408,
        "America/Guyana"=> 65407,
        "America/Halifax"=> 65406,
        "America/Havana"=> 65405,
        "America/Hermosillo"=> 65404,
        "America/Indiana/Indianapolis"=> 65403,
        "America/Indiana/Knox"=> 65402,
        "America/Indiana/Marengo"=> 65401,
        "America/Indiana/Petersburg"=> 65400,
        "America/Indiana/Tell_City"=> 65399,
        "America/Indiana/Vevay"=> 65398,
        "America/Indiana/Vincennes"=> 65397,
        "America/Indiana/Winamac"=> 65396,
        "America/Indianapolis"=> 65395,
        "America/Inuvik"=> 65394,
        "America/Iqaluit"=> 65393,
        "America/Jamaica"=> 65392,
        "America/Jujuy"=> 65391,
        "America/Juneau"=> 65390,
        "America/Kentucky/Louisville"=> 65389,
        "America/Kentucky/Monticello"=> 65388,
        "America/Knox_IN"=> 65387,
        "America/Kralendijk"=> 65386,
        "America/La_Paz"=> 65385,
        "America/Lima"=> 65384,
        "America/Los_Angeles"=> 65383,
        "America/Louisville"=> 65382,
        "America/Lower_Princes"=> 65381,
        "America/Maceio"=> 65380,
        "America/Managua"=> 65379,
        "America/Manaus"=> 65378,
        "America/Marigot"=> 65377,
        "America/Martinique"=> 65376,
        "America/Matamoros"=> 65375,
        "America/Mazatlan"=> 65374,
        "America/Mendoza"=> 65373,
        "America/Menominee"=> 65372,
        "America/Merida"=> 65371,
        "America/Metlakatla"=> 65370,
        "America/Mexico_City"=> 65369,
        "America/Miquelon"=> 65368,
        "America/Moncton"=> 65367,
        "America/Monterrey"=> 65366,
        "America/Montevideo"=> 65365,
        "America/Montreal"=> 65364,
        "America/Montserrat"=> 65363,
        "America/Nassau"=> 65362,
        "America/New_York"=> 65361,
        "America/Nipigon"=> 65360,
        "America/Nome"=> 65359,
        "America/Noronha"=> 65358,
        "America/North_Dakota/Beulah"=> 65357,
        "America/North_Dakota/Center"=> 65356,
        "America/North_Dakota/New_Salem"=> 65355,
        "America/Ojinaga"=> 65354,
        "America/Panama"=> 65353,
        "America/Pangnirtung"=> 65352,
        "America/Paramaribo"=> 65351,
        "America/Phoenix"=> 65350,
        "America/Port-au-Prince"=> 65349,
        "America/Port_of_Spain"=> 65348,
        "America/Porto_Acre"=> 65347,
        "America/Porto_Velho"=> 65346,
        "America/Puerto_Rico"=> 65345,
        "America/Punta_Arenas"=> 65344,
        "America/Rainy_River"=> 65343,
        "America/Rankin_Inlet"=> 65342,
        "America/Recife"=> 65341,
        "America/Regina"=> 65340,
        "America/Resolute"=> 65339,
        "America/Rio_Branco"=> 65338,
        "America/Rosario"=> 65337,
        "America/Santa_Isabel"=> 65336,
        "America/Santarem"=> 65335,
        "America/Santiago"=> 65334,
        "America/Santo_Domingo"=> 65333,
        "America/Sao_Paulo"=> 65332,
        "America/Scoresbysund"=> 65331,
        "America/Shiprock"=> 65330,
        "America/Sitka"=> 65329,
        "America/St_Barthelemy"=> 65328,
        "America/St_Johns"=> 65327,
        "America/St_Kitts"=> 65326,
        "America/St_Lucia"=> 65325,
        "America/St_Thomas"=> 65324,
        "America/St_Vincent"=> 65323,
        "America/Swift_Current"=> 65322,
        "America/Tegucigalpa"=> 65321,
        "America/Thule"=> 65320,
        "America/Thunder_Bay"=> 65319,
        "America/Tijuana"=> 65318,
        "America/Toronto"=> 65317,
        "America/Tortola"=> 65316,
        "America/Vancouver"=> 65315,
        "America/Virgin"=> 65314,
        "America/Whitehorse"=> 65313,
        "America/Winnipeg"=> 65312,
        "America/Yakutat"=> 65311,
        "America/Yellowknife"=> 65310,
        "Antarctica/Casey"=> 65309,
        "Antarctica/Davis"=> 65308,
        "Antarctica/DumontDUrville"=> 65307,
        "Antarctica/Macquarie"=> 65306,
        "Antarctica/Mawson"=> 65305,
        "Antarctica/McMurdo"=> 65304,
        "Antarctica/Palmer"=> 65303,
        "Antarctica/Rothera"=> 65302,
        "Antarctica/South_Pole"=> 65301,
        "Antarctica/Syowa"=> 65300,
        "Antarctica/Troll"=> 65299,
        "Antarctica/Vostok"=> 65298,
        "Arctic/Longyearbyen"=> 65297,
        "Asia/Aden"=> 65296,
        "Asia/Almaty"=> 65295,
        "Asia/Amman"=> 65294,
        "Asia/Anadyr"=> 65293,
        "Asia/Aqtau"=> 65292,
        "Asia/Aqtobe"=> 65291,
        "Asia/Ashgabat"=> 65290,
        "Asia/Ashkhabad"=> 65289,
        "Asia/Atyrau"=> 65288,
        "Asia/Baghdad"=> 65287,
        "Asia/Bahrain"=> 65286,
        "Asia/Baku"=> 65285,
        "Asia/Bangkok"=> 65284,
        "Asia/Barnaul"=> 65283,
        "Asia/Beirut"=> 65282,
        "Asia/Bishkek"=> 65281,
        "Asia/Brunei"=> 65280,
        "Asia/Calcutta"=> 65279,
        "Asia/Chita"=> 65278,
        "Asia/Choibalsan"=> 65277,
        "Asia/Chongqing"=> 65276,
        "Asia/Chungking"=> 65275,
        "Asia/Colombo"=> 65274,
        "Asia/Dacca"=> 65273,
        "Asia/Damascus"=> 65272,
        "Asia/Dhaka"=> 65271,
        "Asia/Dili"=> 65270,
        "Asia/Dubai"=> 65269,
        "Asia/Dushanbe"=> 65268,
        "Asia/Famagusta"=> 65267,
        "Asia/Gaza"=> 65266,
        "Asia/Harbin"=> 65265,
        "Asia/Hebron"=> 65264,
        "Asia/Ho_Chi_Minh"=> 65263,
        "Asia/Hong_Kong"=> 65262,
        "Asia/Hovd"=> 65261,
        "Asia/Irkutsk"=> 65260,
        "Asia/Istanbul"=> 65259,
        "Asia/Jakarta"=> 65258,
        "Asia/Jayapura"=> 65257,
        "Asia/Jerusalem"=> 65256,
        "Asia/Kabul"=> 65255,
        "Asia/Kamchatka"=> 65254,
        "Asia/Karachi"=> 65253,
        "Asia/Kashgar"=> 65252,
        "Asia/Kathmandu"=> 65251,
        "Asia/Katmandu"=> 65250,
        "Asia/Khandyga"=> 65249,
        "Asia/Kolkata"=> 65248,
        "Asia/Krasnoyarsk"=> 65247,
        "Asia/Kuala_Lumpur"=> 65246,
        "Asia/Kuching"=> 65245,
        "Asia/Kuwait"=> 65244,
        "Asia/Macao"=> 65243,
        "Asia/Macau"=> 65242,
        "Asia/Magadan"=> 65241,
        "Asia/Makassar"=> 65240,
        "Asia/Manila"=> 65239,
        "Asia/Muscat"=> 65238,
        "Asia/Nicosia"=> 65237,
        "Asia/Novokuznetsk"=> 65236,
        "Asia/Novosibirsk"=> 65235,
        "Asia/Omsk"=> 65234,
        "Asia/Oral"=> 65233,
        "Asia/Phnom_Penh"=> 65232,
        "Asia/Pontianak"=> 65231,
        "Asia/Pyongyang"=> 65230,
        "Asia/Qatar"=> 65229,
        "Asia/Qyzylorda"=> 65228,
        "Asia/Rangoon"=> 65227,
        "Asia/Riyadh"=> 65226,
        "Asia/Saigon"=> 65225,
        "Asia/Sakhalin"=> 65224,
        "Asia/Samarkand"=> 65223,
        "Asia/Seoul"=> 65222,
        "Asia/Shanghai"=> 65221,
        "Asia/Singapore"=> 65220,
        "Asia/Srednekolymsk"=> 65219,
        "Asia/Taipei"=> 65218,
        "Asia/Tashkent"=> 65217,
        "Asia/Tbilisi"=> 65216,
        "Asia/Tehran"=> 65215,
        "Asia/Tel_Aviv"=> 65214,
        "Asia/Thimbu"=> 65213,
        "Asia/Thimphu"=> 65212,
        "Asia/Tokyo"=> 65211,
        "Asia/Tomsk"=> 65210,
        "Asia/Ujung_Pandang"=> 65209,
        "Asia/Ulaanbaatar"=> 65208,
        "Asia/Ulan_Bator"=> 65207,
        "Asia/Urumqi"=> 65206,
        "Asia/Ust-Nera"=> 65205,
        "Asia/Vientiane"=> 65204,
        "Asia/Vladivostok"=> 65203,
        "Asia/Yakutsk"=> 65202,
        "Asia/Yangon"=> 65201,
        "Asia/Yekaterinburg"=> 65200,
        "Asia/Yerevan"=> 65199,
        "Atlantic/Azores"=> 65198,
        "Atlantic/Bermuda"=> 65197,
        "Atlantic/Canary"=> 65196,
        "Atlantic/Cape_Verde"=> 65195,
        "Atlantic/Faeroe"=> 65194,
        "Atlantic/Faroe"=> 65193,
        "Atlantic/Jan_Mayen"=> 65192,
        "Atlantic/Madeira"=> 65191,
        "Atlantic/Reykjavik"=> 65190,
        "Atlantic/South_Georgia"=> 65189,
        "Atlantic/St_Helena"=> 65188,
        "Atlantic/Stanley"=> 65187,
        "Australia/ACT"=> 65186,
        "Australia/Adelaide"=> 65185,
        "Australia/Brisbane"=> 65184,
        "Australia/Broken_Hill"=> 65183,
        "Australia/Canberra"=> 65182,
        "Australia/Currie"=> 65181,
        "Australia/Darwin"=> 65180,
        "Australia/Eucla"=> 65179,
        "Australia/Hobart"=> 65178,
        "Australia/LHI"=> 65177,
        "Australia/Lindeman"=> 65176,
        "Australia/Lord_Howe"=> 65175,
        "Australia/Melbourne"=> 65174,
        "Australia/NSW"=> 65173,
        "Australia/North"=> 65172,
        "Australia/Perth"=> 65171,
        "Australia/Queensland"=> 65170,
        "Australia/South"=> 65169,
        "Australia/Sydney"=> 65168,
        "Australia/Tasmania"=> 65167,
        "Australia/Victoria"=> 65166,
        "Australia/West"=> 65165,
        "Australia/Yancowinna"=> 65164,
        "BET"=> 65163,
        "BST"=> 65162,
        "Brazil/Acre"=> 65161,
        "Brazil/DeNoronha"=> 65160,
        "Brazil/East"=> 65159,
        "Brazil/West"=> 65158,
        "CAT"=> 65157,
        "CET"=> 65156,
        "CNT"=> 65155,
        "CST"=> 65154,
        "CST6CDT"=> 65153,
        "CTT"=> 65152,
        "Canada/Atlantic"=> 65151,
        "Canada/Central"=> 65150,
        "Canada/East-Saskatchewan"=> 65149,
        "Canada/Eastern"=> 65148,
        "Canada/Mountain"=> 65147,
        "Canada/Newfoundland"=> 65146,
        "Canada/Pacific"=> 65145,
        "Canada/Saskatchewan"=> 65144,
        "Canada/Yukon"=> 65143,
        "Chile/Continental"=> 65142,
        "Chile/EasterIsland"=> 65141,
        "Cuba"=> 65140,
        "EAT"=> 65139,
        "ECT"=> 65138,
        "EET"=> 65137,
        "EST"=> 65136,
        "EST5EDT"=> 65135,
        "Egypt"=> 65134,
        "Eire"=> 65133,
        "Etc/GMT"=> 65132,
        "Etc/GMT+0"=> 65131,
        "Etc/GMT+1"=> 65130,
        "Etc/GMT+10"=> 65129,
        "Etc/GMT+11"=> 65128,
        "Etc/GMT+12"=> 65127,
        "Etc/GMT+2"=> 65126,
        "Etc/GMT+3"=> 65125,
        "Etc/GMT+4"=> 65124,
        "Etc/GMT+5"=> 65123,
        "Etc/GMT+6"=> 65122,
        "Etc/GMT+7"=> 65121,
        "Etc/GMT+8"=> 65120,
        "Etc/GMT+9"=> 65119,
        "Etc/GMT-0"=> 65118,
        "Etc/GMT-1"=> 65117,
        "Etc/GMT-10"=> 65116,
        "Etc/GMT-11"=> 65115,
        "Etc/GMT-12"=> 65114,
        "Etc/GMT-13"=> 65113,
        "Etc/GMT-14"=> 65112,
        "Etc/GMT-2"=> 65111,
        "Etc/GMT-3"=> 65110,
        "Etc/GMT-4"=> 65109,
        "Etc/GMT-5"=> 65108,
        "Etc/GMT-6"=> 65107,
        "Etc/GMT-7"=> 65106,
        "Etc/GMT-8"=> 65105,
        "Etc/GMT-9"=> 65104,
        "Etc/GMT0"=> 65103,
        "Etc/Greenwich"=> 65102,
        "Etc/UCT"=> 65101,
        "Etc/UTC"=> 65100,
        "Etc/Universal"=> 65099,
        "Etc/Zulu"=> 65098,
        "Europe/Amsterdam"=> 65097,
        "Europe/Andorra"=> 65096,
        "Europe/Astrakhan"=> 65095,
        "Europe/Athens"=> 65094,
        "Europe/Belfast"=> 65093,
        "Europe/Belgrade"=> 65092,
        "Europe/Berlin"=> 65091,
        "Europe/Bratislava"=> 65090,
        "Europe/Brussels"=> 65089,
        "Europe/Bucharest"=> 65088,
        "Europe/Budapest"=> 65087,
        "Europe/Busingen"=> 65086,
        "Europe/Chisinau"=> 65085,
        "Europe/Copenhagen"=> 65084,
        "Europe/Dublin"=> 65083,
        "Europe/Gibraltar"=> 65082,
        "Europe/Guernsey"=> 65081,
        "Europe/Helsinki"=> 65080,
        "Europe/Isle_of_Man"=> 65079,
        "Europe/Istanbul"=> 65078,
        "Europe/Jersey"=> 65077,
        "Europe/Kaliningrad"=> 65076,
        "Europe/Kiev"=> 65075,
        "Europe/Kirov"=> 65074,
        "Europe/Lisbon"=> 65073,
        "Europe/Ljubljana"=> 65072,
        "Europe/London"=> 65071,
        "Europe/Luxembourg"=> 65070,
        "Europe/Madrid"=> 65069,
        "Europe/Malta"=> 65068,
        "Europe/Mariehamn"=> 65067,
        "Europe/Minsk"=> 65066,
        "Europe/Monaco"=> 65065,
        "Europe/Moscow"=> 65064,
        "Europe/Nicosia"=> 65063,
        "Europe/Oslo"=> 65062,
        "Europe/Paris"=> 65061,
        "Europe/Podgorica"=> 65060,
        "Europe/Prague"=> 65059,
        "Europe/Riga"=> 65058,
        "Europe/Rome"=> 65057,
        "Europe/Samara"=> 65056,
        "Europe/San_Marino"=> 65055,
        "Europe/Sarajevo"=> 65054,
        "Europe/Saratov"=> 65053,
        "Europe/Simferopol"=> 65052,
        "Europe/Skopje"=> 65051,
        "Europe/Sofia"=> 65050,
        "Europe/Stockholm"=> 65049,
        "Europe/Tallinn"=> 65048,
        "Europe/Tirane"=> 65047,
        "Europe/Tiraspol"=> 65046,
        "Europe/Ulyanovsk"=> 65045,
        "Europe/Uzhgorod"=> 65044,
        "Europe/Vaduz"=> 65043,
        "Europe/Vatican"=> 65042,
        "Europe/Vienna"=> 65041,
        "Europe/Vilnius"=> 65040,
        "Europe/Volgograd"=> 65039,
        "Europe/Warsaw"=> 65038,
        "Europe/Zagreb"=> 65037,
        "Europe/Zaporozhye"=> 65036,
        "Europe/Zurich"=> 65035,
        "Factory"=> 65034,
        "GB"=> 65033,
        "GB-Eire"=> 65032,
        "GMT+0"=> 65031,
        "GMT-0"=> 65030,
        "GMT0"=> 65029,
        "Greenwich"=> 65028,
        "HST"=> 65027,
        "Hongkong"=> 65026,
        "IET"=> 65025,
        "IST"=> 65024,
        "Iceland"=> 65023,
        "Indian/Antananarivo"=> 65022,
        "Indian/Chagos"=> 65021,
        "Indian/Christmas"=> 65020,
        "Indian/Cocos"=> 65019,
        "Indian/Comoro"=> 65018,
        "Indian/Kerguelen"=> 65017,
        "Indian/Mahe"=> 65016,
        "Indian/Maldives"=> 65015,
        "Indian/Mauritius"=> 65014,
        "Indian/Mayotte"=> 65013,
        "Indian/Reunion"=> 65012,
        "Iran"=> 65011,
        "Israel"=> 65010,
        "JST"=> 65009,
        "Jamaica"=> 65008,
        "Japan"=> 65007,
        "Kwajalein"=> 65006,
        "Libya"=> 65005,
        "MET"=> 65004,
        "MIT"=> 65003,
        "MST"=> 65002,
        "MST7MDT"=> 65001,
        "Mexico/BajaNorte"=> 65000,
        "Mexico/BajaSur"=> 64999,
        "Mexico/General"=> 64998,
        "NET"=> 64997,
        "NST"=> 64996,
        "NZ"=> 64995,
        "NZ-CHAT"=> 64994,
        "Navajo"=> 64993,
        "PLT"=> 64992,
        "PNT"=> 64991,
        "PRC"=> 64990,
        "PRT"=> 64989,
        "PST"=> 64988,
        "PST8PDT"=> 64987,
        "Pacific/Apia"=> 64986,
        "Pacific/Auckland"=> 64985,
        "Pacific/Bougainville"=> 64984,
        "Pacific/Chatham"=> 64983,
        "Pacific/Chuuk"=> 64982,
        "Pacific/Easter"=> 64981,
        "Pacific/Efate"=> 64980,
        "Pacific/Enderbury"=> 64979,
        "Pacific/Fakaofo"=> 64978,
        "Pacific/Fiji"=> 64977,
        "Pacific/Funafuti"=> 64976,
        "Pacific/Galapagos"=> 64975,
        "Pacific/Gambier"=> 64974,
        "Pacific/Guadalcanal"=> 64973,
        "Pacific/Guam"=> 64972,
        "Pacific/Honolulu"=> 64971,
        "Pacific/Johnston"=> 64970,
        "Pacific/Kiritimati"=> 64969,
        "Pacific/Kosrae"=> 64968,
        "Pacific/Kwajalein"=> 64967,
        "Pacific/Majuro"=> 64966,
        "Pacific/Marquesas"=> 64965,
        "Pacific/Midway"=> 64964,
        "Pacific/Nauru"=> 64963,
        "Pacific/Niue"=> 64962,
        "Pacific/Norfolk"=> 64961,
        "Pacific/Noumea"=> 64960,
        "Pacific/Pago_Pago"=> 64959,
        "Pacific/Palau"=> 64958,
        "Pacific/Pitcairn"=> 64957,
        "Pacific/Pohnpei"=> 64956,
        "Pacific/Ponape"=> 64955,
        "Pacific/Port_Moresby"=> 64954,
        "Pacific/Rarotonga"=> 64953,
        "Pacific/Saipan"=> 64952,
        "Pacific/Samoa"=> 64951,
        "Pacific/Tahiti"=> 64950,
        "Pacific/Tarawa"=> 64949,
        "Pacific/Tongatapu"=> 64948,
        "Pacific/Truk"=> 64947,
        "Pacific/Wake"=> 64946,
        "Pacific/Wallis"=> 64945,
        "Pacific/Yap"=> 64944,
        "Poland"=> 64943,
        "Portugal"=> 64942,
        "ROC"=> 64941,
        "ROK"=> 64940,
        "SST"=> 64939,
        "Singapore"=> 64938,
        "SystemV/AST4"=> 64937,
        "SystemV/AST4ADT"=> 64936,
        "SystemV/CST6"=> 64935,
        "SystemV/CST6CDT"=> 64934,
        "SystemV/EST5"=> 64933,
        "SystemV/EST5EDT"=> 64932,
        "SystemV/HST10"=> 64931,
        "SystemV/MST7"=> 64930,
        "SystemV/MST7MDT"=> 64929,
        "SystemV/PST8"=> 64928,
        "SystemV/PST8PDT"=> 64927,
        "SystemV/YST9"=> 64926,
        "SystemV/YST9YDT"=> 64925,
        "Turkey"=> 64924,
        "UCT"=> 64923,
        "US/Alaska"=> 64922,
        "US/Aleutian"=> 64921,
        "US/Arizona"=> 64920,
        "US/Central"=> 64919,
        "US/East-Indiana"=> 64918,
        "US/Eastern"=> 64917,
        "US/Hawaii"=> 64916,
        "US/Indiana-Starke"=> 64915,
        "US/Michigan"=> 64914,
        "US/Mountain"=> 64913,
        "US/Pacific"=> 64912,
        "US/Pacific-New"=> 64911,
        "US/Samoa"=> 64910,
        "UTC"=> 64909,
        "Universal"=> 64908,
        "VST"=> 64907,
        "W-SU"=> 64906,
        "WET"=> 64905,
        "Zulu"=> 64904,
        "America/Nuuk"=> 64903,
        "Asia/Qostanay"=> 64902,
)
end

function get_timezone_name_by_id_dict()::Dict{UInt16, String}
    Dict(
        65535=> "GMT",
        65534=> "ACT",
        65533=> "AET",
        65532=> "AGT",
        65531=> "ART",
        65530=> "AST",
        65529=> "Africa/Abidjan",
        65528=> "Africa/Accra",
        65527=> "Africa/Addis_Ababa",
        65526=> "Africa/Algiers",
        65525=> "Africa/Asmara",
        65524=> "Africa/Asmera",
        65523=> "Africa/Bamako",
        65522=> "Africa/Bangui",
        65521=> "Africa/Banjul",
        65520=> "Africa/Bissau",
        65519=> "Africa/Blantyre",
        65518=> "Africa/Brazzaville",
        65517=> "Africa/Bujumbura",
        65516=> "Africa/Cairo",
        65515=> "Africa/Casablanca",
        65514=> "Africa/Ceuta",
        65513=> "Africa/Conakry",
        65512=> "Africa/Dakar",
        65511=> "Africa/Dar_es_Salaam",
        65510=> "Africa/Djibouti",
        65509=> "Africa/Douala",
        65508=> "Africa/El_Aaiun",
        65507=> "Africa/Freetown",
        65506=> "Africa/Gaborone",
        65505=> "Africa/Harare",
        65504=> "Africa/Johannesburg",
        65503=> "Africa/Juba",
        65502=> "Africa/Kampala",
        65501=> "Africa/Khartoum",
        65500=> "Africa/Kigali",
        65499=> "Africa/Kinshasa",
        65498=> "Africa/Lagos",
        65497=> "Africa/Libreville",
        65496=> "Africa/Lome",
        65495=> "Africa/Luanda",
        65494=> "Africa/Lubumbashi",
        65493=> "Africa/Lusaka",
        65492=> "Africa/Malabo",
        65491=> "Africa/Maputo",
        65490=> "Africa/Maseru",
        65489=> "Africa/Mbabane",
        65488=> "Africa/Mogadishu",
        65487=> "Africa/Monrovia",
        65486=> "Africa/Nairobi",
        65485=> "Africa/Ndjamena",
        65484=> "Africa/Niamey",
        65483=> "Africa/Nouakchott",
        65482=> "Africa/Ouagadougou",
        65481=> "Africa/Porto-Novo",
        65480=> "Africa/Sao_Tome",
        65479=> "Africa/Timbuktu",
        65478=> "Africa/Tripoli",
        65477=> "Africa/Tunis",
        65476=> "Africa/Windhoek",
        65475=> "America/Adak",
        65474=> "America/Anchorage",
        65473=> "America/Anguilla",
        65472=> "America/Antigua",
        65471=> "America/Araguaina",
        65470=> "America/Argentina/Buenos_Aires",
        65469=> "America/Argentina/Catamarca",
        65468=> "America/Argentina/ComodRivadavia",
        65467=> "America/Argentina/Cordoba",
        65466=> "America/Argentina/Jujuy",
        65465=> "America/Argentina/La_Rioja",
        65464=> "America/Argentina/Mendoza",
        65463=> "America/Argentina/Rio_Gallegos",
        65462=> "America/Argentina/Salta",
        65461=> "America/Argentina/San_Juan",
        65460=> "America/Argentina/San_Luis",
        65459=> "America/Argentina/Tucuman",
        65458=> "America/Argentina/Ushuaia",
        65457=> "America/Aruba",
        65456=> "America/Asuncion",
        65455=> "America/Atikokan",
        65454=> "America/Atka",
        65453=> "America/Bahia",
        65452=> "America/Bahia_Banderas",
        65451=> "America/Barbados",
        65450=> "America/Belem",
        65449=> "America/Belize",
        65448=> "America/Blanc-Sablon",
        65447=> "America/Boa_Vista",
        65446=> "America/Bogota",
        65445=> "America/Boise",
        65444=> "America/Buenos_Aires",
        65443=> "America/Cambridge_Bay",
        65442=> "America/Campo_Grande",
        65441=> "America/Cancun",
        65440=> "America/Caracas",
        65439=> "America/Catamarca",
        65438=> "America/Cayenne",
        65437=> "America/Cayman",
        65436=> "America/Chicago",
        65435=> "America/Chihuahua",
        65434=> "America/Coral_Harbour",
        65433=> "America/Cordoba",
        65432=> "America/Costa_Rica",
        65431=> "America/Creston",
        65430=> "America/Cuiaba",
        65429=> "America/Curacao",
        65428=> "America/Danmarkshavn",
        65427=> "America/Dawson",
        65426=> "America/Dawson_Creek",
        65425=> "America/Denver",
        65424=> "America/Detroit",
        65423=> "America/Dominica",
        65422=> "America/Edmonton",
        65421=> "America/Eirunepe",
        65420=> "America/El_Salvador",
        65419=> "America/Ensenada",
        65418=> "America/Fort_Nelson",
        65417=> "America/Fort_Wayne",
        65416=> "America/Fortaleza",
        65415=> "America/Glace_Bay",
        65414=> "America/Godthab",
        65413=> "America/Goose_Bay",
        65412=> "America/Grand_Turk",
        65411=> "America/Grenada",
        65410=> "America/Guadeloupe",
        65409=> "America/Guatemala",
        65408=> "America/Guayaquil",
        65407=> "America/Guyana",
        65406=> "America/Halifax",
        65405=> "America/Havana",
        65404=> "America/Hermosillo",
        65403=> "America/Indiana/Indianapolis",
        65402=> "America/Indiana/Knox",
        65401=> "America/Indiana/Marengo",
        65400=> "America/Indiana/Petersburg",
        65399=> "America/Indiana/Tell_City",
        65398=> "America/Indiana/Vevay",
        65397=> "America/Indiana/Vincennes",
        65396=> "America/Indiana/Winamac",
        65395=> "America/Indianapolis",
        65394=> "America/Inuvik",
        65393=> "America/Iqaluit",
        65392=> "America/Jamaica",
        65391=> "America/Jujuy",
        65390=> "America/Juneau",
        65389=> "America/Kentucky/Louisville",
        65388=> "America/Kentucky/Monticello",
        65387=> "America/Knox_IN",
        65386=> "America/Kralendijk",
        65385=> "America/La_Paz",
        65384=> "America/Lima",
        65383=> "America/Los_Angeles",
        65382=> "America/Louisville",
        65381=> "America/Lower_Princes",
        65380=> "America/Maceio",
        65379=> "America/Managua",
        65378=> "America/Manaus",
        65377=> "America/Marigot",
        65376=> "America/Martinique",
        65375=> "America/Matamoros",
        65374=> "America/Mazatlan",
        65373=> "America/Mendoza",
        65372=> "America/Menominee",
        65371=> "America/Merida",
        65370=> "America/Metlakatla",
        65369=> "America/Mexico_City",
        65368=> "America/Miquelon",
        65367=> "America/Moncton",
        65366=> "America/Monterrey",
        65365=> "America/Montevideo",
        65364=> "America/Montreal",
        65363=> "America/Montserrat",
        65362=> "America/Nassau",
        65361=> "America/New_York",
        65360=> "America/Nipigon",
        65359=> "America/Nome",
        65358=> "America/Noronha",
        65357=> "America/North_Dakota/Beulah",
        65356=> "America/North_Dakota/Center",
        65355=> "America/North_Dakota/New_Salem",
        65354=> "America/Ojinaga",
        65353=> "America/Panama",
        65352=> "America/Pangnirtung",
        65351=> "America/Paramaribo",
        65350=> "America/Phoenix",
        65349=> "America/Port-au-Prince",
        65348=> "America/Port_of_Spain",
        65347=> "America/Porto_Acre",
        65346=> "America/Porto_Velho",
        65345=> "America/Puerto_Rico",
        65344=> "America/Punta_Arenas",
        65343=> "America/Rainy_River",
        65342=> "America/Rankin_Inlet",
        65341=> "America/Recife",
        65340=> "America/Regina",
        65339=> "America/Resolute",
        65338=> "America/Rio_Branco",
        65337=> "America/Rosario",
        65336=> "America/Santa_Isabel",
        65335=> "America/Santarem",
        65334=> "America/Santiago",
        65333=> "America/Santo_Domingo",
        65332=> "America/Sao_Paulo",
        65331=> "America/Scoresbysund",
        65330=> "America/Shiprock",
        65329=> "America/Sitka",
        65328=> "America/St_Barthelemy",
        65327=> "America/St_Johns",
        65326=> "America/St_Kitts",
        65325=> "America/St_Lucia",
        65324=> "America/St_Thomas",
        65323=> "America/St_Vincent",
        65322=> "America/Swift_Current",
        65321=> "America/Tegucigalpa",
        65320=> "America/Thule",
        65319=> "America/Thunder_Bay",
        65318=> "America/Tijuana",
        65317=> "America/Toronto",
        65316=> "America/Tortola",
        65315=> "America/Vancouver",
        65314=> "America/Virgin",
        65313=> "America/Whitehorse",
        65312=> "America/Winnipeg",
        65311=> "America/Yakutat",
        65310=> "America/Yellowknife",
        65309=> "Antarctica/Casey",
        65308=> "Antarctica/Davis",
        65307=> "Antarctica/DumontDUrville",
        65306=> "Antarctica/Macquarie",
        65305=> "Antarctica/Mawson",
        65304=> "Antarctica/McMurdo",
        65303=> "Antarctica/Palmer",
        65302=> "Antarctica/Rothera",
        65301=> "Antarctica/South_Pole",
        65300=> "Antarctica/Syowa",
        65299=> "Antarctica/Troll",
        65298=> "Antarctica/Vostok",
        65297=> "Arctic/Longyearbyen",
        65296=> "Asia/Aden",
        65295=> "Asia/Almaty",
        65294=> "Asia/Amman",
        65293=> "Asia/Anadyr",
        65292=> "Asia/Aqtau",
        65291=> "Asia/Aqtobe",
        65290=> "Asia/Ashgabat",
        65289=> "Asia/Ashkhabad",
        65288=> "Asia/Atyrau",
        65287=> "Asia/Baghdad",
        65286=> "Asia/Bahrain",
        65285=> "Asia/Baku",
        65284=> "Asia/Bangkok",
        65283=> "Asia/Barnaul",
        65282=> "Asia/Beirut",
        65281=> "Asia/Bishkek",
        65280=> "Asia/Brunei",
        65279=> "Asia/Calcutta",
        65278=> "Asia/Chita",
        65277=> "Asia/Choibalsan",
        65276=> "Asia/Chongqing",
        65275=> "Asia/Chungking",
        65274=> "Asia/Colombo",
        65273=> "Asia/Dacca",
        65272=> "Asia/Damascus",
        65271=> "Asia/Dhaka",
        65270=> "Asia/Dili",
        65269=> "Asia/Dubai",
        65268=> "Asia/Dushanbe",
        65267=> "Asia/Famagusta",
        65266=> "Asia/Gaza",
        65265=> "Asia/Harbin",
        65264=> "Asia/Hebron",
        65263=> "Asia/Ho_Chi_Minh",
        65262=> "Asia/Hong_Kong",
        65261=> "Asia/Hovd",
        65260=> "Asia/Irkutsk",
        65259=> "Asia/Istanbul",
        65258=> "Asia/Jakarta",
        65257=> "Asia/Jayapura",
        65256=> "Asia/Jerusalem",
        65255=> "Asia/Kabul",
        65254=> "Asia/Kamchatka",
        65253=> "Asia/Karachi",
        65252=> "Asia/Kashgar",
        65251=> "Asia/Kathmandu",
        65250=> "Asia/Katmandu",
        65249=> "Asia/Khandyga",
        65248=> "Asia/Kolkata",
        65247=> "Asia/Krasnoyarsk",
        65246=> "Asia/Kuala_Lumpur",
        65245=> "Asia/Kuching",
        65244=> "Asia/Kuwait",
        65243=> "Asia/Macao",
        65242=> "Asia/Macau",
        65241=> "Asia/Magadan",
        65240=> "Asia/Makassar",
        65239=> "Asia/Manila",
        65238=> "Asia/Muscat",
        65237=> "Asia/Nicosia",
        65236=> "Asia/Novokuznetsk",
        65235=> "Asia/Novosibirsk",
        65234=> "Asia/Omsk",
        65233=> "Asia/Oral",
        65232=> "Asia/Phnom_Penh",
        65231=> "Asia/Pontianak",
        65230=> "Asia/Pyongyang",
        65229=> "Asia/Qatar",
        65228=> "Asia/Qyzylorda",
        65227=> "Asia/Rangoon",
        65226=> "Asia/Riyadh",
        65225=> "Asia/Saigon",
        65224=> "Asia/Sakhalin",
        65223=> "Asia/Samarkand",
        65222=> "Asia/Seoul",
        65221=> "Asia/Shanghai",
        65220=> "Asia/Singapore",
        65219=> "Asia/Srednekolymsk",
        65218=> "Asia/Taipei",
        65217=> "Asia/Tashkent",
        65216=> "Asia/Tbilisi",
        65215=> "Asia/Tehran",
        65214=> "Asia/Tel_Aviv",
        65213=> "Asia/Thimbu",
        65212=> "Asia/Thimphu",
        65211=> "Asia/Tokyo",
        65210=> "Asia/Tomsk",
        65209=> "Asia/Ujung_Pandang",
        65208=> "Asia/Ulaanbaatar",
        65207=> "Asia/Ulan_Bator",
        65206=> "Asia/Urumqi",
        65205=> "Asia/Ust-Nera",
        65204=> "Asia/Vientiane",
        65203=> "Asia/Vladivostok",
        65202=> "Asia/Yakutsk",
        65201=> "Asia/Yangon",
        65200=> "Asia/Yekaterinburg",
        65199=> "Asia/Yerevan",
        65198=> "Atlantic/Azores",
        65197=> "Atlantic/Bermuda",
        65196=> "Atlantic/Canary",
        65195=> "Atlantic/Cape_Verde",
        65194=> "Atlantic/Faeroe",
        65193=> "Atlantic/Faroe",
        65192=> "Atlantic/Jan_Mayen",
        65191=> "Atlantic/Madeira",
        65190=> "Atlantic/Reykjavik",
        65189=> "Atlantic/South_Georgia",
        65188=> "Atlantic/St_Helena",
        65187=> "Atlantic/Stanley",
        65186=> "Australia/ACT",
        65185=> "Australia/Adelaide",
        65184=> "Australia/Brisbane",
        65183=> "Australia/Broken_Hill",
        65182=> "Australia/Canberra",
        65181=> "Australia/Currie",
        65180=> "Australia/Darwin",
        65179=> "Australia/Eucla",
        65178=> "Australia/Hobart",
        65177=> "Australia/LHI",
        65176=> "Australia/Lindeman",
        65175=> "Australia/Lord_Howe",
        65174=> "Australia/Melbourne",
        65173=> "Australia/NSW",
        65172=> "Australia/North",
        65171=> "Australia/Perth",
        65170=> "Australia/Queensland",
        65169=> "Australia/South",
        65168=> "Australia/Sydney",
        65167=> "Australia/Tasmania",
        65166=> "Australia/Victoria",
        65165=> "Australia/West",
        65164=> "Australia/Yancowinna",
        65163=> "BET",
        65162=> "BST",
        65161=> "Brazil/Acre",
        65160=> "Brazil/DeNoronha",
        65159=> "Brazil/East",
        65158=> "Brazil/West",
        65157=> "CAT",
        65156=> "CET",
        65155=> "CNT",
        65154=> "CST",
        65153=> "CST6CDT",
        65152=> "CTT",
        65151=> "Canada/Atlantic",
        65150=> "Canada/Central",
        65149=> "Canada/East-Saskatchewan",
        65148=> "Canada/Eastern",
        65147=> "Canada/Mountain",
        65146=> "Canada/Newfoundland",
        65145=> "Canada/Pacific",
        65144=> "Canada/Saskatchewan",
        65143=> "Canada/Yukon",
        65142=> "Chile/Continental",
        65141=> "Chile/EasterIsland",
        65140=> "Cuba",
        65139=> "EAT",
        65138=> "ECT",
        65137=> "EET",
        65136=> "EST",
        65135=> "EST5EDT",
        65134=> "Egypt",
        65133=> "Eire",
        65132=> "Etc/GMT",
        65131=> "Etc/GMT+0",
        65130=> "Etc/GMT+1",
        65129=> "Etc/GMT+10",
        65128=> "Etc/GMT+11",
        65127=> "Etc/GMT+12",
        65126=> "Etc/GMT+2",
        65125=> "Etc/GMT+3",
        65124=> "Etc/GMT+4",
        65123=> "Etc/GMT+5",
        65122=> "Etc/GMT+6",
        65121=> "Etc/GMT+7",
        65120=> "Etc/GMT+8",
        65119=> "Etc/GMT+9",
        65118=> "Etc/GMT-0",
        65117=> "Etc/GMT-1",
        65116=> "Etc/GMT-10",
        65115=> "Etc/GMT-11",
        65114=> "Etc/GMT-12",
        65113=> "Etc/GMT-13",
        65112=> "Etc/GMT-14",
        65111=> "Etc/GMT-2",
        65110=> "Etc/GMT-3",
        65109=> "Etc/GMT-4",
        65108=> "Etc/GMT-5",
        65107=> "Etc/GMT-6",
        65106=> "Etc/GMT-7",
        65105=> "Etc/GMT-8",
        65104=> "Etc/GMT-9",
        65103=> "Etc/GMT0",
        65102=> "Etc/Greenwich",
        65101=> "Etc/UCT",
        65100=> "Etc/UTC",
        65099=> "Etc/Universal",
        65098=> "Etc/Zulu",
        65097=> "Europe/Amsterdam",
        65096=> "Europe/Andorra",
        65095=> "Europe/Astrakhan",
        65094=> "Europe/Athens",
        65093=> "Europe/Belfast",
        65092=> "Europe/Belgrade",
        65091=> "Europe/Berlin",
        65090=> "Europe/Bratislava",
        65089=> "Europe/Brussels",
        65088=> "Europe/Bucharest",
        65087=> "Europe/Budapest",
        65086=> "Europe/Busingen",
        65085=> "Europe/Chisinau",
        65084=> "Europe/Copenhagen",
        65083=> "Europe/Dublin",
        65082=> "Europe/Gibraltar",
        65081=> "Europe/Guernsey",
        65080=> "Europe/Helsinki",
        65079=> "Europe/Isle_of_Man",
        65078=> "Europe/Istanbul",
        65077=> "Europe/Jersey",
        65076=> "Europe/Kaliningrad",
        65075=> "Europe/Kiev",
        65074=> "Europe/Kirov",
        65073=> "Europe/Lisbon",
        65072=> "Europe/Ljubljana",
        65071=> "Europe/London",
        65070=> "Europe/Luxembourg",
        65069=> "Europe/Madrid",
        65068=> "Europe/Malta",
        65067=> "Europe/Mariehamn",
        65066=> "Europe/Minsk",
        65065=> "Europe/Monaco",
        65064=> "Europe/Moscow",
        65063=> "Europe/Nicosia",
        65062=> "Europe/Oslo",
        65061=> "Europe/Paris",
        65060=> "Europe/Podgorica",
        65059=> "Europe/Prague",
        65058=> "Europe/Riga",
        65057=> "Europe/Rome",
        65056=> "Europe/Samara",
        65055=> "Europe/San_Marino",
        65054=> "Europe/Sarajevo",
        65053=> "Europe/Saratov",
        65052=> "Europe/Simferopol",
        65051=> "Europe/Skopje",
        65050=> "Europe/Sofia",
        65049=> "Europe/Stockholm",
        65048=> "Europe/Tallinn",
        65047=> "Europe/Tirane",
        65046=> "Europe/Tiraspol",
        65045=> "Europe/Ulyanovsk",
        65044=> "Europe/Uzhgorod",
        65043=> "Europe/Vaduz",
        65042=> "Europe/Vatican",
        65041=> "Europe/Vienna",
        65040=> "Europe/Vilnius",
        65039=> "Europe/Volgograd",
        65038=> "Europe/Warsaw",
        65037=> "Europe/Zagreb",
        65036=> "Europe/Zaporozhye",
        65035=> "Europe/Zurich",
        65034=> "Factory",
        65033=> "GB",
        65032=> "GB-Eire",
        65031=> "GMT+0",
        65030=> "GMT-0",
        65029=> "GMT0",
        65028=> "Greenwich",
        65027=> "HST",
        65026=> "Hongkong",
        65025=> "IET",
        65024=> "IST",
        65023=> "Iceland",
        65022=> "Indian/Antananarivo",
        65021=> "Indian/Chagos",
        65020=> "Indian/Christmas",
        65019=> "Indian/Cocos",
        65018=> "Indian/Comoro",
        65017=> "Indian/Kerguelen",
        65016=> "Indian/Mahe",
        65015=> "Indian/Maldives",
        65014=> "Indian/Mauritius",
        65013=> "Indian/Mayotte",
        65012=> "Indian/Reunion",
        65011=> "Iran",
        65010=> "Israel",
        65009=> "JST",
        65008=> "Jamaica",
        65007=> "Japan",
        65006=> "Kwajalein",
        65005=> "Libya",
        65004=> "MET",
        65003=> "MIT",
        65002=> "MST",
        65001=> "MST7MDT",
        65000=> "Mexico/BajaNorte",
        64999=> "Mexico/BajaSur",
        64998=> "Mexico/General",
        64997=> "NET",
        64996=> "NST",
        64995=> "NZ",
        64994=> "NZ-CHAT",
        64993=> "Navajo",
        64992=> "PLT",
        64991=> "PNT",
        64990=> "PRC",
        64989=> "PRT",
        64988=> "PST",
        64987=> "PST8PDT",
        64986=> "Pacific/Apia",
        64985=> "Pacific/Auckland",
        64984=> "Pacific/Bougainville",
        64983=> "Pacific/Chatham",
        64982=> "Pacific/Chuuk",
        64981=> "Pacific/Easter",
        64980=> "Pacific/Efate",
        64979=> "Pacific/Enderbury",
        64978=> "Pacific/Fakaofo",
        64977=> "Pacific/Fiji",
        64976=> "Pacific/Funafuti",
        64975=> "Pacific/Galapagos",
        64974=> "Pacific/Gambier",
        64973=> "Pacific/Guadalcanal",
        64972=> "Pacific/Guam",
        64971=> "Pacific/Honolulu",
        64970=> "Pacific/Johnston",
        64969=> "Pacific/Kiritimati",
        64968=> "Pacific/Kosrae",
        64967=> "Pacific/Kwajalein",
        64966=> "Pacific/Majuro",
        64965=> "Pacific/Marquesas",
        64964=> "Pacific/Midway",
        64963=> "Pacific/Nauru",
        64962=> "Pacific/Niue",
        64961=> "Pacific/Norfolk",
        64960=> "Pacific/Noumea",
        64959=> "Pacific/Pago_Pago",
        64958=> "Pacific/Palau",
        64957=> "Pacific/Pitcairn",
        64956=> "Pacific/Pohnpei",
        64955=> "Pacific/Ponape",
        64954=> "Pacific/Port_Moresby",
        64953=> "Pacific/Rarotonga",
        64952=> "Pacific/Saipan",
        64951=> "Pacific/Samoa",
        64950=> "Pacific/Tahiti",
        64949=> "Pacific/Tarawa",
        64948=> "Pacific/Tongatapu",
        64947=> "Pacific/Truk",
        64946=> "Pacific/Wake",
        64945=> "Pacific/Wallis",
        64944=> "Pacific/Yap",
        64943=> "Poland",
        64942=> "Portugal",
        64941=> "ROC",
        64940=> "ROK",
        64939=> "SST",
        64938=> "Singapore",
        64937=> "SystemV/AST4",
        64936=> "SystemV/AST4ADT",
        64935=> "SystemV/CST6",
        64934=> "SystemV/CST6CDT",
        64933=> "SystemV/EST5",
        64932=> "SystemV/EST5EDT",
        64931=> "SystemV/HST10",
        64930=> "SystemV/MST7",
        64929=> "SystemV/MST7MDT",
        64928=> "SystemV/PST8",
        64927=> "SystemV/PST8PDT",
        64926=> "SystemV/YST9",
        64925=> "SystemV/YST9YDT",
        64924=> "Turkey",
        64923=> "UCT",
        64922=> "US/Alaska",
        64921=> "US/Aleutian",
        64920=> "US/Arizona",
        64919=> "US/Central",
        64918=> "US/East-Indiana",
        64917=> "US/Eastern",
        64916=> "US/Hawaii",
        64915=> "US/Indiana-Starke",
        64914=> "US/Michigan",
        64913=> "US/Mountain",
        64912=> "US/Pacific",
        64911=> "US/Pacific-New",
        64910=> "US/Samoa",
        64909=> "UTC",
        64908=> "Universal",
        64907=> "VST",
        64906=> "W-SU",
        64905=> "WET",
        64904=> "Zulu",
        64903=> "America/Nuuk",
        64902=> "Asia/Qostanay",
)
end


text:
@testset "Setup Database" begin
    db = setup_db("./test/data/TEST_PowerFlowNetworks_SQLite.sqlite")
    @test SQLite.tables(db)[:name] == ["instances", "decompositions", "merges", "combinations"]
end

ext: jl

max_stars_repo_name: charlyalizadeh/PowerFlowNetworks

max_issues_repo_name: charlyalizadeh/PowerFlowNetworks

max_forks_repo_name: charlyalizadeh/PowerFlowNetworks


text:
function Base.cat(xs::CuArray{T,N}...; dims::Int) where {T,N}
    length(xs) == 1 && return xs[1]
    N = max(dims, maximum(ndims,xs))
    # dims = Int[size(xs[1],i) for i=1:N]
    xs = map(xs) do x
        if ndims(x) == N
            x
        else
            Base.setindex(size(x), dims)
            dims[dim] = size(x,dim)
            reshape(x, dims...)
        end
    end

    dims[dim] = 0
    for x in xs
        dims[dim] += size(x,dim)
        for d = 1:N
            d == dim && continue
            @assert size(x,d) == size(xs[1],d)
        end
    end

    y = CuArray{T}(dims...)
    ysize = Any[Colon() for i=1:N]
    offset = 0
    for x in xs
        ysize[dim] = offset+1:offset+size(x,dim)
        suby = view(y, ysize...)
        copyto!(suby, x)
        offset += size(x,dim)
    end
    y
end

@generated function concat_binarysearch!(y::CuArray{T,N}, dim::Int, xs::Vector{CuArray{T,N}}) where {T,N}
    Ct = cstring(T)
    f = CuFunction("""
    $Array_h

    __global__ void concat(Array<$Ct,$N> y, int dim, $Ct** xs, int lengthXs, int *cumdims) {
        int idxY = blockIdx.x * blockDim.x + threadIdx.x;
        if (idxY >= y.length()) return;

        int ndIdx[$N];
        y.idx2ndIdx(ndIdx, idxY);

        int left = 0;
        int right = lengthXs;
        while (left < right - 1) {
            int m = (left + right) / 2;
            if (ndIdx[dim] < cumdims[m]) right = m;
            else left = m;
        }

        int xsIdx = left;
        ndIdx[dim] -= cumdims[xsIdx];

        // get element of x
        int idxX = 0;
        int strideX = 1;
        for (int d = 0; d < $N; d++) {
            idxX += ndIdx[d] * strideX;
            if (d == dim) strideX *= cumdims[xsIdx+1] - cumdims[xsIdx];
            else strideX *= y.dims[d];
        }
        y[idxY] = xs[xsIdx][idxX];
    }""")
    quote
        cumdims = Array{Cint}(length(xs)+1)
        cumdims[1] = 0
        for i = 2:length(cumdims)
            cumdims[i] = cumdims[i-1] + size(xs[i-1],dim)
        end
        d_cumdims = CuArray(cumdims)
        d_xs = cubox(xs)

        gdims, bdims = cudims(length(y))
        culaunch($f, gdims, bdims, y, dim-1, d_xs.ptr, length(xs), d_cumdims.ptr)
        y
    end
end


text:
using MOSLab
using Plots
using LaTeXStrings
T = 300.0 # Temperature Kelvin
N_a = 5e16 # Bulk Doping in cm^-3
t_ox = 4e-7 # oxide thickness in cm
t_si = 2.5e-5 # Silicon thickness
Vgv = 1.0 # Gate Voltage
PB = SemiconductorData(T,BoltzmanDist(),PSilicon(N_a))
MOS = MOSStructure(Alluminium(),SiO2(),PB,t_ox,t_si)
sol = PoissonVoronoi(Vgv,MOS,201)
BandDiagram(sol)
plot!(legend=:topright)
savefig("BandDiagram.png")
PBFermi = SemiconductorData(T,FermiDist(),PSilicon(N_a))
MOSFermi = MOSStructure(Alluminium(),SiO2(),PBFermi,t_ox,t_si)
plot(-2.3:0.05:2.3,x-> ψs(x,MOS),label="Boltzmann Distribution")
plot!(-2.3:0.05:2.3,x-> ψs(x,MOSFermi),label="Fermi Distribution",legend=:topleft)
xlabel!("Vg [V]")
ppsi = ylabel!(L"\psi_s \  [V]")
savefig("psi_comp.png")


text:
# # Two dimensional turbulence example
#
# In this example, we initialize a random velocity field and observe its viscous,
# turbulent decay in a two-dimensional domain. This example demonstrates:
#
#   * How to run a model with no buoyancy equation or tracers;
#   * How to create user-defined fields
#   * How to use differentiation functions
#
# For this example, we need `PyPlot` for plotting and `Statistics` for setting up
# a random initial condition with zero mean velocity.

using Oceananigans, Oceananigans.AbstractOperations, PyPlot, Statistics

# In addition to importing plotting and statistics packages, we import
# some types from `Oceananigans` that will aid in the calculation
# and visualization of voriticty.

using Oceananigans: Face, Cell

# `Face` and `Cell` represent "locations" on the staggered grid. We instantiate the
# model with a simple isotropic diffusivity.

model = Model(
        grid = RegularCartesianGrid(size=(128, 128, 1), length=(2π, 2π, 2π)),
    buoyancy = nothing,
     tracers = nothing,
     closure = ConstantIsotropicDiffusivity(ν=1e-3, κ=1e-3)
)

# Our initial condition randomizes `u` and `v`. We also ensure that both have
# zero mean for purely aesthetic reasons.

u₀ = rand(size(model.grid)...)
u₀ .-= mean(u₀)

set!(model, u=u₀, v=u₀)

# Next we create an object called an `Operation` that represents a vorticity calculation.
# We'll use this object to calculate vorticity on-line as the simulation progresses.

u, v, w = model.velocities

# Create an object that represents the 'operation' required to compute vorticity.
vorticity_operation = ∂x(v) - ∂y(u)

# The instance `vorticity_operation` is a binary subtraction between two derivative operations
# acting on `OffsetArrays` (the underyling representation of `u`, and `v`). In order to use
# `vorticity_operation` we create a field `ω` to store the result of the operation, and a
# `Computation` object for coordinate the computation of vorticity and storage in `ω`:

ω = Field(Face, Face, Cell, model.architecture, model.grid)

vorticity_computation = Computation(vorticity_operation, ω)

# We ask for computation of vorticity by writing
#
# `compute!(vorticity_computation)`,
#
# as shown below.
#
# Finally, we run the model.

fig, ax = subplots()

for i = 1:10
    time_step!(model, Nt=100, Δt=1e-1)

    compute!(vorticity_computation)

    cla()
    imshow(interior(ω)[:, :, 1])
    ax.axis("off")
    pause(0.1)
end

# We plot out the final vorticity field.
gcf()


text:
####### Mass and temperature dependent feeding interaction functional responses

# function to generate F given B (biomass of species), and parameters generated using ModelParameters()

function functional_response(h = 1 ;B, parameters)
    ### Extract maximum ingestion and half saturation density
    y = parameters.y
    B0 = parameters.B0

    # Empty matrix to store functional responses
    F = zeros(3,3)

    # find feeding interactions as cartesian index of matrix
    idf = findall(!iszero, y)
    # identify consumers from idf coords
    consumers = [i[1] for i in idf]
    # identify resources of consumers
    for c in consumers
        # find all resource indexes for each consumer
        resources = findall(!iszero, y[c,:]) # e.g if c = 2 (intermediate), then r = 1 (basal)
        for r in resources
            num = y[c,r] * (B[r]^h)
            denom = (B0[c,r]^h) + B[r]
            F[c,r] = num / denom
        end
    end
    return F
end
# fr = functional_response(B = B, parameters = p)
# p.B0[]
# B = [1,0.5,0.5]

function functional_response_CG(B, parameters, dose; slope = 5.0, lower = 0.0, xmid = 50.0, h = 1)
    ### Extract maximum ingestion and half saturation density
    y = parameters.y
    B0 = parameters.B0

    # Empty matrix to store functional responses
    F = zeros(3,3)

    # find feeding interactions as cartesian index of matrix
    idf = findall(!iszero, y)
    # identify consumers from idf coords
    consumers = [i[1] for i in idf]
    # identify resources of consumers
    for c in consumers
        # find all resource indexes for each consumer
        resources = findall(!iszero, y[c,:]) # e.g if c = 2 (intermediate), then r = 1 (basal)
        for r in resources
            num = y[c,r] * (B[r]^h)
            denom = (B0[c,r]^h) + B[r]
            F[c,r] = num / denom
        end
    end

    ### Calculate effect proportion from concentration C
    response = log_logistic(dose, slope, lower, xmid)

    return response .* F
end

#write function to calculate consumption gains and losses from the functional response, biomasses and assimilation energy
function consumption(e = 0.85; B, fr)
    feeding = B .* fr
    gain = e .* vec(sum(feeding, dims = 2))
    loss = vec(sum(feeding, dims = 1))
    return (gain, loss)
end
#consumption(B = v1, fr = f1)

### Playing, testing ...
# v1 = [1, 10, 100]
# f1 = [0 0 0; .5 0 0; 0 .8 0]

# vf1 = v1 .* f1

max_stars_repo_name: hanamayall/simple-feeding-DR

max_issues_repo_name: hanamayall/simple-feeding-DR

max_forks_repo_name: hanamayall/simple-feeding-DR


text:
type GeomLine <: AbstractGeom
    data::DataFrame
    aes::Aesthetic

    function GeomLine()
        return new()
    end
end

function geom_line()
    return GeomLine()
end

x_minimum(geom::GeomLine) = minimum(geom.data[geom.aes.x])
x_maximum(geom::GeomLine) = maximum(geom.data[geom.aes.x])
y_minimum(geom::GeomLine) = minimum(geom.data[geom.aes.y])
y_maximum(geom::GeomLine) = maximum(geom.data[geom.aes.y])

# GR backend
function plotlayer(geom::GeomLine)
    x = geom.data[geom.aes.x]
    y = geom.data[geom.aes.y]
    setlinewidth(2)
    setlinecolorind(2)
    polyline(x, y)
    return nothing
end


text:
# pwd() doesn't work - it is evaluated in the directory in which the function is called
# const deps_path = joinpath(dirname(pwd()), "deps", "ddm_fpt_lib")

# function showdir()
#    println(@__DIR__)
#    println(pwd())
# end

const deps_path = joinpath(dirname(@__DIR__), "deps", "ddm_fpt_lib")

function fpt(dm::DiffusionModel; tmax::Real = 15)

    mu = dm.drift
    sig = dm.sigma
    bound_hi = dm.bound_hi
    bound_lo = dm.bound_lo
    Δt = Float64(dm.Δt)

    nsteps = Int(tmax / Δt)
    g1 = Array{Float64}(undef, nsteps)
    g2 = Array{Float64}(undef, nsteps)

    err = ccall((:ddm_fpt, deps_path),
            Cint,(Ptr{Cdouble}, Cint, Ptr{Cdouble},
            Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble},
            Cint, Cdouble, Cdouble, Ptr{Cdouble},
            Ptr{Cdouble}),
            mu, length(mu),
            sig, length(sig),
            bound_lo, length(bound_lo),
            bound_hi, length(bound_hi),
            Δt, tmax, g1, g2)

    return (upper = g1, lower = g2)

end

function Base.rand(dm::DiffusionModel, n::Int64 = 1000;
                    seed::Int64 = 123)

    mu = dm.drift
    sig = dm.sigma
    bound_hi = dm.bound_hi
    bound_lo = dm.bound_lo
    ndt = dm.ndt
    Δt = Float64(dm.Δt)

    t = Array{Float64}(undef, n)
    bound_cond = Array{Int64}(undef, n)
    err = ccall((:ddm_rand, deps_path),Cint,(Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint,
                                                Cdouble, Cint, Cint, Ptr{Cdouble}, Ptr{Cint}),
            mu,length(mu),sig,length(sig),bound_lo,length(bound_lo),bound_hi,length(bound_hi),Δt,n,seed,t,bound_cond)

    ndts = ndt[1] .+ (ndt[2] - ndt[1]) .* Base.rand(n)
    t += t .+ ndts
    return (rt = t, choice = bound_cond)
end

function ddm_fpt(mu::Array{Float64,1},
                sig::Array{Float64,1},
                bound_lo::Array{Float64,1},
                bound_hi::Array{Float64,1};
                Δt::Float64 = 0.01,
                tmax::Float64 = 15)

    # @assert bound_lo < 0.0
    # @assert bound_hi > 0.0
    # @assert Δt > 0.0
    # @assert tmax > 0.0

    nsteps = Int(tmax / Δt)
    g1 = Array{Float64}(undef, nsteps)
    g2 = Array{Float64}(undef, nsteps)

    err = ccall((:ddm_fpt, deps_path),
            Cint,(Ptr{Cdouble}, Cint, Ptr{Cdouble},
            Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble},
            Cint, Cdouble, Cdouble, Ptr{Cdouble},
            Ptr{Cdouble}),
            mu, length(mu),
            sig, length(sig),
            bound_lo, length(bound_lo),
            bound_hi, length(bound_hi),
            Δt, tmax, g1, g2)

    return (upper = g1, lower = g2)
end

function ddm_rand(mu::Array{Float64,1},
                sig::Array{Float64,1},
                bound_lo::Array{Float64,1},
                bound_hi::Array{Float64,1};
                Δt::Float64 = 0.01,
                n::Int64 = 1000,
                seed::Int64 = 123)

#     @assert bound_lo <= 0.0
#     @assert bound_hi >= 0.0
#     @assert Δt > 0.0
#     @assert tmax > 0.0

    t = Array{Float64}(undef, n)
    bound_cond = Array{Int64}(undef, n)

    err = ccall((:ddm_rand, deps_path),Cint,(Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint,
                                                Cdouble, Cint, Cint, Ptr{Cdouble}, Ptr{Cint}),
            mu,length(mu),sig,length(sig),bound_lo,length(bound_lo),bound_hi,length(bound_hi),Δt,n,seed,t,bound_cond)

    return (rt = t, choice = bound_cond)
end

function ddm_rand(mu::Array{Float64,1},
                sig::Array{Float64,1},
                bound_lo::Array{Float64,1},
                bound_hi::Array{Float64,1},
                ndt::Tuple{Float64, Float64};
                Δt::Float64 = 0.01,
                n::Int64 = 1000,
                seed::Int64 = 123)

#     @assert bound_lo <= 0.0
#     @assert bound_hi >= 0.0
#     @assert Δt > 0.0
#     @assert tmax > 0.0

    t = Array{Float64}(undef, n)
    bound_cond = Array{Int64}(undef, n)
    err = ccall((:ddm_rand, deps_path),Cint,(Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint,
                                                Cdouble, Cint, Cint, Ptr{Cdouble}, Ptr{Cint}),
            mu,length(mu),sig,length(sig),bound_lo,length(bound_lo),bound_hi,length(bound_hi),Δt,n,seed,t,bound_cond)

    ndts = ndt[1] .+ (ndt[2] - ndt[1]) .* Base.rand(n)
    t += t .+ ndts
    return (rt = t, choice = bound_cond)
end


text:
#= SCALAR MULTIPLICATION =#

*(a::Blade{sig,k,bits}, b::Scalar) where {sig,k,bits} = Blade{sig,k,bits}(a.coeff*b)
*(a::Scalar, b::Blade{sig,k,bits}) where {sig,k,bits} = Blade{sig,k,bits}(a*b.coeff)

constructor(::Multivector{sig,k}) where {sig,k} = Multivector{sig,k}
constructor(::MixedMultivector{sig}) where sig = MixedMultivector{sig}
*(a::CompositeMultivector{<:AbstractVector}, b::Scalar) = constructor(a)(a.components*b)
*(a::Scalar, b::CompositeMultivector{<:AbstractVector}) = constructor(b)(a*b.components)

-(a::AbstractMultivector) = -one(eltype(a))*a

promote_to(x::T, ::Type{S}) where {T,S} = convert(promote_type(T, S), x)
/(a::AbstractMultivector, b::Scalar) = a*inv(promote_to(b, eltype(a)))
\(a::Scalar, b::AbstractMultivector) = inv(promote_to(a, eltype(b)))*b

#= ADDITION =#

# warning: `for u ∈ blades(b) ... end` is not fast

# mutating addition which does not require same element/storage types
function add!(a::CompositeMultivector, b::Blade)
	a.components[bits_to_key(a, bitsof(b))] += b.coeff
	a
end
function add!(a::CompositeMultivector, b::CompositeMultivector)
	for u ∈ blades(b)
		a = add!(a, u)
	end
	a
end
function add!(a::MixedMultivector, b::Multivector)
	for (bits, x) ∈ zip(bits_of_grade(grade(b)), b.components)
		a.components[bits_to_key(a, bits)] += x
	end
	a
end

# mutating add! falls back to normal add for immutable storagetypes
add!(a::CompositeMultivector{<:StaticVector}, b::Blade) = add(a, b)
add!(a::CompositeMultivector{<:StaticVector}, b::Multivector) = add(a, b)
add!(a::CompositeMultivector{<:StaticVector}, b::MixedMultivector) = add(a, b)

add(As::Multivector{sig,k,<:AbstractVector}...) where {sig,k} = Multivector{sig,k}(.+((a.components for a ∈ As)...))
add(As::MixedMultivector{sig,<:AbstractVector}...) where sig = MixedMultivector{sig}(.+((a.components for a ∈ As)...))

add(As::HomogeneousMultivector{sig,k}...) where {sig,k} = add(convert.(best_type(Multivector, As...), As)...)
add(As::AbstractMultivector{sig}...) where sig = add(convert.(best_type(MixedMultivector, As...), As)...)

+(a::AbstractMultivector) = a
+(a::AbstractMultivector...) = add(a...)
-(a::AbstractMultivector, b::AbstractMultivector) = a + (-b)

# scalar addition
+(a::AbstractMultivector{sig}, b::Scalar) where sig = a + Blade{sig}(b, bits_scalar())
+(a::Scalar, b::AbstractMultivector) = b + a
-(a::AbstractMultivector, b::Scalar) = a + (-b)
-(a::Scalar, b::AbstractMultivector) = a + (-b)

#= THE GEOMETRIC PRODUCT =#

"""
	a*b
	geometric_prod(a, b)

Geometric product of multivectors.

If both arguments are blades, then the result is a `Blade`.
Otherwise, the geometric product is general `MixedMultivector`.
"""
geometric_prod

function geometric_prod(a::Blade, b::Blade)
	sig = shared_sig(a, b)
	factor, bits = geometric_prod_bits(sig, bitsof(a), bitsof(b))
	Blade{sig,grade(bits),bits}(factor*(a.coeff*b.coeff))
end

function geometric_prod(a::AbstractMultivector, b::AbstractMultivector)
	Π = zero(best_type(MixedMultivector, a, b))
	for u ∈ blades(a), v ∈ blades(b)
		Π = add!(Π, geometric_prod(u, v))
	end
	Π
end

"""
	*(::AbstractMultivector, ::AbstractMultivector)

Geometric product. See [`$(repr(geometric_prod))`](@ref).
"""
*(a::AbstractMultivector, b::AbstractMultivector) = geometric_prod(a, b)

#= GRADED PRODUCTS =#

"""
	homogeneous_prod(a, b, Val(k))

The grade `k` part of the geometric product of `a` and `b`, i.e., ``⟨ab⟩_k``.
Equivalent to, but more efficient than, `grade(geometric_prod(a, b), k)`.
"""
homogeneous_prod

homogeneous_prod(a::Scalar, b::Scalar, ::Val{k}) where k = iszero(k) ? a*b : zero(a*b)
function homogeneous_prod(a::Blade, b::Blade, ::Val{k}) where k
	bits = bitsof(a) ⊻ bitsof(b)
	if grade(bits) == k
		geometric_prod(a, b)
	else
		zero(best_type(Blade, a, b; bits=Val(bits)))
	end
end
function homogeneous_prod(a::AbstractMultivector, b::AbstractMultivector, ::Val{k}) where k
	Π = zero(best_type(Multivector, a, b; grade=Val(k)))

	if (a, b) isa NTuple{2,HomogeneousMultivector}
		k ∈ abs(grade(a) - grade(b)):2:(grade(a) + grade(b)) || return Π
	else
		0 <= k <= dimension(a) || return Π
	end

	for u ∈ blades(a), v ∈ blades(b)
		if grade(bitsof(u) ⊻ bitsof(v)) == k
			Π = add!(Π, homogeneous_prod(u, v, k))
		end
	end
	Π
end
homogeneous_prod(a, b, k::Integer) = homogeneous_prod(a, b, Val(k))

"""
	graded_prod(a, b, grade_selector::Function)

Homogenised geometric product with resulting grade given as a function of the grades of `a` and `b`.

If ``a_p`` and ``b_q`` are multivectors of grade ``p`` and ``q`` respectively, then this is
equal to ``⟨a_p b_q⟩_{k(p,q)}`` where ``k(p,q)`` is `grade_selector(p, q)`.
If `a` or `b` are multi-graded, then this extends linearly to ``∑_{p,q} ⟨⟨a⟩_p ⟨b⟩_q⟩_{k(p,q)}``.
"""
graded_prod

function graded_prod(a::AbstractMultivector, b::AbstractMultivector, grade_selector::Function)
	Π = zero(best_type(MixedMultivector, a, b))
	for u ∈ blades(a), v ∈ blades(b)
		k = grade_selector(grade(u), grade(v))
		0 <= k <= dimension(Π) || continue
		Π = add!(Π, homogeneous_prod(u, v, k))
	end
	Π
end
function graded_prod(a::HomogeneousMultivector, b::HomogeneousMultivector, grade_selector::Function)
	homogeneous_prod(a, b, grade_selector(grade(a), grade(b)))
end
graded_prod(a::AbstractMultivector, b::Scalar, grade_selector) = graded_prod(a, one(a)b, grade_selector)
graded_prod(a::Scalar, b::AbstractMultivector, grade_selector) = graded_prod(one(b)a, b, grade_selector)
graded_prod(a::Scalar, b::Scalar, grade_selector) = homogeneous_prod(a, b, grade_selector(0, 0))

"""
	∧(a, b)

Wedge product of multivectors.

For homogeneous multivectors, `a∧b` is of grade `grade(a) + grade(b)`.
For mixed multivectors, the definition extends by linearity to ``a∧b = ∑_{pq} ⟨⟨a⟩_p ⟨b⟩_q⟩_{p + q}``.
"""
∧(a, b) = graded_prod(a, b, +)

"""
	⋅(a, b)

Generalized inner product (or "fat" dot product) of multivectors.

For homogeneous multivectors, `a⋅b` is of grade `abs(grade(a) - grade(b))`.
For mixed multivectors, the definition extends by linearity to ``a⋅b = ∑_{pq} ⟨⟨a⟩_p ⟨b⟩_q⟩_{|p - q|}``.
"""
⋅(a, b) = graded_prod(a, b, abs∘-)

"""
	⨼(a, b)

Left contraction of multivectors.

For homogeneous multivectors, `a⨼b` is of grade `grade(b) - grade(a)`.
For mixed multivectors, the definition extends by linearity to ``a⨼b = ∑_{pq} ⟨⟨a⟩_p ⟨b⟩_q⟩_{q - p}``.
"""
⨼(a, b) = graded_prod(a, b, (p, q) -> q - p)

"""
	⨽(a, b)

Right contraction of multivectors.

For homogeneous multivectors, `a⨽b` is of grade `grade(a) - grade(b)`.
For mixed multivectors, the definition extends by linearity to ``a⨽b = ∑_{pq} ⟨⟨a⟩_p ⟨b⟩_q⟩_{p - q}``.
"""
⨽(a, b) = graded_prod(a, b, (p, q) -> p - q)

"""
	∗(a, b)

Scalar product of multivectors, equal to `scalar(a*b)`.
"""
∗(a, b) = graded_prod(a, b, (p, q) -> 0)

#= MULTIPLICATIVE INVERSES =#

Base.inv(a::Blade) = a/scalar(a*a) # blades are guaranteed to have scalar squares
function Base.inv(a::CompositeMultivector)
	a² = a^2
	if isscalar(a²)
		a/scalar(a²)
	else
		inv_matrixmethod(a)
	end
end

function inv_matrixmethod(a::AbstractMultivector)
	A = hcat([full_components_vector(a*blade_like(a, 1, unsigned(i - 1)))
		for i ∈ 1:2^dimension(a)]...)
	id = full_components_vector(one(a))
	inv_components = A\id
	# result should be converted into the same storage type as original
	a⁻¹ = best_type(MixedMultivector, a; set_eltype=eltype(inv_components))(inv_components)
end

/(a::AbstractMultivector, b::AbstractMultivector) = a*inv(b)
\(a::AbstractMultivector, b::AbstractMultivector) = inv(a)*b

/(a::Scalar, b::AbstractMultivector) = a*inv(b)
\(a::AbstractMultivector, b::Scalar) = inv(a)*b

#= EXPONENTIATION =#

# if a² is a scalar, then a²ⁿ = |a²|ⁿ, a²ⁿ⁺¹ = |a²|ⁿa
function power_with_scalar_square(a::AbstractMultivector, a², p::Integer)
	# if p is even, p = 2n; if odd, p = 2n + 1
	aⁿ = a²^fld(p, 2)
	iseven(p) ? aⁿ*one(a) : aⁿ*a
end

function power_by_squaring(a::AbstractMultivector, p::Integer)
	p >= 0 || return power_by_squaring(a, abs(p))
	Π = one(best_type(MixedMultivector, a))
	aⁿ = a
	while p > 0
		if isone(p & 1)
			Π *= aⁿ
		end
		aⁿ *= aⁿ
		p >>= 1
	end
	Π
end

^(a::Blade, p::Integer) = power_with_scalar_square(a, scalar(a*a), p)

function ^(a::CompositeMultivector, p::Integer)
	p == 0 && return one(a)
	p == 1 && return a
	a² = a*a
	p == 2 && return a²
	if isscalar(a²)
		power_with_scalar_square(a, scalar(a²), p)
	else
		power_by_squaring(a, p)
	end
end

#= GRADE PROJECTION =#

grade(a::Scalar) = 0
grade(a, k::Integer) where sig = grade(a) == k ? a : zero(a)
function grade(a::MixedMultivector{sig,S}, k::Integer) where {sig,S}
	b = zero(best_type(Multivector, a, grade=Val(k)))
	for u ∈ blades(a)
		if grade(u) == k
			b = add!(b, u)
		end
	end
	b
end

# experimental notation for even/odd grade projections
# grade(a::MixedMultivector, ::typeof(+)) = sum(grade(a, k) for k ∈ 0:2:dimension(a))
# grade(a::MixedMultivector, ::typeof(-)) = sum(grade(a, k) for k ∈ 1:2:dimension(a))

scalar(a::AbstractMultivector) = getcomponent(a)

isscalar(a::HomogeneousMultivector) = iszero(grade(a))
isscalar(a::MixedMultivector) = iszero(a.components[begin + 1:end])

#= AUTOMORPHISMS & DUALITY OPERATIONS =#

reversionsign(k, x=1) = mod(k, 4) <= 1 ? +x : -x

"""
	~(a::AbstractMultivector)
	reversion(a::AbstractMultivector)

The reverse of a multivector.

The reversion antiautomorphism ``ρ`` is defined by ``ρ(u) = u`` on vectors
and ``ρ(ab) = ρ(b)ρ(a)`` on higher-grade elements.
"""
reversion, ~

reversion(a::Scalar) = a
reversion(a::HomogeneousMultivector{sig,k}) where {sig,k} = reversionsign(k, a)
reversion(a::MixedMultivector) = mapcomponents(b -> reversion(b).coeff, a)

Base.:~(a::AbstractMultivector) = reversion(a)

"""
	involute(a::AbstractMultivector)

The involute of a multivector, negating the odd-grade part.

The involution automorphism ``ι`` is defined by ``ι(u) = -u`` on vectors
and ``ι(ab) = ι(a)ι(b)`` on higher-grade elements.
"""
involute

involute(a::Scalar) = a
involute(a::HomogeneousMultivector) = iseven(grade(a)) ? a : -a
involute(a::MixedMultivector) = mapcomponents(u -> (iseven(grade(u)) ? u : -u).coeff, a)

# TODO: show the Clifford conjugate cong = reversion∘involute be defined as the adjoint?

# TODO: terminology: 'volume element' or 'pseudoscalar'?
# InstanceOrType{T} = Union{T,Type{T}}
unit_pseudoscalar(a::Union{<:AbstractMultivector,Type{<:AbstractMultivector}}) = oneunit(best_type(Blade, a; bits=Val(bits_first_of_grade(dimension(a)))))
unit_pseudoscalar(sig) = prod(basis(sig))

# TODO: which type of dual operation? aI, Ia, a/I, I\a?
# the Hodge dual is defined as ``φ ∧ ⋆ϕ = ⟨φ,ϕ⟩ vol`` for forms of the same degree
# so the choice `dual(a) = aI` agrees with the Hodge dual on blades of the same grade.
dual(a::AbstractMultivector) = a*unit_pseudoscalar(a)


text:
@fastmath function calc_polars(x, y)
    r = sqrt(x^2 + y^2)
    if r == 0.0
        return 0.0, 0.0
    else
        theta = atand(x, y)
        if theta < 0.0
            theta += 360.0
        end
        return r, theta
    end
end

"""Generate weather for shortest path test functions."""
function generate_constant_weather(tws_val, twa_val, cs_val, cd_val,
                          wahi_val, wadi_val, n_locs, t_len)
    empty = zeros(t_len, n_locs, n_locs)
    tws = copy(empty)
    twa = copy(empty)
    cs = copy(empty)
    cd = copy(empty)
    wahi = copy(empty)
    wadi = copy(empty)
    for i in eachindex(empty)
        tws[i] = tws_val[1]
        twa[i] = twa_val[1]
        cs[i] = cs_val[1]
        cd[i] = cd_val[1]
        wahi[i] = wahi_val[1]
        wadi[i] = wadi_val[1]
    end
    return tws, twa, cs, cd, wahi, wadi
end


text:
include("../neat_test.jl")

st = get_simulation_state("Resultados_23:07:2021/limited/checkpoint-dt1-limited-10000g.jld2")

#nbins = parse(Int, ARGS[1])

#print("Number of bins: ", nbins)
#plot_neat_IP(st, imagename="IP-dt1-$(nbins)bins-limited.png", nbins=nbins)

bins = [5, 6, 9, 10, 15]
# best resut: 15 bins

for b in bins
    println("Number of bins: ", b)
    plot_neat_IP(st, imagename="IP-dt1-$(b)bins-limited-fixed.png", nbins=b)
    println("Image generated")
end

# nohup julia IP_bins_img_test.jl 19 &> nohup-MLP-dt1-IP-19b-30:07:2021.out &

# nohup julia IP_bins_img_test.jl &> nohup-MLP-dt1-IP-fixed-13:08:2021.out &

max_stars_repo_name: Lucas-Muniz/MNEAT

max_issues_repo_name: Lucas-Muniz/MNEAT

max_forks_repo_name: Lucas-Muniz/MNEAT


text:
using Parameters
# Potassium channels
@with_kw struct IKParams
    k_o = 5.4
    G_KP = 8.28E-3
    P_NA_K = 0.0183
    G_K = 0.282 * sqrt(k_o / 5.4)
    G_K1 = 0.748 * sqrt(k_o / 5.4)
end

# Rate of change of Xk gating variable
function dxk(x_k, vm)
    Δv = vm + 30
    α = -7.9e-5 * Δv / expm1(-0.148 * Δv)
    β = 1.31e-4 * Δv / expm1(0.0687 * Δv)
    d_x_k = α - x_k * (α + β)
end

# Time-dependent K current (iK) (μA/cm²)
function ik(vm, eNaK, x_k, G_K)
    x1_inv = 1 + exp((vm - 40) / 40)
    i_k = G_K * x_k^2 / x1_inv * (vm - eNaK)
end

# Plataeu K current (iKp) (uA/cm^2)
ikp(vm, eK, G_KP) = G_KP * (vm - eK) / (1 + exp((7.488 - vm) / 5.98))

# Time-independent K current (iK1) (uA/cm^2)
function ik1(vm, eK, G_K1)
    Δv = vm - eK
    α = 1.02 / (1 + exp(0.2385 * (Δv - 59.215)))
    β = (0.4912 * exp(0.08032 * (Δv + 5.476)) + exp(0.06175 * (Δv - 594.31))) / (1 + exp(-0.5143 * (Δv + 4.753)))
    ik1 = G_K1 * Δv * α / (α + β)
end


text:
using SearchLight
using Items

function seed()
    items = [
        Item(a="Hello", b=1),
        Item(a="World", b=2)
    ]
    for item in items
        save(item)
    end
end

max_stars_repo_name: jaantollander/genie-webapp-db

max_issues_repo_name: jaantollander/genie-webapp-db

max_forks_repo_name: jaantollander/genie-webapp-db


text:
function part1(input, preamble_length_str = "25")
    preamble_length = parse(Int, preamble_length_str)
    numbers = parse.(Int, readlines(input))
    return find_invalid(numbers, preamble_length)
end

function part2(input, preamble_length_str = "25")
    preamble_length = parse(Int, preamble_length_str)
    numbers = parse.(Int, readlines(input))
    invalid = find_invalid(numbers, preamble_length)
    for i = 1:length(numbers)
        partial_sum = numbers[i]
        j = i + 1
        while j <= length(numbers)
            partial_sum += numbers[j]
            if partial_sum == invalid
                return sum(extrema(numbers[i:j]))
            elseif partial_sum > invalid
                break
            end
            j += 1
        end
    end
end

function find_invalid(numbers, preamble_length)
    for i = (preamble_length + 1):length(numbers)
        if !is_sum_of_two(numbers[i], numbers[(i - preamble_length):(i - 1)])
            return numbers[i]
        end
    end
    @assert false
end

function is_sum_of_two(n, v)
    for i = 1:length(v)
        for j = (i + 1):length(v)
            v[i] + v[j] == n && return true
        end
    end
    return false
end


text:
# Arrays
"""
    nfan(n_out, n_in=1) -> Tuple
    nfan(dims...)
    nfan(dims::Tuple)

For a layer characterized by dimensions `dims`, return a tuple `(fan_in, fan_out)`, where `fan_in`
is the number of input neurons connected to an output one, and `fan_out` is the number of output neurons
connected to an input one.

This function is mainly used by weight initializers, e.g., [`kaiming_normal`](@ref Flux.kaiming_normal).

# Examples

```jldoctest
julia> layer = Dense(10, 20)
Dense(10, 20)

julia> Flux.nfan(size(layer.W))
(10, 20)

julia> layer = Conv((3, 3), 2=>10)
Conv((3, 3), 2=>10)

julia> Flux.nfan(size(layer.weight))
(18, 90)
```
"""
nfan() = 1, 1 # fan_in, fan_out
nfan(n) = 1, n # A vector is treated as a n×1 matrix
nfan(n_out, n_in) = n_in, n_out # In case of Dense kernels: arranged as matrices
nfan(dims::Tuple) = nfan(dims...)
nfan(dims...) = prod(dims[1:end-2]) .* (dims[end-1], dims[end]) # In case of convolution kernels

ofeltype(x, y) = convert(float(eltype(x)), y)
epseltype(x) = eps(float(eltype(x)))

"""
    glorot_uniform([rng=GLOBAL_RNG], dims...)

Return an `Array` of size `dims` containing random variables taken from a uniform
distribution in the interval ``[-x, x]``, where `x = sqrt(6 / (fan_in + fan_out))`.

This method is described in [1] and also known as Xavier initialization.

# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> Flux.glorot_uniform(2, 3)
2×3 Array{Float32,2}:
 0.601094  -0.57414   -0.814925
 0.900868   0.805994   0.057514
```

# See also

* glorot initialization using normal distribution: [`glorot_normal`](@ref Flux.glorot_normal)
* kaiming initialization using normal distribution: [`kaiming_normal`](@ref Flux.kaiming_normal)
* kaiming initialization using uniform distribution: [`kaiming_uniform`](@ref Flux.kaiming_uniform)
* sparse initialization: [`sparse_init`](@ref Flux.sparse_init)
* calculation of `fan_in` and `fan_out`: [`nfan`](@ref Flux.nfan)

# References

[1] Glorot, Xavier, and Yoshua Bengio. "Understanding the difficulty of training deep feedforward neural networks." _Proceedings of the thirteenth international conference on artificial intelligence and statistics_. 2010.
"""
glorot_uniform(rng::AbstractRNG, dims...) = (rand(rng, Float32, dims...) .- 0.5f0) .* sqrt(24.0f0 / sum(nfan(dims...)))
glorot_uniform(dims...) = glorot_uniform(Random.GLOBAL_RNG, dims...)
glorot_uniform(rng::AbstractRNG) = (dims...) -> glorot_uniform(rng, dims...)

"""
    glorot_normal([rng=GLOBAL_RNG], dims...)

Return an `Array` of size `dims` containing random variables taken from a normal
distribution with mean 0 and standard deviation `sqrt(2 / (fan_in + fan_out))`.

This method is described in [1] and also known as Xavier initialization.

# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> Flux.glorot_normal(3, 2)
3×2 Array{Float32,2}:
  0.429505  -0.0852891
  0.523935   0.371009
 -0.223261   0.188052
```

# See also

* glorot initialization using uniform distribution: [`glorot_uniform`](@ref Flux.glorot_uniform)
* kaiming initialization using normal distribution: [`kaiming_normal`](@ref Flux.kaiming_normal)
* kaiming initialization using uniform distribution: [`kaiming_uniform`](@ref Flux.kaiming_uniform)
* sparse initialization: [`sparse_init`](@ref Flux.sparse_init)
* calculation of `fan_in` and `fan_out`: [`nfan`](@ref Flux.nfan)

# References

[1] Glorot, Xavier, and Yoshua Bengio. "Understanding the difficulty of training deep feedforward neural networks." _Proceedings of the thirteenth international conference on artificial intelligence and statistics_. 2010.
"""
glorot_normal(rng::AbstractRNG, dims...) = randn(rng, Float32, dims...) .* sqrt(2.0f0 / sum(nfan(dims...)))
glorot_normal(dims...) = glorot_normal(Random.GLOBAL_RNG, dims...)
glorot_normal(rng::AbstractRNG) = (dims...) -> glorot_normal(rng, dims...)

"""
    kaiming_uniform([rng=GLOBAL_RNG], dims...; gain = √2)

Return an `Array` of size `dims` containing random variables taken from a uniform distribution in the
interval `[-x, x]`, where `x = gain * sqrt(3/fan_in)`.

This method is described in [1] and also known as He initialization.

# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> Flux.kaiming_uniform(3, 2)
3×2 Array{Float32,2}:
  0.950413   1.27439
  1.4244    -1.28851
 -0.907795   0.0909376
```

# See also

* kaiming initialization using normal distribution: [`kaiming_normal`](@ref Flux.kaiming_normal)
* glorot initialization using normal distribution: [`glorot_normal`](@ref Flux.glorot_normal)
* glorot initialization using uniform distribution: [`glorot_uniform`](@ref Flux.glorot_uniform)
* sparse initialization: [`sparse_init`](@ref Flux.sparse_init)
* calculation of `fan_in` and `fan_out`: [`nfan`](@ref Flux.nfan)

# References

[1] He, Kaiming, et al. "Delving deep into rectifiers: Surpassing human-level performance on imagenet classification." _Proceedings of the IEEE international conference on computer vision_. 2015.
"""
function kaiming_uniform(rng::AbstractRNG, dims...; gain = √2)
  bound = Float32(√3 * gain / sqrt(first(nfan(dims...)))) # fan_in
  return (rand(rng, Float32, dims...) .- 0.5f0) .* 2bound
end

kaiming_uniform(dims...; kwargs...) = kaiming_uniform(Random.GLOBAL_RNG, dims...; kwargs...)
kaiming_uniform(rng::AbstractRNG; init_kwargs...) = (dims...; kwargs...) -> kaiming_uniform(rng, dims...; init_kwargs..., kwargs...)

"""
    kaiming_normal([rng=GLOBAL_RNG], dims...; gain = √2)

Return an `Array` of size `dims` containing random variables taken from a normal
distribution with mean 0 and standard deviation `gain * sqrt(fan_in)`.

This method is described in [1] and also known as He initialization.

# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> Flux.kaiming_normal(3, 2)
3×2 Array{Float32,2}:
  0.679107  -0.134854
  0.828413   0.586617
 -0.353007   0.297336
```

# See also

* kaiming initialization using uniform distribution: [`kaiming_uniform`](@ref Flux.kaiming_uniform)
* glorot initialization using normal distribution: [`glorot_normal`](@ref Flux.glorot_normal)
* glorot initialization using uniform distribution: [`glorot_uniform`](@ref Flux.glorot_uniform)
* sparse initialization: [`sparse_init`](@ref Flux.sparse_init)
* calculation of `fan_in` and `fan_out`: [`nfan`](@ref Flux.nfan)

# References

[1] He, Kaiming, et al. "Delving deep into rectifiers: Surpassing human-level performance on imagenet classification." _Proceedings of the IEEE international conference on computer vision_. 2015.
"""
function kaiming_normal(rng::AbstractRNG, dims...; gain = √2f0)
  std = Float32(gain / sqrt(first(nfan(dims...)))) # fan_in
  return randn(rng, Float32, dims...) .* std
end

kaiming_normal(dims...; kwargs...) = kaiming_normal(Random.GLOBAL_RNG, dims...; kwargs...)
kaiming_normal(rng::AbstractRNG; init_kwargs...) = (dims...; kwargs...) -> kaiming_normal(rng, dims...; init_kwargs..., kwargs...)

"""
    orthogonal([rng=GLOBAL_RNG], dims...; gain = 1)

Return an `Array` of size `dims` which is a (semi) orthogonal matrix, as described in [1].

The input must have at least 2 dimensions.
For `length(dims) > 2`, a `prod(dims[1:(end - 1)])` by `dims[end]` orthogonal matrix
is computed before reshaping it to the original dimensions.

# Examples
```jldoctest; setup = :(using LinearAlgebra)
julia> W = Flux.orthogonal(5, 7);

julia> summary(W)
"5×7 Array{Float32,2}"

julia> W * W' ≈ I(5)
true

julia> W2 = Flux.orthogonal(7, 5);

julia> W2 * W2' ≈ I(7)
false

julia> W2' * W2 ≈ I(5)
true

julia> W3 = Flux.orthogonal(3, 3, 2, 4);

julia> transpose(reshape(W3, :, 4)) * reshape(W3, :, 4) ≈ I(4)
true
```

# See also
* kaiming initialization using normal distribution: [`kaiming_normal`](@ref Flux.kaiming_normal)
* kaiming initialization using uniform distribution: [`kaiming_uniform`](@ref Flux.kaiming_uniform)
* glorot initialization using normal distribution: [`glorot_normal`](@ref Flux.glorot_normal)
* glorot initialization using uniform distribution: [`glorot_uniform`](@ref Flux.glorot_uniform)
* sparse initialization: [`sparse_init`](@ref Flux.sparse_init)

# References
[1] Saxe, McClelland, Ganguli. "Exact solutions to the nonlinear dynamics of learning in deep linear neural networks", ICLR 2014, https://arxiv.org/abs/1312.6120

"""
function orthogonal(rng::AbstractRNG, rows::Integer, cols::Integer; gain = 1)
  mat = rows > cols ? randn(rng, Float32, rows, cols) : randn(rng, Float32, cols, rows)

  Q, R = LinearAlgebra.qr(mat)
  Q = Array(Q) * sign.(LinearAlgebra.Diagonal(R))
  if rows < cols
    Q = transpose(Q)
  end

  return gain * Q
end

function orthogonal(rng::AbstractRNG, d1::Integer, ds::Integer...; kwargs...)
  dims = (d1, ds...)
  rows = prod(dims[1:end-1])
  cols = dims[end]
  return reshape(orthogonal(rng, rows, cols; kwargs...), dims)
end

orthogonal(dims::Integer...; kwargs...) = orthogonal(Random.GLOBAL_RNG, dims...; kwargs...)
orthogonal(rng::AbstractRNG; init_kwargs...) = (dims::Integer...; kwargs...) -> orthogonal(rng, dims...; init_kwargs..., kwargs...)

"""
    sparse_init([rng=GLOBAL_RNG], dims...; sparsity, std = 0.01)

Return an `Array` of size `dims` where each column contains a fixed fraction of
zero elements given by `sparsity`. Non-zero elements are normally distributed
with a mean of zero and standard deviation `std`.

This method is described in [1].

# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> Flux.sparse_init(3, 2, sparsity=0.1)
3×2 Array{Float32,2}:
  0.00828413  0.0
 -0.00353007  0.00297336
  0.0         0.00586617
```

# See also

* kaiming initialization using normal distribution: [`kaiming_normal`](@ref Flux.kaiming_normal)
* kaiming initialization using uniform distribution: [`kaiming_uniform`](@ref Flux.kaiming_uniform)
* glorot initialization using normal distribution: [`glorot_normal`](@ref Flux.glorot_normal)
* glorot initialization using uniform distribution: [`glorot_uniform`](@ref Flux.glorot_uniform)

# References

[1] Martens, J, "Deep learning via Hessian-free optimization" _Proceedings of the 27th International Conference on International Conference on Machine Learning_. 2010.
"""
function sparse_init(rng::AbstractRNG, dims...; sparsity, std = 0.01)
  if length(dims) != 2
    throw(ArgumentError("Only 2-dimensional outputs are supported for sparse initialization."))
  end
  rows, cols = dims
  prop_zero = min(1.0, sparsity)
  num_zeros = ceil(Integer, prop_zero * rows)
  sparse_array = randn(rng, Float32, dims...) .* Float32(std)
  sparse_array[1:num_zeros, :] .= 0f0
  return mapslices(shuffle, sparse_array, dims=1)
end

sparse_init(dims...; kwargs...) = sparse_init(Random.GLOBAL_RNG, dims...; kwargs...)
sparse_init(rng::AbstractRNG; init_kwargs...) = (dims...; kwargs...) -> sparse_init(rng, dims...; init_kwargs..., kwargs...)

"""
    identity_init([rng=GLOBAL_RNG], dims...; gain=1, shift=0)

Return an `Array` of size `dims` which yields an identity mapping when used as parameters in
most Flux layers. Use `gain` to scale the identity by a constant.

Often useful in the context of transfer learning, i.e when one wants to add more capacity to
a model but start from the same mapping.

Use `shift` (integer or tuple) to apply circular shift to the output.
Equivalent to `Base.circshift(identity(dims...), shift)`.

Some caveats: Not all layers will be identity mapping when used with this init. Exceptions
include recurrent layers, `DepthwiseConv` and normalization layers.

Also note that layers must have `input_size == output_size` for identity mapping to be
possible. When this is not the case, extra dimensions of the array are padded with zeros.

For convolutional layers, in addition to the above, the kernel sizes must also be odd and
padding must be applied so that output feature maps have the same size as input feature maps,
e.g by using [`SamePad`](@ref).

Has the following behaviour
*  1D: A `Vector` of `zeros` (useful for an identity bias)
*  2D: An identity matrix (useful for an identity matrix multiplication)
*  More than 2D: A dense block array of center tap spatial filters (useful for an identity convolution)

```jldoctest
julia> Flux.identity_init(3,3)
3×3 Array{Float32,2}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0

julia> Flux.identity_init(3,5)
3×5 Array{Float32,2}:
 1.0  0.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0  0.0
 0.0  0.0  1.0  0.0  0.0

julia> Flux.identity_init(3,3,2,2)
3×3×2×2 Array{Float32,4}:
[:, :, 1, 1] =
 0.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  0.0

[:, :, 2, 1] =
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

[:, :, 1, 2] =
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

[:, :, 2, 2] =
 0.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  0.0
```
"""
# Assume bias
identity_init(cols; gain=1, shift=0) = zeros(Float32, cols)

# Assume matrix multiplication
identity_init(rows, cols; gain=1, shift=0) = circshift(Matrix{Float32}(I * gain, rows,cols), shift)

# Assume convolution
function identity_init(dims...; gain=1, shift=0)
  nin, nout = dims[end-1], dims[end]
  centers = map(d -> cld(d, 2), dims[1:end-2])
  weights = zeros(Float32, dims)
  for i in 1:min(nin,nout)
    weights[centers..., i, i] = gain
  end
  return circshift(weights, shift)
end

identity_init(::AbstractRNG, dims...; kwargs...) = identity_init(dims...; kwargs...)
identity_init(; init_kwargs...) = identity_init(Random.GLOBAL_RNG; init_kwargs...)
identity_init(rng::AbstractRNG; init_kwargs...) = (args...;kwargs...) -> identity_init(rng, args...; init_kwargs..., kwargs...)

ones(T::Type, dims...) = Base.ones(T, dims...)
zeros(T::Type, dims...) = Base.zeros(T, dims...)

ones(dims...) = Base.ones(Float32, dims...)
zeros(dims...) = Base.zeros(Float32, dims...)

"""
    create_bias(weights, bias, length)

Return a bias parameter for a layer, based on the value given
to the constructor's keyword `bias=bias`.

* `bias == true` creates a zero vector, of the same type as weights.
* `bias == false` returns `Zeros()`, a special struct which exists only to encode the absence of bias.
* `bias::AbstractArray` uses the array provided, provided it has the correct size and eltype. If the type is wrong, it will be converted.
"""
function create_bias(weights::AbstractArray, bias::Bool, dims::Integer...)
  bias ? fill!(similar(weights, dims...), 0) : Zeros()
end
function create_bias(weights::AbstractArray, bias::AbstractArray, dims::Integer...)
  size(bias) == dims || throw(DimensionMismatch("expected bias of size $(dims), got size $(size(bias))"))
  if eltype(bias) == eltype(weights)
    return bias
  else
    @warn "converting bias to match element type of weights" typeof(weights) typeof(bias) maxlog=3 _id=hash(dims)
    return broadcast(eltype(weights), bias)
  end
end

"""
    unsqueeze(xs, dim)

Return `xs` reshaped into an array one dimensionality higher than `xs`,
where `dim` indicates in which dimension `xs` is extended.

See also [`flatten`](@ref), [`stack`](@ref).

# Examples
```jldoctest
julia> Flux.unsqueeze([1 2; 3 4], 2)
2×1×2 Array{Int64,3}:
[:, :, 1] =
 1
 3

[:, :, 2] =
 2
 4

julia> xs = [[1, 2], [3, 4], [5, 6]]
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [3, 4]
 [5, 6]

julia> Flux.unsqueeze(xs, 1)
1×3 Array{Array{Int64,1},2}:
 [1, 2]  [3, 4]  [5, 6]
```
"""
unsqueeze(xs::AbstractArray, dim::Integer) = reshape(xs, (size(xs)[1:dim-1]..., 1, size(xs)[dim:end]...))

"""
    unsqueeze(dim)

Returns a function which, acting on an array, inserts a dimension of size 1 at `dim`.

# Examples
```jldoctest
julia> rand(21, 22, 23) |> Flux.unsqueeze(2) |> size
(21, 1, 22, 23)

julia> m = Chain(Flux.unsqueeze(3), Flux.unsqueeze(4), Conv((3,3), 1=>7, pad=SamePad()));

julia> rand(Float32, 10, 10) |> m |> size
(10, 10, 7, 1)
```
"""
unsqueeze(dim::Integer) = Base.Fix2(unsqueeze, dim)

Base.show_function(io::IO, u::Base.Fix2{typeof(unsqueeze)}, ::Bool) = print(io, "unsqueeze(", u.x, ")")

"""
    stack(xs, dim)

Concatenate the given `Array` of `Array`s `xs` into a single `Array` along the
given dimension `dim`.

# Examples
```jldoctest
julia> xs = [[1, 2], [3, 4], [5, 6]]
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [3, 4]
 [5, 6]

julia> Flux.stack(xs, 1)
3×2 Array{Int64,2}:
 1  2
 3  4
 5  6

julia> cat(xs, dims=1)
3-element Array{Array{Int64,1},1}:
 [1, 2]
 [3, 4]
 [5, 6]
```
"""
stack(xs, dim) = cat(unsqueeze.(xs, dim)..., dims=dim)

"""
    unstack(xs, dim)

Unroll the given `xs` into an `Array` of `Array`s along the given dimension `dim`.

# Examples
```jldoctest
julia> Flux.unstack([1 3 5 7; 2 4 6 8], 2)
4-element Array{Array{Int64,1},1}:
 [1, 2]
 [3, 4]
 [5, 6]
 [7, 8]
```
"""
unstack(xs, dim) = [copy(selectdim(xs, dim, i)) for i in 1:size(xs, dim)]

"""
    chunk(xs, n)

Split `xs` into `n` parts.

# Examples
```jldoctest
julia> Flux.chunk(1:10, 3)
3-element Array{UnitRange{Int64},1}:
 1:4
 5:8
 9:10

julia> Flux.chunk(collect(1:10), 3)
3-element Array{SubArray{Int64,1,Array{Int64,1},Tuple{UnitRange{Int64}},true},1}:
 [1, 2, 3, 4]
 [5, 6, 7, 8]
 [9, 10]
```
"""
chunk(xs, n) = collect(Iterators.partition(xs, ceil(Int, length(xs)/n)))

batchindex(xs, i) = (reverse(Base.tail(reverse(axes(xs))))..., i)

"""
    frequencies(xs)

Count the number of times that each element of `xs` appears.

# Examples
```jldoctest
julia> Flux.frequencies(['a','b','b'])
Dict{Char,Int64} with 2 entries:
  'a' => 1
  'b' => 2
```
"""
function frequencies(xs)
  fs = Dict{eltype(xs),Int}()
  for x in xs
    fs[x] = get(fs, x, 0) + 1
  end
  return fs
end

head(x::Tuple) = reverse(Base.tail(reverse(x)))

squeezebatch(x) = reshape(x, head(size(x)))

"""
    batch(xs)

Batch the arrays in `xs` into a single array.

# Examples
```jldoctest
julia> Flux.batch([[1,2,3],[4,5,6]])
3×2 Array{Int64,2}:
 1  4
 2  5
 3  6
```
"""
function batch(xs)
  data = first(xs) isa AbstractArray ?
    similar(first(xs), size(first(xs))..., length(xs)) :
    Vector{eltype(xs)}(undef, length(xs))
  for (i, x) in enumerate(xs)
    data[batchindex(data, i)...] = x
  end
  return data
end

"""
Return the given sequence padded with `p` up to a maximum length of `n`.

# Examples
```jldoctest
julia> rpad([1, 2], 4, 0)
4-element Array{Int64,1}:
 1
 2
 0
 0

julia> rpad([1, 2, 3], 2, 0)
3-element Array{Int64,1}:
 1
 2
 3
```
"""
Base.rpad(v::AbstractVector, n::Integer, p) = [v; fill(p, max(n - length(v), 0))]

"""
    batchseq(seqs, pad)

Take a list of `N` sequences, and turn them into a single sequence where each
item is a batch of `N`. Short sequences will be padded by `pad`.

# Examples
```jldoctest
julia> Flux.batchseq([[1, 2, 3], [4, 5]], 0)
3-element Array{Array{Int64,1},1}:
 [1, 4]
 [2, 5]
 [3, 0]
```
"""
function batchseq(xs, pad = nothing, n = maximum(length(x) for x in xs))
  xs_ = [rpad(x, n, pad) for x in xs]
  [batch([xs_[j][i] for j = 1:length(xs_)]) for i = 1:n]
end

# Flattening models to weight vectors, and back

function _restructure(m, xs)
  i = 0
  fmap(m) do x
    x isa AbstractArray || return x
    x = reshape(xs[i.+(1:length(x))], size(x))
    i += length(x)
    return x
  end
end

@adjoint function _restructure(m, xs)
  _restructure(m, xs), dm -> (nothing,destructure(dm)[1])
end

"""
    destructure(m)

Flatten a model's parameters into a single weight vector.

    julia> m = Chain(Dense(10, 5, σ), Dense(5, 2), softmax)
    Chain(Dense(10, 5, σ), Dense(5, 2), softmax)

    julia> θ, re = destructure(m);

    julia> θ
    67-element Array{Float32,1}:
    -0.1407104
    ...

The second return value `re` allows you to reconstruct the original network after making
modifications to the weight vector (for example, with a hypernetwork).

    julia> re(θ .* 2)
    Chain(Dense(10, 5, σ), Dense(5, 2), softmax)
"""
function destructure(m)
  xs = Zygote.Buffer([])
  fmap(m) do x
    x isa AbstractArray && push!(xs, x)
    return x
  end
  return vcat(vec.(copy(xs))...), p -> _restructure(m, p)
end

# Other

"""
    throttle(f, timeout; leading=true, trailing=false)

Return a function that when invoked, will only be triggered at most once
during `timeout` seconds.

Normally, the throttled function will run as much as it can, without ever
going more than once per `wait` duration; but if you'd like to disable the
execution on the leading edge, pass `leading=false`. To enable execution on
the trailing edge, pass `trailing=true`.
"""
function throttle(f, timeout; leading=true, trailing=false)
  cooldown = true
  later = nothing
  result = nothing

  function throttled(args...; kwargs...)
    yield()

    if cooldown
      if leading
        result = f(args...; kwargs...)
      else
        later = () -> f(args...; kwargs...)
      end

      cooldown = false
      @async try
        while (sleep(timeout); later != nothing)
          later()
          later = nothing
        end
      finally
        cooldown = true
      end
    elseif trailing
      later = () -> (result = f(args...; kwargs...))
    end

    return result
  end
end


text:
module TSML

# reexport some needed functions from packages to Main
include("pkgdeps.jl")

export fit, fit!, transform, transform!,fit_transform, fit_transform!

using AMLPipelineBase
using AMLPipelineBase: AbsTypes, Utils, BaselineModels, Pipelines
using AMLPipelineBase: BaseFilters, FeatureSelectors, DecisionTreeLearners
using AMLPipelineBase: EnsembleMethods, CrossValidators
using AMLPipelineBase: NARemovers

export Machine, Learner, Transformer, Workflow, Computer
export holdout, kfold, score, infer_eltype, nested_dict_to_tuples,
       nested_dict_set!, nested_dict_merge, create_transformer,
       mergedict, getiris,getprofb,
       skipmean,skipmedian,skipstd,
       aggregatorclskipmissing
export Baseline, Identity
export Imputer,OneHotEncoder,Wrapper
export PrunedTree,RandomForest,Adaboost
export VoteEnsemble, StackEnsemble, BestLearner
export FeatureSelector, CatFeatureSelector, NumFeatureSelector, CatNumDiscriminator
export crossvalidate
export NARemover
export @pipeline @pipelinex, @pipelinez
export +, |>, *, |, >>
export Pipeline, ComboPipeline

import AMLPipelineBase.AbsTypes: fit, fit!, transform, transform!

# ----------------------------------------------

include("valdatefilters.jl")
using .ValDateFilters
export Matrifier,Dateifier,
       DateValizer,DateValgator,DateValNNer,DateValMultiNNer,
       CSVDateValReader, CSVDateValWriter, DateValLinearImputer
       #BzCSVDateValReader
export impute, impute!,interp, interp!, locf, nocb

include("statifier.jl")
using .Statifiers
export Statifier,tsmlfullstat

include("mlbase.jl")
using .MLBaseWrapper
export Standardize,standardize, standardize!,
       estimate, transform,StandardScaler

include("monotonicer.jl")
using .Monotonicers
export Monotonicer,ismonotonic,dailyflips

include("cliwrapper.jl")
using .CLIWrappers
export tsmlrun

include("tsclassifier.jl")
using .TSClassifiers
export TSClassifier, getstats

include("outliernicer.jl")
using .Outliernicers
export Outliernicer

include("normalizer.jl")
using .Normalizers
export Normalizer

#include("svm.jl")
#using .SVMModels
#export SVMModel

#include("timescaledb.jl")
#using .TimescaleDBs
#export TimescaleDB

include("argparse.jl")
using .ArgumentParsers
export tsmlmain

include("plotter.jl")
using .Plotters
export Plotter

include("demo.jl")
using .TSMLDemo
export tsml_demo

#include("schema.jl")
#using .Schemalizers
#export Schemalizer, ML, table

end # module


text:
using SparseIR
using Test

import PyCall: pyimport, PyNULL, PyVector

sparse_ir = pyimport("sparse_ir")

@testset "kernel.KernelFlat" begin
    lambda_ = 10.0
    kernels = [(SparseIR.LogisticKernel, sparse_ir.LogisticKernel),
               (SparseIR.RegularizedBoseKernel, sparse_ir.RegularizedBoseKernel)]
    for (K, K_py) in kernels
        k = K(lambda_)
        k_py = K_py(lambda_)
        @test k_py(0.1, -0.2) ≈ k(0.1, -0.2)
    end
end


text:
using LJsimulation
using Test

@testset "LJsimulation.jl" begin

@testset "LJ potential energy" begin

       data = Data()
       p = initial_point(data)

       LJsimulation.utotal(p,data)≃ -7472.1648

end

end


text:
using Test
using DeepCorrections
using Random
using POMDPs
using POMDPModels
using POMDPSimulators
using Flux
using DeepQLearning
using DiscreteValueIteration

test_env_path = joinpath(dirname(pathof(DeepQLearning)),"..", "test", "test_env.jl")
include(test_env_path)

function evaluate(mdp, policy, rng, n_ep=100, max_steps=100)
    avg_r = 0.
    sim = RolloutSimulator(rng=rng, max_steps=max_steps)
    for i=1:n_ep
        DeepQLearning.resetstate!(policy)
        avg_r += simulate(sim, mdp, policy)
    end
    return avg_r/=n_ep
end

@testset begin "Dummy Corrections"
    # set random seed for test block
    Random.seed!(2)
    rng = MersenneTwister(2)
    mdp = TestMDP((5,5), 4, 6)
    model = Chain(x->flattenbatch(x), Dense(100, 8, tanh), Dense(8, 4))
    dqn_solver = DeepQLearningSolver(qnetwork = model, max_steps=20000, learning_rate=0.005,
                                    eval_freq=2000,num_ep_eval=100,
                                    log_freq = 1000,
                                    double_q = false, dueling=true, prioritized_replay=false,
                                    rng=rng)
    solver = DeepCorrectionSolver(dqn = dqn_solver)
    corr_pol = solve(solver, mdp)
    r_basic = evaluate(mdp, corr_pol, rng)
    @test r_basic >= 1.0
end

@testset begin "Perfect Qlo"
    # set random seed for test block
    Random.seed!(2)
    rng = MersenneTwister(2)
    # value table
    mdp = SimpleGridWorld()
    vi_pol = solve(ValueIterationSolver(), mdp)
    function vi_values(mdp::SimpleGridWorld, s::AbstractArray)
        s_gw = convert_s(GWPos, s, mdp)
        si = stateindex(mdp, s_gw)
        return vi_pol.qmat[si, :]
    end
    model = Chain(x->flattenbatch(x), Dense(2, 32, relu), Dense(32, n_actions(mdp)))
    dqn_solver = DeepQLearningSolver(qnetwork = model, prioritized_replay=true, max_steps=40_000, learning_rate=0.01,
                                     log_freq=1000, eval_freq = 2000,
                                     eps_fraction = 0.1, eps_end = 0.01,
                                     double_q=true, dueling=true, rng=rng)
    solver = DeepCorrectionSolver(dqn = dqn_solver,
                                  lowfi_values = vi_values,
                                  correction = additive_correction)

    corr_policy = solve(solver, mdp)
    r_gw =  evaluate(mdp, corr_policy, rng)
    @test r_gw >= 0.
end

@testset begin "Use Policy for Lowfi Values"
        # set random seed for test block
    Random.seed!(2)
    rng = MersenneTwister(2)
    # value table
    mdp = SimpleGridWorld()
    vi_pol = solve(ValueIterationSolver(), mdp)
    POMDPs.stateindex(mdp::SimpleGridWorld, s::AbstractArray) = stateindex(mdp, convert(Vector{Int64}, s))
    model = Chain(x->flattenbatch(x), Dense(2, 32, relu), Dense(32, n_actions(mdp)))
    dqn_solver = DeepQLearningSolver(qnetwork = model, prioritized_replay=true, max_steps=40_000, learning_rate=0.01,
                                     log_freq=1000, eval_freq = 2000,
                                     eps_fraction = 0.1, eps_end = 0.01,
                                     double_q=true, dueling=true, rng=rng)
    solver = DeepCorrectionSolver(dqn = dqn_solver,
                                  lowfi_values = vi_pol,
                                  correction = additive_correction)

    corr_policy = solve(solver, mdp)
    r_gw =  evaluate(mdp, corr_policy, rng)
    @test r_gw >= 0.
end