text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:2] <= 1)

                     @variable(m, -47.02611826463841 <= q <= 46.175694332378946)

                     add_NL_constraint(m, :(log(1 + exp(0.14172886209520552 + -0.7326244672203441*log(1 + exp(-0.9862473619768446 + 0.12598046880516867*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.9857820194451663*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3507087497777257*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.16930171271231975*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + 0.6188053648075824*log(1 + exp(-0.8901994655270467 + 0.3517572387180481*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5057680398491988*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15346000401268212*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.000907155550359029*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + 0.748255673773524*log(1 + exp(0.9418689270026719 + 0.23440750676702393*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.9578891219409944*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4332120963929875*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15216088947964046*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.19681615050825796*log(1 + exp(-0.3160427191298667 + -0.1453900085539872*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3370407689400481*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5646332930109117*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4312398718758548*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))))) + log(1 + exp(0.7126847484534728 + 0.5521736820641339*log(1 + exp(-0.9862473619768446 + 0.12598046880516867*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.9857820194451663*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3507087497777257*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.16930171271231975*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.5863621462894022*log(1 + exp(-0.8901994655270467 + 0.3517572387180481*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5057680398491988*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15346000401268212*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.000907155550359029*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.2365722039484086*log(1 + exp(0.9418689270026719 + 0.23440750676702393*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.9578891219409944*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4332120963929875*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15216088947964046*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.47134077688752996*log(1 + exp(-0.3160427191298667 + -0.1453900085539872*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3370407689400481*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5646332930109117*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4312398718758548*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))))) + log(1 + exp(0.3678622626620536 + -0.645924933237755*log(1 + exp(-0.9862473619768446 + 0.12598046880516867*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.9857820194451663*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3507087497777257*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.16930171271231975*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + 0.23980134898526861*log(1 + exp(-0.8901994655270467 + 0.3517572387180481*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5057680398491988*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15346000401268212*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.000907155550359029*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + 0.5641271464877478*log(1 + exp(0.9418689270026719 + 0.23440750676702393*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.9578891219409944*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4332120963929875*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15216088947964046*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.22456183587218126*log(1 + exp(-0.3160427191298667 + -0.1453900085539872*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3370407689400481*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5646332930109117*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4312398718758548*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))))) + log(1 + exp(-0.9861590919257504 + -0.9031060096581198*log(1 + exp(-0.9862473619768446 + 0.12598046880516867*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.9857820194451663*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3507087497777257*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.16930171271231975*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.6492392304855641*log(1 + exp(-0.8901994655270467 + 0.3517572387180481*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5057680398491988*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15346000401268212*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.000907155550359029*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + 0.1540584284169868*log(1 + exp(0.9418689270026719 + 0.23440750676702393*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.9578891219409944*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4332120963929875*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.15216088947964046*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))) + -0.8682585596517867*log(1 + exp(-0.3160427191298667 + -0.1453900085539872*log(1 + exp(-0.32432918385015697 + -0.6977940842525037*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.476420397288412*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.5549201217740469*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.4315951265237059*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.3370407689400481*log(1 + exp(0.2633379906083797 + 0.3509284626355762*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.5977055959243147*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.642253969451728*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.10048605306401859*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + 0.5646332930109117*log(1 + exp(-0.34549165187553976 + 0.5367448324029058*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.7077894233575681*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + -0.4911236080946888*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + -0.5306931393323575*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))) + -0.4312398718758548*log(1 + exp(0.538919292477293 + 0.8088100362525972*log(1 + exp(-0.9860262540836815 + 0.8911186935536937*$(x[1]) + 0.64267061852934*$(x[2]))) + -0.4318478690072691*log(1 + exp(-0.12607269491856643 + -0.6901389567897818*$(x[1]) + -0.5431979251870089*$(x[2]))) + 0.8077402924106214*log(1 + exp(0.4882924486844056 + 0.5602141072539029*$(x[1]) + 0.7222626702909976*$(x[2]))) + 0.12603114956525063*log(1 + exp(-0.9654866490330036 + -0.27186143772128135*$(x[1]) + -0.864410033347212*$(x[2]))))))))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m


text:
module Example2018

export Point
struct Point{T}
    x::T
    y::T
end

function Base. +(p::Point, q::Point)
    Point(p.x + q.x, p.y + q.y)
end

export MPoint
mutable struct MPoint{T}
    x::T
    y::T
end

###############################################################################

#### defined polynomial type
export Polynomial
struct Polynomial{T}
    coeffs::Vector{T}
end

# edit base function for type polynomial

function Base. +(p::Polynomial, q::Polynomial)
    l = max(length(p.coeffs), length(q.coeffs))
    rcoeffs = zeros(eltype(p.coeffs),l)
    for (i,c) in enumerate(p.coeffs)
        rcoeffs[i] += c
    end
    for (i,c) in enumerate(q.coeffs)
        rcoeffs[i] += c
    end
    Polynomial(rcoeffs)
end

function Base. *(a, p::Polynomial)
    Polynomial(map(x->a*x, p.coeffs))
end
Base. *(p::Polynomial, a) = a*p

function Base. -(p::Polynomial)
    (-1) * p
end

function Base. -(p::Polynomial,q::Polynomial)
    p + (-q)
end

function Base. ==(p::Polynomial,q::Polynomial)
    d = p - q
    #all(c -> c==0, d.coeffs)
    # or
    all(d.coeffs .== 0)
end

##### function on Polynomial
export evaluate
function evaluate(p::Polynomial, x)
    sum(c * x^(i-1) for (i,c) in enumerate(p.coeffs))
end

export deriv
function deriv(p::Polynomial)
    Polynomial([(i-1) * c for (i,c) in enumerate(p.coeffs)][2:end])
end

#### play with package

# ApproxFun package
# ForwardDiff package
# ReverseDiff

# Rewrite.jl julia
# JuliaGraphs : not working with 1.0 for now

# BenchmarkTools
# check profile stuff for performance

# PyCall call python package into Julia
# Interact: have interacting stuff in Julia

# see package for
# how to store the data ? : CSV : nice but not super efficient
#                            HDF5 file, see package

# FunctionalCollections package
#
end

ext: jl


text:
using MPI, Test
include("../testhelpers.jl")

@testset "Diagnostics" begin
  tests = [
    (2,"sin_test.jl")
   ]

  runmpi(tests, @__FILE__)
end


text:
# The following function is taken from the standard library of Julia
# (base/download.jl, commit: 05574672881f341104a30519ef9d7534540e175e).
# License is MIT: https://julialang.org/license
function find_curl()
    if Sys.isapple() && Sys.isexecutable("/usr/bin/curl")
        "/usr/bin/curl"
    elseif Sys.iswindows() && Sys.isexecutable(joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe"))
        joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe")
    elseif Sys.which("curl") !== nothing
        "curl"
    else
        nothing
    end
end


text:
mutable struct P_misfit
	x::TD # modelled data
	y::TD # observed data
	w::TD # weights
	dJx::TD # gradient w.r.t. x
	ynorm::Float64 # normalize functional with energy of y
end

function P_misfit(x, y; w=nothing)

	if(w===nothing)
		w=Data.TD_ones(y.fields,y.tgrid,y.acqgeom)
	end
	!(isapprox(w,y)) && error("weights have to be similar to y")
	!(isapprox(x,y)) && error("cannot measure LS misfit b/w dissimilar data")

	!(isequal(x.acqgeom, y.acqgeom)) && error("observed and modelled data should have same acqgeom")
	!(isequal(x.fields, y.fields)) && error("observed and modelled data should have same fields")

	dJx=TD_zeros(x)

	ynorm = dot(y, y)
	(ynorm == 0.0) && error("y cannot be zero")

	pa=P_misfit(x,y,w,dJx,ynorm)

	return pa
end

function func_grad!(pa::P_misfit, grad=nothing)

	# some aliases

	y=pa.y
	x=pa.x
	tgrid = x.tgrid;
	acq = x.acqgeom;
	fields = x.fields;
	nss = acq.nss;

	J = 0.0;
	for ifield=1:length(fields), iss=1:acq.nss
		xr=x.d[iss,ifield]
		yr=y.d[iss,ifield]
		wr=pa.w.d[iss,ifield]

		if(grad===nothing)
			JJ=Misfits.error_squared_euclidean!(nothing,xr,yr,wr,norm_flag=false)
		elseif(grad==:dJx)
			dJxr=pa.dJx.d[iss,ifield]
			JJ=Misfits.error_squared_euclidean!(dJxr,xr,yr,wr,norm_flag=false)
		else
			error("invalid grad")
		end
		J += JJ
	end
	return J
end

#=

"""
Calculate the distance between the observed data `y` and the calculated data `x`.
The time grid of the observed data can be different from that of the modelled data.
The acqistion geometry of both the data sets should be the same.

If `J` is the distance, the gradient of the misfit w.r.t to the calculated data is returned as `dJx`
* `w` used for data preconditioning
* `coupling` source and receiver coupling functions
"""
mutable struct P_misfit_ssf
	x::TD # modelled data
	y::TD # observed data
	pa::P_misfit
	dJx::TD # gradient w.r.t. x
	xr::TD # modelled data after resampling
	xrc::TD # modelled data after resampling and convolution with source coupling
	dJxr::TD # gradient w.r.t. xr
	dJxrc::TD # gradient w.r.t. xr
	dJx::TD # gradient w.r.t. x
	dJssf::Matrix{Vector{Float64}} # gradient w.r.t source filters
	ynorm::Float64 # normalize functional with energy of y
	coup::Coupling.TD
	paconvssf::Vector{FBD.P_conv{Float64,2,2,1}} # convolutional model for source filters
	paconvrf::FBD.P_conv{Float64,1} # convolutional model for receiver filters
	pacse::Matrix{FBD.P_misfit_xcorr}
	func::Matrix{Function} # function to compute misfit for every ss and fields
	painterp::Interpolation.Param{Float64}
	interp_flag # decide if interpolation is necessary or not
end

function P_misfit_ssf(x, y; w=nothing, coup=nothing, func_attrib=:cls)

	if(coup===nothing)
		 coup=Coupling.TD_delta(y.tgrid,[0.1,0.1],[0.0, 0.0], [:P], y.acqgeom)
	end

	paconvssf=[FBD.P_conv(ssize=[coup.tgridssf.nx],
			dsize=[length(y.tgrid),y.acqgeom.nr[iss]],
			gsize=[length(y.tgrid),y.acqgeom.nr[iss]],
		      slags=coup.ssflags,
		      dlags=[length(y.tgrid)-1, 0],
		      glags=[length(y.tgrid)-1, 0]) for iss in 1:y.acqgeom.nss]

	dJssf=deepcopy(coup.ssf)

	pacls=P_misfit(TD_zeros(y), y; w=w)

	!(isequal(x.acqgeom, y.acqgeom)) && error("observed and modelled data should have same acqgeom")
	!(isequal(x.fields, y.fields)) && error("observed and modelled data should have same fields")

	xr=TD_zeros(y)
	xrc=TD_zeros(y)
	dJxr=TD_zeros(y)
	dJxrc=TD_zeros(y)
	dJx=TD_zeros(x)

	ynorm = dot(y, y)
	(ynorm == 0.0) && error("y cannot be zero")

	dJxc=zeros(length(y.tgrid))

	if(func_attrib==:cls)
		pacse=[FBD.P_misfit_xcorr(1, 1,y=zeros(1,1)) for i in 1:2, j=1:2] # dummy
		func=[(dJx,x)->Misfits.error_squared_euclidean!(dJx,x,y.d[iss,ifield],w.d[iss,ifield]) for iss in 1:y.acqgeom.nss, ifield=1:length(y.fields)]
	elseif(func_attrib==:xcorrcls)
		pacse=[FBD.P_misfit_xcorr(length(y.tgrid), y.acqgeom.nr[iss],y=y.d[iss,ifield]) for iss in 1:y.acqgeom.nss, ifield=1:length(y.fields)]
		func=[(dJx,x)->FBD.func_grad!(dJx,x,pacse[iss,ifield]) for iss in 1:y.acqgeom.nss, ifield=1:length(y.fields)]
	end

	pa=P_misfit(x,y,w,xr,xrc,dJxr,dJxrc,
		    dJx,dJssf,ynorm,coup,paconvssf, paconvrf, pacse, func, painterp, interp_flag)

	return pa
end

function func_grad!(pa::P_misfit_ssf, grad=nothing)

	tgrid = pa.x.tgrid;
	acq = pa.x.acqgeom;
	fields = pa.x.fields;
	nss = acq.nss;

	if(pa.interp_flag)
		# resample xr <-- x
		interp_spray!(pa.x, pa.xr, :interp, pa=pa.painterp)
		println("ffffff, HELEL")
	else
		copyto!(pa.xr,pa.x)
	end

	xr=pa.xr
	xrc=pa.xrc
	y=pa.y

	J = 0.0;
	for ifield=1:length(fields), iss=1:acq.nss
		xrr=xr.d[iss,ifield]
		xrcc=xrc.d[iss,ifield]
		wav=pa.coup.ssf[iss,ifield]

		nt=size(xrr,1)
		nr=size(xrr,2)

		paconv=pa.paconvssf[iss]
		# xrc <- xr apply source filter to xr
		FBD.mod!(paconv, :d, g=xrr, s=wav, d=xrcc)

		if(grad===nothing)
			JJ=pa.func[iss,ifield](nothing,  xrcc)
		elseif((grad==:dJx) || (grad==:dJssf))
			dJxrcc=pa.dJxrc.d[iss,ifield]
			JJ=pa.func[iss,ifield](dJxrcc,  xrcc)
		else
			error("invalid grad")
		end

		# dJxr <- dJxrc  apply adjoint of source filter to dJxc
		if(grad==:dJx)
			dJxrr=pa.dJxr.d[iss,ifield]
			dJxrcc=pa.dJxrc.d[iss,ifield]
			FBD.mod!(paconv, :g, g=dJxrr, s=wav, d=dJxrcc)
		end

		# dJssf <- dJxrc
		if(grad==:dJssf)
			dJwav=pa.dJssf[iss,ifield]
			FBD.mod!(paconv, :s, g=xrr, s=dJwav, d=dJxrcc)
		end
		J += JJ
	end

	if(pa.interp_flag)
		# spray dJx <-- dJxr
		interp_spray!(pa.dJx, pa.dJxr, :spray, pa=pa.painterp)
		println("ffffff, HELEL")
	else
		copyto!(pa.dJx,pa.dJxr)
	end

	(J == 0.0) && warn("misfit computed is zero")

	return J

end

=#


text:
"""
    bresenhams_line_algorithm(maxx, maxy, x1, y1, x2, y2)

maxx, maxy: Integer max values

Assuming x1 and x2 are coordinates > 0.5, return integer coordinates between the two coordinates.

x1 to y2 may be floats, but this is intended to be 'floating point indexes' in a matrix.

Based on
https://stackoverflow.com/questions/40273880/draw-a-line-between-two-pixels-on-a-grayscale-image-in-julia

Adapted for float input arguments and limit checks.
"""
function bresenhams_line_algorithm(maxx::T, maxy::T, x1, y1, x2, y2) where {T<:Int}
    @assert round(Int, x1) <= maxx
    @assert round(Int, y1) <= maxy
    @assert round(Int, x1) >= 1
    @assert round(Int, y1) >= 1
    @assert round(Int, x2) <= maxx
    @assert round(Int, y2) <= maxy
    @assert round(Int, x2) >= 1
    @assert round(Int, y2) >= 1

    # Calculate distances
    dx = x2 - x1
    dy = y2 - y1

    # Determine how steep the line is
    is_steep = abs(dy) > abs(dx)

    # Rotate line
    if is_steep
        x1, y1 = y1, x1
        x2, y2 = y2, x2
        maxy, maxx = maxx, maxy
    end

    # Swap start and end points if necessary and store swap state
    swapped = if x1 > x2
        x1, x2 = x2, x1
        y1, y2 = y2, y1
        true
    else
        false
    end

    # Recalculate differentials
    dx = x2 - x1
    dy = y2 - y1

    # Calculate error
    error = round(Int, dx / 2.0)

    ystep = if y1 < y2
        1
    else
        -1
    end

    vy = Vector{Int}()

    # Iterate while generating points between start and end
    y = round(Int, y1)
    xiter = round(Int, x1):(round(Int, x2))
    for x in xiter
        push!(vy, y)
        error -= abs(dy)
        if error < 0
            y += ystep
            # edge case, a subpixel line might cover two pixels due to rounding.
            # However, if that happens to be on the edge, don't bleed over and don't cause an
            # error throw.
            if y > maxy || y < 1
                y -= ystep
                error -= dx
            end
            error += dx
        end
    end
    # Reverse the list if the coordinates were swapped
    if swapped
        if is_steep
            zip(reverse(vy), reverse(xiter))
        else
            zip(reverse(xiter), reverse(vy))
        end
    else
        if is_steep
            zip(vy, xiter)
        else
            zip(xiter, vy)
        end
    end
end

"""
    crossing_line_algorithm(maxx, maxy, cx, cy)

maxx, maxy: Integer max values

Return indices for pixels in a 10x10 to 11x11 cross centered at cx, cy

cx, cy may be floats, but this is intended to be 'floating point indexes' in a matrix.
"""

function crossing_line_algorithm(maxx::T, maxy::T, cx, cy) where T<:Int
    indices = Set{Tuple{Int64, Int64}}()
    d = 5
    xb = clamp(cx - d, 1, maxx)
    xt = clamp(cx + d, 1, maxx)
    yb = clamp(cy - d, 1, maxy)
    yt = clamp(cy + d, 1, maxy)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xt, yb, xb, yt)
    push!(indices, lineindices...)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xb, yb, xt, yt)
    push!(indices, lineindices...)
    indices
end

"""
    box_line_algorithm(maxx, maxy, cx, cy)

maxx, maxy: Integer max values

Return indices for pixels in a 10x10 to 11x11 cross centered at cx, cy

cx, cy may be floats, but this is intended to be 'floating point indexes' in a matrix.
"""

function box_line_algorithm(maxx::T, maxy::T, cx, cy) where T<:Int
    indices = Set{Tuple{Int64, Int64}}()
    d = 5
    xb = clamp(cx - d, 1, maxx)
    xt = clamp(cx + d, 1, maxx)
    yb = clamp(cy - d, 1, maxy)
    yt = clamp(cy + d, 1, maxy)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xt, yb, xb, yb)
    push!(indices, lineindices...)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xt, yt, xb, yt)
    push!(indices, lineindices...)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xt, yb, xt, yt)
    push!(indices, lineindices...)
    lineindices = bresenhams_line_algorithm( maxx, maxy, xb, yb, xb, yt)
    push!(indices, lineindices...)
    indices
end

"""
    circle_algorithm(maxx, maxy, cx, cy)

maxx, maxy: Integer max values

Return indices for pixels in a 10 pixel diameter circle centered at cx, cy

cx, cy may be floats, but this is intended to be 'floating point indexes' in a matrix.
"""
function circle_algorithm(maxx::T, maxy::T, cx, cy) where T<:Int
    indices = Set{Tuple{Int64, Int64}}()
    d = 10
    pts = 2 * round(Int, π * d)
    for ϕ in range(0.0, 2π, length = pts)
        x = clamp(round(Int, cx + d * cos(ϕ) / 2), 1, maxx)
        y = clamp(round(Int, cy + d * cos(ϕ) / 2), 1, maxy)
        push!(indices, (x, y))
    end
    indices
end


text:
using Documenter
using BSplines

DocMeta.setdocmeta!(BSplines, :DocTestSetup, :(using BSplines))

makedocs(
         sitename = "BSplines.jl",
         format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
         modules = [BSplines],
         pages = [
                  "Home" => "index.md"
                  "Manual" => [
                               "The `BSplineBasis` type" => "basis.md"
                               "The `Spline` type" => "spline.md"
                               "Higher-level functions" => "functions.md"
                               "Plotting" => "plotting.md"
                              ]
                  "API documentation" => "api.md"
                 ]
        )

deploydocs(repo = "github.com/sostock/BSplines.jl.git")


text:
"""
# script run

- Julia version: 1.4
- Author: niallcullinane
- Date: 2020-08-20

Runs set of tests and benchmarks.
Commits and pushes results to Git.
"""

using DrWatson
@quickactivate "MEngProject"
using MEngProject,
    CUDA,
    DifferentialEquations,
    PyPlot,
    NNlib,
    ImageFiltering,
    Images,
    ImageIO,
    MEngProject.LaminartKernels,
    MEngProject.LaminartInitFunc,
    MEngProject.Utils,
    BenchmarkTools,
    Test

using OrdinaryDiffEq,
    ParameterizedFunctions, LSODA, Sundials, DiffEqDevTools, Noise

# CUDA.allowscalar(false)

try
    include("test_illusions.jl")
catch err
    print(err)
end
CUDA.reclaim()
try
    include("test_noise.jl")
catch err
    print(err)
end
CUDA.reclaim()
try
    include("test_parameterVar.jl")
catch err
    print(err)
end
CUDA.reclaim()
try
    include("test_kernelsVar.jl")
catch err
    print(err)
end
CUDA.reclaim()
# try include("test_eqAtEquil.jl")catch err; print(err) end
CUDA.reclaim()
#
#
# # try include("bench_solver.jl")catch err; print(err) end
try
    include("bench_imp.jl")
catch err
    print(err)
end
CUDA.reclaim()
# try include("bench_eq.jl")catch err; print(err) end
try
    include("bench_kernels_dim.jl")
catch err
    print(err)
end
CUDA.reclaim()
try
    include("bench_dim.jl")
catch err
    print(err)
end
CUDA.reclaim()
#
# run(`git pull`)
# run(`git add plots/*`)
# run(`git commit -m "test"`)
# run(`git push`)

# include("scripts/test_illusions.jl")
# include("scripts/test_noise.jl")
# include("scripts/test_parameterVar.jl")
# include("scripts/test_kernelsVar.jl")
# # include("scripts/test_eqAtEquil.jl")
# #
# #
# # include("scripts/bench_solver.jl")
# include("scripts/bench_imp.jl")
# # include("scripts/bench_eq.jl")
# include("scripts/bench_kernels_dim.jl")
# include("scripts/bench_dim.jl")


text:
module TestOpenml

using Test
using HTTP
using MLJBase
import Tables.istable

response_test = OpenML.load_Dataset_Description(61)
ntp_test = OpenML.load(61)
@test istable(ntp_test)
dqlist_test = OpenML.load_Data_Qualities_List()
data_features_test = OpenML.load_Data_Features(61)
data_qualities_test = OpenML.load_Data_Qualities(61)
limit = 5
offset = 8
filters_test = OpenML.load_List_And_Filter("limit/$limit/offset/$offset")

@testset "HTTP connection" begin
    @test typeof(response_test) <: Dict
    @test response_test["data_set_description"]["name"] == "iris"
    @test response_test["data_set_description"]["format"] == "ARFF"
end

@testset "ARFF file conversion to NamedTuples" begin
    @test isempty(ntp_test) == false
    @test length(ntp_test) == 150
    @test length(ntp_test[1]) == 5
end

@testset "data api functions" begin
    @test typeof(dqlist_test["data_qualities_list"]) <: Dict

    @test typeof(data_features_test) <: Dict
    @test length(data_features_test["data_features"]["feature"]) == 5
    @test data_features_test["data_features"]["feature"][1]["name"] == "sepallength"

    @test typeof(data_qualities_test) <: Dict

    @test length(filters_test["data"]["dataset"]) == limit
    @test length(filters_test["data"]["dataset"][1]) == offset
end

end
true


text:
using .Makie

include("Makie/trankplot.jl")


text:
# This file is auto-generated by AWSMetadata.jl
using AWS
using AWS.AWSServices: chime_sdk_identity
using AWS.Compat
using AWS.UUIDs

"""
    create_app_instance(client_request_token, name)
    create_app_instance(client_request_token, name, params::Dict{String,<:Any})

Creates an Amazon Chime SDK messaging AppInstance under an AWS account. Only SDK messaging
customers use this API. CreateAppInstance supports idempotency behavior as described in the
AWS API Standard. identity

# Arguments
- `client_request_token`: The ClientRequestToken of the AppInstance.
- `name`: The name of the AppInstance.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"Metadata"`: The metadata of the AppInstance. Limited to a 1KB string in UTF-8.
- `"Tags"`: Tags assigned to the AppInstanceUser.
"""
function create_app_instance(
    ClientRequestToken, Name; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "POST",
        "/app-instances",
        Dict{String,Any}("ClientRequestToken" => ClientRequestToken, "Name" => Name);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function create_app_instance(
    ClientRequestToken,
    Name,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "POST",
        "/app-instances",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "ClientRequestToken" => ClientRequestToken, "Name" => Name
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    create_app_instance_admin(app_instance_admin_arn, app_instance_arn)
    create_app_instance_admin(app_instance_admin_arn, app_instance_arn, params::Dict{String,<:Any})

Promotes an AppInstanceUser to an AppInstanceAdmin. The promoted user can perform the
following actions.     ChannelModerator actions across all channels in the AppInstance.
DeleteChannelMessage actions.   Only an AppInstanceUser can be promoted to an
AppInstanceAdmin role.

# Arguments
- `app_instance_admin_arn`: The ARN of the administrator of the current AppInstance.
- `app_instance_arn`: The ARN of the AppInstance.

"""
function create_app_instance_admin(
    AppInstanceAdminArn, appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "POST",
        "/app-instances/$(appInstanceArn)/admins",
        Dict{String,Any}("AppInstanceAdminArn" => AppInstanceAdminArn);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function create_app_instance_admin(
    AppInstanceAdminArn,
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "POST",
        "/app-instances/$(appInstanceArn)/admins",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}("AppInstanceAdminArn" => AppInstanceAdminArn),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    create_app_instance_user(app_instance_arn, app_instance_user_id, client_request_token, name)
    create_app_instance_user(app_instance_arn, app_instance_user_id, client_request_token, name, params::Dict{String,<:Any})

Creates a user under an Amazon Chime AppInstance. The request consists of a unique
appInstanceUserId and Name for that user.

# Arguments
- `app_instance_arn`: The ARN of the AppInstance request.
- `app_instance_user_id`: The user ID of the AppInstance.
- `client_request_token`: The token assigned to the user requesting an AppInstance.
- `name`: The user's name.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"Metadata"`: The request's metadata. Limited to a 1KB string in UTF-8.
- `"Tags"`: Tags assigned to the AppInstanceUser.
"""
function create_app_instance_user(
    AppInstanceArn,
    AppInstanceUserId,
    ClientRequestToken,
    Name;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "POST",
        "/app-instance-users",
        Dict{String,Any}(
            "AppInstanceArn" => AppInstanceArn,
            "AppInstanceUserId" => AppInstanceUserId,
            "ClientRequestToken" => ClientRequestToken,
            "Name" => Name,
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function create_app_instance_user(
    AppInstanceArn,
    AppInstanceUserId,
    ClientRequestToken,
    Name,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "POST",
        "/app-instance-users",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "AppInstanceArn" => AppInstanceArn,
                    "AppInstanceUserId" => AppInstanceUserId,
                    "ClientRequestToken" => ClientRequestToken,
                    "Name" => Name,
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_app_instance(app_instance_arn)
    delete_app_instance(app_instance_arn, params::Dict{String,<:Any})

Deletes an AppInstance and all associated data asynchronously.

# Arguments
- `app_instance_arn`: The ARN of the AppInstance.

"""
function delete_app_instance(
    appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instances/$(appInstanceArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_app_instance(
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instances/$(appInstanceArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_app_instance_admin(app_instance_admin_arn, app_instance_arn)
    delete_app_instance_admin(app_instance_admin_arn, app_instance_arn, params::Dict{String,<:Any})

Demotes an AppInstanceAdmin to an AppInstanceUser. This action does not delete the user.

# Arguments
- `app_instance_admin_arn`: The ARN of the AppInstance's administrator.
- `app_instance_arn`: The ARN of the AppInstance.

"""
function delete_app_instance_admin(
    appInstanceAdminArn, appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instances/$(appInstanceArn)/admins/$(appInstanceAdminArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_app_instance_admin(
    appInstanceAdminArn,
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instances/$(appInstanceArn)/admins/$(appInstanceAdminArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    delete_app_instance_user(app_instance_user_arn)
    delete_app_instance_user(app_instance_user_arn, params::Dict{String,<:Any})

Deletes an AppInstanceUser.

# Arguments
- `app_instance_user_arn`: The ARN of the user request being deleted.

"""
function delete_app_instance_user(
    appInstanceUserArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instance-users/$(appInstanceUserArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function delete_app_instance_user(
    appInstanceUserArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "DELETE",
        "/app-instance-users/$(appInstanceUserArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_app_instance(app_instance_arn)
    describe_app_instance(app_instance_arn, params::Dict{String,<:Any})

Returns the full details of an AppInstance.

# Arguments
- `app_instance_arn`: The ARN of the AppInstance.

"""
function describe_app_instance(
    appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_app_instance(
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_app_instance_admin(app_instance_admin_arn, app_instance_arn)
    describe_app_instance_admin(app_instance_admin_arn, app_instance_arn, params::Dict{String,<:Any})

Returns the full details of an AppInstanceAdmin.

# Arguments
- `app_instance_admin_arn`: The ARN of the AppInstanceAdmin.
- `app_instance_arn`: The ARN of the AppInstance.

"""
function describe_app_instance_admin(
    appInstanceAdminArn, appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/admins/$(appInstanceAdminArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_app_instance_admin(
    appInstanceAdminArn,
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/admins/$(appInstanceAdminArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    describe_app_instance_user(app_instance_user_arn)
    describe_app_instance_user(app_instance_user_arn, params::Dict{String,<:Any})

Returns the full details of an AppInstanceUser.

# Arguments
- `app_instance_user_arn`: The ARN of the AppInstanceUser.

"""
function describe_app_instance_user(
    appInstanceUserArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instance-users/$(appInstanceUserArn)";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function describe_app_instance_user(
    appInstanceUserArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instance-users/$(appInstanceUserArn)",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    get_app_instance_retention_settings(app_instance_arn)
    get_app_instance_retention_settings(app_instance_arn, params::Dict{String,<:Any})

Gets the retention settings for an AppInstance.

# Arguments
- `app_instance_arn`: The ARN of the AppInstance.

"""
function get_app_instance_retention_settings(
    appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/retention-settings";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function get_app_instance_retention_settings(
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/retention-settings",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_app_instance_admins(app_instance_arn)
    list_app_instance_admins(app_instance_arn, params::Dict{String,<:Any})

Returns a list of the administrators in the AppInstance.

# Arguments
- `app_instance_arn`: The ARN of the AppInstance.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"max-results"`: The maximum number of administrators that you want to return.
- `"next-token"`: The token returned from previous API requests until the number of
  administrators is reached.
"""
function list_app_instance_admins(
    appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/admins";
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_app_instance_admins(
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instances/$(appInstanceArn)/admins",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_app_instance_users(app-instance-arn)
    list_app_instance_users(app-instance-arn, params::Dict{String,<:Any})

List all AppInstanceUsers created under a single AppInstance.

# Arguments
- `app-instance-arn`: The ARN of the AppInstance.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"max-results"`: The maximum number of requests that you want returned.
- `"next-token"`: The token passed by previous API calls until all requested users are
  returned.
"""
function list_app_instance_users(
    app_instance_arn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instance-users",
        Dict{String,Any}("app-instance-arn" => app_instance_arn);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function list_app_instance_users(
    app_instance_arn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "GET",
        "/app-instance-users",
        Dict{String,Any}(
            mergewith(
                _merge, Dict{String,Any}("app-instance-arn" => app_instance_arn), params
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    list_app_instances()
    list_app_instances(params::Dict{String,<:Any})

Lists all Amazon Chime AppInstances created under a single AWS account.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"max-results"`: The maximum number of AppInstances that you want to return.
- `"next-token"`: The token passed by previous API requests until you reach the maximum
  number of AppInstances.
"""
function list_app_instances(; aws_config::AbstractAWSConfig=global_aws_config())
    return chime_sdk_identity(
        "GET", "/app-instances"; aws_config=aws_config, feature_set=SERVICE_FEATURE_SET
    )
end
function list_app_instances(
    params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "GET",
        "/app-instances",
        params;
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    put_app_instance_retention_settings(app_instance_retention_settings, app_instance_arn)
    put_app_instance_retention_settings(app_instance_retention_settings, app_instance_arn, params::Dict{String,<:Any})

Sets the amount of time in days that a given AppInstance retains data.

# Arguments
- `app_instance_retention_settings`: The time in days to retain data. Data type: number.
- `app_instance_arn`: The ARN of the AppInstance.

"""
function put_app_instance_retention_settings(
    AppInstanceRetentionSettings,
    appInstanceArn;
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "PUT",
        "/app-instances/$(appInstanceArn)/retention-settings",
        Dict{String,Any}("AppInstanceRetentionSettings" => AppInstanceRetentionSettings);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function put_app_instance_retention_settings(
    AppInstanceRetentionSettings,
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "PUT",
        "/app-instances/$(appInstanceArn)/retention-settings",
        Dict{String,Any}(
            mergewith(
                _merge,
                Dict{String,Any}(
                    "AppInstanceRetentionSettings" => AppInstanceRetentionSettings
                ),
                params,
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    update_app_instance(metadata, name, app_instance_arn)
    update_app_instance(metadata, name, app_instance_arn, params::Dict{String,<:Any})

Updates AppInstance metadata.

# Arguments
- `metadata`: The metadata that you want to change.
- `name`: The name that you want to change.
- `app_instance_arn`: The ARN of the AppInstance.

"""
function update_app_instance(
    Metadata, Name, appInstanceArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "PUT",
        "/app-instances/$(appInstanceArn)",
        Dict{String,Any}("Metadata" => Metadata, "Name" => Name);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function update_app_instance(
    Metadata,
    Name,
    appInstanceArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "PUT",
        "/app-instances/$(appInstanceArn)",
        Dict{String,Any}(
            mergewith(
                _merge, Dict{String,Any}("Metadata" => Metadata, "Name" => Name), params
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end

"""
    update_app_instance_user(metadata, name, app_instance_user_arn)
    update_app_instance_user(metadata, name, app_instance_user_arn, params::Dict{String,<:Any})

Updates the details of an AppInstanceUser. You can update names and metadata.

# Arguments
- `metadata`: The metadata of the AppInstanceUser.
- `name`: The name of the AppInstanceUser.
- `app_instance_user_arn`: The ARN of the AppInstanceUser.

"""
function update_app_instance_user(
    Metadata, Name, appInstanceUserArn; aws_config::AbstractAWSConfig=global_aws_config()
)
    return chime_sdk_identity(
        "PUT",
        "/app-instance-users/$(appInstanceUserArn)",
        Dict{String,Any}("Metadata" => Metadata, "Name" => Name);
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end
function update_app_instance_user(
    Metadata,
    Name,
    appInstanceUserArn,
    params::AbstractDict{String};
    aws_config::AbstractAWSConfig=global_aws_config(),
)
    return chime_sdk_identity(
        "PUT",
        "/app-instance-users/$(appInstanceUserArn)",
        Dict{String,Any}(
            mergewith(
                _merge, Dict{String,Any}("Metadata" => Metadata, "Name" => Name), params
            ),
        );
        aws_config=aws_config,
        feature_set=SERVICE_FEATURE_SET,
    )
end


text:
function PlotStems(label_id, values::AbstractArray{T}, count::Integer, y_ref::Real = 0., xscale::Real = 1., x0::Real = 0., offset::Integer = 0, stride::Integer = sizeof(T)) where {T<:ImPlotData}
    ImPlot_PlotStems(label_id, values, count, y_ref, xscale, x0, offset, stride)
end

function PlotStems(label_id, x::AbstractArray{T}, y::AbstractArray{T}, count::Integer, y_ref::Integer = 0, offset::Integer = 0, stride::Integer = sizeof(T)) where {T>:ImPlotData}
    ImPlot_PlotStems(label_id, x, y, count, y_ref, offset, stride)
end

function PlotStems(label_id, values::AbstractArray{T}, count::Integer, y_ref::Real = 0., xscale::Real = 1., x0::Real = 0., offset::Integer = 0, stride::Integer = sizeof(Float64)) where {T<:Real}
    ImPlot_PlotStems(label_id, Float64.(values), count, y_ref, xscale, x0, offset, stride)
end

function PlotStems(label_id, x::AbstractArray{T}, y::AbstractArray{T}, count::Integer, y_ref::Integer = 0, offset::Integer = 0, stride::Integer = sizeof(Float64)) where {T<:Real}
    ImPlot_PlotStems(label_id, Float64.(x), Float64.(y), count, y_ref, offset, stride)
end

function PlotStems(values::AbstractArray{T}; count::Integer = length(values), label_id::String = "",
                   y_ref = 0.0, xscale = 1.0, x0 = 0.0, offset::Integer = 0,
                   stride::Integer = 1) where {T <: ImPlotData}

    ImPlot_PlotStems(label_id, values, count, y_ref, xscale, x0, offset, stride * sizeof(T))
end

function PlotStems(values::AbstractArray{T}; count::Integer = length(values), label_id::String = "",
                   y_ref = 0.0, xscale = 1.0, x0 = 0.0, offset::Integer = 0,
                   stride::Integer = 1) where {T <: Real}

    ImPlot_PlotStems(label_id, Float64.(values), count, y_ref, xscale, x0, offset, stride * sizeof(Float64))
end

function PlotStems(x::AbstractArray{T}, y::AbstractArray{T};
                   count::Integer = min(length(x), length(y)), label_id::String = "",
                   y_ref = 0.0, offset::Integer = 0, stride::Integer = 1) where {T<:ImPlotData}

    ImPlot_PlotStems(label_id, x, y, count, y_ref, offset, stride * sizeof(T))
end

function PlotStems(x::AbstractArray{T}, y::AbstractArray{T}; count::Integer = min(length(x), length(y)),
                   label_id::String = "", y_ref = 0.0, offset::Integer = 0, stride::Integer = 1) where {T<:Real}

    ImPlot_PlotStems(label_id, Float64.(x), Float64.(y), count, y_ref, offset, stride * sizeof(Float64))
end

PlotStems(x::AbstractArray{T1}, y::AbstractArray{T2}; kwargs...) where {T1<:Real,T2<:Real} = PlotBars(promote(x, y)...; kwargs...)


text:
# This file includes channel objects.

export AWGNChannel

"""
    $TYPEDEF

Additive white Gaussian noise channel.

!!! note If `tsample` and `tsymbol` are `NaN`, then the channel operates in the vector channel mode. Otherwise, the
    channel operates in waveform channel mode.

# Fields

    $TYPEDFIELDS
"""
mutable struct AWGNChannel
    "Value of the noise mode(may be `SNR`, `EsNo`, `EbNo` in dB"
    esno::Float64
    "Sampling period of the channel"
    tsample::Float64
    "Symbol duration if channel operates in waveform channel mode"
    tsymbol::Float64
end
AWGNChannel(esno=1) = AWGNChannel(esno, NaN, NaN)

iswaveform(channel::AWGNChannel) = channel.tsample !== NaN && channel.tsymbol !== NaN

(channel::AWGNChannel)(tx) = iswaveform(channel) ? wavecorrupt(channel, tx) : veccorrupt(channel, tx)

function veccorrupt(channel::AWGNChannel, tx)
    # `tx` is corrupted with complex additive white Gaussian noise with mean zero and variance `2N0`. The variance of
    # the noise determined by channel esno and signal enerygy per symbol
    K = length(tx)
    N = length(tx[1])
    Es = sum(energy.(tx)) / K
    σ = sqrt(Es / dbtoval(channel.esno))
    n = collect(eachrow(σ * randn(ComplexF64, K, N)))
    tx + n
end

function wavecorrupt(channel::AWGNChannel, tx)
    # `tx` is corrupted with complex additive white Gaussian noise with mean zero and variance `2N0`. The variance of
    # the noise determined by channel esno, signal enerygy per symbol and sampling period of the channel.
    K = length(tx)
    l = length(tx[1])
    ts = channel.tsample
    fs  = 1 / ts
    Es = sum(txi -> energy(txi, ts), tx) / K
    σ = sqrt(Es * fs / dbtoval(channel.esno))
    n = collect(eachrow(σ * randn(ComplexF64, K, l)))
    tx + n
end


text:
module SquareGreedTopologies

export SquareGreedIndex, SquareGreedTopology, SquareGreedIndexes, SquareGreedNeighborhood, manhattan_distance, ring_distance, euclidean_distance

using ...PCG.Types
using ...PCG.Geometry: Point
using ...PCG.Topologies
using ...PCG.Topologies: Topology, TopologyIndex, coordinates

const SquareGreedSize = Int64

struct SquareGreedIndex <: TopologyIndex
    x::SquareGreedSize
    y::SquareGreedSize
end

Base.zero(::Type{SquareGreedIndex}) = SquareGreedIndex(0, 0)
Base.zero(::SquareGreedIndex) = SquareGreedIndex(0, 0)

function Types.neighborsof(i::SquareGreedIndex)
    return [SquareGreedIndex(i.x+1, i.y+0),
            SquareGreedIndex(i.x+1, i.y+1),
            SquareGreedIndex(i.x+0, i.y+1),
            SquareGreedIndex(i.x-1, i.y+1),
            SquareGreedIndex(i.x-1, i.y+0),
            SquareGreedIndex(i.x-1, i.y-1),
            SquareGreedIndex(i.x-0, i.y-1),
            SquareGreedIndex(i.x+1, i.y-1)]
end

const SquareGreedIndexes = Vector{SquareGreedIndex}

# TODO: move somewere or remove
Point(cell::SquareGreedIndex) = Point(cell.x, cell.y)

Base.:+(a::Point, b::SquareGreedIndex) = Point(a.x + b.x,
                                               a.y + b.y)

Base.:+(a::SquareGreedIndex, b::SquareGreedIndex) = SquareGreedIndex(a.x + b.x,
                                                                     a.y + b.y)

struct SquareGreedTopology <: Topology
    width::SquareGreedSize
    height::SquareGreedSize
end

function Topologies.is_valid(topology::SquareGreedTopology, index::SquareGreedIndex)
    return (1 <= index.x <= topology.width &&
            1 <= index.y <= topology.height)
end

Topologies.index_type(::SquareGreedTopology) = SquareGreedIndex

# TODO: check if indexes generated in column-first order
function Topologies.coordinates(topology::SquareGreedTopology)
    return (SquareGreedIndex(x, y) for y=1:topology.height, x=1:topology.width)
end

function manhattan_distance(a::SquareGreedIndex, b::SquareGreedIndex=zero(SquareGreedIndex))
    return abs(a.x-b.x) + abs(a.y-b.y)
end

function ring_distance(a::SquareGreedIndex, b::SquareGreedIndex=zero(SquareGreedIndex))
    return max(abs(a.x-b.x), abs(a.y-b.y))
end

function euclidean_distance(a::SquareGreedIndex, b::SquareGreedIndex=zero(SquareGreedIndex))
    return sqrt((a.x-b.x)^2 + abs(a.y-b.y)^2)
end

end

max_stars_repo_name: Tiendil/pcg-julia

max_issues_repo_name: Tiendil/pcg-julia

max_forks_repo_name: Tiendil/pcg-julia


text:
#!/usr/bin/env julia

module YAMLTests

import YAML
using Compat.Test

const tests = [
    "spec-02-01",
    "spec-02-02",
    "spec-02-03",
    "spec-02-04",
    "spec-02-05",
    "spec-02-06",
    "spec-02-07",
    "spec-02-08",
    "spec-02-09",
    "spec-02-10",
    "spec-02-11",
    "spec-02-12",
    "spec-02-13",
    "spec-02-14",
    "spec-02-15",
    "spec-02-16",
    "spec-02-17",
    "spec-02-18",
    "spec-02-19",
    "spec-02-20",
    "spec-02-21",
    "spec-02-22",
    "spec-02-23",
    "empty_scalar",
    "no_trailing_newline",
    "windows_newlines",
    "escape_sequences",
    "issue15",
    "issue30",
    "issue36",
    "issue39",
    "cartesian",
    "ar1",
    "ar1_cartesian",
    "merge-01"
]

function equivalent(xs::Dict, ys::Dict)
    if Set(collect(keys(xs))) != Set(collect(keys(ys)))
        return false
    end

    for k in keys(xs)
        if !equivalent(xs[k], ys[k])
            return false
        end
    end

    true
end

function equivalent(xs::AbstractArray, ys::AbstractArray)
    if length(xs) != length(ys)
        return false
    end

    for (x, y) in zip(xs, ys)
        if !equivalent(x, y)
            return false
        end
    end

    true
end

function equivalent(x::Float64, y::Float64)
    isnan(x) && isnan(y) ? true : x == y
end

function equivalent(x, y)
    x == y
end

# test custom tags
function construct_type_map(t::Symbol, constructor::YAML.Constructor,
                            node::YAML.Node)
    mapping = YAML.construct_mapping(constructor, node)
    mapping[:tag] = t
    mapping
end

const more_constructors = let
    pairs = [("!Cartesian", :Cartesian),
             ("!AR1", :AR1)]
    Dict{AbstractString,Function}([(t, (c, n) -> construct_type_map(s, c, n))
                           for (t, s) in pairs])
end

const testdir = dirname(@__FILE__)
@testset for test in tests
    data = YAML.load_file(
        joinpath(testdir, string(test, ".data")),
        more_constructors
    )
    expected = evalfile(joinpath(testdir, string(test, ".expected")))
    @test equivalent(data, expected)
end

end  # module


text:
include("util.jl")

lines = getlines("inputs/6.txt")

function maxnum()::Int64
    maxnum = 0
    for line in lines
        for num in split(line, ",")
            maxnum = max(maxnum,parse(Int64,num))
        end
    end
    return maxnum
end

const FULL = maxnum()*4
const HALF = floor(maxnum()*2)

function get_coords(lines)::Dict{Symbol,Tuple{Int64,Int64}}
    retval = Dict()
    for line in 1:length(lines)
        coords = split(lines[line], ",")
        x = parse(Int64,coords[1])+HALF
        y = parse(Int64,coords[2])+HALF
        retval[Symbol(line)] = (x,y)
    end
    return retval
end

function closest(x::Int64, y::Int64, coords::Dict{Symbol,Tuple{Int64,Int64}})::Symbol
    distances::Dict{Symbol,Int64} = Dict()
    for s in keys(coords)
        distance = abs(x-coords[s][1])+abs(y-coords[s][2])
        distances[s] = distance
    end
    shortest = sort(collect(distances), by=x->x[2])
    if shortest[1][2] == shortest[2][2]
        return Symbol(".")
    else
        return shortest[1][1]
    end
end

function get_grid(coords::Dict{Symbol,Tuple{Int64,Int64}})::Array{Symbol,2}
    grid::Array{Symbol,2} = map(x -> Symbol("."), zeros(FULL,FULL))
    for i in 1:FULL
        for j in 1:FULL
            grid[j,i] = closest(i,j,coords)
        end
    end
    return grid
end

function total_distance(x::Int64,y::Int64,coords::Dict{Symbol,Tuple{Int64,Int64}})::Int64
    distances = []
    for p in coords
        d = abs(x-p[2][1])+abs(y-p[2][2])
        push!(distances, d)
    end
    return sum(distances)
end

function part_2_region_size(coords::Dict{Symbol,Tuple{Int64,Int64}})
    grid = zeros(FULL,FULL)
    for i in 1:FULL
        for j in 1:FULL
            td = total_distance(i,j,coords)
            if td < 10000
                grid[i,j] = 1
            end
        end
    end
    return grid
end

function largest_area(grid::Array{Symbol,2})
    is::Set{Symbol} = Set([Symbol(".")])
    is = union(is, Set(grid[1,:]))
    is = union(is, Set(grid[FULL,:]))
    is = union(is, Set(grid[:,1]))
    is = union(is, Set(grid[:,FULL]))
    legal = setdiff(Set(grid),is)
    sizes = []
    for s in legal
        g = map(x -> begin
            if x == s
                1
            else
                0
            end
        end, grid)
        push!(sizes, sum(g))
    end
    return sizes
end

coords = get_coords(lines)
grid = get_grid(coords)
a = largest_area(grid)
maximum(a)
sum(part_2_region_size(coords))


text:
# data splitting
function data_split(d::Dataset, data::Tuple, obsdim, at)
    x, y = data
    return map(partition(d, y, at)) do inds
        return selectdim(x, obsdim, inds), selectdim(y, 1, inds)
    end
end

function data_split(d::Dataset, data::AbstractDataFrame, obsdim, at)
    y = data.targets |> Vector
    return map(partition(d, y, at)) do inds
        return data[inds, :]
    end
end

# data shuffle
function data_shuffle(data, obsdim, flag::Bool; seed = 1234)
    return flag ? data_shuffle(data, obsdim; seed) : data
end

function data_shuffle(data::Tuple, obsdim; seed = 1234)
    Random.seed!(seed)
    x, y = data
    prm = Random.randperm(length(y))
    return selectdim(x, obsdim, prm), selectdim(y, 1, prm)
end

function data_shuffle(data::AbstractDataFrame, obsdim; seed = 1234)
    Random.seed!(seed)
    y = data.targets
    prm = Random.randperm(length(y))
    return data[prm, :]
end

# binarization
data_binarize(data, poslabels, flag::Bool) = flag ? data_binarize(data, poslabels) : data

function data_binarize(data::Tuple, poslabels)
    x, y = data
    return x, data_binarize(y, poslabels)
end

function data_binarize(data::AbstractDataFrame, poslabels)
    y = data.targets
    select!(data, Not(:targets))
    insertcols!(data, 1, :targets => data_binarize(y, poslabels))
    return data
end

data_binarize(y::AbstractVector, poslabels::AbstractString) = y .== poslabels
data_binarize(y::AbstractVector, poslabels::Symbol) = y .== poslabels
data_binarize(y::AbstractVector, poslabels) = in.(y, Ref(poslabels))

function data_binarize_regression(data::Tuple, threshold::Real)
    x, y = data
    return x, y .>= threshold
end

function data_binarize_regression(data::AbstractDataFrame, threshold::Real)
    y = data.targets
    select!(data, Not(:targets))
    insertcols!(data, 1, :targets => y .>= threshold)
    return data
end

max_stars_repo_name: VaclavMacha/DatasetProvider

max_issues_repo_name: VaclavMacha/DatasetProvider

max_forks_repo_name: VaclavMacha/DatasetProvider


text:
# Autogenerated wrapper script for rubberband_jll for i686-linux-gnu-cxx03
export librubberband, rubberband

using FFTW_jll
using libsamplerate_jll
using libsndfile_jll
JLLWrappers.@generate_wrapper_header("rubberband")
JLLWrappers.@declare_library_product(librubberband, "librubberband.so.2.1.2")
JLLWrappers.@declare_executable_product(rubberband)
function __init__()
    JLLWrappers.@generate_init_header(FFTW_jll, libsamplerate_jll, libsndfile_jll)
    JLLWrappers.@init_library_product(
        librubberband,
        "lib/librubberband.so",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_executable_product(
        rubberband,
        "bin/rubberband",
    )

    JLLWrappers.@generate_init_footer()
end  # __init__()


text:
using Rimu
using Test
using Rimu.StochasticStyles

using Rimu.StochasticStyles: projected_deposit!, diagonal_step!, spawn!
using Rimu.StochasticStyles:
    Exact, SingleSpawn, WithReplacement, WithoutReplacement, Bernoulli, DynamicSemistochastic

@testset "Generic Hamiltonian-free functions" begin
    matrix = [1 2 3; 4 5 6; 7 8 9]
    @test diagonal_element(matrix, 3) == 9
    @test offdiagonals(matrix, 1) == [2 => 4, 3 => 7]
    @test offdiagonals(matrix, 2) == [1 => 2, 3 => 8]

    add, prob, val = random_offdiagonal(matrix, 1)
    @test add in (2, 3)
    @test prob == 1/2
    @test val in (4, 7)

    vec = [1, 2, 3, 4, 5]
    deposit!(vec, 1, 2, 1 => 2)
    deposit!(vec, 4, -2, 1 => 2)
    @test vec == [3, 2, 3, 2, 5]

    @test StochasticStyle(vec) == IsStochasticInteger{Int64}()
    @test StochasticStyle(Float32.(vec)) == IsDeterministic{Float32}()

    names, values = step_stats(vec, Val(2))
    @test names == (:spawn_attempts, :spawns, :deaths, :clones, :zombies, :annihilations)
    @test length(values) == 2
    @test values[1] == values[2] == Rimu.MultiScalar((0, 0, 0, 0, 0, 0))

    w = [1.0, 2.0, 3.0]

    @test fciqmc_col!(w, matrix, 1, 2, 0.1, 0.2) == (1, )
    @test w[1] == 1.0 + (1 + 0.2 * (0.1 - matrix[1, 1])) * 2
    @test w[2] == 2.0 - 0.2 * matrix[2, 1] * 2
    @test w[3] == 3.0 - 0.2 * matrix[3, 1] * 2
end

@testset "projected_deposit!" begin
    @testset "Integer" begin
        for r in (true, false)
            for _ in 1:20
                dv = DVec(:a => 1)
                @test projected_deposit!(dv, :a, 0.5, :a => 1, 0, r) isa Tuple{Int, Int}
                @test dv[:a] == 1 || dv[:a] == 2

                @test projected_deposit!(dv, :b, -5.5, :a => 1, 0, r) isa Tuple{Int, Int}
                @test dv[:b] == -5 || dv[:b] == -6

                for i in 1:13
                    @test projected_deposit!(dv, :c, 1, :a => 1, 0, r) isa Tuple{Int, Int}
                end
                @test dv[:c] == 13
            end
        end
    end

    @testset "Exact" begin
        for r in (true, false)
            for _ in 1:20
                dv = DVec(:a => 1.0)
                projected_deposit!(dv, :a, -1, :a => 1.0, 0, r)
                @test isempty(dv)

                projected_deposit!(dv, :a, 1e-9, :a => 1.0, 0, r)
                projected_deposit!(dv, :b, -1 - 1e-9, :a => 1.0, 0, r)
                @test dv[:a] == 1e-9
                @test dv[:b] == -1 - 1e-9
            end
        end
    end

    @testset "Projected" begin
        for r in (true, false)
            for _ in 1:20
                dv = DVec(:a => 1.0)
                projected_deposit!(dv, :a, 0.5, :a => 1.0, 1.0, r)
                projected_deposit!(dv, :b, -0.5, :a => 1.0, 1.0, r)
                projected_deposit!(dv, :c, 1.1, :a => 1.0, 1.0, r)
                projected_deposit!(dv, :d, 0.1, :a => 1.0, 0.685, r)
                @test dv[:a] == 1.0 || dv[:a] == 2.0
                @test dv[:b] == 0.0 || dv[:b] == -1.0
                @test dv[:c] == 1.1
                @test dv[:d] == 0.685 || dv[:d] == 0
            end
        end
    end
end

@testset "diagonal_step!" begin
    add = BoseFS((1,1,1))
    H = HubbardReal1D(add)
    @testset "Integer" begin
        # nothing happens - one annihilation
        dv = DVec(add => -1)
        @test diagonal_step!(dv, H, add, 1, 1e-5, 0, 0, true) == (0, 0, 0, 1)
        dv = DVec(add => -1)
        @test diagonal_step!(dv, H, add, 1, 1e-5, 0, 0, false) == (0, 0, 0, 0)
        @test dv[add] == 0

        # clones
        for _ in 1:20
            dv = DVec(add => 0)
            st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, 10, 0, true)
            @test st[1] == 4 || st[1] == 5
            @test dv[BoseFS((2,0,1))] == 5 || dv[BoseFS((2,0,1))] == 6
        end
        # deaths
        for _ in 1:20
            dv = DVec(add => 0)
            st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -0.5, 0, true)
            @test st[2] == 0 || st[2] == 1
            @test dv[BoseFS((2,0,1))] == 0 || dv[BoseFS((2,0,1))] == 1
        end
        # zombies
        for _ in 1:20
            dv = DVec(add => 0)
            st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -10, 0, true)
            @test st[2] == 1
            @test st[3] == 4 || st[3] == 5
            @test dv[BoseFS((2,0,1))] == -4 || dv[BoseFS((2,0,1))] == -5
        end
    end
    @testset "Exact" begin
        # nothing happens - one annihilation
        dv = DVec(add => -1.0)
        @test diagonal_step!(dv, H, add, 1, 1e-5, 0, 0, true) == (0, 0, 0, 1)
        @test dv[add] == 0
        # clones
        dv = DVec(add => 0.0)
        st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, 10, 0, true)
        @test st[1] == 4.5
        @test dv[BoseFS((2,0,1))] == 5.5
        # deaths
        dv = DVec(add => 0.0)
        st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -0.5, 0, true)
        @test st[2] == 0.75
        @test dv[BoseFS((2,0,1))] == 0.25
        # zombies
        dv = DVec(add => 0.0)
        st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -10, 0, true)
        @test st[2] == 1
        @test st[3] == 4.5
        @test dv[BoseFS((2,0,1))] == -4.5
    end
    @testset "Projected" begin
        # nothing happens - but may be projected anyway
        for _ in 1:20
            dv = DVec(add => 0.0)
            st = diagonal_step!(dv, H, add, 1, 1e-5, 0, 1.5, true)
            @test st[2] == 1.0 || st[2] == 0.5
            @test dv[add] == 0.0 || dv[add] == 1.5
        end

        # clones
        dv = DVec(add => 0.0)
        st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, 10, 1, true)
        @test st[1] == 4.5
        @test dv[BoseFS((2,0,1))] == 5.5
        # deaths
        for _ in 1:20
            dv = DVec(add => 0.0)
            st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -0.5, 1, true)
            @test st[2] == 0.0 || st[2] == 1.0
            @test dv[BoseFS((2,0,1))] == 0.0 || dv[BoseFS((2,0,1))] == 1.0
        end
        # zombies
        dv = DVec(add => 0.0)
        st = diagonal_step!(dv, H, BoseFS((2,0,1)), 1, 0.5, -10, 1, true)
        @test st[2] == 1
        @test st[3] == 4.5
        @test dv[BoseFS((2,0,1))] == -4.5
    end
end

@testset "spawn!" begin
    dss_r = DynamicSemistochastic(WithReplacement(), 1.0, Inf)
    dss_w = DynamicSemistochastic(WithoutReplacement(), 1.0, Inf)
    dss_b = DynamicSemistochastic(Bernoulli(), 1.0, Inf)
    dss_ws = DynamicSemistochastic(WithoutReplacement(0, 1.1), 1.0, Inf)
    dss_bs = DynamicSemistochastic(Bernoulli(0, 1.5), 1.0, Inf)
    dss_s = DynamicSemistochastic(SingleSpawn(), 1.0, Inf)

    # The expected value for all spawning strategies should be the same. This tests makes
    # enough spawns to hopefully reach that average consistently.
    for (add, H) in [
        (BoseFS((0,0,0,3,1,1)), HubbardMom1D(BoseFS((0,0,0,3,1,1)); u=6.0)),
        (BoseFS((5,0,0,5,0,0,0)), HubbardReal1D(near_uniform(BoseFS{10,7}); u=1.0)),
    ]
        exact = DVec(add => 1.0)
        vanilla = DVec(add => 1.0)
        strong = DVec(add => 1.0)
        single = DVec(add => 1.0)
        semi_rep = DVec(add => 1.0)
        semi_bern = DVec(add => 1.0)
        semi_wo = DVec(add => 1.0)
        semi_bern_strong = DVec(add => 1.0)
        semi_wo_strong = DVec(add => 1.0)
        semi_single = DVec(add => 1.0)

        for _ in 1:10000
            val = rand() * num_offdiagonals(H, add) * 1.2
            spawn!(Exact(), exact, H, add, val, 1e-5)
            spawn!(WithReplacement(), vanilla, H, add, val, 1e-5)
            spawn!(WithReplacement(0.0, 2.0), strong, H, add, val, 1e-5)
            spawn!(SingleSpawn(), single, H, add, val, 1e-5)
            spawn!(dss_r, semi_rep, H, add, val, 1e-5)
            spawn!(dss_w, semi_wo, H, add, val, 1e-5)
            spawn!(dss_b, semi_bern, H, add, val, 1e-5)
            spawn!(dss_ws, semi_wo_strong, H, add, val, 1e-5)
            spawn!(dss_bs, semi_bern_strong, H, add, val, 1e-5)
            spawn!(dss_s, semi_single, H, add, val, 1e-5)
        end

        for k in keys(exact)
            @test exact[k] ≈ vanilla[k] rtol=0.1
            @test exact[k] ≈ strong[k] rtol=0.1
            @test exact[k] ≈ single[k] rtol=0.3 # ← very noisy.
            @test exact[k] ≈ semi_rep[k] rtol=0.1
            @test exact[k] ≈ semi_bern[k] rtol=0.1
            @test exact[k] ≈ semi_wo[k] rtol=0.1
            @test exact[k] ≈ semi_bern_strong[k] rtol=0.1
            @test exact[k] ≈ semi_wo_strong[k] rtol=0.1
            @test exact[k] ≈ semi_single[k] rtol=0.3 # ← very noisy.
        end
    end
end

@testset "Compression does not change 1-norm on average." begin
    add = BoseFS((0,0,0,10,0,0,0))
    H = HubbardMom1D(add)
    dv = DVec(add => 1.0, style=IsDeterministic())
    lomc!(H, dv)

    for compression in (
        StochasticStyles.ThresholdCompression(),
        StochasticStyles.ThresholdCompression(2),
        StochasticStyles.DoubleOrNothing(),
        StochasticStyles.DoubleOrNothing(prob=0.1),
        StochasticStyles.DoubleOrNothingWithThreshold(),
        StochasticStyles.DoubleOrNothingWithTarget(target=500),
    )
        target = similar(dv)
        for _ in 1:1000
            compressed = StochasticStyles.compress!(compression, copy(dv))
            add!(target, compressed)
        end
        @test walkernumber(target * (1/1000)) ≈ walkernumber(dv) rtol=0.1
    end
end