forked from scijs/ndarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathndarray.min.js
More file actions
1 lines (1 loc) · 6.15 KB
/
Copy pathndarray.min.js
File metadata and controls
1 lines (1 loc) · 6.15 KB
1
var t="undefined"!=typeof Float64Array;function r(t,r){return t[0]-r[0]}function n(){var t,n=this.stride,e=new Array(n.length);for(t=0;t<e.length;++t)e[t]=[Math.abs(n[t]),t];e.sort(r);var i=new Array(e.length);for(t=0;t<i.length;++t)i[t]=e[t][1];return i}function e(t,r){var e=["View",r,"d",t].join("");r<0&&(e="View_Nil"+t);var o="generic"===t;if(-1===r){var s="function "+e+"(a){this.data=a;};var proto="+e+".prototype;proto.dtype='"+t+"';proto.index=function(){return -1};proto.size=0;proto.dimension=-1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function(){return new "+e+"(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_"+e+"(a){return new "+e+"(a);}";return new Function(s)()}if(0===r){s="function "+e+"(a,d) {this.data = a;this.offset = d};var proto="+e+".prototype;proto.dtype='"+t+"';proto.index=function(){return this.offset};proto.dimension=0;proto.size=1;proto.shape=proto.stride=proto.order=[];proto.lo=proto.hi=proto.transpose=proto.step=function "+e+"_copy() {return new "+e+"(this.data,this.offset)};proto.pick=function "+e+"_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function "+e+"_get(){return "+(o?"this.data.get(this.offset)":"this.data[this.offset]")+"};proto.set=function "+e+"_set(v){return "+(o?"this.data.set(this.offset,v)":"this.data[this.offset]=v")+"};return function construct_"+e+"(a,b,c,d){return new "+e+"(a,d)}";return new Function("TrivialArray",s)(i[t][0])}s=["'use strict'"];var a=function(t){for(var r=new Array(t),n=0;n<t;++n)r[n]=n;return r}(r),u=a.map((function(t){return"i"+t})),p="this.offset+"+a.map((function(t){return"this.stride["+t+"]*i"+t})).join("+"),f=a.map((function(t){return"b"+t})).join(","),h=a.map((function(t){return"c"+t})).join(",");s.push("function "+e+"(a,"+f+","+h+",d){this.data=a","this.shape=["+f+"]","this.stride=["+h+"]","this.offset=d|0}","var proto="+e+".prototype","proto.dtype='"+t+"'","proto.dimension="+r),s.push("Object.defineProperty(proto,'size',{get:function "+e+"_size(){return "+a.map((function(t){return"this.shape["+t+"]"})).join("*"),"}})"),1===r?s.push("proto.order=[0]"):(s.push("Object.defineProperty(proto,'order',{get:"),r<4?(s.push("function "+e+"_order(){"),2===r?s.push("return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})"):3===r&&s.push("var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):s.push("ORDER})")),s.push("proto.set=function "+e+"_set("+u.join(",")+",v){"),o?s.push("return this.data.set("+p+",v)}"):s.push("return this.data["+p+"]=v}"),s.push("proto.get=function "+e+"_get("+u.join(",")+"){"),o?s.push("return this.data.get("+p+")}"):s.push("return this.data["+p+"]}"),s.push("proto.index=function "+e+"_index(",u.join(),"){return "+p+"}"),s.push("proto.hi=function "+e+"_hi("+u.join(",")+"){return new "+e+"(this.data,"+a.map((function(t){return["(typeof i",t,"!=='number'||i",t,"<0)?this.shape[",t,"]:i",t,"|0"].join("")})).join(",")+","+a.map((function(t){return"this.stride["+t+"]"})).join(",")+",this.offset)}");var c=a.map((function(t){return"a"+t+"=this.shape["+t+"]"})),d=a.map((function(t){return"c"+t+"=this.stride["+t+"]"}));s.push("proto.lo=function "+e+"_lo("+u.join(",")+"){var b=this.offset,d=0,"+c.join(",")+","+d.join(","));for(var b=0;b<r;++b)s.push("if(typeof i"+b+"==='number'&&i"+b+">=0){d=i"+b+"|0;b+=c"+b+"*d;a"+b+"-=d}");s.push("return new "+e+"(this.data,"+a.map((function(t){return"a"+t})).join(",")+","+a.map((function(t){return"c"+t})).join(",")+",b)}"),s.push("proto.step=function "+e+"_step("+u.join(",")+"){var "+a.map((function(t){return"a"+t+"=this.shape["+t+"]"})).join(",")+","+a.map((function(t){return"b"+t+"=this.stride["+t+"]"})).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(b=0;b<r;++b)s.push("if(typeof i"+b+"==='number'){d=i"+b+"|0;if(d<0){c+=b"+b+"*(a"+b+"-1);a"+b+"=ceil(-a"+b+"/d)}else{a"+b+"=ceil(a"+b+"/d)}b"+b+"*=d}");s.push("return new "+e+"(this.data,"+a.map((function(t){return"a"+t})).join(",")+","+a.map((function(t){return"b"+t})).join(",")+",c)}");var l=new Array(r),j=new Array(r);for(b=0;b<r;++b)l[b]="a[i"+b+"]",j[b]="b[i"+b+"]";s.push("proto.transpose=function "+e+"_transpose("+u+"){"+u.map((function(t,r){return t+"=("+t+"===undefined?"+r+":"+t+"|0)"})).join(";"),"var a=this.shape,b=this.stride;return new "+e+"(this.data,"+l.join(",")+","+j.join(",")+",this.offset)}"),s.push("proto.pick=function "+e+"_pick("+u+"){var a=[],b=[],c=this.offset");for(b=0;b<r;++b)s.push("if(typeof i"+b+"==='number'&&i"+b+">=0){c=(c+this.stride["+b+"]*i"+b+")|0}else{a.push(this.shape["+b+"]);b.push(this.stride["+b+"])}");return s.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),s.push("return function construct_"+e+"(data,shape,stride,offset){return new "+e+"(data,"+a.map((function(t){return"shape["+t+"]"})).join(",")+","+a.map((function(t){return"stride["+t+"]"})).join(",")+",offset)}"),new Function("CTOR_LIST","ORDER",s.join("\n"))(i[t],n)}var i={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};function o(r,n,o,s){if(void 0===r)return(0,i.array[0])([]);"number"==typeof r&&(r=[r]),void 0===n&&(n=[r.length]);var a=n.length;if(void 0===o){o=new Array(a);for(var u=a-1,p=1;u>=0;--u)o[u]=p,p*=n[u]}if(void 0===s){s=0;for(u=0;u<a;++u)o[u]<0&&(s-=(n[u]-1)*o[u])}for(var f=function(r){if(t)switch(Object.prototype.toString.call(r)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped";case"[object BigInt64Array]":return"bigint64";case"[object BigUint64Array]":return"biguint64"}return Array.isArray(r)?"array":"generic"}(r),h=i[f];h.length<=a+1;)h.push(e(f,h.length-1));return(0,h[a+1])(r,n,o,s)}export{o as default};