PostgreSQL library for linear algebra algorithms
git clone https://github.com/PX4/eigen.git
sudo cp -r eigen/Eigen /usr/local/include/
sudo cp -r eigen/unsupported /usr/local/include/
git clone -b 3.4 https://github.com/changtonghf/pg_eigen.git
cd pg_eigen
--compile & install
make PG_CONFIG=/usr/pgsql-14/bin/pg_config
make PG_CONFIG=/usr/pgsql-14/bin/pg_config install
--uninstall & clean
make PG_CONFIG=/usr/pgsql-14/bin/pg_config uninstall
make PG_CONFIG=/usr/pgsql-14/bin/pg_config clean
select array_reduce('minimum', array[[[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]],[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]],[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]],[[[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75],[76,77,78,79,80]],[[81,82,83,84,85],[86,87,88,89,90],[91,92,93,94,95],[96,97,98,99,100]],[[101,102,103,104,105],[106,107,108,109,110],[111,112,113,114,115],[116,117,118,119,120]]]]::float4[], array[0,1,2]::int[]);
array_reduce
--------------
{1,2,3,4,5}
(1 row)
select array_reduce('maximum', array[[[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]],[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]],[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]],[[[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75],[76,77,78,79,80]],[[81,82,83,84,85],[86,87,88,89,90],[91,92,93,94,95],[96,97,98,99,100]],[[101,102,103,104,105],[106,107,108,109,110],[111,112,113,114,115],[116,117,118,119,120]]]]::float4[], array[0,1,2]::int[]);
array_reduce
-----------------------
{116,117,118,119,120}
(1 row)
select array_reduce('sum', array[[[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]],[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]],[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]],[[[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75],[76,77,78,79,80]],[[81,82,83,84,85],[86,87,88,89,90],[91,92,93,94,95],[96,97,98,99,100]],[[101,102,103,104,105],[106,107,108,109,110],[111,112,113,114,115],[116,117,118,119,120]]]]::float4[], array[0,1,2]::int[]);
array_reduce
----------------------------
{1404,1428,1452,1476,1500}
(1 row)
select array_reduce('mean', array[[[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]],[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]],[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]],[[[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75],[76,77,78,79,80]],[[81,82,83,84,85],[86,87,88,89,90],[91,92,93,94,95],[96,97,98,99,100]],[[101,102,103,104,105],[106,107,108,109,110],[111,112,113,114,115],[116,117,118,119,120]]]]::float4[], array[0,1,2]::int[]);
array_reduce
----------------------------
{58.5,59.5,60.5,61.5,62.5}
(1 row)
select array_reduce('prod', array[[[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]],[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]],[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]],[[[61,62,63,64,65],[66,67,68,69,70],[71,72,73,74,75],[76,77,78,79,80]],[[81,82,83,84,85],[86,87,88,89,90],[91,92,93,94,95],[96,97,98,99,100]],[[101,102,103,104,105],[106,107,108,109,110],[111,112,113,114,115],[116,117,118,119,120]]]]::float4[], array[0,1,2]::int[]);
array_reduce
------------------------------------------------
{Infinity,Infinity,Infinity,Infinity,Infinity}
(1 row)
/*
* The first parameter represents the direction of the Fourier transform, where true indicates the forward transform and false indicates the inverse transform.
* The second parameter is the sampled signal data to be processed.
* The third parameter represents the axis along which the computation should be performed.
*/
--real case 2D
select array_fft(true, array[[1,2,3],[4,5,6]]::float[],array[0,1]);
array_fft
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{21,-8.881784197001252e-16},{-2.999999999999999,1.7320508075688812},{-3.0000000000000044,-1.7320508075688679}},{{-9,7.954818481105242e-17},{-5.828313194834535e-16,-5.928928440470584e-16},{2.572730330570817e-16,-2.1590185687695387e-15}}}
(1 row)
--real case 3D
select array_fft(true, array[[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]],[[17,18,19,20],[21,22,23,24],[25,26,27,28],[29,30,31,32]],[[33,34,35,36],[37,38,39,40],[41,42,43,44],[45,46,47,48]],[[49,50,51,52],[53,54,55,56],[57,58,59,60],[61,62,63,64]]]::float[],array[0,1,2]);
array_fft
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{2080,0},{-32,32},{-32,0},{-32,-32}},{{-128,128},{0,0},{0,0},{0,0}},{{-128,0},{0,0},{0,0},{0,0}},{{-128,-128},{0,0},{0,0},{0,0}}},{{{-512,512},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}}},{{{-512,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}}},{{{-512,-512},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0},{0,0}}}}
(1 row)
--complex case 3D
select array_fft(true, array[[[[1,0],[2,0],[3,0],[4,0]],[[5,0],[6,0],[7,0],[8,0]],[[9,0],[10,0],[11,0],[12,0]]],[[[13,0],[14,0],[15,0],[16,0]],[[17,0],[18,0],[19,0],[20,0]],[[21,0],[22,0],[23,0],[24,0]]]]::float[],array[0,1,2]);
array_fft
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{300,-9.769962616701378e-15},{-11.999999999999998,12},{-12,8.881784197001252e-16},{-12.000000000000002,-12}},{{-47.99999999999997,27.712812921102085},{-7.993605777301127e-15,-1.0658141036401503e-14},{3.552713678800501e-15,-7.105427357601002e-15},{8.881784197001252e-16,3.552713678800501e-15}},{{-48.00000000000007,-27.712812921101907},{-3.552713678800501e-15,0},{3.552713678800501e-15,-7.105427357601002e-15},{1.0658141036401503e-14,3.552713678800501e-15}}},{{{-144,1.2727709569768387e-15},{0,0},{0,0},{0,0}},{{-9.325301111735256e-15,-9.486285504752935e-15},{0,0},{0,0},{0,0}},{{4.1163685289133076e-15,-3.454429710031262e-14},{0,0},{0,0},{0,0}}}}
(1 row)
/*
* The 1st parameter represents random distribution type ['random_normal','truncated_normal','random_uniform','random_gamma'].
* The 2nd parameter represents generated random tensor dimensions.
* The 3rd,4th parameter represents different meanings in different types of random distributions.
* e.g. {'random_normal':['mean','stddev'],'truncated_normal':['mean','stddev'],'random_uniform':['min','max'],'random_gamma':['alpha','beta']}
* The 5th parameter represents random seed.
*/
select array_random('random_normal',array[4,4,4]::int4[],NULL,NULL,NULL);
array_random
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{1.4121317028867102,0.28608508563707563,0.7397978384058509,-0.24844586139341887},{0.7736072753183582,-0.2905937231390207,-0.8897592549990537,-1.7706046118918262},{1.5095978434452302,-0.7131549946663066,-0.595285927446035,-1.755644283620687},{0.007948099582136027,-1.7144896511497925,0.159278101089712,-0.3698435888572085}},{{-0.9395507146918786,1.6892258282420372,-0.5817366594536404,-0.5476174454983859},{-2.1175095824154764,-0.6937642836696352,1.060862048754157,-1.0671275603510413},{0.9517032075797296,0.0578303345226581,-0.700938407849263,0.7408124691557497},{-0.4897887551285538,0.09788175019871946,-1.315951417254708,1.800033807639251}},{{0.13084363086478423,0.23959812818189152,-0.169753783395673,1.265635211391652},{-0.4510026473587821,0.4978565840007883,-0.029806323532307652,-0.6817861184919237},{-0.534106507146958,0.051003905557653884,1.3570013084481,-2.3653198138178033},{1.9083494625227555,-0.5485915903651154,-0.2369925889531453,-2.149303518836518}},{{-0.8912823418230947,-0.587135027765074,0.19539829013422638,-1.1257841256790753},{0.2212643506826746,-0.871641471160528,0.8668763561385187,0.9074787082644987},{1.0060446668665768,-1.4772771155488635,-0.6103063843201098,0.5580805910287563},{0.5923738860100832,-1.673277140191504,-0.8948748833441303,0.3003617489607814}}}
(1 row)
select array_random('truncated_normal',array[4,4,4]::int4[],NULL,NULL,NULL);
array_random
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.35805642565546103,0.4716255958176307,-0.692131844563211,0.6663607063936081},{-0.22278790880391142,-0.4048326840167041,0.2723345335925019,-0.7176778421674779},{1.2191275552694942,0.5791692633492114,-0.3992851766601257,0.33372496669918594},{-1.1396879932581143,-1.088546853710638,-1.0394050347334467,0.5553248030548171}},{{1.5149458058195087,-0.8222826786992584,0.9488535114746416,0.6945980138686119},{-1.4158530597403258,0.3660032203812954,0.10560610278472715,0.009673235675448965},{0.2855630369636992,-0.3353943420790237,0.27597030419891255,-0.09334382119131257},{0.8491510373249188,-0.13428567402614305,0.5779005419790104,-1.0654482908432665}},{{-1.2484065954294885,-1.7145890048103414,-1.4661323241308066,-0.28442415914525143},{-1.6201862912554261,0.22595843080802372,-0.3051602752336001,0.7784966044968221},{0.10686057433121066,-0.8981882037310847,-0.11616412753850011,-1.560019116578599},{1.675397240161011,-0.6158079815471982,1.7145250405321413,0.08433282581331228}},{{-1.1458293800721657,-1.423544004726015,0.5998159171796317,-0.26214152524349765},{0.393506156414755,1.999353299227243,-0.2920053196869714,-1.1790195333373141},{-0.42726643033149475,0.06756746812037173,-1.060877037991233,0.021219994231680767},{0.9344350537326622,0.8535483880343059,-0.7152172901128067,-1.1407969381170227}}}
(1 row)
select array_random('random_uniform',array[4,4,4]::int4[],NULL,NULL,NULL);
array_random
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.5494712464738791,0.017900056951201334,0.8505125841290521,0.7531810561647415},{0.04327733360391492,0.6067238010676059,0.4853298690180786,0.7494440248980573},{0.21177493733067568,0.8754123524338837,0.9137999998508064,0.6177301300320891},{0.6967580950272616,0.260374597910966,0.3859287741198158,0.939565157274433}},{{0.6597573079624268,0.06659948567391524,0.4741860307833823,0.18052609915020446},{0.561667800948007,0.2140083227851447,0.7278522066829888,0.7447571527150374},{0.8049272668591244,0.11876785771474231,0.48456250913233684,0.13660643845385786},{0.8402065252222238,0.8618849373385533,0.1166819007937551,0.34156229688588763}},{{0.5193710560515523,0.22696586568623056,0.6916271330008161,0.7008357851559985},{0.6315079656201078,0.5471087541819628,0.18010575089269934,0.06139531628853287},{0.12785912014847886,0.9464661357881743,0.8594356509271944,0.6473426327923559},{0.45052749021970306,0.5540662640063023,0.018949806440335455,0.7387585932511922}},{{0.38055064995410953,0.2669185614085197,0.38407683747446614,0.8234707533252595},{0.22971268429255304,0.5435838810668184,0.2249402375939355,0.042601343890718214},{0.954937541292246,0.05790414825550391,0.2983572973114171,0.7178659272802072},{0.9105162117640778,0.7425559541019955,0.8929482829731417,0.7469127162312885}}}
(1 row)
select array_random('random_gamma',array[4,4,4]::int4[],NULL,NULL,NULL);
array_random
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.0846928572069294,0.17322454248649438,0.9018416719068567,0.7877928846180328},{1.2067278921000923,0.48472225116812473,3.38654408752678,0.8395944383893759},{0.018142621956015684,1.31029647280458,0.4680089433152287,1.2623106251292835},{2.0471857775154136,1.4841991725091377,2.6409820013183625,0.24699170184685107}},{{0.4549153967481168,1.4449421127631508,0.6662293756706684,4.096546412170345},{1.1193654556117771,0.3361720523003423,0.31806160249636767,1.3700486308741409},{1.4730382496306744,0.37359421970805246,0.16223253643514068,1.063162125075472},{0.42834580760584734,0.36090526653039057,0.05100410905040468,0.21368818676638127}},{{10.869628943110696,1.9723792409215801,0.14595401407671985,1.4656023551217543},{0.0908986581202579,1.0382409934152121,0.14269873596415428,0.465939185823815},{1.1547618891021874,0.02225157836820917,1.4716729401638682,1.138454141289693},{0.6791448922137641,0.7297375986611805,2.3523915977007004,0.22664409945239733}},{{0.3901294859613621,1.9856262145871402,1.6325380899815338,3.7709901252849782},{5.229609348091675,0.415245266155755,0.9130976756075097,0.5766729665500477},{2.9606270283030054,0.996840523188567,2.330443574512788,0.3886014548761588},{0.8196774771733536,0.9590820673199938,1.3838637975684287,0.023081093084865164}}}
(1 row)
select array_random('random_normal',array[4,4,4]::int4[],1.0,0.25,NULL);
array_random
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.5767518439911872,0.9312976377922761,1.0382360663884729,0.7350516082057741},{0.9104215674151729,0.857961250077465,1.1204963740612481,1.0204692205810764},{1.244027333970552,0.7508369208982455,1.0683337559819766,1.2237253240059798},{1.15713531575476,1.0381470280700134,0.7989140168831829,0.8785875288888944}},{{1.0295041550583373,0.8943649141050255,0.9989391045880573,1.4344081364951984},{1.5118000008611066,1.0504501368127128,1.1654954784273106,0.8242136021372823},{0.9666251103806883,0.7344222516614154,0.9768699226837495,1.4064537467350957},{0.8522250959218242,1.547514755828031,0.4849933596549332,1.3164672063201295}},{{1.2023756362824387,1.3200497967473592,1.0563899986952738,1.3110158422289286},{1.1138893813436712,0.7526186260027141,1.0943246470637054,0.9889974984198618},{0.5948410213470543,1.2160501732002635,0.9014207506206415,1.6351096562204117},{0.9226110648164638,0.6324872189254009,0.7738842993535073,1.1059056479948872}},{{1.142522985812235,1.219752473785686,1.330122286151008,1.2978817100521487},{1.0071026540620223,1.0382453228995907,0.9794796207647793,1.183699189250913},{0.6477192520792215,1.0388596553817306,0.9604870860668432,0.9678347681553603},{1.2094606396060656,1.2645014517884123,0.7282328967274074,1.731780182354533}}}
(1 row)
select array_random('truncated_normal',array[4,4,4]::int4[],1,0.25,NULL);
array_random
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{1.0317113653990448,1.1944621208352733,1.2630459710201851,1.2804197646634192},{0.8322627883516521,0.955533431032182,0.808314457883764,1.0979839313932964},{1.2974144496862206,0.8067521693393385,1.1341499665262804,0.8421223326781337},{0.8207600614571309,1.1720213678834976,1.0579592519430905,0.9334738647280821}},{{0.9710950807968919,0.9435866625532202,0.6025713804991744,1.0675711172579356},{0.698699195406647,0.9736147307396124,1.1384897750031358,1.0846103254471484},{0.8412225797962398,0.7566168584179864,0.8192405674340238,0.7200855294134596},{0.9780449242667408,1.4189036792581051,0.7247932395684112,0.7658457704174968}},{{0.8585777278061555,1.2384807813174388,0.9642110842021213,1.057836897746461},{0.5569652333557766,1.0006721482877592,1.209384220916153,0.7652165464332737},{0.8417235202067492,0.9386018091502206,1.1260598827278019,0.7656175699601049},{1.2992331883709762,1.1284667044541388,0.5754542938933503,1.2736459920981993}},{{0.8736553263449236,1.00587988524592,1.461047656887244,1.2096142147317952},{1.1798547514578464,0.9863325738762636,1.1248011721481295,0.8159344560387819},{0.9675661954134003,0.7583607155520673,0.7272169267074584,1.3042550474829133},{0.7535907942767599,0.923213949088173,1.0723658658554633,0.6727267659072105}}}
(1 row)
select array_random('random_uniform',array[4,4,4]::int4[],0.0,2.0,NULL);
array_random
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.5860415639300601,1.0825503878894718,0.1656274340866644,1.234731105644463},{1.2455903684881318,0.7721942075971255,1.536636269006584,1.8089455837311048},{0.9481254021612373,0.9091075515445822,1.626945170023398,0.16333503205026584},{0.29054250413830834,1.7599726495670793,1.1656759211710381,1.8294290039910595}},{{1.4385386582550024,1.10422054151696,0.892714588818608,1.0905823477282781},{1.780315350447028,1.9043929653571783,1.5348267147789065,1.0916507111299847},{0.7588212482132144,1.3855204232475655,0.718035864943127,0.93267778951147},{1.5458131483577315,1.2137904559609691,0.5555628252200637,0.9521557986440667}},{{1.392929747027946,1.251789562775264,1.7020265419853096,0.14210120147331304},{0.054640907400990146,1.4715810533652316,1.0449089801525053,1.5808543006182003},{0.26224433876887887,0.7970444407112084,0.9086733996410532,0.5606198301143996},{0.6363739880924529,0.3158856440791089,0.6037089227251092,1.510576356278498}},{{1.929911549739787,1.0744765271990915,0.8608202415787041,1.5933436370892058},{1.8888129742573032,0.6591418108234126,1.2000970109575668,1.8332814217929176},{1.1636765384435666,1.375325493553176,1.6554353859660098,1.4223792668159292},{1.019188211554794,1.6044102246840122,1.4657877975720375,1.8734175757211105}}}
(1 row)
select array_random('random_gamma',array[4,4,4]::int4[],3.0,2.0,NULL);
array_random
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{5.966558209630635,6.3814356709285445,10.9895138840905,3.0227283599769743},{6.182554153072222,3.009493900423842,4.822208062745396,6.336827168784252},{3.2095849610306413,5.181545485260656,3.7484685776600353,7.153899463653719},{11.615316407800936,14.271347831985029,8.816189652251955,6.355811949053376}},{{6.737338847904011,5.346995393165239,2.399971677044293,8.63670009308983},{9.188472028239385,6.491198445056402,9.107773372790385,8.17596280974018},{6.994559330015062,5.947796179499905,7.390512171908085,4.199113465929459},{2.5208991443703406,13.310001952913469,1.0066584861977392,3.3927884618307975}},{{3.3988645212018374,4.858189588760022,12.863709571110814,12.337954948414811},{1.5505713770518303,3.9885528318851784,10.68235078609402,6.776792442978493},{4.814235691289715,10.110685882759325,2.6881440970026635,3.603000285120026},{16.111256333990365,5.907017503834447,1.3186922199274038,3.416861310010864}},{{5.021591138664799,4.331767000188952,5.323296459960494,4.943286085742649},{3.924482565430967,7.172347028348657,3.456740175605212,4.176044060642246},{5.499298911446491,2.394715046549421,7.51530821090731,11.671645166063076},{7.469599590297861,7.3195419827254184,5.117911012427106,10.301932096820897}}}
(1 row)
select array_random('truncated_normal',array[4,4,4]::int4[],1,0.25,20);
array_random
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{1.0331905288359131,1.1235614435455674,1.1149920950509864,1.0358302089140703},{0.9345464997519622,1.0246599925911617,1.0905982780534949,1.097758991216043},{1.1774255965303235,1.213054463465337,1.2776435143042169,0.9828560388446397},{1.1532741288669905,0.9304477144599472,0.561346547430682,0.950975966178969}},{{0.5361005889371546,1.1377428226247652,0.9090691059625928,0.7508934810891588},{0.7086744519254646,1.3274251507912178,1.0807180044048013,1.1617709176205429},{0.8751305286518598,0.9049247625456592,1.4003421940088148,0.9458327286466025},{0.8091744139059351,1.3666976298792688,0.8865943387454781,1.1637418374348871}},{{1.2253277204262787,0.7457806639578023,0.6960477575851098,0.8376997119557975},{0.896457843720137,1.0709398151419318,0.976241307347084,0.975748353109458},{0.9625947444380722,1.3129269555876455,0.743581588716895,0.6644787612694403},{1.3805411982286193,0.9463697705631909,1.2142996270362096,1.2708219215118535}},{{0.8836354908147168,1.1346421454439124,0.8681294411104956,1.115918061344799},{0.5504549193363732,1.1479456969699982,1.2935182334083732,1.2898375765428844},{0.9777122918349118,1.0789183607743513,1.343488976333727,1.1300449851391647},{0.9360077290743223,1.0842610201852074,0.8703952814390722,1.3318185161076204}}}
(1 row)
select array_shuffle(array[[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],[37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]],[[73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144]]],NULL);
array_shuffle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{87,22,69,73,65,29,70,137,31,116,113,78,14,114,28,136,74,10,124,106,76,25,85,77,100,86,141,33,120,24,101,91,123,60,84,102},{110,17,143,48,7,94,67,112,38,27,127,103,140,115,88,62,54,79,119,40,125,142,46,51,53,130,55,44,104,8,132,61,15,58,9,32}},{{37,72,12,35,2,82,66,43,52,92,117,126,1,36,89,81,97,16,19,21,109,71,3,49,64,108,135,90,99,23,131,75,98,105,107,39},{18,95,41,122,96,93,50,111,138,42,118,59,133,34,121,45,47,128,57,139,68,56,83,134,20,144,6,13,11,4,30,26,129,80,5,63}}}
(1 row)
select array_shuffle(array[[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],[37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]],[[73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144]]],0);
array_shuffle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{78,22,57,31,55,69,58,4,77,42,96,131,13,29,11,88,50,33,111,27,104,136,37,91,76,119,122,53,25,132,92,97,52,34,113,49},{59,83,137,68,64,141,66,105,72,82,138,109,126,121,41,39,40,115,8,43,142,70,5,128,144,143,9,98,117,48,94,47,46,32,139,15}},{{116,75,106,127,62,71,61,28,67,81,1,90,86,103,10,120,35,44,51,36,123,100,26,95,56,17,118,54,101,24,79,12,80,38,99,112},{14,20,89,2,114,19,16,129,135,18,84,63,130,23,108,134,73,3,140,124,125,65,30,133,45,93,7,107,74,110,21,102,87,60,85,6}}}
(1 row)
select array_shuffle(array[[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],[37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]],[[73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144]]],1);
array_shuffle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{28,31,15,26,7,49,59,56,70,14,34,40,64,51,60,24,55,62,68,29,3,25,63,10,19,71,21,48,4,6,33,50,16,35,66,57},{45,36,67,52,9,44,37,53,11,13,42,38,5,39,27,18,46,1,47,43,17,41,72,61,22,12,32,8,54,23,65,69,20,2,30,58}},{{90,86,87,109,117,93,92,116,105,118,103,73,88,138,82,107,94,142,75,97,134,126,80,83,143,91,121,99,130,135,127,137,81,100,122,79},{108,113,74,133,112,104,98,78,76,84,132,85,89,131,139,110,95,140,119,106,102,96,128,120,125,129,77,136,144,114,115,124,141,101,111,123}}}
(1 row)
select array_shuffle(array[[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],[37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]],[[73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144]]],2);
array_shuffle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{9,26,12,25,35,8,14,19,11,28,33,36,20,4,16,31,24,6,34,2,7,30,3,15,23,17,27,5,22,32,1,18,29,13,10,21},{54,38,44,59,64,52,60,61,71,45,49,39,43,58,66,41,68,40,56,48,70,42,57,55,69,53,50,37,65,67,47,62,63,72,51,46}},{{105,75,103,79,107,77,90,88,100,84,97,73,87,85,81,82,99,106,76,94,83,108,98,96,74,95,80,89,93,101,92,104,91,86,78,102},{110,144,126,111,132,119,135,136,128,127,141,129,122,118,117,138,137,124,130,121,112,131,116,140,134,115,123,143,109,125,142,114,120,133,113,139}}}
(1 row)
select array_shuffle(array[[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],[37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72]],[[73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144]]],3);
array_shuffle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{67,60,103,48,5,42,123,80,53,94,93,45,59,40,97,29,73,127,102,7,96,64,77,22,89,71,118,140,25,128,21,19,30,82,27,15},{72,76,79,131,124,139,39,134,50,69,114,12,117,132,119,125,51,88,55,75,142,17,23,116,136,135,99,58,111,84,54,8,91,138,36,137}},{{129,107,1,38,122,110,20,133,92,13,81,61,86,106,95,44,6,47,115,109,2,65,120,9,16,143,4,10,32,108,18,98,52,87,126,113},{49,121,24,3,41,90,34,56,62,37,130,46,144,85,11,43,33,66,70,63,74,141,112,83,28,100,104,68,57,26,78,35,105,31,14,101}}}
(1 row)
select array_binaryop('add', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[], array[[1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2]]::float8[]);
array_binaryop
-------------------------------------------------------
{{11,11,11,11,11,11,11,11},{13,13,13,13,13,13,13,13}}
(1 row)
select array_binaryop('sub', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[], array[[1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2]]::float8[]);
array_binaryop
---------------------------------------
{{9,9,9,9,9,9,9,9},{9,9,9,9,9,9,9,9}}
(1 row)
select array_binaryop('mul', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[], array[[1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2]]::float8[]);
array_binaryop
-------------------------------------------------------
{{10,10,10,10,10,10,10,10},{22,22,22,22,22,22,22,22}}
(1 row)
select array_binaryop('div', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[], array[[1,1,1,1,1,1,1,1],[2,2,2,2,2,2,2,2]]::float8[]);
array_binaryop
---------------------------------------------------------------
{{10,10,10,10,10,10,10,10},{5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5}}
(1 row)
/*
* The 1st parameter represents data-format of input tensor {1D:NWC,2D:NHWC,3D:NDHWC}.
* The 2nd parameter represents input tensor to be processed.
* The 3rd parameter represents filter/kernel tensor.
* The 4th parameter represents stride, the number of entries by which the filter is moved right at each step.
* The 5th parameter represents padding ['SAME','VALID'].
*/
--real case 1D
select array_convolve('NWC',array[[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5],[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10],[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15],[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20],[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]],[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5],[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10],[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15],[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20],[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]]]::float8[],array[[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2]],[[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3]]]::float8[],array[1,1,1]::int4[],'SAME');
array_convolve
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{24,24,24,24,24,24,24,24},{42,42,42,42,42,42,42,42},{60,60,60,60,60,60,60,60},{78,78,78,78,78,78,78,78},{96,96,96,96,96,96,96,96},{114,114,114,114,114,114,114,114},{132,132,132,132,132,132,132,132},{150,150,150,150,150,150,150,150},{168,168,168,168,168,168,168,168},{186,186,186,186,186,186,186,186},{204,204,204,204,204,204,204,204},{222,222,222,222,222,222,222,222},{240,240,240,240,240,240,240,240},{258,258,258,258,258,258,258,258},{276,276,276,276,276,276,276,276},{294,294,294,294,294,294,294,294},{312,312,312,312,312,312,312,312},{330,330,330,330,330,330,330,330},{348,348,348,348,348,348,348,348},{366,366,366,366,366,366,366,366},{384,384,384,384,384,384,384,384},{402,402,402,402,402,402,402,402},{420,420,420,420,420,420,420,420},{438,438,438,438,438,438,438,438},{222,222,222,222,222,222,222,222}},{{24,24,24,24,24,24,24,24},{42,42,42,42,42,42,42,42},{60,60,60,60,60,60,60,60},{78,78,78,78,78,78,78,78},{96,96,96,96,96,96,96,96},{114,114,114,114,114,114,114,114},{132,132,132,132,132,132,132,132},{150,150,150,150,150,150,150,150},{168,168,168,168,168,168,168,168},{186,186,186,186,186,186,186,186},{204,204,204,204,204,204,204,204},{222,222,222,222,222,222,222,222},{240,240,240,240,240,240,240,240},{258,258,258,258,258,258,258,258},{276,276,276,276,276,276,276,276},{294,294,294,294,294,294,294,294},{312,312,312,312,312,312,312,312},{330,330,330,330,330,330,330,330},{348,348,348,348,348,348,348,348},{366,366,366,366,366,366,366,366},{384,384,384,384,384,384,384,384},{402,402,402,402,402,402,402,402},{420,420,420,420,420,420,420,420},{438,438,438,438,438,438,438,438},{222,222,222,222,222,222,222,222}}}
(1 row)
--real case 2D
select array_convolve('NHWC',array[[[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5]],[[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10]],[[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15]],[[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20]],[[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]]],[[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5]],[[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10]],[[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15]],[[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20]],[[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]]]]::float8[],array[[[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2]],[[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3]]],[[[4,4,4,4,4,4,4,4],[4,4,4,4,4,4,4,4],[4,4,4,4,4,4,4,4]],[[5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5]],[[6,6,6,6,6,6,6,6],[6,6,6,6,6,6,6,6],[6,6,6,6,6,6,6,6]]],[[[7,7,7,7,7,7,7,7],[7,7,7,7,7,7,7,7],[7,7,7,7,7,7,7,7]],[[8,8,8,8,8,8,8,8],[8,8,8,8,8,8,8,8],[8,8,8,8,8,8,8,8]],[[9,9,9,9,9,9,9,9],[9,9,9,9,9,9,9,9],[9,9,9,9,9,9,9,9]]]]::float8[],array[1,1,1,1]::int4[],'SAME');
array_convolve
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{384,384,384,384,384,384,384,384},{606,606,606,606,606,606,606,606},{723,723,723,723,723,723,723,723},{840,840,840,840,840,840,840,840},{552,552,552,552,552,552,552,552}},{{828,828,828,828,828,828,828,828},{1233,1233,1233,1233,1233,1233,1233,1233},{1368,1368,1368,1368,1368,1368,1368,1368},{1503,1503,1503,1503,1503,1503,1503,1503},{954,954,954,954,954,954,954,954}},{{1323,1323,1323,1323,1323,1323,1323,1323},{1908,1908,1908,1908,1908,1908,1908,1908},{2043,2043,2043,2043,2043,2043,2043,2043},{2178,2178,2178,2178,2178,2178,2178,2178},{1359,1359,1359,1359,1359,1359,1359,1359}},{{1818,1818,1818,1818,1818,1818,1818,1818},{2583,2583,2583,2583,2583,2583,2583,2583},{2718,2718,2718,2718,2718,2718,2718,2718},{2853,2853,2853,2853,2853,2853,2853,2853},{1764,1764,1764,1764,1764,1764,1764,1764}},{{960,960,960,960,960,960,960,960},{1308,1308,1308,1308,1308,1308,1308,1308},{1371,1371,1371,1371,1371,1371,1371,1371},{1434,1434,1434,1434,1434,1434,1434,1434},{840,840,840,840,840,840,840,840}}},{{{384,384,384,384,384,384,384,384},{606,606,606,606,606,606,606,606},{723,723,723,723,723,723,723,723},{840,840,840,840,840,840,840,840},{552,552,552,552,552,552,552,552}},{{828,828,828,828,828,828,828,828},{1233,1233,1233,1233,1233,1233,1233,1233},{1368,1368,1368,1368,1368,1368,1368,1368},{1503,1503,1503,1503,1503,1503,1503,1503},{954,954,954,954,954,954,954,954}},{{1323,1323,1323,1323,1323,1323,1323,1323},{1908,1908,1908,1908,1908,1908,1908,1908},{2043,2043,2043,2043,2043,2043,2043,2043},{2178,2178,2178,2178,2178,2178,2178,2178},{1359,1359,1359,1359,1359,1359,1359,1359}},{{1818,1818,1818,1818,1818,1818,1818,1818},{2583,2583,2583,2583,2583,2583,2583,2583},{2718,2718,2718,2718,2718,2718,2718,2718},{2853,2853,2853,2853,2853,2853,2853,2853},{1764,1764,1764,1764,1764,1764,1764,1764}},{{960,960,960,960,960,960,960,960},{1308,1308,1308,1308,1308,1308,1308,1308},{1371,1371,1371,1371,1371,1371,1371,1371},{1434,1434,1434,1434,1434,1434,1434,1434},{840,840,840,840,840,840,840,840}}}}
(1 row)
--real case 3D
select array_convolve('NDHWC',array[[[[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5]],[[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10]],[[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15]],[[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20]],[[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]]],[[[26,26,26],[27,27,27],[28,28,28],[29,29,29],[30,30,30]],[[31,31,31],[32,32,32],[33,33,33],[34,34,34],[35,35,35]],[[36,36,36],[37,37,37],[38,38,38],[39,39,39],[40,40,40]],[[41,41,41],[42,42,42],[43,43,43],[44,44,44],[45,45,45]],[[46,46,46],[47,47,47],[48,48,48],[49,49,49],[50,50,50]]]],[[[[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5]],[[6,6,6],[7,7,7],[8,8,8],[9,9,9],[10,10,10]],[[11,11,11],[12,12,12],[13,13,13],[14,14,14],[15,15,15]],[[16,16,16],[17,17,17],[18,18,18],[19,19,19],[20,20,20]],[[21,21,21],[22,22,22],[23,23,23],[24,24,24],[25,25,25]]],[[[26,26,26],[27,27,27],[28,28,28],[29,29,29],[30,30,30]],[[31,31,31],[32,32,32],[33,33,33],[34,34,34],[35,35,35]],[[36,36,36],[37,37,37],[38,38,38],[39,39,39],[40,40,40]],[[41,41,41],[42,42,42],[43,43,43],[44,44,44],[45,45,45]],[[46,46,46],[47,47,47],[48,48,48],[49,49,49],[50,50,50]]]]]::float8[],array[[[[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2],[2,2,2,2,2,2,2,2]],[[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3]]],[[[4,4,4,4,4,4,4,4],[4,4,4,4,4,4,4,4],[4,4,4,4,4,4,4,4]],[[5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5]],[[6,6,6,6,6,6,6,6],[6,6,6,6,6,6,6,6],[6,6,6,6,6,6,6,6]]],[[[7,7,7,7,7,7,7,7],[7,7,7,7,7,7,7,7],[7,7,7,7,7,7,7,7]],[[8,8,8,8,8,8,8,8],[8,8,8,8,8,8,8,8],[8,8,8,8,8,8,8,8]],[[9,9,9,9,9,9,9,9],[9,9,9,9,9,9,9,9],[9,9,9,9,9,9,9,9]]]],[[[[10,10,10,10,10,10,10,10],[10,10,10,10,10,10,10,10],[10,10,10,10,10,10,10,10]],[[11,11,11,11,11,11,11,11],[11,11,11,11,11,11,11,11],[11,11,11,11,11,11,11,11]],[[12,12,12,12,12,12,12,12],[12,12,12,12,12,12,12,12],[12,12,12,12,12,12,12,12]]],[[[13,13,13,13,13,13,13,13],[13,13,13,13,13,13,13,13],[13,13,13,13,13,13,13,13]],[[14,14,14,14,14,14,14,14],[14,14,14,14,14,14,14,14],[14,14,14,14,14,14,14,14]],[[15,15,15,15,15,15,15,15],[15,15,15,15,15,15,15,15],[15,15,15,15,15,15,15,15]]],[[[16,16,16,16,16,16,16,16],[16,16,16,16,16,16,16,16],[16,16,16,16,16,16,16,16]],[[17,17,17,17,17,17,17,17],[17,17,17,17,17,17,17,17],[17,17,17,17,17,17,17,17]],[[18,18,18,18,18,18,18,18],[18,18,18,18,18,18,18,18],[18,18,18,18,18,18,18,18]]]]]::float8[],array[1,1,1,1,1]::int4[],'SAME');
array_convolve
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{{6000,6000,6000,6000,6000,6000,6000,6000},{8916,8916,8916,8916,8916,8916,8916,8916},{9312,9312,9312,9312,9312,9312,9312,9312},{9708,9708,9708,9708,9708,9708,9708,9708},{6360,6360,6360,6360,6360,6360,6360,6360}},{{9234,9234,9234,9234,9234,9234,9234,9234},{13617,13617,13617,13617,13617,13617,13617,13617},{14130,14130,14130,14130,14130,14130,14130,14130},{14643,14643,14643,14643,14643,14643,14643,14643},{9522,9522,9522,9522,9522,9522,9522,9522}},{{11034,11034,11034,11034,11034,11034,11034,11034},{16182,16182,16182,16182,16182,16182,16182,16182},{16695,16695,16695,16695,16695,16695,16695,16695},{17208,17208,17208,17208,17208,17208,17208,17208},{11142,11142,11142,11142,11142,11142,11142,11142}},{{12834,12834,12834,12834,12834,12834,12834,12834},{18747,18747,18747,18747,18747,18747,18747,18747},{19260,19260,19260,19260,19260,19260,19260,19260},{19773,19773,19773,19773,19773,19773,19773,19773},{12762,12762,12762,12762,12762,12762,12762,12762}},{{7872,7872,7872,7872,7872,7872,7872,7872},{11400,11400,11400,11400,11400,11400,11400,11400},{11688,11688,11688,11688,11688,11688,11688,11688},{11976,11976,11976,11976,11976,11976,11976,11976},{7656,7656,7656,7656,7656,7656,7656,7656}}},{{{2484,2484,2484,2484,2484,2484,2484,2484},{3531,3531,3531,3531,3531,3531,3531,3531},{3648,3648,3648,3648,3648,3648,3648,3648},{3765,3765,3765,3765,3765,3765,3765,3765},{2352,2352,2352,2352,2352,2352,2352,2352}},{{3303,3303,3303,3303,3303,3303,3303,3303},{4608,4608,4608,4608,4608,4608,4608,4608},{4743,4743,4743,4743,4743,4743,4743,4743},{4878,4878,4878,4878,4878,4878,4878,4878},{2979,2979,2979,2979,2979,2979,2979,2979}},{{3798,3798,3798,3798,3798,3798,3798,3798},{5283,5283,5283,5283,5283,5283,5283,5283},{5418,5418,5418,5418,5418,5418,5418,5418},{5553,5553,5553,5553,5553,5553,5553,5553},{3384,3384,3384,3384,3384,3384,3384,3384}},{{4293,4293,4293,4293,4293,4293,4293,4293},{5958,5958,5958,5958,5958,5958,5958,5958},{6093,6093,6093,6093,6093,6093,6093,6093},{6228,6228,6228,6228,6228,6228,6228,6228},{3789,3789,3789,3789,3789,3789,3789,3789}},{{2160,2160,2160,2160,2160,2160,2160,2160},{2883,2883,2883,2883,2883,2883,2883,2883},{2946,2946,2946,2946,2946,2946,2946,2946},{3009,3009,3009,3009,3009,3009,3009,3009},{1740,1740,1740,1740,1740,1740,1740,1740}}}},{{{{6000,6000,6000,6000,6000,6000,6000,6000},{8916,8916,8916,8916,8916,8916,8916,8916},{9312,9312,9312,9312,9312,9312,9312,9312},{9708,9708,9708,9708,9708,9708,9708,9708},{6360,6360,6360,6360,6360,6360,6360,6360}},{{9234,9234,9234,9234,9234,9234,9234,9234},{13617,13617,13617,13617,13617,13617,13617,13617},{14130,14130,14130,14130,14130,14130,14130,14130},{14643,14643,14643,14643,14643,14643,14643,14643},{9522,9522,9522,9522,9522,9522,9522,9522}},{{11034,11034,11034,11034,11034,11034,11034,11034},{16182,16182,16182,16182,16182,16182,16182,16182},{16695,16695,16695,16695,16695,16695,16695,16695},{17208,17208,17208,17208,17208,17208,17208,17208},{11142,11142,11142,11142,11142,11142,11142,11142}},{{12834,12834,12834,12834,12834,12834,12834,12834},{18747,18747,18747,18747,18747,18747,18747,18747},{19260,19260,19260,19260,19260,19260,19260,19260},{19773,19773,19773,19773,19773,19773,19773,19773},{12762,12762,12762,12762,12762,12762,12762,12762}},{{7872,7872,7872,7872,7872,7872,7872,7872},{11400,11400,11400,11400,11400,11400,11400,11400},{11688,11688,11688,11688,11688,11688,11688,11688},{11976,11976,11976,11976,11976,11976,11976,11976},{7656,7656,7656,7656,7656,7656,7656,7656}}},{{{2484,2484,2484,2484,2484,2484,2484,2484},{3531,3531,3531,3531,3531,3531,3531,3531},{3648,3648,3648,3648,3648,3648,3648,3648},{3765,3765,3765,3765,3765,3765,3765,3765},{2352,2352,2352,2352,2352,2352,2352,2352}},{{3303,3303,3303,3303,3303,3303,3303,3303},{4608,4608,4608,4608,4608,4608,4608,4608},{4743,4743,4743,4743,4743,4743,4743,4743},{4878,4878,4878,4878,4878,4878,4878,4878},{2979,2979,2979,2979,2979,2979,2979,2979}},{{3798,3798,3798,3798,3798,3798,3798,3798},{5283,5283,5283,5283,5283,5283,5283,5283},{5418,5418,5418,5418,5418,5418,5418,5418},{5553,5553,5553,5553,5553,5553,5553,5553},{3384,3384,3384,3384,3384,3384,3384,3384}},{{4293,4293,4293,4293,4293,4293,4293,4293},{5958,5958,5958,5958,5958,5958,5958,5958},{6093,6093,6093,6093,6093,6093,6093,6093},{6228,6228,6228,6228,6228,6228,6228,6228},{3789,3789,3789,3789,3789,3789,3789,3789}},{{2160,2160,2160,2160,2160,2160,2160,2160},{2883,2883,2883,2883,2883,2883,2883,2883},{2946,2946,2946,2946,2946,2946,2946,2946},{3009,3009,3009,3009,3009,3009,3009,3009},{1740,1740,1740,1740,1740,1740,1740,1740}}}}}
(1 row)
/*
* The 1st parameter represents pooling ['max','avg'].
* The 2nd parameter represents data-format of input tensor {1D:NWC,2D:NHWC,3D:NDHWC}.
* The 3rd parameter represents input tensor to be processed.
* The 4th parameter represents filter/kernel size list.
* The 5th parameter represents stride, the number of entries by which the filter is moved right at each step.
* The 6th parameter represents padding ['SAME','VALID'].
*/
--real case 1D
select array_pool('max','NWC',array[[[24,24,24,24,24,24,24,24],[42,42,42,42,42,42,42,42],[60,60,60,60,60,60,60,60],[78,78,78,78,78,78,78,78],[96,96,96,96,96,96,96,96],[114,114,114,114,114,114,114,114],[132,132,132,132,132,132,132,132],[150,150,150,150,150,150,150,150],[168,168,168,168,168,168,168,168],[186,186,186,186,186,186,186,186],[204,204,204,204,204,204,204,204],[222,222,222,222,222,222,222,222],[240,240,240,240,240,240,240,240],[258,258,258,258,258,258,258,258],[276,276,276,276,276,276,276,276],[294,294,294,294,294,294,294,294],[312,312,312,312,312,312,312,312],[330,330,330,330,330,330,330,330],[348,348,348,348,348,348,348,348],[366,366,366,366,366,366,366,366],[384,384,384,384,384,384,384,384],[402,402,402,402,402,402,402,402],[420,420,420,420,420,420,420,420],[438,438,438,438,438,438,438,438],[222,222,222,222,222,222,222,222]]]::float8[],array[1,2,1]::int4[],array[1,2,1]::int4[],'SAME');
array_pool
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{42,42,42,42,42,42,42,42},{78,78,78,78,78,78,78,78},{114,114,114,114,114,114,114,114},{150,150,150,150,150,150,150,150},{186,186,186,186,186,186,186,186},{222,222,222,222,222,222,222,222},{258,258,258,258,258,258,258,258},{294,294,294,294,294,294,294,294},{330,330,330,330,330,330,330,330},{366,366,366,366,366,366,366,366},{402,402,402,402,402,402,402,402},{438,438,438,438,438,438,438,438},{222,222,222,222,222,222,222,222}}}
(1 row)
--real case 2D
select array_pool('max','NHWC',array[[[[384,384,384,384,384,384,384,384],[606,606,606,606,606,606,606,606],[723,723,723,723,723,723,723,723],[840,840,840,840,840,840,840,840],[552,552,552,552,552,552,552,552]],[[828,828,828,828,828,828,828,828],[1233,1233,1233,1233,1233,1233,1233,1233],[1368,1368,1368,1368,1368,1368,1368,1368],[1503,1503,1503,1503,1503,1503,1503,1503],[954,954,954,954,954,954,954,954]],[[1323,1323,1323,1323,1323,1323,1323,1323],[1908,1908,1908,1908,1908,1908,1908,1908],[2043,2043,2043,2043,2043,2043,2043,2043],[2178,2178,2178,2178,2178,2178,2178,2178],[1359,1359,1359,1359,1359,1359,1359,1359]],[[1818,1818,1818,1818,1818,1818,1818,1818],[2583,2583,2583,2583,2583,2583,2583,2583],[2718,2718,2718,2718,2718,2718,2718,2718],[2853,2853,2853,2853,2853,2853,2853,2853],[1764,1764,1764,1764,1764,1764,1764,1764]],[[960,960,960,960,960,960,960,960],[1308,1308,1308,1308,1308,1308,1308,1308],[1371,1371,1371,1371,1371,1371,1371,1371],[1434,1434,1434,1434,1434,1434,1434,1434],[840,840,840,840,840,840,840,840]]]]::float8[],array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME');
array_pool
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{1233,1233,1233,1233,1233,1233,1233,1233},{1503,1503,1503,1503,1503,1503,1503,1503},{954,954,954,954,954,954,954,954}},{{2583,2583,2583,2583,2583,2583,2583,2583},{2853,2853,2853,2853,2853,2853,2853,2853},{1764,1764,1764,1764,1764,1764,1764,1764}},{{1308,1308,1308,1308,1308,1308,1308,1308},{1434,1434,1434,1434,1434,1434,1434,1434},{840,840,840,840,840,840,840,840}}}}
(1 row)
--real case 3D
select array_pool('max','NDHWC',array[[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]]]::float8[],array[1,2,2,2,1]::int4[],array[1,2,2,2,1]::int4[],'SAME');
array_pool
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{{13617,13617,13617,13617,13617,13617,13617,13617},{14643,14643,14643,14643,14643,14643,14643,14643},{9522,9522,9522,9522,9522,9522,9522,9522}},{{18747,18747,18747,18747,18747,18747,18747,18747},{19773,19773,19773,19773,19773,19773,19773,19773},{12762,12762,12762,12762,12762,12762,12762,12762}},{{11400,11400,11400,11400,11400,11400,11400,11400},{11976,11976,11976,11976,11976,11976,11976,11976},{7656,7656,7656,7656,7656,7656,7656,7656}}}}}
(1 row)
--real case 1D
select array_pool('avg','NWC',array[[[24,24,24,24,24,24,24,24],[42,42,42,42,42,42,42,42],[60,60,60,60,60,60,60,60],[78,78,78,78,78,78,78,78],[96,96,96,96,96,96,96,96],[114,114,114,114,114,114,114,114],[132,132,132,132,132,132,132,132],[150,150,150,150,150,150,150,150],[168,168,168,168,168,168,168,168],[186,186,186,186,186,186,186,186],[204,204,204,204,204,204,204,204],[222,222,222,222,222,222,222,222],[240,240,240,240,240,240,240,240],[258,258,258,258,258,258,258,258],[276,276,276,276,276,276,276,276],[294,294,294,294,294,294,294,294],[312,312,312,312,312,312,312,312],[330,330,330,330,330,330,330,330],[348,348,348,348,348,348,348,348],[366,366,366,366,366,366,366,366],[384,384,384,384,384,384,384,384],[402,402,402,402,402,402,402,402],[420,420,420,420,420,420,420,420],[438,438,438,438,438,438,438,438],[222,222,222,222,222,222,222,222]]]::float8[],array[1,2,1]::int4[],array[1,2,1]::int4[],'SAME');
array_pool
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{33,33,33,33,33,33,33,33},{69,69,69,69,69,69,69,69},{105,105,105,105,105,105,105,105},{141,141,141,141,141,141,141,141},{177,177,177,177,177,177,177,177},{213,213,213,213,213,213,213,213},{249,249,249,249,249,249,249,249},{285,285,285,285,285,285,285,285},{321,321,321,321,321,321,321,321},{357,357,357,357,357,357,357,357},{393,393,393,393,393,393,393,393},{429,429,429,429,429,429,429,429},{111,111,111,111,111,111,111,111}}}
(1 row)
--real case 2D
select array_pool('avg','NHWC',array[[[[384,384,384,384,384,384,384,384],[606,606,606,606,606,606,606,606],[723,723,723,723,723,723,723,723],[840,840,840,840,840,840,840,840],[552,552,552,552,552,552,552,552]],[[828,828,828,828,828,828,828,828],[1233,1233,1233,1233,1233,1233,1233,1233],[1368,1368,1368,1368,1368,1368,1368,1368],[1503,1503,1503,1503,1503,1503,1503,1503],[954,954,954,954,954,954,954,954]],[[1323,1323,1323,1323,1323,1323,1323,1323],[1908,1908,1908,1908,1908,1908,1908,1908],[2043,2043,2043,2043,2043,2043,2043,2043],[2178,2178,2178,2178,2178,2178,2178,2178],[1359,1359,1359,1359,1359,1359,1359,1359]],[[1818,1818,1818,1818,1818,1818,1818,1818],[2583,2583,2583,2583,2583,2583,2583,2583],[2718,2718,2718,2718,2718,2718,2718,2718],[2853,2853,2853,2853,2853,2853,2853,2853],[1764,1764,1764,1764,1764,1764,1764,1764]],[[960,960,960,960,960,960,960,960],[1308,1308,1308,1308,1308,1308,1308,1308],[1371,1371,1371,1371,1371,1371,1371,1371],[1434,1434,1434,1434,1434,1434,1434,1434],[840,840,840,840,840,840,840,840]]]]::float8[],array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME');
array_pool
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{762.75,762.75,762.75,762.75,762.75,762.75,762.75,762.75},{1108.5,1108.5,1108.5,1108.5,1108.5,1108.5,1108.5,1108.5},{376.5,376.5,376.5,376.5,376.5,376.5,376.5,376.5}},{{1908,1908,1908,1908,1908,1908,1908,1908},{2448,2448,2448,2448,2448,2448,2448,2448},{780.75,780.75,780.75,780.75,780.75,780.75,780.75,780.75}},{{567,567,567,567,567,567,567,567},{701.25,701.25,701.25,701.25,701.25,701.25,701.25,701.25},{210,210,210,210,210,210,210,210}}}}
(1 row)
--real case 3D
select array_pool('avg','NDHWC',array[[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]]]::float8[],array[1,2,2,2,1]::int4[],array[1,2,2,2,1]::int4[],'SAME');
array_pool
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{{6461.625,6461.625,6461.625,6461.625,6461.625,6461.625,6461.625,6461.625},{8103.375,8103.375,8103.375,8103.375,8103.375,8103.375,8103.375,8103.375},{2651.625,2651.625,2651.625,2651.625,2651.625,2651.625,2651.625,2651.625}},{{9766.125,9766.125,9766.125,9766.125,9766.125,9766.125,9766.125,9766.125},{12028.5,12028.5,12028.5,12028.5,12028.5,12028.5,12028.5,12028.5},{3884.625,3884.625,3884.625,3884.625,3884.625,3884.625,3884.625,3884.625}},{{3039.375,3039.375,3039.375,3039.375,3039.375,3039.375,3039.375,3039.375},{3702.375,3702.375,3702.375,3702.375,3702.375,3702.375,3702.375,3702.375},{1174.5,1174.5,1174.5,1174.5,1174.5,1174.5,1174.5,1174.5}}}}}
(1 row)
select array_activate('relu', array[[-9,-8,-7,-6,-5,-4,-3,-2,-1,0],[0,1,2,3,4,5,6,7,8,9]]::float8[], NULL);
array_activate
-----------------------------------------------
{{0,0,0,0,0,0,0,0,0,0},{0,1,2,3,4,5,6,7,8,9}}
(1 row)
select array_activate('sigmoid', array[[-9,-8,-7,-6,-5,-4,-3,-2,-1,0],[0,1,2,3,4,5,6,7,8,9]]::float8[], NULL);
array_activate
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{0.00012339457598623172,0.0003353501304664781,0.0009110511944006454,0.0024726231566347743,0.0066928509242848554,0.01798620996209156,0.04742587317756678,0.11920292202211755,0.2689414213699951,0.5},{0.5,0.7310585786300049,0.8807970779778823,0.9525741268224334,0.9820137900379085,0.9933071490757153,0.9975273768433653,0.9990889488055994,0.9996646498695336,0.9998766054240137}}
(1 row)
select array_activate('tanh', array[[-9,-8,-7,-6,-5,-4,-3,-2,-1,0],[0,1,2,3,4,5,6,7,8,9]]::float8[], NULL);
array_activate
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{-0.999999969540041,-0.9999997749296758,-0.9999983369439447,-0.9999877116507956,-0.9999092042625951,-0.999329299739067,-0.9950547536867305,-0.9640275800758169,-0.7615941559557649,0},{0,0.7615941559557649,0.9640275800758169,0.9950547536867305,0.999329299739067,0.9999092042625951,0.9999877116507956,0.9999983369439447,0.9999997749296758,0.999999969540041}}
(1 row)
select array_activate('leaky relu', array[[-9,-8,-7,-6,-5,-4,-3,-2,-1,0],[0,1,2,3,4,5,6,7,8,9]]::float8[], 0.01);
array_activate
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{-0.08999999798834324,-0.07999999821186066,-0.06999999843537807,-0.05999999865889549,-0.04999999888241291,-0.03999999910593033,-0.029999999329447746,-0.019999999552965164,-0.009999999776482582,0},{0,1,2,3,4,5,6,7,8,9}}
(1 row)
select array_activate('elu', array[[-9,-8,-7,-6,-5,-4,-3,-2,-1,0],[0,1,2,3,4,5,6,7,8,9]]::float8[], 0.01);
array_activate
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{-0.0099987656784693,-0.009996645150278538,-0.00999088095703086,-0.009975212255269962,-0.009932620307997776,-0.009816843391689103,-0.00950212910393222,-0.008646646974366248,-0.006321205446995622,0},{0,1,2,3,4,5,6,7,8,9}}
(1 row)
/*
* The 1st parameter represents input tensor to be processed.
* The 2nd parameter represents drop rate.
* The 3rd parameter represents noise shape for randomly generated keep/drop flags.
* The 4th parameter represents random seed.
* with probability rate elements of input are set to 0. the remaining elements are scaled up by 1.0 / (1 - rate).
*/
select array_dropout(array[[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]::float8[], 0.8, NULL, 1);
array_dropout
---------------------------------------------------------------------------------------
{{0,0,5.000000298023242,0,0},{0,0,5.000000298023242,0,0},{0,5.000000298023242,0,0,0}}
(1 row)
select array_dropout(array[[1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1]]::float8[], 2.0/3, array[1,10]::int4[], 1);
array_dropout
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{0,0,3.000000178813945,0,0,0,0,3.000000178813945,0,0},{0,0,3.000000178813945,0,0,0,0,3.000000178813945,0,0},{0,0,3.000000178813945,0,0,0,0,3.000000178813945,0,0}}
(1 row)
/*
* The 1st parameter represents left input tensor to be processed.
* The 2nd parameter represents right input tensor to be processed.
* The 3rd parameter represents matrix multiplication dimensions.
* The 4th parameter represents transpose & adjoint flag [AT,BT,AH,BH].
*/
--real case
select array_matmul(array[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]::float8[],array[[[13,16],[14,17],[15,18]],[[19,22],[20,23],[21,24]]]::float8[], array[1,2]::int4[], NULL);
array_matmul
----------------------------------------------
{{{86,104},{212,257}},{{482,554},{662,761}}}
(1 row)
select array_matmul(array[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]::float8[],array[[[13,16],[14,17],[15,18]],[[19,22],[20,23],[21,24]]]::float8[], array[1,2]::int4[], array[false,false,false,false]);
array_matmul
----------------------------------------------
{{{86,104},{212,257}},{{482,554},{662,761}}}
(1 row)
select array_matmul(array[[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]::float8[],array[[[13,14,15],[16,17,18]],[[19,20,21],[22,23,24]]]::float8[], array[1,2]::int4[], array[false,true,false,false]);
array_matmul
----------------------------------------------
{{{86,104},{212,257}},{{482,554},{662,761}}}
(1 row)
--complex case
select array_matmul(array[[[[1,2],[3,4],[5,6],[7,8]],[[9,10],[11,12],[13,14],[15,16]],[[17,18],[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30],[31,32]],[[33,34],[35,36],[37,38],[39,40]],[[41,42],[43,44],[45,46],[47,48]]]]::float8[],array[[[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]],[[13,14],[15,16],[17,18]],[[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30]],[[31,32],[33,34],[35,36]],[[37,38],[39,40],[41,42]],[[43,44],[45,46],[47,48]]]]::float8[], array[1,2]::int4[], NULL);
array_matmul
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{-60,496},{-68,568},{-76,640}},{{-92,1168},{-100,1368},{-108,1568}},{{-124,1840},{-132,2168},{-140,2496}}},{{{-252,7984},{-260,8440},{-268,8896}},{{-284,10192},{-292,10776},{-300,11360}},{{-316,12400},{-324,13112},{-332,13824}}}}
(1 row)
select array_matmul(array[[[[1,2],[3,4],[5,6],[7,8]],[[9,10],[11,12],[13,14],[15,16]],[[17,18],[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30],[31,32]],[[33,34],[35,36],[37,38],[39,40]],[[41,42],[43,44],[45,46],[47,48]]]]::float8[],array[[[[1,2],[3,4],[5,6]],[[7,8],[9,10],[11,12]],[[13,14],[15,16],[17,18]],[[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30]],[[31,32],[33,34],[35,36]],[[37,38],[39,40],[41,42]],[[43,44],[45,46],[47,48]]]]::float8[], array[1,2]::int4[], array[false,false,false,false]);
array_matmul
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{-60,496},{-68,568},{-76,640}},{{-92,1168},{-100,1368},{-108,1568}},{{-124,1840},{-132,2168},{-140,2496}}},{{{-252,7984},{-260,8440},{-268,8896}},{{-284,10192},{-292,10776},{-300,11360}},{{-316,12400},{-324,13112},{-332,13824}}}}
(1 row)
select array_matmul(array[[[[1,2],[3,4],[5,6],[7,8]],[[9,10],[11,12],[13,14],[15,16]],[[17,18],[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30],[31,32]],[[33,34],[35,36],[37,38],[39,40]],[[41,42],[43,44],[45,46],[47,48]]]]::float8[],array[[[[1,2],[3,4],[5,6],[7,8]],[[9,10],[11,12],[13,14],[15,16]],[[17,18],[19,20],[21,22],[23,24]]],[[[25,26],[27,28],[29,30],[31,32]],[[33,34],[35,36],[37,38],[39,40]],[[41,42],[43,44],[45,46],[47,48]]]]::float8[], array[1,2]::int4[], array[false,false,false,true]);
array_matmul
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{204,0},{492,32},{780,64}},{{492,-32},{1292,0},{2092,32}},{{780,-64},{2092,-32},{3404,0}}},{{{6540,0},{8364,32},{10188,64}},{{8364,-32},{10700,0},{13036,32}},{{10188,-64},{13036,-32},{15884,0}}}}
(1 row)
/*
* The 1st parameter represents input tensor to be processed.
* The 2nd parameter represents dimension softmax would be performed on.
*/
select array_softmax(array[[-1,0,1,2,3],[-4,-2,-1,0,4]]::int4[],1);
array_softmax
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{0.011656230956039605,0.03168492079612427,0.0861285444362687,0.23412165725273662,0.6364086465588308},{0.0003263674839084742,0.002411547647466562,0.006555266148571514,0.01781906085237466,0.9728877578676788}}
(1 row)
select array_softmax(array[[-1,0,1,2,3],[-4,-2,-1,0,4]]::float4[],1);
array_softmax
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{0.011656230956039605,0.03168492079612427,0.0861285444362687,0.23412165725273662,0.6364086465588308},{0.0003263674839084742,0.002411547647466562,0.006555266148571514,0.01781906085237466,0.9728877578676788}}
(1 row)
select array_softmax(array[[[-1,0,1,2,3],[-4,-3,-2,-1,0]],[[-5,0,1,2,2],[-4,-2,-1,0,4]]]::float8[],1);
array_softmax
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{0.9525741268224333,0.9525741268224334,0.9525741268224331,0.9525741268224333,0.9525741268224333},{0.047425873177566795,0.04742587317756679,0.047425873177566774,0.047425873177566774,0.04742587317756678}},{{0.2689414213699951,0.8807970779778823,0.8807970779778824,0.8807970779778824,0.11920292202211756},{0.731058578630005,0.11920292202211755,0.11920292202211753,0.11920292202211755,0.8807970779778824}}}
(1 row)
/*
* The 1st parameter represents index reduce function ['argmax','argmax'].
* The 2nd parameter represents input tensor to be processed.
* The 3rd parameter represents dimension index reduce would be performed on.
*/
select array_argpos('argmax', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], NULL);
array_argpos
--------------
{2,2,0,2,2}
(1 row)
select array_argpos('argmax', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], 0);
array_argpos
--------------
{2,2,0,2,2}
(1 row)
select array_argpos('argmax', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], 1);
array_argpos
--------------
{2,2,1}
(1 row)
select array_argpos('argmin', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], NULL);
array_argpos
--------------
{0,1,1,1,0}
(1 row)
select array_argpos('argmin', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], 0);
array_argpos
--------------
{0,1,1,1,0}
(1 row)
select array_argpos('argmin', array[[2,20,30,3,6],[3,11,16,1,8],[14,45,23,5,27]]::float8[], 1);
array_argpos
--------------
{0,3,3}
(1 row)
/*
* The 1st parameter represents loss function [{'MAE':'mean_absolute_error'},{'MSE':'mean_squared_error'},{'CCE':'categorical_cross_entropy'},{'SCE':'softmax_cross_entropy'}].
* The 2nd parameter represents predict input tensor to be processed.
* The 3rd parameter represents true input tensor to be processed.
* The 4th parameter represents dimension index reduce would be performed on.
*/
select array_loss('SCE', array[[0.6,0.4],[-1.1,0.4],[0.5,0.2],[0.9,1.6]]::float8[], array[[1,0],[0,1],[1,0],[0,1]]::float8[], 0);
array_loss
----------------------------------------
{2.5694189609301676,2.429274099194261}
(1 row)
select array_loss('SCE', array[[0.6,0.4],[-1.1,0.4],[0.5,0.2],[0.9,1.6]]::float8[], array[[1,0],[0,1],[1,0],[0,1]]::float8[], 1);
array_loss
----------------------------------------------------------------------------
{0.598138869381592,0.2014132779827524,0.554355244468527,0.403186048885458}
(1 row)
select array_loss('MSE', array[[0.6,0.4],[-1.1,0.4],[0.5,0.2],[0.9,1.6]]::float8[], array[[1,0],[0,1],[1,0],[0,1]]::float8[], 1);
array_loss
---------------------------------------------------------------------------------
{0.16000000000000003,0.7850000000000001,0.14500000000000002,0.5850000000000001}
(1 row)
select array_reshape(array[[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]],[[17,18,19,20],[21,22,23,24],[25,26,27,28],[29,30,31,32]],[[33,34,35,36],[37,38,39,40],[41,42,43,44],[45,46,47,48]],[[49,50,51,52],[53,54,55,56],[57,58,59,60],[61,62,63,64]]]::float8[],array[16,4]::int4[]);
array_reshape
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16},{17,18,19,20},{21,22,23,24},{25,26,27,28},{29,30,31,32},{33,34,35,36},{37,38,39,40},{41,42,43,44},{45,46,47,48},{49,50,51,52},{53,54,55,56},{57,58,59,60},{61,62,63,64}}
(1 row)
/*
* The 1st parameter represents pooling ['max','avg'].
* The 2nd parameter represents data-format of input tensor {1D:NWC,2D:NHWC,3D:NDHWC}.
* The 3rd parameter represents input tensor to be processed.
* The 4th parameter represents filter/kernel size list.
* The 5th parameter represents stride, the number of entries by which the filter is moved right at each step.
* The 6th parameter represents padding ['SAME','VALID'].
* The 7th parameter represents gradient of the LOSS function with respect to the output of pooling operation.
*/
--real case 3D
select array_unpool('max','NDHWC',array[[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]],[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]]]::float8[],array[1,2,2,2,1]::int4[],array[1,2,2,2,1]::int4[],'SAME',array[[[[[1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617],[1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643],[0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522]],[[1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747],[1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773],[1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762]],[[1.1400,1.1400,1.1400,1.1400,1.1400,1.1400,1.1400,1.1400],[1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976],[0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656]]]],[[[[1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617],[1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643],[0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522]],[[1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747],[1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773],[1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762]],[[1.1400,1.1400,1.1400,1.1400,1.1400,1.1400,1.1400,1.1400],[1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976],[0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656]]]]]::float8[]);
array_unpool
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617},{0,0,0,0,0,0,0,0},{1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643},{0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747},{0,0,0,0,0,0,0,0},{1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773},{1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762}},{{0,0,0,0,0,0,0,0},{1.14,1.14,1.14,1.14,1.14,1.14,1.14,1.14},{0,0,0,0,0,0,0,0},{1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976},{0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656}}},{{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}}}},{{{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617,1.3617},{0,0,0,0,0,0,0,0},{1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643,1.4643},{0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522,0.9522}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747,1.8747},{0,0,0,0,0,0,0,0},{1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773,1.9773},{1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762,1.2762}},{{0,0,0,0,0,0,0,0},{1.14,1.14,1.14,1.14,1.14,1.14,1.14,1.14},{0,0,0,0,0,0,0,0},{1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976,1.1976},{0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656,0.7656}}},{{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}}}}}
(1 row)
select array_unpool('avg','NDHWC',array[[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]],[[[[6000,6000,6000,6000,6000,6000,6000,6000],[8916,8916,8916,8916,8916,8916,8916,8916],[9312,9312,9312,9312,9312,9312,9312,9312],[9708,9708,9708,9708,9708,9708,9708,9708],[6360,6360,6360,6360,6360,6360,6360,6360]],[[9234,9234,9234,9234,9234,9234,9234,9234],[13617,13617,13617,13617,13617,13617,13617,13617],[14130,14130,14130,14130,14130,14130,14130,14130],[14643,14643,14643,14643,14643,14643,14643,14643],[9522,9522,9522,9522,9522,9522,9522,9522]],[[11034,11034,11034,11034,11034,11034,11034,11034],[16182,16182,16182,16182,16182,16182,16182,16182],[16695,16695,16695,16695,16695,16695,16695,16695],[17208,17208,17208,17208,17208,17208,17208,17208],[11142,11142,11142,11142,11142,11142,11142,11142]],[[12834,12834,12834,12834,12834,12834,12834,12834],[18747,18747,18747,18747,18747,18747,18747,18747],[19260,19260,19260,19260,19260,19260,19260,19260],[19773,19773,19773,19773,19773,19773,19773,19773],[12762,12762,12762,12762,12762,12762,12762,12762]],[[7872,7872,7872,7872,7872,7872,7872,7872],[11400,11400,11400,11400,11400,11400,11400,11400],[11688,11688,11688,11688,11688,11688,11688,11688],[11976,11976,11976,11976,11976,11976,11976,11976],[7656,7656,7656,7656,7656,7656,7656,7656]]],[[[2484,2484,2484,2484,2484,2484,2484,2484],[3531,3531,3531,3531,3531,3531,3531,3531],[3648,3648,3648,3648,3648,3648,3648,3648],[3765,3765,3765,3765,3765,3765,3765,3765],[2352,2352,2352,2352,2352,2352,2352,2352]],[[3303,3303,3303,3303,3303,3303,3303,3303],[4608,4608,4608,4608,4608,4608,4608,4608],[4743,4743,4743,4743,4743,4743,4743,4743],[4878,4878,4878,4878,4878,4878,4878,4878],[2979,2979,2979,2979,2979,2979,2979,2979]],[[3798,3798,3798,3798,3798,3798,3798,3798],[5283,5283,5283,5283,5283,5283,5283,5283],[5418,5418,5418,5418,5418,5418,5418,5418],[5553,5553,5553,5553,5553,5553,5553,5553],[3384,3384,3384,3384,3384,3384,3384,3384]],[[4293,4293,4293,4293,4293,4293,4293,4293],[5958,5958,5958,5958,5958,5958,5958,5958],[6093,6093,6093,6093,6093,6093,6093,6093],[6228,6228,6228,6228,6228,6228,6228,6228],[3789,3789,3789,3789,3789,3789,3789,3789]],[[2160,2160,2160,2160,2160,2160,2160,2160],[2883,2883,2883,2883,2883,2883,2883,2883],[2946,2946,2946,2946,2946,2946,2946,2946],[3009,3009,3009,3009,3009,3009,3009,3009],[1740,1740,1740,1740,1740,1740,1740,1740]]]]]::float8[],array[1,2,2,2,1]::int4[],array[1,2,2,2,1]::int4[],'SAME',array[[[[[6.461625,6.461625,6.461625,6.461625,6.461625,6.461625,6.461625,6.461625],[8.103375,8.103375,8.103375,8.103375,8.103375,8.103375,8.103375,8.103375],[2.651625,2.651625,2.651625,2.651625,2.651625,2.651625,2.651625,2.651625]],[[9.766125,9.766125,9.766125,9.766125,9.766125,9.766125,9.766125,9.766125],[12.0285,12.0285,12.0285,12.0285,12.0285,12.0285,12.0285,12.0285],[3.884625,3.884625,3.884625,3.884625,3.884625,3.884625,3.884625,3.884625]],[[3.039375,3.039375,3.039375,3.039375,3.039375,3.039375,3.039375,3.039375],[3.702375,3.702375,3.702375,3.702375,3.702375,3.702375,3.702375,3.702375],[1.1745,1.1745,1.1745,1.1745,1.1745,1.1745,1.1745,1.1745]]]],[[[[6.461625,6.461625,6.461625,6.461625,6.461625,6.461625,6.461625,6.461625],[8.103375,8.103375,8.103375,8.103375,8.103375,8.103375,8.103375,8.103375],[2.651625,2.651625,2.651625,2.651625,2.651625,2.651625,2.651625,2.651625]],[[9.766125,9.766125,9.766125,9.766125,9.766125,9.766125,9.766125,9.766125],[12.0285,12.0285,12.0285,12.0285,12.0285,12.0285,12.0285,12.0285],[3.884625,3.884625,3.884625,3.884625,3.884625,3.884625,3.884625,3.884625]],[[3.039375,3.039375,3.039375,3.039375,3.039375,3.039375,3.039375,3.039375],[3.702375,3.702375,3.702375,3.702375,3.702375,3.702375,3.702375,3.702375],[1.1745,1.1745,1.1745,1.1745,1.1745,1.1745,1.1745,1.1745]]]]]::float8[]);
array_unpool
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125}}},{{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125}}}},{{{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125}}},{{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125,0.807703125},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875,1.012921875},{0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125,0.331453125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625,1.220765625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625,1.5035625},{0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125,0.485578125}},{{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875,0.379921875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875,0.462796875},{0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125,0.1468125}}}}}
(1 row)
/*
* The 1st parameter represents data-format of input tensor {1D:NWC,2D:NHWC,3D:NDHWC}.
* The 2nd parameter represents input tensor to be processed.
* The 3rd parameter represents filter/kernel tensor.
* The 4th parameter represents stride, the number of entries by which the filter is moved right at each step.
* The 5th parameter represents padding ['SAME','VALID'].
* The 6th parameter represents ∂L/∂Y.
*/
--real case 2D assuming Loss = y
select * from array_convt('NHWC',array[[[[1.0],[2.0],[3.0]],[[4.0],[5.0],[6.0]],[[7.0],[8.0],[9.0]]],[[[1.0],[2.0],[3.0]],[[4.0],[5.0],[6.0]],[[7.0],[8.0],[9.0]]]]::float8[],array[[[[1.0]],[[2.0]]],[[[3.0]],[[4.0]]]]::float8[],array[1,1,1,1]::int4[],'SAME',array_fill(1::float8,array[2,3,3,1]));
∂weight | ∂input | ∂bias
-----------------------------------+---------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------
{{{{90}},{{66}}},{{{78}},{{56}}}} | {{{{1},{3},{3}},{{4},{10},{10}},{{4},{10},{10}}},{{{1},{3},{3}},{{4},{10},{10}},{{4},{10},{10}}}} | {{{{18},{18},{18}},{{18},{18},{18}},{{18},{18},{18}}},{{{18},{18},{18}},{{18},{18},{18}},{{18},{18},{18}}}}
(1 row)
--real case 2D assuming Loss = y
select * from array_convt('NHWC',array[[[[1.0],[2.0],[3.0],[2.0],[3.0]],[[4.0],[5.0],[6.0],[2.0],[3.0]],[[7.0],[8.0],[9.0],[2.0],[3.0]]],[[[1.0],[2.0],[3.0],[2.0],[3.0]],[[4.0],[5.0],[6.0],[5.0],[6.0]],[[7.0],[8.0],[9.0],[8.0],[9.0]]]]::float8[],array[[[[1.0]],[[2.0]],[[3.0]]],[[[3.0]],[[4.0]],[[5.0]]]]::float8[],array[1,1,1,1]::int4[],'SAME',array_fill(1::float8,array[2,3,5,1]));
∂weight | ∂input | ∂bias
-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{111}},{{138}},{{114}}},{{{95}},{{116}},{{94}}}} | {{{{3},{6},{6},{6},{5}},{{10},{18},{18},{18},{14}},{{10},{18},{18},{18},{14}}},{{{3},{6},{6},{6},{5}},{{10},{18},{18},{18},{14}},{{10},{18},{18},{18},{14}}}} | {{{{30},{30},{30},{30},{30}},{{30},{30},{30},{30},{30}},{{30},{30},{30},{30},{30}}},{{{30},{30},{30},{30},{30}},{{30},{30},{30},{30},{30}},{{30},{30},{30},{30},{30}}}}
(1 row)
--real case 2D assuming Loss = tf.square(y)
select * from array_convt('NHWC',array[[[[1.0],[2.0],[3.0]],[[4.0],[5.0],[6.0]],[[7.0],[8.0],[9.0]]],[[[1.0],[2.0],[3.0]],[[4.0],[5.0],[6.0]],[[7.0],[8.0],[9.0]]]]::float8[],array[[[[1.0]],[[2.0]]],[[[3.0]],[[4.0]]]]::float8[],array[1,1,1,1]::int4[],'SAME',array[[[[76],[96],[44]],[[136],[156],[68]],[[48],[54],[20]]],[[[76],[96],[44]],[[136],[156],[68]],[[48],[54],[20]]]]::float8[]);
∂weight | ∂input | ∂bias
-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------
{{{{6160}},{{5852}}},{{{7720}},{{6896}}}} | {{{{76},{248},{236}},{{364},{1020},{896}},{{456},{1162},{956}}},{{{76},{248},{236}},{{364},{1020},{896}},{{456},{1162},{956}}}} | {{{{1396},{1396},{1396}},{{1396},{1396},{1396}},{{1396},{1396},{1396}}},{{{1396},{1396},{1396}},{{1396},{1396},{1396}},{{1396},{1396},{1396}}}}
(1 row)
select array_unaryop('sqrt', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795,3.1622776601683795},{3.3166247903554,3.3166247903554,3.3166247903554,3.3166247903554,3.3166247903554,3.3166247903554,3.3166247903554,3.3166247903554}}
(1 row)
select array_unaryop('abs', array[[-10,-10,-10,-10,-10,-10,-10,-10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
-------------------------------------------------------
{{10,10,10,10,10,10,10,10},{11,11,11,11,11,11,11,11}}
(1 row)
select array_unaryop('sigmoid', array[[-10,-10,-10,-10,-10,-10,-10,-10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05,4.5397868702434395e-05},{0.999983298578152,0.999983298578152,0.999983298578152,0.999983298578152,0.999983298578152,0.999983298578152,0.999983298578152,0.999983298578152}}
(1 row)
select array_unaryop('exp', array[[-10,-10,-10,-10,-10,-10,-10,-10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05,4.539992976248485e-05},{59874.14171519782,59874.14171519782,59874.14171519782,59874.14171519782,59874.14171519782,59874.14171519782,59874.14171519782,59874.14171519782}}
(1 row)
select array_unaryop('log', array[[10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{2.3025850929940455,2.3025850929940455,2.3025850929940455,2.3025850929940455,2.3025850929940455,2.3025850929940455,2.3025850929940455,2.3025850929940455},{2.3978952727983702,2.3978952727983702,2.3978952727983702,2.3978952727983702,2.3978952727983702,2.3978952727983702,2.3978952727983702,2.3978952727983702}}
(1 row)
select array_unaryop('sign', array[[-10,-10,-10,-10,-10,-10,-10,-10],[11,11,11,11,11,11,11,11]]::float8[]);
array_unaryop
-----------------------------------------------
{{-1,-1,-1,-1,-1,-1,-1,-1},{1,1,1,1,1,1,1,1}}
(1 row)
create table if not exists public.cv2_cat_dog_hw3c(id bigserial primary key,label int4,image float8[]);
create table if not exists public.cat_dog_model(layer int4,name text,value float8[]);
--load train data. psql -f sql/cv2_cat_dog_hw3c.sql or \i sql/cv2_cat_dog_hw3c.sql
--create convolutional neural network train procedure
create or replace procedure cat_dog_train(float8 default 0.95) as
$$
declare
a0 bigint[] := (select array_shuffle(array_agg(id),0) from public.cv2_cat_dog_hw3c);
t0 bigint := 0;
i bigint;
r1 record;
st timestamp;
ed timestamp;
---------------------------------------------------------------------------------------------------constant variables
ref int4[] := array_fill(255.0::float8, array[32,64,64,03]);
d1r int4[] := array_fill(000.0::float8, array[32,64,64,32]);
d2r int4[] := array_fill(000.0::float8, array[32,32,32,32]);
d3r int4[] := array_fill(000.0::float8, array[32,16,16,64]);
d5r int4[] := array_fill(000.0::float8, array[00032,01024]);
d5s int4[] := array_dropout(array_fill(1.0::float8, array[32,1024]), 0.3, NULL, 20);
d6s int4[] := array_dropout(array_fill(1.0::float8, array[32,0002]), 0.3, NULL, 20);
---------------------------------------------------------------------------------------------------Weights/Biases
w1 float8[] := array_random('truncated_normal',array[03,03,03,32]::int4[],NULL,0.05,20);
b1 float8[] := array_fill(0.05::float8,array[32,64,64,32]::int4[]);
w2 float8[] := array_random('truncated_normal',array[03,03,32,32]::int4[],NULL,0.05,20);
b2 float8[] := array_fill(0.05::float8,array[32,32,32,32]::int4[]);
w3 float8[] := array_random('truncated_normal',array[03,03,32,64]::int4[],NULL,0.05,20);
b3 float8[] := array_fill(0.05::float8,array[32,16,16,64]::int4[]);
w5 float8[] := array_random('truncated_normal',array[04096,01024]::int4[],NULL,0.05,20);
b5 float8[] := array_fill(0.05::float8,array[00032,01024]::int4[]);
w6 float8[] := array_random('truncated_normal',array[01024,00002]::int4[],NULL,0.05,20);
b6 float8[] := array_fill(0.05::float8,array[00032,00002]::int4[]);
---------------------------------------------------------------------------------------------------Mean Estimation/Variance Estimation
w1m float8[] := array_fill(0::float8,array[03,03,03,32]);
b1m float8[] := array_fill(0::float8,array[32,64,64,32]);
w2m float8[] := array_fill(0::float8,array[03,03,32,32]);
b2m float8[] := array_fill(0::float8,array[32,32,32,32]);
w3m float8[] := array_fill(0::float8,array[03,03,32,64]);
b3m float8[] := array_fill(0::float8,array[32,16,16,64]);
w5m float8[] := array_fill(0::float8,array[04096,01024]);
b5m float8[] := array_fill(0::float8,array[00032,01024]);
w6m float8[] := array_fill(0::float8,array[01024,00002]);
b6m float8[] := array_fill(0::float8,array[00032,00002]);
w1v float8[] := array_fill(0::float8,array[03,03,03,32]);
b1v float8[] := array_fill(0::float8,array[32,64,64,32]);
w2v float8[] := array_fill(0::float8,array[03,03,32,32]);
b2v float8[] := array_fill(0::float8,array[32,32,32,32]);
w3v float8[] := array_fill(0::float8,array[03,03,32,64]);
b3v float8[] := array_fill(0::float8,array[32,16,16,64]);
w5v float8[] := array_fill(0::float8,array[04096,01024]);
b5v float8[] := array_fill(0::float8,array[00032,01024]);
w6v float8[] := array_fill(0::float8,array[01024,00002]);
b6v float8[] := array_fill(0::float8,array[00032,00002]);
mht float8[];
vht float8[];
---------------------------------------------------------------------------------------------------layer
i0 float8[];
l0 float8[];
l1 float8[];
l2 float8[];
l3 float8[];
l4 float8[];
l5 float8[];
l6 float8[];
e7 float8[];
c7 float8[];
s7 float8[];
a7 float8[];
---------------------------------------------------------------------------------------------------layer internal variables
l1a float8[];
l1b float8[];
l1c float8[];
l2a float8[];
l2b float8[];
l2c float8[];
l3a float8[];
l3b float8[];
l3c float8[];
a7a float8[];
a7b float8[];
a7c float8[];
---------------------------------------------------------------------------------------------------gradient
∂6e float8[];
∂6d float8[];
∂6w float8[];
∂6x float8[];
∂6b float8[];
∂5r float8[];
∂5d float8[];
∂5w float8[];
∂5x float8[];
∂5b float8[];
∂4x float8[];
∂3r float8[];
∂3p float8[];
∂3w float8[];
∂3x float8[];
∂3b float8[];
∂2r float8[];
∂2p float8[];
∂2w float8[];
∂2x float8[];
∂2b float8[];
∂1r float8[];
∂1p float8[];
∂1w float8[];
∂1x float8[];
∂1b float8[];
---------------------------------------------------------------------------------------------------epsilon
w1ε float8[] := array_fill(1.0e-8::float8, array[03,03,03,32]);
b1ε float8[] := array_fill(1.0e-8::float8, array[32,64,64,32]);
w2ε float8[] := array_fill(1.0e-8::float8, array[03,03,32,32]);
b2ε float8[] := array_fill(1.0e-8::float8, array[32,32,32,32]);
w3ε float8[] := array_fill(1.0e-8::float8, array[03,03,32,64]);
b3ε float8[] := array_fill(1.0e-8::float8, array[32,16,16,64]);
w5ε float8[] := array_fill(1.0e-8::float8, array[04096,01024]);
b5ε float8[] := array_fill(1.0e-8::float8, array[00032,01024]);
w6ε float8[] := array_fill(1.0e-8::float8, array[01024,00002]);
b6ε float8[] := array_fill(1.0e-8::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------learning rate
w1α float8[] := array_fill(1.0e-4::float8, array[03,03,03,32]);
b1α float8[] := array_fill(1.0e-4::float8, array[32,64,64,32]);
w2α float8[] := array_fill(1.0e-4::float8, array[03,03,32,32]);
b2α float8[] := array_fill(1.0e-4::float8, array[32,32,32,32]);
w3α float8[] := array_fill(1.0e-4::float8, array[03,03,32,64]);
b3α float8[] := array_fill(1.0e-4::float8, array[32,16,16,64]);
w5α float8[] := array_fill(1.0e-4::float8, array[04096,01024]);
b5α float8[] := array_fill(1.0e-4::float8, array[00032,01024]);
w6α float8[] := array_fill(1.0e-4::float8, array[01024,00002]);
b6α float8[] := array_fill(1.0e-4::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------beta1
w1β float8[] := array_fill(0.9000::float8, array[03,03,03,32]);
b1β float8[] := array_fill(0.9000::float8, array[32,64,64,32]);
w2β float8[] := array_fill(0.9000::float8, array[03,03,32,32]);
b2β float8[] := array_fill(0.9000::float8, array[32,32,32,32]);
w3β float8[] := array_fill(0.9000::float8, array[03,03,32,64]);
b3β float8[] := array_fill(0.9000::float8, array[32,16,16,64]);
w5β float8[] := array_fill(0.9000::float8, array[04096,01024]);
b5β float8[] := array_fill(0.9000::float8, array[00032,01024]);
w6β float8[] := array_fill(0.9000::float8, array[01024,00002]);
b6β float8[] := array_fill(0.9000::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------beta2
w1γ float8[] := array_fill(0.9990::float8, array[03,03,03,32]);
b1γ float8[] := array_fill(0.9990::float8, array[32,64,64,32]);
w2γ float8[] := array_fill(0.9990::float8, array[03,03,32,32]);
b2γ float8[] := array_fill(0.9990::float8, array[32,32,32,32]);
w3γ float8[] := array_fill(0.9990::float8, array[03,03,32,64]);
b3γ float8[] := array_fill(0.9990::float8, array[32,16,16,64]);
w5γ float8[] := array_fill(0.9990::float8, array[04096,01024]);
b5γ float8[] := array_fill(0.9990::float8, array[00032,01024]);
w6γ float8[] := array_fill(0.9990::float8, array[01024,00002]);
b6γ float8[] := array_fill(0.9990::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------1-beta1
w1β_ float8[] := array_fill(0.100::float8, array[03,03,03,32]);
b1β_ float8[] := array_fill(0.100::float8, array[32,64,64,32]);
w2β_ float8[] := array_fill(0.100::float8, array[03,03,32,32]);
b2β_ float8[] := array_fill(0.100::float8, array[32,32,32,32]);
w3β_ float8[] := array_fill(0.100::float8, array[03,03,32,64]);
b3β_ float8[] := array_fill(0.100::float8, array[32,16,16,64]);
w5β_ float8[] := array_fill(0.100::float8, array[04096,01024]);
b5β_ float8[] := array_fill(0.100::float8, array[00032,01024]);
w6β_ float8[] := array_fill(0.100::float8, array[01024,00002]);
b6β_ float8[] := array_fill(0.100::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------1-beta2
w1γ_ float8[] := array_fill(0.001::float8, array[03,03,03,32]);
b1γ_ float8[] := array_fill(0.001::float8, array[32,64,64,32]);
w2γ_ float8[] := array_fill(0.001::float8, array[03,03,32,32]);
b2γ_ float8[] := array_fill(0.001::float8, array[32,32,32,32]);
w3γ_ float8[] := array_fill(0.001::float8, array[03,03,32,64]);
b3γ_ float8[] := array_fill(0.001::float8, array[32,16,16,64]);
w5γ_ float8[] := array_fill(0.001::float8, array[04096,01024]);
b5γ_ float8[] := array_fill(0.001::float8, array[00032,01024]);
w6γ_ float8[] := array_fill(0.001::float8, array[01024,00002]);
b6γ_ float8[] := array_fill(0.001::float8, array[00032,00002]);
---------------------------------------------------------------------------------------------------
begin
create temporary table if not exists cv_cat_dog_tensor_set(gid bigint,labels bigint[],images double precision[]) on commit preserve rows;
execute 'truncate table cv_cat_dog_tensor_set';
commit;
insert into cv_cat_dog_tensor_set(gid,labels,images)
select gid,array_agg(label order by rn),array_agg(image order by rn)
from (select x.rn,(x.rn-1)/32 as gid,p.id,case p.label when 0 then array[1,0] else array[0,1] end as label,p.image
from public.cv2_cat_dog_hw3c p
inner join unnest(a0) with ordinality as x(id,rn)
on p.id = x.id
order by x.rn asc) s
group by gid;
delete from cv_cat_dog_tensor_set where gid = (select max(gid) from cv_cat_dog_tensor_set);
for i in 1 .. 30
loop
for r1 in select gid,labels,images from cv_cat_dog_tensor_set
loop
st := clock_timestamp();
i0 := array_binaryop('div',r1.images,ref);
l0 := cast(r1.labels as float8[]);
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',i0,w1,array[1,1,1,1]::int4[],'SAME') into l1a;
select array_binaryop('add',l1a,b1) into l1b;
select array_activate('relu', l1b, NULL) into l1c;
select array_pool('max','NHWC',l1c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l1;
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',l1,w2,array[1,1,1,1]::int4[],'SAME') into l2a;
select array_binaryop('add',l2a,b2) into l2b;
select array_activate('relu', l2b, NULL) into l2c;
select array_pool('max','NHWC',l2c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l2;
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',l2,w3,array[1,1,1,1]::int4[],'SAME') into l3a;
select array_binaryop('add',l3a,b3) into l3b;
select array_activate('relu', l3b, NULL) into l3c;
select array_pool('max','NHWC',l3c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l3;
---------------------------------------------------------------------------------------------------flatten
select array_reshape(l3,array[32,4096]::int4[]) into l4;
---------------------------------------------------------------------------------------------------dense
select array_matmul(l4,w5, array[0,1]::int4[], NULL) into l5;
select array_binaryop('add',l5,b5) into l5;
select array_dropout(l5, 0.3, NULL, 20) into l5;
select array_activate('relu', l5, NULL) into l5;
---------------------------------------------------------------------------------------------------dense
select array_matmul(l5,w6, array[0,1]::int4[], NULL) into l6;
select array_binaryop('add',l6,b6) into l6;
select array_dropout(l6, 0.3, NULL, 20) into l6;
---------------------------------------------------------------------------------------------------loss
select array_loss('SCE', l6, l0, 1) into e7;
select array_reduce('mean', e7, NULL) into c7;
---------------------------------------------------------------------------------------------------accuracy
select array_softmax(l6,1) into s7;
select array_argpos('argmax', s7, 1) into a7a;
select array_argpos('argmax', l0, 1) into a7b;
select array_binaryop('eq', a7a, a7b) into a7c;
select array_reduce('mean', a7c, NULL) into a7;
---------------------------------------------------------------------------------------------------derivation
select array_binaryop('sub', array_softmax(l6,1), l0) into ∂6e; --[32,2]
select array_binaryop('mul', ∂6e, d6s) into ∂6d; --[32,2]
select array_matmul(l5, ∂6d, array[0,1]::int4[], array[true,false,false,false]) into ∂6w; --[1024,2]
select array_matmul(∂6d, w6, array[0,1]::int4[], array[false,true,false,false]) into ∂6x; --[32,1024]
∂6b := ∂6d; --[32,2]
-------------------------------------------------
select array_binaryop('mul', ∂6x, array_binaryop('gt', l5, d5r)) into ∂5r;
select array_binaryop('mul', ∂5r, d5s) into ∂5d; --[32,1024]
select array_matmul(l4, ∂5d, array[0,1]::int4[], array[true,false,false,false]) into ∂5w; --[4096,1024]
select array_matmul(∂5d, w5, array[0,1]::int4[], array[false,true,false,false]) into ∂5x; --[32,4096]
∂5b := ∂6x; --[32,1024]
-------------------------------------------------
select array_reshape(∂5x,array[32,8,8,64]::int4[]) into ∂4x; --[32,8,8,64]
-------------------------------------------------
select array_unpool('max','NHWC',l3c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME',∂4x) into ∂3p; --[32,16,16,64]
select array_binaryop('mul', ∂3p, array_binaryop('gt', l3c, d3r)) into ∂3r;
select ∂weight,∂input,∂bias into ∂3w,∂3x,∂3b from array_convt('NHWC',l2,w3,array[1,1,1,1]::int4[],'SAME',∂3r);
-------------------------------------------------
select array_unpool('max','NHWC',l2c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME',∂3x) into ∂2p; --[32,32,32,32]
select array_binaryop('mul', ∂2p, array_binaryop('gt', l2c, d2r)) into ∂2r;
select ∂weight,∂input,∂bias into ∂2w,∂2x,∂2b from array_convt('NHWC',l1,w2,array[1,1,1,1]::int4[],'SAME',∂2r);
-------------------------------------------------
select array_unpool('max','NHWC',l1c,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME',∂2x) into ∂1p; --[32,64,64,32]
select array_binaryop('mul', ∂1p, array_binaryop('gt', l1c, d1r)) into ∂1r;
select ∂weight,∂input,∂bias into ∂1w,∂1x,∂1b from array_convt('NHWC',i0,w1,array[1,1,1,1]::int4[],'SAME',∂1r);
---------------------------------------------------------------------------------------------------
t0 := t0 + 1;
---------------------------------------------------------------------------------------------------AdamOptimizer
w1m := array_binaryop('add',array_binaryop('mul', w1m, w1β),array_binaryop('mul', w1β_, ∂1w));
w1v := array_binaryop('add',array_binaryop('mul', w1v, w1γ),array_binaryop('mul', w1γ_, array_binaryop('mul', ∂1w, ∂1w)));
mht := array_binaryop('div', w1m, array_fill(1 - power(0.900::float8,t0), array[03,03,03,32]));
vht := array_binaryop('div', w1v, array_fill(1 - power(0.999::float8,t0), array[03,03,03,32]));
w1 := array_binaryop('sub', w1, array_binaryop('div', array_binaryop('mul', mht, w1α),array_binaryop('add',array_unaryop('sqrt',vht),w1ε)));
-------------------------------------------------
b1m := array_binaryop('add',array_binaryop('mul', b1m, b1β),array_binaryop('mul', b1β_, ∂1b));
b1v := array_binaryop('add',array_binaryop('mul', b1v, b1γ),array_binaryop('mul', b1γ_, array_binaryop('mul', ∂1b, ∂1b)));
mht := array_binaryop('div', b1m, array_fill(1 - power(0.900::float8,t0), array[32,64,64,32]));
vht := array_binaryop('div', b1v, array_fill(1 - power(0.999::float8,t0), array[32,64,64,32]));
b1 := array_binaryop('sub', b1, array_binaryop('div', array_binaryop('mul', mht, b1α),array_binaryop('add',array_unaryop('sqrt',vht),b1ε)));
-------------------------------------------------
w2m := array_binaryop('add',array_binaryop('mul', w2m, w2β),array_binaryop('mul', w2β_, ∂2w));
w2v := array_binaryop('add',array_binaryop('mul', w2v, w2γ),array_binaryop('mul', w2γ_, array_binaryop('mul', ∂2w, ∂2w)));
mht := array_binaryop('div', w2m, array_fill(1 - power(0.900::float8,t0), array[03,03,32,32]));
vht := array_binaryop('div', w2v, array_fill(1 - power(0.999::float8,t0), array[03,03,32,32]));
w2 := array_binaryop('sub', w2, array_binaryop('div', array_binaryop('mul', mht, w2α),array_binaryop('add',array_unaryop('sqrt',vht),w2ε)));
-------------------------------------------------
b2m := array_binaryop('add',array_binaryop('mul', b2m, b2β),array_binaryop('mul', b2β_, ∂2b));
b2v := array_binaryop('add',array_binaryop('mul', b2v, b2γ),array_binaryop('mul', b2γ_, array_binaryop('mul', ∂2b, ∂2b)));
mht := array_binaryop('div', b2m, array_fill(1 - power(0.900::float8,t0), array[32,32,32,32]));
vht := array_binaryop('div', b2v, array_fill(1 - power(0.999::float8,t0), array[32,32,32,32]));
b2 := array_binaryop('sub', b2, array_binaryop('div', array_binaryop('mul', mht, b2α),array_binaryop('add',array_unaryop('sqrt',vht),b2ε)));
-------------------------------------------------
w3m := array_binaryop('add',array_binaryop('mul', w3m, w3β),array_binaryop('mul', w3β_, ∂3w));
w3v := array_binaryop('add',array_binaryop('mul', w3v, w3γ),array_binaryop('mul', w3γ_, array_binaryop('mul', ∂3w, ∂3w)));
mht := array_binaryop('div', w3m, array_fill(1 - power(0.900::float8,t0), array[03,03,32,64]));
vht := array_binaryop('div', w3v, array_fill(1 - power(0.999::float8,t0), array[03,03,32,64]));
w3 := array_binaryop('sub', w3, array_binaryop('div', array_binaryop('mul', mht, w3α),array_binaryop('add',array_unaryop('sqrt',vht),w3ε)));
-------------------------------------------------
b3m := array_binaryop('add',array_binaryop('mul', b3m, b3β),array_binaryop('mul', b3β_, ∂3b));
b3v := array_binaryop('add',array_binaryop('mul', b3v, b3γ),array_binaryop('mul', b3γ_, array_binaryop('mul', ∂3b, ∂3b)));
mht := array_binaryop('div', b3m, array_fill(1 - power(0.900::float8,t0), array[32,16,16,64]));
vht := array_binaryop('div', b3v, array_fill(1 - power(0.999::float8,t0), array[32,16,16,64]));
b3 := array_binaryop('sub', b3, array_binaryop('div', array_binaryop('mul', mht, b3α),array_binaryop('add',array_unaryop('sqrt',vht),b3ε)));
-------------------------------------------------
w5m := array_binaryop('add',array_binaryop('mul', w5m, w5β),array_binaryop('mul', w5β_, ∂5w));
w5v := array_binaryop('add',array_binaryop('mul', w5v, w5γ),array_binaryop('mul', w5γ_, array_binaryop('mul', ∂5w, ∂5w)));
mht := array_binaryop('div', w5m, array_fill(1 - power(0.900::float8,t0), array[04096,01024]));
vht := array_binaryop('div', w5v, array_fill(1 - power(0.999::float8,t0), array[04096,01024]));
w5 := array_binaryop('sub', w5, array_binaryop('div', array_binaryop('mul', mht, w5α),array_binaryop('add',array_unaryop('sqrt',vht),w5ε)));
-------------------------------------------------
b5m := array_binaryop('add',array_binaryop('mul', b5m, b5β),array_binaryop('mul', b5β_, ∂5b));
b5v := array_binaryop('add',array_binaryop('mul', b5v, b5γ),array_binaryop('mul', b5γ_, array_binaryop('mul', ∂5b, ∂5b)));
mht := array_binaryop('div', b5m, array_fill(1 - power(0.900::float8,t0), array[00032,01024]));
vht := array_binaryop('div', b5v, array_fill(1 - power(0.999::float8,t0), array[00032,01024]));
b5 := array_binaryop('sub', b5, array_binaryop('div', array_binaryop('mul', mht, b5α),array_binaryop('add',array_unaryop('sqrt',vht),b5ε)));
-------------------------------------------------
w6m := array_binaryop('add',array_binaryop('mul', w6m, w6β),array_binaryop('mul', w6β_, ∂6w));
w6v := array_binaryop('add',array_binaryop('mul', w6v, w6γ),array_binaryop('mul', w6γ_, array_binaryop('mul', ∂6w, ∂6w)));
mht := array_binaryop('div', w6m, array_fill(1 - power(0.900::float8,t0), array[01024,00002]));
vht := array_binaryop('div', w6v, array_fill(1 - power(0.999::float8,t0), array[01024,00002]));
w6 := array_binaryop('sub', w6, array_binaryop('div', array_binaryop('mul', mht, w6α),array_binaryop('add',array_unaryop('sqrt',vht),w6ε)));
-------------------------------------------------
b6m := array_binaryop('add',array_binaryop('mul', b6m, b6β),array_binaryop('mul', b6β_, ∂6b));
b6v := array_binaryop('add',array_binaryop('mul', b6v, b6γ),array_binaryop('mul', b6γ_, array_binaryop('mul', ∂6b, ∂6b)));
mht := array_binaryop('div', b6m, array_fill(1 - power(0.900::float8,t0), array[00032,00002]));
vht := array_binaryop('div', b6v, array_fill(1 - power(0.999::float8,t0), array[00032,00002]));
b6 := array_binaryop('sub', b6, array_binaryop('div', array_binaryop('mul', mht, b6α),array_binaryop('add',array_unaryop('sqrt',vht),b6ε)));
---------------------------------------------------------------------------------------------------
ed := clock_timestamp();
raise notice 'cost : %, epoch : %, accuracy : %', extract(epoch from (ed - st)), t0, a7;
if a7[1] > $1 then
raise notice 'epoch % train accuracy % meets expected goal %', t0, a7, $1;
end if;
---------------------------------------------------------------------------------------------------
end loop;
end loop;
---------------------------------------------------------------------------------------------------
insert into public.cat_dog_model(layer,name,value) values(1,'w1' ,w1 );
insert into public.cat_dog_model(layer,name,value) values(1,'b1' ,b1 );
insert into public.cat_dog_model(layer,name,value) values(2,'w2' ,w2 );
insert into public.cat_dog_model(layer,name,value) values(2,'b2' ,b2 );
insert into public.cat_dog_model(layer,name,value) values(3,'w3' ,w3 );
insert into public.cat_dog_model(layer,name,value) values(3,'b3' ,b3 );
insert into public.cat_dog_model(layer,name,value) values(5,'w5' ,w5 );
insert into public.cat_dog_model(layer,name,value) values(5,'b5' ,b5 );
insert into public.cat_dog_model(layer,name,value) values(6,'w6' ,w6 );
insert into public.cat_dog_model(layer,name,value) values(6,'b6' ,b6 );
---------------------------------------------------------------------------------------------------
insert into public.cat_dog_model(layer,name,value) values(1,'w1m',w1m);
insert into public.cat_dog_model(layer,name,value) values(1,'b1m',b1m);
insert into public.cat_dog_model(layer,name,value) values(2,'w2m',w2m);
insert into public.cat_dog_model(layer,name,value) values(2,'b2m',b2m);
insert into public.cat_dog_model(layer,name,value) values(3,'w3m',w3m);
insert into public.cat_dog_model(layer,name,value) values(3,'b3m',b3m);
insert into public.cat_dog_model(layer,name,value) values(5,'w5m',w5m);
insert into public.cat_dog_model(layer,name,value) values(5,'b5m',b5m);
insert into public.cat_dog_model(layer,name,value) values(6,'w6m',w6m);
insert into public.cat_dog_model(layer,name,value) values(6,'b6m',b6m);
---------------------------------------------------------------------------------------------------
insert into public.cat_dog_model(layer,name,value) values(1,'w1v',w1v);
insert into public.cat_dog_model(layer,name,value) values(1,'b1v',b1v);
insert into public.cat_dog_model(layer,name,value) values(2,'w2v',w2v);
insert into public.cat_dog_model(layer,name,value) values(2,'b2v',b2v);
insert into public.cat_dog_model(layer,name,value) values(3,'w3v',w3v);
insert into public.cat_dog_model(layer,name,value) values(3,'b3v',b3v);
insert into public.cat_dog_model(layer,name,value) values(5,'w5v',w5v);
insert into public.cat_dog_model(layer,name,value) values(5,'b5v',b5v);
insert into public.cat_dog_model(layer,name,value) values(6,'w6v',w6v);
insert into public.cat_dog_model(layer,name,value) values(6,'b6v',b6v);
---------------------------------------------------------------------------------------------------
end;
$$ language plpgsql;
--start train
call cat_dog_train(0.95);
--a thousand years later, then dump result to sql file in sql folder
create table if not exists public.cv2_cat_dog_predict(id bigserial primary key,label int4,image float8[]);
--load predict data. psql -f sql/cv2_cat_dog_predict.sql or \i sql/cv2_cat_dog_predict.sql
--create convolutional neural network predict function
create or replace function cat_dog_predict(bigint) returns bigint as
$$
declare
im float8[] := (select array_agg(image) from public.cv2_cat_dog_predict where id = $1);
---------------------------------------------------------------------------------------------------Weights/Biases
w1 float8[] := (select value from public.cat_dog_model where layer = 1 and name = 'w1');
b1 float8[] := (select value[1:1][1:64][1:64][1:32] from public.cat_dog_model where layer = 1 and name = 'b1');
w2 float8[] := (select value from public.cat_dog_model where layer = 2 and name = 'w2');
b2 float8[] := (select value[1:1][1:32][1:32][1:32] from public.cat_dog_model where layer = 2 and name = 'b2');
w3 float8[] := (select value from public.cat_dog_model where layer = 3 and name = 'w3');
b3 float8[] := (select value[1:1][1:16][1:16][1:64] from public.cat_dog_model where layer = 3 and name = 'b3');
w5 float8[] := (select value from public.cat_dog_model where layer = 5 and name = 'w5');
b5 float8[] := (select value[1:1][1:1024] from public.cat_dog_model where layer = 5 and name = 'b5');
w6 float8[] := (select value from public.cat_dog_model where layer = 6 and name = 'w6');
b6 float8[] := (select value[1:1][1:0002] from public.cat_dog_model where layer = 6 and name = 'b6');
---------------------------------------------------------------------------------------------------layer
i0 float8[];
l0 float8[];
l1 float8[];
l2 float8[];
l3 float8[];
l4 float8[];
l5 float8[];
l6 float8[];
e7 float8[];
c7 float8[];
s7 float8[];
a7 float8[];
---------------------------------------------------------------------------------------------------
begin
i0 := array_binaryop('div',im,array_fill(255.0::float8, array[01,64,64,03]));
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',i0,w1,array[1,1,1,1]::int4[],'SAME') into l1;
select array_binaryop('add',l1,b1) into l1;
select array_activate('relu', l1, NULL) into l1;
select array_pool('max','NHWC',l1,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l1;
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',l1,w2,array[1,1,1,1]::int4[],'SAME') into l2;
select array_binaryop('add',l2,b2) into l2;
select array_activate('relu', l2, NULL) into l2;
select array_pool('max','NHWC',l2,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l2;
---------------------------------------------------------------------------------------------------conv2d
select array_convolve('NHWC',l2,w3,array[1,1,1,1]::int4[],'SAME') into l3;
select array_binaryop('add',l3,b3) into l3;
select array_activate('relu', l3, NULL) into l3;
select array_pool('max','NHWC',l3,array[1,2,2,1]::int4[],array[1,2,2,1]::int4[],'SAME') into l3;
---------------------------------------------------------------------------------------------------flatten
select array_reshape(l3,array[1,4096]::int4[]) into l4;
---------------------------------------------------------------------------------------------------dense
select array_matmul(l4,w5, array[0,1]::int4[], NULL) into l5;
select array_binaryop('add',l5,b5) into l5;
select array_dropout(l5, 0.3, NULL, 20) into l5;
select array_activate('relu', l5, NULL) into l5;
---------------------------------------------------------------------------------------------------dense
select array_matmul(l5,w6, array[0,1]::int4[], NULL) into l6;
select array_binaryop('add',l6,b6) into l6;
select array_dropout(l6, 0.3, NULL, 20) into l6;
---------------------------------------------------------------------------------------------------predict
select array_softmax(l6,1) into s7;
select array_argpos('argmax', s7, 1) into a7;
return a7[1];
end;
$$ language plpgsql;
--test predict
select cat_dog_predict(1); --return 0 dog
select cat_dog_predict(300); --return 1 cat