From b1dc676c45cd37863122ace3ae677efea81dedea Mon Sep 17 00:00:00 2001 From: archmoj Date: Sat, 7 Aug 2021 12:57:17 -0400 Subject: [PATCH 01/15] ignore lock file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ddc9ab3..c7b283a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ logs results npm-debug.log +package-lock.json node_modules/* *.DS_Store \ No newline at end of file From 24777661dbecf1ceb5ac423b3a645436fa6960f9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Sat, 7 Aug 2021 12:57:43 -0400 Subject: [PATCH 02/15] bump version as a minor --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbfb670..d5367b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndarray", - "version": "1.0.19", + "version": "1.1.0", "description": "Multidimensional Arrays", "main": "ndarray.js", "directories": { From a696247f6333bd0c2f2e6b756ab59db51130bd4a Mon Sep 17 00:00:00 2001 From: archmoj Date: Sat, 7 Aug 2021 15:45:08 -0400 Subject: [PATCH 03/15] use variable names different from the keys used in constructor functions --- ndarray.js | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/ndarray.js b/ndarray.js index 43c9b5a..4c68b86 100644 --- a/ndarray.js +++ b/ndarray.js @@ -22,19 +22,19 @@ function order() { return result } -function compileConstructor(dtype, dimension) { - var className = ["View", dimension, "d", dtype].join("") - if(dimension < 0) { - className = "View_Nil" + dtype +function compileConstructor(inType, inDimension) { + var className = ["View", inDimension, "d", inType].join("") + if(inDimension < 0) { + className = "View_Nil" + inType } - var useGetters = (dtype === "generic") + var useGetters = (inType === "generic") - if(dimension === -1) { + if(inDimension === -1) { //Special case for trivial arrays var code = "function "+className+"(a){this.data=a;};\ var proto="+className+".prototype;\ -proto.dtype='"+dtype+"';\ +proto.dtype='"+inType+"';\ proto.index=function(){return -1};\ proto.size=0;\ proto.dimension=-1;\ @@ -46,7 +46,7 @@ proto.pick=function(){return null};\ return function construct_"+className+"(a){return new "+className+"(a);}" var procedure = new Function(code) return procedure() - } else if(dimension === 0) { + } else if(inDimension === 0) { //Special case for 0d arrays var code = "function "+className+"(a,d) {\ @@ -54,7 +54,7 @@ this.data = a;\ this.offset = d\ };\ var proto="+className+".prototype;\ -proto.dtype='"+dtype+"';\ +proto.dtype='"+inType+"';\ proto.index=function(){return this.offset};\ proto.dimension=0;\ proto.size=1;\ @@ -78,13 +78,13 @@ return "+(useGetters ? "this.data.set(this.offset,v)" : "this.data[this.offset]= };\ return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" var procedure = new Function("TrivialArray", code) - return procedure(CACHED_CONSTRUCTORS[dtype][0]) + return procedure(CACHED_CONSTRUCTORS[inType][0]) } var code = ["'use strict'"] //Create constructor for view - var indices = iota(dimension) + var indices = iota(inDimension) var args = indices.map(function(i) { return "i"+i }) var index_str = "this.offset+" + indices.map(function(i) { return "this.stride[" + i + "]*i" + i @@ -101,8 +101,8 @@ return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" "this.stride=[" + strideArg + "]", "this.offset=d|0}", "var proto="+className+".prototype", - "proto.dtype='"+dtype+"'", - "proto.dimension="+dimension) + "proto.dtype='"+inType+"'", + "proto.dimension="+inDimension) //view.size: code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){\ @@ -110,15 +110,15 @@ return "+indices.map(function(i) { return "this.shape["+i+"]" }).join("*"), "}})") //view.order: - if(dimension === 1) { + if(inDimension === 1) { code.push("proto.order=[0]") } else { code.push("Object.defineProperty(proto,'order',{get:") - if(dimension < 4) { + if(inDimension < 4) { code.push("function "+className+"_order(){") - if(dimension === 2) { + if(inDimension === 2) { code.push("return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})") - } else if(dimension === 3) { + } else if(inDimension === 3) { code.push( "var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);\ if(s0>s1){\ @@ -176,7 +176,7 @@ return [0,2,1];\ var a_vars = indices.map(function(i) { return "a"+i+"=this.shape["+i+"]" }) var c_vars = indices.map(function(i) { return "c"+i+"=this.stride["+i+"]" }) code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(",")) - for(var i=0; i=0){\ d=i"+i+"|0;\ @@ -199,7 +199,7 @@ a"+i+"-=d}") indices.map(function(i) { return "b"+i+"=this.stride["+i+"]" }).join(",")+",c=this.offset,d=0,ceil=Math.ceil") - for(var i=0; i=0){c=(c+this.stride["+i+"]*i"+i+")|0}else{a.push(this.shape["+i+"]);b.push(this.stride["+i+"])}") } code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}") @@ -249,7 +249,7 @@ b"+i+"*=d\ //Compile procedure var procedure = new Function("CTOR_LIST", "ORDER", code.join("\n")) - return procedure(CACHED_CONSTRUCTORS[dtype], order) + return procedure(CACHED_CONSTRUCTORS[inType], order) } function arrayDType(data) { @@ -337,10 +337,10 @@ function wrappedNDArrayCtor(data, shape, stride, offset) { } } } - var dtype = arrayDType(data) - var ctor_list = CACHED_CONSTRUCTORS[dtype] + var inType = arrayDType(data) + var ctor_list = CACHED_CONSTRUCTORS[inType] while(ctor_list.length <= d+1) { - ctor_list.push(compileConstructor(dtype, ctor_list.length-1)) + ctor_list.push(compileConstructor(inType, ctor_list.length-1)) } var ctor = ctor_list[d+1] return ctor(data, shape, stride, offset) From 80ccd157696e8a088d3ba898fa35c011a692aad1 Mon Sep 17 00:00:00 2001 From: archmoj Date: Sat, 7 Aug 2021 20:49:41 -0400 Subject: [PATCH 04/15] pass in dtype --- ndarray.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ndarray.js b/ndarray.js index 4c68b86..257e5d7 100644 --- a/ndarray.js +++ b/ndarray.js @@ -34,7 +34,7 @@ function compileConstructor(inType, inDimension) { var code = "function "+className+"(a){this.data=a;};\ var proto="+className+".prototype;\ -proto.dtype='"+inType+"';\ +proto.dtype=dtype;\ proto.index=function(){return -1};\ proto.size=0;\ proto.dimension=-1;\ @@ -44,8 +44,8 @@ function(){return new "+className+"(this.data);};\ proto.get=proto.set=function(){};\ proto.pick=function(){return null};\ return function construct_"+className+"(a){return new "+className+"(a);}" - var procedure = new Function(code) - return procedure() + var procedure = new Function("dtype", code) + return procedure(inType) } else if(inDimension === 0) { //Special case for 0d arrays var code = @@ -54,7 +54,7 @@ this.data = a;\ this.offset = d\ };\ var proto="+className+".prototype;\ -proto.dtype='"+inType+"';\ +proto.dtype=dtype;\ proto.index=function(){return this.offset};\ proto.dimension=0;\ proto.size=1;\ @@ -77,8 +77,8 @@ proto.set=function "+className+"_set(v){\ return "+(useGetters ? "this.data.set(this.offset,v)" : "this.data[this.offset]=v")+"\ };\ return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" - var procedure = new Function("TrivialArray", code) - return procedure(CACHED_CONSTRUCTORS[inType][0]) + var procedure = new Function("dtype", "TrivialArray", code) + return procedure(inType, CACHED_CONSTRUCTORS[inType][0]) } var code = ["'use strict'"] @@ -101,7 +101,7 @@ return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" "this.stride=[" + strideArg + "]", "this.offset=d|0}", "var proto="+className+".prototype", - "proto.dtype='"+inType+"'", + "proto.dtype=dtype", "proto.dimension="+inDimension) //view.size: @@ -248,8 +248,8 @@ b"+i+"*=d\ }).join(",")+",offset)}") //Compile procedure - var procedure = new Function("CTOR_LIST", "ORDER", code.join("\n")) - return procedure(CACHED_CONSTRUCTORS[inType], order) + var procedure = new Function("dtype", "CTOR_LIST", "ORDER", code.join("\n")) + return procedure(inType, CACHED_CONSTRUCTORS[inType], order) } function arrayDType(data) { From 09167845a27d15aa24ff9101c40cf1196011c702 Mon Sep 17 00:00:00 2001 From: archmoj Date: Sat, 7 Aug 2021 21:04:21 -0400 Subject: [PATCH 05/15] handle generic case inside functions --- ndarray.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/ndarray.js b/ndarray.js index 257e5d7..e8c0673 100644 --- a/ndarray.js +++ b/ndarray.js @@ -27,7 +27,6 @@ function compileConstructor(inType, inDimension) { if(inDimension < 0) { className = "View_Nil" + inType } - var useGetters = (inType === "generic") if(inDimension === -1) { //Special case for trivial arrays @@ -71,11 +70,9 @@ proto.pick=function "+className+"_pick(){\ return TrivialArray(this.data);\ };\ proto.valueOf=proto.get=function "+className+"_get(){\ -return "+(useGetters ? "this.data.get(this.offset)" : "this.data[this.offset]")+ -"};\ +return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};\ proto.set=function "+className+"_set(v){\ -return "+(useGetters ? "this.data.set(this.offset,v)" : "this.data[this.offset]=v")+"\ -};\ +return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};\ return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" var procedure = new Function("dtype", "TrivialArray", code) return procedure(inType, CACHED_CONSTRUCTORS[inType][0]) @@ -145,19 +142,13 @@ return [0,2,1];\ //view.set(i0, ..., v): code.push( "proto.set=function "+className+"_set("+args.join(",")+",v){") - if(useGetters) { - code.push("return this.data.set("+index_str+",v)}") - } else { - code.push("return this.data["+index_str+"]=v}") - } + code.push( + "return dtype === 'generic' ? this.data.set("+index_str+",v) : this.data["+index_str+"]=v;};") //view.get(i0, ...): code.push("proto.get=function "+className+"_get("+args.join(",")+"){") - if(useGetters) { - code.push("return this.data.get("+index_str+")}") - } else { - code.push("return this.data["+index_str+"]}") - } + code.push( + "return dtype === 'generic' ? this.data.get("+index_str+") : this.data["+index_str+"];};") //view.index: code.push( From e49059d1405db927ddf755817e8787b9c154d61a Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 10:40:44 -0400 Subject: [PATCH 06/15] it appears there is no need to use dtype in classname --- ndarray.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ndarray.js b/ndarray.js index e8c0673..69843d7 100644 --- a/ndarray.js +++ b/ndarray.js @@ -23,10 +23,8 @@ function order() { } function compileConstructor(inType, inDimension) { - var className = ["View", inDimension, "d", inType].join("") - if(inDimension < 0) { - className = "View_Nil" + inType - } + var dKey = inDimension === -1 ? 'G' : inDimension + var className = "View" + dKey if(inDimension === -1) { //Special case for trivial arrays From 29196191be7a11e55d05be200b5f508787d50926 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 11:36:18 -0400 Subject: [PATCH 07/15] convert function constructors to normal functions from -1 to 5d --- ndarray.js | 416 ++++++++++++++++++++++++++--------------------------- 1 file changed, 207 insertions(+), 209 deletions(-) diff --git a/ndarray.js b/ndarray.js index 69843d7..90997cf 100644 --- a/ndarray.js +++ b/ndarray.js @@ -22,222 +22,220 @@ function order() { return result } +var allFns = { + 'G': function(dtype) { + function ViewG(a){this.data=a;};var proto=ViewG.prototype;proto.dtype=dtype;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 ViewG(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_ViewG(a){return new ViewG(a);} + }, + '0': function(dtype,TrivialArray) { + function View0(a,d) {this.data = a;this.offset = d};var proto=View0.prototype;proto.dtype=dtype;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 View0_copy() {return new View0(this.data,this.offset)};proto.pick=function View0_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function View0_get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function View0_set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct_View0(a,b,c,d){return new View0(a,d)} + }, + '1': function(dtype,CTOR_LIST,ORDER) { + function View1(a,b0,c0,d){this.data=a + this.shape=[b0] + this.stride=[c0] + this.offset=d|0} + var proto=View1.prototype + proto.dtype=dtype + proto.dimension=1 + Object.defineProperty(proto,'size',{get:function View1_size(){return this.shape[0] + }}) + proto.order=[0] + proto.set=function View1_set(i0,v){ + return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0,v) : this.data[this.offset+this.stride[0]*i0]=v;}; + proto.get=function View1_get(i0){ + return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0) : this.data[this.offset+this.stride[0]*i0];}; + proto.index=function View1_index( + i0 + ){return this.offset+this.stride[0]*i0} + proto.hi=function View1_hi(i0){return new View1(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} + proto.lo=function View1_lo(i0){var b=this.offset,d=0,a0=this.shape[0],c0=this.stride[0] + if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} + return new View1(this.data,a0,c0,b)} + proto.step=function View1_step(i0){var a0=this.shape[0],b0=this.stride[0],c=this.offset,d=0,ceil=Math.ceil + if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} + return new View1(this.data,a0,b0,c)} + proto.transpose=function View1_transpose(i0){i0=(i0===undefined?0:i0|0) + var a=this.shape,b=this.stride;return new View1(this.data,a[i0],b[i0],this.offset)} + proto.pick=function View1_pick(i0){var a=[],b=[],c=this.offset + if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} + var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} + return function construct_View1(data,shape,stride,offset){return new View1(data,shape[0],stride[0],offset)} + }, + '2': function(dtype,CTOR_LIST,ORDER) { + function View2(a,b0,b1,c0,c1,d){this.data=a + this.shape=[b0,b1] + this.stride=[c0,c1] + this.offset=d|0} + var proto=View2.prototype + proto.dtype=dtype + proto.dimension=2 + Object.defineProperty(proto,'size',{get:function View2_size(){return this.shape[0]*this.shape[1] + }}) + Object.defineProperty(proto,'order',{get: + function View2_order(){ + return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}}) + proto.set=function View2_set(i0,i1,v){ + return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1]=v;}; + proto.get=function View2_get(i0,i1){ + return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1];}; + proto.index=function View2_index( + i0,i1 + ){return this.offset+this.stride[0]*i0+this.stride[1]*i1} + proto.hi=function View2_hi(i0,i1){return new View2(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} + proto.lo=function View2_lo(i0,i1){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],c0=this.stride[0],c1=this.stride[1] + if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} + if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} + return new View2(this.data,a0,a1,c0,c1,b)} + proto.step=function View2_step(i0,i1){var a0=this.shape[0],a1=this.shape[1],b0=this.stride[0],b1=this.stride[1],c=this.offset,d=0,ceil=Math.ceil + if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} + if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} + return new View2(this.data,a0,a1,b0,b1,c)} + proto.transpose=function View2_transpose(i0,i1){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0) + var a=this.shape,b=this.stride;return new View2(this.data,a[i0],a[i1],b[i0],b[i1],this.offset)} + proto.pick=function View2_pick(i0,i1){var a=[],b=[],c=this.offset + if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} + if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} + var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} + return function construct_View2(data,shape,stride,offset){return new View2(data,shape[0],shape[1],stride[0],stride[1],offset)} + }, + '3': function(dtype,CTOR_LIST,ORDER) { + function View3(a,b0,b1,b2,c0,c1,c2,d){this.data=a + this.shape=[b0,b1,b2] + this.stride=[c0,c1,c2] + this.offset=d|0} + var proto=View3.prototype + proto.dtype=dtype + proto.dimension=3 + Object.defineProperty(proto,'size',{get:function View3_size(){return this.shape[0]*this.shape[1]*this.shape[2] + }}) + Object.defineProperty(proto,'order',{get: + function View3_order(){ + 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];}}}) + proto.set=function View3_set(i0,i1,i2,v){ + return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2]=v;}; + proto.get=function View3_get(i0,i1,i2){ + return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2];}; + proto.index=function View3_index( + i0,i1,i2 + ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2} + proto.hi=function View3_hi(i0,i1,i2){return new View3(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} + proto.lo=function View3_lo(i0,i1,i2){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2] + if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} + if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} + if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} + return new View3(this.data,a0,a1,a2,c0,c1,c2,b)} + proto.step=function View3_step(i0,i1,i2){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],c=this.offset,d=0,ceil=Math.ceil + if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} + if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} + if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} + return new View3(this.data,a0,a1,a2,b0,b1,b2,c)} + proto.transpose=function View3_transpose(i0,i1,i2){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0) + var a=this.shape,b=this.stride;return new View3(this.data,a[i0],a[i1],a[i2],b[i0],b[i1],b[i2],this.offset)} + proto.pick=function View3_pick(i0,i1,i2){var a=[],b=[],c=this.offset + if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} + if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} + if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} + var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} + return function construct_View3(data,shape,stride,offset){return new View3(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} + }, + '4': function(dtype,CTOR_LIST,ORDER) { + function View4(a,b0,b1,b2,b3,c0,c1,c2,c3,d){this.data=a + this.shape=[b0,b1,b2,b3] + this.stride=[c0,c1,c2,c3] + this.offset=d|0} + var proto=View4.prototype + proto.dtype=dtype + proto.dimension=4 + Object.defineProperty(proto,'size',{get:function View4_size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3] + }}) + Object.defineProperty(proto,'order',{get: + ORDER}) + proto.set=function View4_set(i0,i1,i2,i3,v){ + return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3]=v;}; + proto.get=function View4_get(i0,i1,i2,i3){ + return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3];}; + proto.index=function View4_index( + i0,i1,i2,i3 + ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3} + proto.hi=function View4_hi(i0,i1,i2,i3){return new View4(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} + proto.lo=function View4_lo(i0,i1,i2,i3){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3] + if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} + if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} + if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} + if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} + return new View4(this.data,a0,a1,a2,a3,c0,c1,c2,c3,b)} + proto.step=function View4_step(i0,i1,i2,i3){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],c=this.offset,d=0,ceil=Math.ceil + if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} + if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} + if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} + if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} + return new View4(this.data,a0,a1,a2,a3,b0,b1,b2,b3,c)} + proto.transpose=function View4_transpose(i0,i1,i2,i3){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0) + var a=this.shape,b=this.stride;return new View4(this.data,a[i0],a[i1],a[i2],a[i3],b[i0],b[i1],b[i2],b[i3],this.offset)} + proto.pick=function View4_pick(i0,i1,i2,i3){var a=[],b=[],c=this.offset + if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} + if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} + if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} + if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} + var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} + return function construct_View4(data,shape,stride,offset){return new View4(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} + }, + '5': function anonymous(dtype,CTOR_LIST,ORDER) { + function View5(a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4,d){this.data=a + this.shape=[b0,b1,b2,b3,b4] + this.stride=[c0,c1,c2,c3,c4] + this.offset=d|0} + var proto=View5.prototype + proto.dtype=dtype + proto.dimension=5 + Object.defineProperty(proto,'size',{get:function View5_size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4] + }}) + Object.defineProperty(proto,'order',{get: + ORDER}) + proto.set=function View5_set(i0,i1,i2,i3,i4,v){ + return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4]=v;}; + proto.get=function View5_get(i0,i1,i2,i3,i4){ + return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4];}; + proto.index=function View5_index( + i0,i1,i2,i3,i4 + ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4} + proto.hi=function View5_hi(i0,i1,i2,i3,i4){return new View5(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} + proto.lo=function View5_lo(i0,i1,i2,i3,i4){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3],c4=this.stride[4] + if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} + if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} + if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} + if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} + if(typeof i4==='number'&&i4>=0){d=i4|0;b+=c4*d;a4-=d} + return new View5(this.data,a0,a1,a2,a3,a4,c0,c1,c2,c3,c4,b)} + proto.step=function View5_step(i0,i1,i2,i3,i4){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],b4=this.stride[4],c=this.offset,d=0,ceil=Math.ceil + if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} + if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} + if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} + if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} + if(typeof i4==='number'){d=i4|0;if(d<0){c+=b4*(a4-1);a4=ceil(-a4/d)}else{a4=ceil(a4/d)}b4*=d} + return new View5(this.data,a0,a1,a2,a3,a4,b0,b1,b2,b3,b4,c)} + proto.transpose=function View5_transpose(i0,i1,i2,i3,i4){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0);i4=(i4===undefined?4:i4|0) + var a=this.shape,b=this.stride;return new View5(this.data,a[i0],a[i1],a[i2],a[i3],a[i4],b[i0],b[i1],b[i2],b[i3],b[i4],this.offset)} + proto.pick=function View5_pick(i0,i1,i2,i3,i4){var a=[],b=[],c=this.offset + if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} + if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} + if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} + if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} + if(typeof i4==='number'&&i4>=0){c=(c+this.stride[4]*i4)|0}else{a.push(this.shape[4]);b.push(this.stride[4])} + var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} + return function construct_View5(data,shape,stride,offset){return new View5(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} + } +} + function compileConstructor(inType, inDimension) { - var dKey = inDimension === -1 ? 'G' : inDimension - var className = "View" + dKey + var dKey = inDimension === -1 ? 'G' : String(inDimension) + var procedure = allFns[dKey] if(inDimension === -1) { - //Special case for trivial arrays - var code = - "function "+className+"(a){this.data=a;};\ -var proto="+className+".prototype;\ -proto.dtype=dtype;\ -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 "+className+"(this.data);};\ -proto.get=proto.set=function(){};\ -proto.pick=function(){return null};\ -return function construct_"+className+"(a){return new "+className+"(a);}" - var procedure = new Function("dtype", code) return procedure(inType) } else if(inDimension === 0) { - //Special case for 0d arrays - var code = - "function "+className+"(a,d) {\ -this.data = a;\ -this.offset = d\ -};\ -var proto="+className+".prototype;\ -proto.dtype=dtype;\ -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 "+className+"_copy() {\ -return new "+className+"(this.data,this.offset)\ -};\ -proto.pick=function "+className+"_pick(){\ -return TrivialArray(this.data);\ -};\ -proto.valueOf=proto.get=function "+className+"_get(){\ -return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};\ -proto.set=function "+className+"_set(v){\ -return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};\ -return function construct_"+className+"(a,b,c,d){return new "+className+"(a,d)}" - var procedure = new Function("dtype", "TrivialArray", code) return procedure(inType, CACHED_CONSTRUCTORS[inType][0]) } - - var code = ["'use strict'"] - - //Create constructor for view - var indices = iota(inDimension) - var args = indices.map(function(i) { return "i"+i }) - var index_str = "this.offset+" + indices.map(function(i) { - return "this.stride[" + i + "]*i" + i - }).join("+") - var shapeArg = indices.map(function(i) { - return "b"+i - }).join(",") - var strideArg = indices.map(function(i) { - return "c"+i - }).join(",") - code.push( - "function "+className+"(a," + shapeArg + "," + strideArg + ",d){this.data=a", - "this.shape=[" + shapeArg + "]", - "this.stride=[" + strideArg + "]", - "this.offset=d|0}", - "var proto="+className+".prototype", - "proto.dtype=dtype", - "proto.dimension="+inDimension) - - //view.size: - code.push("Object.defineProperty(proto,'size',{get:function "+className+"_size(){\ -return "+indices.map(function(i) { return "this.shape["+i+"]" }).join("*"), -"}})") - - //view.order: - if(inDimension === 1) { - code.push("proto.order=[0]") - } else { - code.push("Object.defineProperty(proto,'order',{get:") - if(inDimension < 4) { - code.push("function "+className+"_order(){") - if(inDimension === 2) { - code.push("return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}})") - } else if(inDimension === 3) { - code.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];\ -}}})") - } - } else { - code.push("ORDER})") - } - } - - //view.set(i0, ..., v): - code.push( -"proto.set=function "+className+"_set("+args.join(",")+",v){") - code.push( - "return dtype === 'generic' ? this.data.set("+index_str+",v) : this.data["+index_str+"]=v;};") - - //view.get(i0, ...): - code.push("proto.get=function "+className+"_get("+args.join(",")+"){") - code.push( - "return dtype === 'generic' ? this.data.get("+index_str+") : this.data["+index_str+"];};") - - //view.index: - code.push( - "proto.index=function "+className+"_index(", args.join(), "){return "+index_str+"}") - - //view.hi(): - code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+ - indices.map(function(i) { - return ["(typeof i",i,"!=='number'||i",i,"<0)?this.shape[", i, "]:i", i,"|0"].join("") - }).join(",")+","+ - indices.map(function(i) { - return "this.stride["+i + "]" - }).join(",")+",this.offset)}") - - //view.lo(): - var a_vars = indices.map(function(i) { return "a"+i+"=this.shape["+i+"]" }) - var c_vars = indices.map(function(i) { return "c"+i+"=this.stride["+i+"]" }) - code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(",")) - for(var i=0; i=0){\ -d=i"+i+"|0;\ -b+=c"+i+"*d;\ -a"+i+"-=d}") - } - code.push("return new "+className+"(this.data,"+ - indices.map(function(i) { - return "a"+i - }).join(",")+","+ - indices.map(function(i) { - return "c"+i - }).join(",")+",b)}") - - //view.step(): - code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+ - indices.map(function(i) { - return "a"+i+"=this.shape["+i+"]" - }).join(",")+","+ - indices.map(function(i) { - return "b"+i+"=this.stride["+i+"]" - }).join(",")+",c=this.offset,d=0,ceil=Math.ceil") - for(var i=0; i=0){c=(c+this.stride["+i+"]*i"+i+")|0}else{a.push(this.shape["+i+"]);b.push(this.stride["+i+"])}") - } - code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}") - - //Add return statement - code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+ - indices.map(function(i) { - return "shape["+i+"]" - }).join(",")+","+ - indices.map(function(i) { - return "stride["+i+"]" - }).join(",")+",offset)}") - - //Compile procedure - var procedure = new Function("dtype", "CTOR_LIST", "ORDER", code.join("\n")) return procedure(inType, CACHED_CONSTRUCTORS[inType], order) } From 817589f30252b1355d3dc533a9d17466e4df6b5b Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 11:50:30 -0400 Subject: [PATCH 08/15] simplfiy function names --- ndarray.js | 108 ++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/ndarray.js b/ndarray.js index 90997cf..17c1943 100644 --- a/ndarray.js +++ b/ndarray.js @@ -24,10 +24,10 @@ function order() { var allFns = { 'G': function(dtype) { - function ViewG(a){this.data=a;};var proto=ViewG.prototype;proto.dtype=dtype;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 ViewG(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct_ViewG(a){return new ViewG(a);} + function ViewG(a){this.data=a;};var proto=ViewG.prototype;proto.dtype=dtype;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 ViewG(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct(a){return new ViewG(a);} }, '0': function(dtype,TrivialArray) { - function View0(a,d) {this.data = a;this.offset = d};var proto=View0.prototype;proto.dtype=dtype;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 View0_copy() {return new View0(this.data,this.offset)};proto.pick=function View0_pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function View0_get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function View0_set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct_View0(a,b,c,d){return new View0(a,d)} + function View0(a,d) {this.data = a;this.offset = d};var proto=View0.prototype;proto.dtype=dtype;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 copy() {return new View0(this.data,this.offset)};proto.pick=function pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct(a,b,c,d){return new View0(a,d)} }, '1': function(dtype,CTOR_LIST,ORDER) { function View1(a,b0,c0,d){this.data=a @@ -37,29 +37,29 @@ var allFns = { var proto=View1.prototype proto.dtype=dtype proto.dimension=1 - Object.defineProperty(proto,'size',{get:function View1_size(){return this.shape[0] + Object.defineProperty(proto,'size',{get:function size(){return this.shape[0] }}) proto.order=[0] - proto.set=function View1_set(i0,v){ + proto.set=function set(i0,v){ return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0,v) : this.data[this.offset+this.stride[0]*i0]=v;}; - proto.get=function View1_get(i0){ + proto.get=function get(i0){ return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0) : this.data[this.offset+this.stride[0]*i0];}; - proto.index=function View1_index( + proto.index=function index( i0 ){return this.offset+this.stride[0]*i0} - proto.hi=function View1_hi(i0){return new View1(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} - proto.lo=function View1_lo(i0){var b=this.offset,d=0,a0=this.shape[0],c0=this.stride[0] + proto.hi=function hi(i0){return new View1(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} + proto.lo=function lo(i0){var b=this.offset,d=0,a0=this.shape[0],c0=this.stride[0] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} return new View1(this.data,a0,c0,b)} - proto.step=function View1_step(i0){var a0=this.shape[0],b0=this.stride[0],c=this.offset,d=0,ceil=Math.ceil + proto.step=function step(i0){var a0=this.shape[0],b0=this.stride[0],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} return new View1(this.data,a0,b0,c)} - proto.transpose=function View1_transpose(i0){i0=(i0===undefined?0:i0|0) + proto.transpose=function transpose(i0){i0=(i0===undefined?0:i0|0) var a=this.shape,b=this.stride;return new View1(this.data,a[i0],b[i0],this.offset)} - proto.pick=function View1_pick(i0){var a=[],b=[],c=this.offset + proto.pick=function pick(i0){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct_View1(data,shape,stride,offset){return new View1(data,shape[0],stride[0],offset)} + return function construct(data,shape,stride,offset){return new View1(data,shape[0],stride[0],offset)} }, '2': function(dtype,CTOR_LIST,ORDER) { function View2(a,b0,b1,c0,c1,d){this.data=a @@ -69,34 +69,34 @@ var allFns = { var proto=View2.prototype proto.dtype=dtype proto.dimension=2 - Object.defineProperty(proto,'size',{get:function View2_size(){return this.shape[0]*this.shape[1] + Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1] }}) Object.defineProperty(proto,'order',{get: - function View2_order(){ + function order(){ return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}}) - proto.set=function View2_set(i0,i1,v){ + proto.set=function set(i0,i1,v){ return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1]=v;}; - proto.get=function View2_get(i0,i1){ + proto.get=function get(i0,i1){ return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1];}; - proto.index=function View2_index( + proto.index=function index( i0,i1 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1} - proto.hi=function View2_hi(i0,i1){return new View2(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} - proto.lo=function View2_lo(i0,i1){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],c0=this.stride[0],c1=this.stride[1] + proto.hi=function hi(i0,i1){return new View2(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} + proto.lo=function lo(i0,i1){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],c0=this.stride[0],c1=this.stride[1] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} return new View2(this.data,a0,a1,c0,c1,b)} - proto.step=function View2_step(i0,i1){var a0=this.shape[0],a1=this.shape[1],b0=this.stride[0],b1=this.stride[1],c=this.offset,d=0,ceil=Math.ceil + proto.step=function step(i0,i1){var a0=this.shape[0],a1=this.shape[1],b0=this.stride[0],b1=this.stride[1],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} return new View2(this.data,a0,a1,b0,b1,c)} - proto.transpose=function View2_transpose(i0,i1){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0) + proto.transpose=function transpose(i0,i1){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0) var a=this.shape,b=this.stride;return new View2(this.data,a[i0],a[i1],b[i0],b[i1],this.offset)} - proto.pick=function View2_pick(i0,i1){var a=[],b=[],c=this.offset + proto.pick=function pick(i0,i1){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct_View2(data,shape,stride,offset){return new View2(data,shape[0],shape[1],stride[0],stride[1],offset)} + return function construct(data,shape,stride,offset){return new View2(data,shape[0],shape[1],stride[0],stride[1],offset)} }, '3': function(dtype,CTOR_LIST,ORDER) { function View3(a,b0,b1,b2,c0,c1,c2,d){this.data=a @@ -106,37 +106,37 @@ var allFns = { var proto=View3.prototype proto.dtype=dtype proto.dimension=3 - Object.defineProperty(proto,'size',{get:function View3_size(){return this.shape[0]*this.shape[1]*this.shape[2] + Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2] }}) Object.defineProperty(proto,'order',{get: - function View3_order(){ + function order(){ 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];}}}) - proto.set=function View3_set(i0,i1,i2,v){ + proto.set=function set(i0,i1,i2,v){ return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2]=v;}; - proto.get=function View3_get(i0,i1,i2){ + proto.get=function get(i0,i1,i2){ return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2];}; - proto.index=function View3_index( + proto.index=function index( i0,i1,i2 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2} - proto.hi=function View3_hi(i0,i1,i2){return new View3(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} - proto.lo=function View3_lo(i0,i1,i2){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2] + proto.hi=function hi(i0,i1,i2){return new View3(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} + proto.lo=function lo(i0,i1,i2){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} return new View3(this.data,a0,a1,a2,c0,c1,c2,b)} - proto.step=function View3_step(i0,i1,i2){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],c=this.offset,d=0,ceil=Math.ceil + proto.step=function step(i0,i1,i2){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} return new View3(this.data,a0,a1,a2,b0,b1,b2,c)} - proto.transpose=function View3_transpose(i0,i1,i2){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0) + proto.transpose=function transpose(i0,i1,i2){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0) var a=this.shape,b=this.stride;return new View3(this.data,a[i0],a[i1],a[i2],b[i0],b[i1],b[i2],this.offset)} - proto.pick=function View3_pick(i0,i1,i2){var a=[],b=[],c=this.offset + proto.pick=function pick(i0,i1,i2){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct_View3(data,shape,stride,offset){return new View3(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} + return function construct(data,shape,stride,offset){return new View3(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} }, '4': function(dtype,CTOR_LIST,ORDER) { function View4(a,b0,b1,b2,b3,c0,c1,c2,c3,d){this.data=a @@ -146,39 +146,39 @@ var allFns = { var proto=View4.prototype proto.dtype=dtype proto.dimension=4 - Object.defineProperty(proto,'size',{get:function View4_size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3] + Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3] }}) Object.defineProperty(proto,'order',{get: ORDER}) - proto.set=function View4_set(i0,i1,i2,i3,v){ + proto.set=function set(i0,i1,i2,i3,v){ return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3]=v;}; - proto.get=function View4_get(i0,i1,i2,i3){ + proto.get=function get(i0,i1,i2,i3){ return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3];}; - proto.index=function View4_index( + proto.index=function index( i0,i1,i2,i3 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3} - proto.hi=function View4_hi(i0,i1,i2,i3){return new View4(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} - proto.lo=function View4_lo(i0,i1,i2,i3){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3] + proto.hi=function hi(i0,i1,i2,i3){return new View4(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} + proto.lo=function lo(i0,i1,i2,i3){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} return new View4(this.data,a0,a1,a2,a3,c0,c1,c2,c3,b)} - proto.step=function View4_step(i0,i1,i2,i3){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],c=this.offset,d=0,ceil=Math.ceil + proto.step=function step(i0,i1,i2,i3){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} return new View4(this.data,a0,a1,a2,a3,b0,b1,b2,b3,c)} - proto.transpose=function View4_transpose(i0,i1,i2,i3){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0) + proto.transpose=function transpose(i0,i1,i2,i3){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0) var a=this.shape,b=this.stride;return new View4(this.data,a[i0],a[i1],a[i2],a[i3],b[i0],b[i1],b[i2],b[i3],this.offset)} - proto.pick=function View4_pick(i0,i1,i2,i3){var a=[],b=[],c=this.offset + proto.pick=function pick(i0,i1,i2,i3){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct_View4(data,shape,stride,offset){return new View4(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} + return function construct(data,shape,stride,offset){return new View4(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} }, '5': function anonymous(dtype,CTOR_LIST,ORDER) { function View5(a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4,d){this.data=a @@ -188,42 +188,42 @@ var allFns = { var proto=View5.prototype proto.dtype=dtype proto.dimension=5 - Object.defineProperty(proto,'size',{get:function View5_size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4] + Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4] }}) Object.defineProperty(proto,'order',{get: ORDER}) - proto.set=function View5_set(i0,i1,i2,i3,i4,v){ + proto.set=function set(i0,i1,i2,i3,i4,v){ return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4]=v;}; - proto.get=function View5_get(i0,i1,i2,i3,i4){ + proto.get=function get(i0,i1,i2,i3,i4){ return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4];}; - proto.index=function View5_index( + proto.index=function index( i0,i1,i2,i3,i4 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4} - proto.hi=function View5_hi(i0,i1,i2,i3,i4){return new View5(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} - proto.lo=function View5_lo(i0,i1,i2,i3,i4){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3],c4=this.stride[4] + proto.hi=function hi(i0,i1,i2,i3,i4){return new View5(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} + proto.lo=function lo(i0,i1,i2,i3,i4){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3],c4=this.stride[4] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} if(typeof i4==='number'&&i4>=0){d=i4|0;b+=c4*d;a4-=d} return new View5(this.data,a0,a1,a2,a3,a4,c0,c1,c2,c3,c4,b)} - proto.step=function View5_step(i0,i1,i2,i3,i4){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],b4=this.stride[4],c=this.offset,d=0,ceil=Math.ceil + proto.step=function step(i0,i1,i2,i3,i4){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],b4=this.stride[4],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} if(typeof i4==='number'){d=i4|0;if(d<0){c+=b4*(a4-1);a4=ceil(-a4/d)}else{a4=ceil(a4/d)}b4*=d} return new View5(this.data,a0,a1,a2,a3,a4,b0,b1,b2,b3,b4,c)} - proto.transpose=function View5_transpose(i0,i1,i2,i3,i4){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0);i4=(i4===undefined?4:i4|0) + proto.transpose=function transpose(i0,i1,i2,i3,i4){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0);i4=(i4===undefined?4:i4|0) var a=this.shape,b=this.stride;return new View5(this.data,a[i0],a[i1],a[i2],a[i3],a[i4],b[i0],b[i1],b[i2],b[i3],b[i4],this.offset)} - proto.pick=function View5_pick(i0,i1,i2,i3,i4){var a=[],b=[],c=this.offset + proto.pick=function pick(i0,i1,i2,i3,i4){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} if(typeof i4==='number'&&i4>=0){c=(c+this.stride[4]*i4)|0}else{a.push(this.shape[4]);b.push(this.stride[4])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct_View5(data,shape,stride,offset){return new View5(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} + return function construct(data,shape,stride,offset){return new View5(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} } } From 9de4f6f7f9c9e5c04bec69ec89bda968ee81b694 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 11:52:42 -0400 Subject: [PATCH 09/15] genearalize function names --- ndarray.js | 74 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/ndarray.js b/ndarray.js index 17c1943..12c46eb 100644 --- a/ndarray.js +++ b/ndarray.js @@ -24,17 +24,17 @@ function order() { var allFns = { 'G': function(dtype) { - function ViewG(a){this.data=a;};var proto=ViewG.prototype;proto.dtype=dtype;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 ViewG(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct(a){return new ViewG(a);} + function View(a){this.data=a;};var proto=View.prototype;proto.dtype=dtype;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 View(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct(a){return new View(a);} }, '0': function(dtype,TrivialArray) { - function View0(a,d) {this.data = a;this.offset = d};var proto=View0.prototype;proto.dtype=dtype;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 copy() {return new View0(this.data,this.offset)};proto.pick=function pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct(a,b,c,d){return new View0(a,d)} + function View(a,d) {this.data = a;this.offset = d};var proto=View.prototype;proto.dtype=dtype;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 copy() {return new View(this.data,this.offset)};proto.pick=function pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct(a,b,c,d){return new View(a,d)} }, '1': function(dtype,CTOR_LIST,ORDER) { - function View1(a,b0,c0,d){this.data=a + function View(a,b0,c0,d){this.data=a this.shape=[b0] this.stride=[c0] this.offset=d|0} - var proto=View1.prototype + var proto=View.prototype proto.dtype=dtype proto.dimension=1 Object.defineProperty(proto,'size',{get:function size(){return this.shape[0] @@ -47,26 +47,26 @@ var allFns = { proto.index=function index( i0 ){return this.offset+this.stride[0]*i0} - proto.hi=function hi(i0){return new View1(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} + proto.hi=function hi(i0){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} proto.lo=function lo(i0){var b=this.offset,d=0,a0=this.shape[0],c0=this.stride[0] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - return new View1(this.data,a0,c0,b)} + return new View(this.data,a0,c0,b)} proto.step=function step(i0){var a0=this.shape[0],b0=this.stride[0],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - return new View1(this.data,a0,b0,c)} + return new View(this.data,a0,b0,c)} proto.transpose=function transpose(i0){i0=(i0===undefined?0:i0|0) - var a=this.shape,b=this.stride;return new View1(this.data,a[i0],b[i0],this.offset)} + var a=this.shape,b=this.stride;return new View(this.data,a[i0],b[i0],this.offset)} proto.pick=function pick(i0){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View1(data,shape[0],stride[0],offset)} + return function construct(data,shape,stride,offset){return new View(data,shape[0],stride[0],offset)} }, '2': function(dtype,CTOR_LIST,ORDER) { - function View2(a,b0,b1,c0,c1,d){this.data=a + function View(a,b0,b1,c0,c1,d){this.data=a this.shape=[b0,b1] this.stride=[c0,c1] this.offset=d|0} - var proto=View2.prototype + var proto=View.prototype proto.dtype=dtype proto.dimension=2 Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1] @@ -81,29 +81,29 @@ var allFns = { proto.index=function index( i0,i1 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1} - proto.hi=function hi(i0,i1){return new View2(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} + proto.hi=function hi(i0,i1){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} proto.lo=function lo(i0,i1){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],c0=this.stride[0],c1=this.stride[1] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} - return new View2(this.data,a0,a1,c0,c1,b)} + return new View(this.data,a0,a1,c0,c1,b)} proto.step=function step(i0,i1){var a0=this.shape[0],a1=this.shape[1],b0=this.stride[0],b1=this.stride[1],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} - return new View2(this.data,a0,a1,b0,b1,c)} + return new View(this.data,a0,a1,b0,b1,c)} proto.transpose=function transpose(i0,i1){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0) - var a=this.shape,b=this.stride;return new View2(this.data,a[i0],a[i1],b[i0],b[i1],this.offset)} + var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],b[i0],b[i1],this.offset)} proto.pick=function pick(i0,i1){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View2(data,shape[0],shape[1],stride[0],stride[1],offset)} + return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],stride[0],stride[1],offset)} }, '3': function(dtype,CTOR_LIST,ORDER) { - function View3(a,b0,b1,b2,c0,c1,c2,d){this.data=a + function View(a,b0,b1,b2,c0,c1,c2,d){this.data=a this.shape=[b0,b1,b2] this.stride=[c0,c1,c2] this.offset=d|0} - var proto=View3.prototype + var proto=View.prototype proto.dtype=dtype proto.dimension=3 Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2] @@ -118,32 +118,32 @@ var allFns = { proto.index=function index( i0,i1,i2 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2} - proto.hi=function hi(i0,i1,i2){return new View3(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} + proto.hi=function hi(i0,i1,i2){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} proto.lo=function lo(i0,i1,i2){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} - return new View3(this.data,a0,a1,a2,c0,c1,c2,b)} + return new View(this.data,a0,a1,a2,c0,c1,c2,b)} proto.step=function step(i0,i1,i2){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} - return new View3(this.data,a0,a1,a2,b0,b1,b2,c)} + return new View(this.data,a0,a1,a2,b0,b1,b2,c)} proto.transpose=function transpose(i0,i1,i2){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0) - var a=this.shape,b=this.stride;return new View3(this.data,a[i0],a[i1],a[i2],b[i0],b[i1],b[i2],this.offset)} + var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],b[i0],b[i1],b[i2],this.offset)} proto.pick=function pick(i0,i1,i2){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View3(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} + return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} }, '4': function(dtype,CTOR_LIST,ORDER) { - function View4(a,b0,b1,b2,b3,c0,c1,c2,c3,d){this.data=a + function View(a,b0,b1,b2,b3,c0,c1,c2,c3,d){this.data=a this.shape=[b0,b1,b2,b3] this.stride=[c0,c1,c2,c3] this.offset=d|0} - var proto=View4.prototype + var proto=View.prototype proto.dtype=dtype proto.dimension=4 Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3] @@ -157,35 +157,35 @@ var allFns = { proto.index=function index( i0,i1,i2,i3 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3} - proto.hi=function hi(i0,i1,i2,i3){return new View4(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} + proto.hi=function hi(i0,i1,i2,i3){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} proto.lo=function lo(i0,i1,i2,i3){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} - return new View4(this.data,a0,a1,a2,a3,c0,c1,c2,c3,b)} + return new View(this.data,a0,a1,a2,a3,c0,c1,c2,c3,b)} proto.step=function step(i0,i1,i2,i3){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} - return new View4(this.data,a0,a1,a2,a3,b0,b1,b2,b3,c)} + return new View(this.data,a0,a1,a2,a3,b0,b1,b2,b3,c)} proto.transpose=function transpose(i0,i1,i2,i3){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0) - var a=this.shape,b=this.stride;return new View4(this.data,a[i0],a[i1],a[i2],a[i3],b[i0],b[i1],b[i2],b[i3],this.offset)} + var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],a[i3],b[i0],b[i1],b[i2],b[i3],this.offset)} proto.pick=function pick(i0,i1,i2,i3){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View4(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} + return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} }, '5': function anonymous(dtype,CTOR_LIST,ORDER) { - function View5(a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4,d){this.data=a + function View(a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4,d){this.data=a this.shape=[b0,b1,b2,b3,b4] this.stride=[c0,c1,c2,c3,c4] this.offset=d|0} - var proto=View5.prototype + var proto=View.prototype proto.dtype=dtype proto.dimension=5 Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4] @@ -199,23 +199,23 @@ var allFns = { proto.index=function index( i0,i1,i2,i3,i4 ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4} - proto.hi=function hi(i0,i1,i2,i3,i4){return new View5(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} + proto.hi=function hi(i0,i1,i2,i3,i4){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} proto.lo=function lo(i0,i1,i2,i3,i4){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3],c4=this.stride[4] if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} if(typeof i4==='number'&&i4>=0){d=i4|0;b+=c4*d;a4-=d} - return new View5(this.data,a0,a1,a2,a3,a4,c0,c1,c2,c3,c4,b)} + return new View(this.data,a0,a1,a2,a3,a4,c0,c1,c2,c3,c4,b)} proto.step=function step(i0,i1,i2,i3,i4){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],b4=this.stride[4],c=this.offset,d=0,ceil=Math.ceil if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} if(typeof i4==='number'){d=i4|0;if(d<0){c+=b4*(a4-1);a4=ceil(-a4/d)}else{a4=ceil(a4/d)}b4*=d} - return new View5(this.data,a0,a1,a2,a3,a4,b0,b1,b2,b3,b4,c)} + return new View(this.data,a0,a1,a2,a3,a4,b0,b1,b2,b3,b4,c)} proto.transpose=function transpose(i0,i1,i2,i3,i4){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0);i4=(i4===undefined?4:i4|0) - var a=this.shape,b=this.stride;return new View5(this.data,a[i0],a[i1],a[i2],a[i3],a[i4],b[i0],b[i1],b[i2],b[i3],b[i4],this.offset)} + var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],a[i3],a[i4],b[i0],b[i1],b[i2],b[i3],b[i4],this.offset)} proto.pick=function pick(i0,i1,i2,i3,i4){var a=[],b=[],c=this.offset if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} @@ -223,7 +223,7 @@ var allFns = { if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} if(typeof i4==='number'&&i4>=0){c=(c+this.stride[4]*i4)|0}else{a.push(this.shape[4]);b.push(this.stride[4])} var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View5(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} + return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} } } From 8c6183ecc3417540613c8a309bd8dd993b8b5e32 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 13:04:23 -0400 Subject: [PATCH 10/15] prettier functions --- ndarray.js | 1050 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 854 insertions(+), 196 deletions(-) diff --git a/ndarray.js b/ndarray.js index 12c46eb..7332f62 100644 --- a/ndarray.js +++ b/ndarray.js @@ -23,210 +23,868 @@ function order() { } var allFns = { - 'G': function(dtype) { - function View(a){this.data=a;};var proto=View.prototype;proto.dtype=dtype;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 View(this.data);};proto.get=proto.set=function(){};proto.pick=function(){return null};return function construct(a){return new View(a);} + G: function (dtype) { + function View(a) { + this.data = a + } + var proto = View.prototype + proto.dtype = dtype + 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 View(this.data) + } + proto.get = proto.set = function () {} + proto.pick = function () { + return null + } + return function construct(a) { + return new View(a) + } }, - '0': function(dtype,TrivialArray) { - function View(a,d) {this.data = a;this.offset = d};var proto=View.prototype;proto.dtype=dtype;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 copy() {return new View(this.data,this.offset)};proto.pick=function pick(){return TrivialArray(this.data);};proto.valueOf=proto.get=function get(){return dtype === 'generic' ? this.data.get(this.offset) : this.data[this.offset];};proto.set=function set(v){return dtype === 'generic' ? this.data.set(this.offset,v) : this.data[this.offset]=v;};return function construct(a,b,c,d){return new View(a,d)} + 0: function (dtype, TrivialArray) { + function View(a, d) { + this.data = a + this.offset = d + } + var proto = View.prototype + proto.dtype = dtype + 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 copy() { + return new View(this.data, this.offset) + } + proto.pick = function pick() { + return TrivialArray(this.data) + } + proto.valueOf = proto.get = function get() { + return dtype === "generic" ? this.data.get(this.offset) : this.data[this.offset] + } + proto.set = function set(v) { + return dtype === "generic" ? this.data.set(this.offset, v) : (this.data[this.offset] = v) + } + return function construct(a, b, c, d) { + return new View(a, d) + } }, - '1': function(dtype,CTOR_LIST,ORDER) { - function View(a,b0,c0,d){this.data=a - this.shape=[b0] - this.stride=[c0] - this.offset=d|0} - var proto=View.prototype - proto.dtype=dtype - proto.dimension=1 - Object.defineProperty(proto,'size',{get:function size(){return this.shape[0] - }}) - proto.order=[0] - proto.set=function set(i0,v){ - return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0,v) : this.data[this.offset+this.stride[0]*i0]=v;}; - proto.get=function get(i0){ - return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0) : this.data[this.offset+this.stride[0]*i0];}; - proto.index=function index( - i0 - ){return this.offset+this.stride[0]*i0} - proto.hi=function hi(i0){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,this.stride[0],this.offset)} - proto.lo=function lo(i0){var b=this.offset,d=0,a0=this.shape[0],c0=this.stride[0] - if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - return new View(this.data,a0,c0,b)} - proto.step=function step(i0){var a0=this.shape[0],b0=this.stride[0],c=this.offset,d=0,ceil=Math.ceil - if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - return new View(this.data,a0,b0,c)} - proto.transpose=function transpose(i0){i0=(i0===undefined?0:i0|0) - var a=this.shape,b=this.stride;return new View(this.data,a[i0],b[i0],this.offset)} - proto.pick=function pick(i0){var a=[],b=[],c=this.offset - if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} - var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View(data,shape[0],stride[0],offset)} + 1: function (dtype, CTOR_LIST, ORDER) { + function View(a, b0, c0, d) { + this.data = a + this.shape = [b0] + this.stride = [c0] + this.offset = d | 0 + } + var proto = View.prototype + proto.dtype = dtype + proto.dimension = 1 + Object.defineProperty(proto, "size", { + get: function size() { + return this.shape[0] + }, + }) + proto.order = [0] + proto.set = function set(i0, v) { + return dtype === "generic" + ? this.data.set(this.offset + this.stride[0] * i0, v) + : (this.data[this.offset + this.stride[0] * i0] = v) + } + proto.get = function get(i0) { + return dtype === "generic" + ? this.data.get(this.offset + this.stride[0] * i0) + : this.data[this.offset + this.stride[0] * i0] + } + proto.index = function index(i0) { + return this.offset + this.stride[0] * i0 + } + proto.hi = function hi(i0) { + return new View(this.data, typeof i0 !== "number" || i0 < 0 ? this.shape[0] : i0 | 0, this.stride[0], this.offset) + } + proto.lo = function lo(i0) { + var b = this.offset, + d = 0, + a0 = this.shape[0], + c0 = this.stride[0] + if (typeof i0 === "number" && i0 >= 0) { + d = i0 | 0 + b += c0 * d + a0 -= d + } + return new View(this.data, a0, c0, b) + } + proto.step = function step(i0) { + var a0 = this.shape[0], + b0 = this.stride[0], + c = this.offset, + d = 0, + ceil = Math.ceil + if (typeof i0 === "number") { + d = i0 | 0 + if (d < 0) { + c += b0 * (a0 - 1) + a0 = ceil(-a0 / d) + } else { + a0 = ceil(a0 / d) + } + b0 *= d + } + return new View(this.data, a0, b0, c) + } + proto.transpose = function transpose(i0) { + i0 = i0 === undefined ? 0 : i0 | 0 + var a = this.shape, + b = this.stride + return new View(this.data, a[i0], b[i0], this.offset) + } + proto.pick = function pick(i0) { + var a = [], + b = [], + c = this.offset + if (typeof i0 === "number" && i0 >= 0) { + c = (c + this.stride[0] * i0) | 0 + } else { + a.push(this.shape[0]) + b.push(this.stride[0]) + } + var ctor = CTOR_LIST[a.length + 1] + return ctor(this.data, a, b, c) + } + return function construct(data, shape, stride, offset) { + return new View(data, shape[0], stride[0], offset) + } + }, + 2: function (dtype, CTOR_LIST, ORDER) { + function View(a, b0, b1, c0, c1, d) { + this.data = a + this.shape = [b0, b1] + this.stride = [c0, c1] + this.offset = d | 0 + } + var proto = View.prototype + proto.dtype = dtype + proto.dimension = 2 + Object.defineProperty(proto, "size", { + get: function size() { + return this.shape[0] * this.shape[1] + }, + }) + Object.defineProperty(proto, "order", { + get: function order() { + return Math.abs(this.stride[0]) > Math.abs(this.stride[1]) ? [1, 0] : [0, 1] + }, + }) + proto.set = function set(i0, i1, v) { + return dtype === "generic" + ? this.data.set(this.offset + this.stride[0] * i0 + this.stride[1] * i1, v) + : (this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1] = v) + } + proto.get = function get(i0, i1) { + return dtype === "generic" + ? this.data.get(this.offset + this.stride[0] * i0 + this.stride[1] * i1) + : this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1] + } + proto.index = function index(i0, i1) { + return this.offset + this.stride[0] * i0 + this.stride[1] * i1 + } + proto.hi = function hi(i0, i1) { + return new View( + this.data, + typeof i0 !== "number" || i0 < 0 ? this.shape[0] : i0 | 0, + typeof i1 !== "number" || i1 < 0 ? this.shape[1] : i1 | 0, + this.stride[0], + this.stride[1], + this.offset + ) + } + proto.lo = function lo(i0, i1) { + var b = this.offset, + d = 0, + a0 = this.shape[0], + a1 = this.shape[1], + c0 = this.stride[0], + c1 = this.stride[1] + if (typeof i0 === "number" && i0 >= 0) { + d = i0 | 0 + b += c0 * d + a0 -= d + } + if (typeof i1 === "number" && i1 >= 0) { + d = i1 | 0 + b += c1 * d + a1 -= d + } + return new View(this.data, a0, a1, c0, c1, b) + } + proto.step = function step(i0, i1) { + var a0 = this.shape[0], + a1 = this.shape[1], + b0 = this.stride[0], + b1 = this.stride[1], + c = this.offset, + d = 0, + ceil = Math.ceil + if (typeof i0 === "number") { + d = i0 | 0 + if (d < 0) { + c += b0 * (a0 - 1) + a0 = ceil(-a0 / d) + } else { + a0 = ceil(a0 / d) + } + b0 *= d + } + if (typeof i1 === "number") { + d = i1 | 0 + if (d < 0) { + c += b1 * (a1 - 1) + a1 = ceil(-a1 / d) + } else { + a1 = ceil(a1 / d) + } + b1 *= d + } + return new View(this.data, a0, a1, b0, b1, c) + } + proto.transpose = function transpose(i0, i1) { + i0 = i0 === undefined ? 0 : i0 | 0 + i1 = i1 === undefined ? 1 : i1 | 0 + var a = this.shape, + b = this.stride + return new View(this.data, a[i0], a[i1], b[i0], b[i1], this.offset) + } + proto.pick = function pick(i0, i1) { + var a = [], + b = [], + c = this.offset + if (typeof i0 === "number" && i0 >= 0) { + c = (c + this.stride[0] * i0) | 0 + } else { + a.push(this.shape[0]) + b.push(this.stride[0]) + } + if (typeof i1 === "number" && i1 >= 0) { + c = (c + this.stride[1] * i1) | 0 + } else { + a.push(this.shape[1]) + b.push(this.stride[1]) + } + var ctor = CTOR_LIST[a.length + 1] + return ctor(this.data, a, b, c) + } + return function construct(data, shape, stride, offset) { + return new View(data, shape[0], shape[1], stride[0], stride[1], offset) + } }, - '2': function(dtype,CTOR_LIST,ORDER) { - function View(a,b0,b1,c0,c1,d){this.data=a - this.shape=[b0,b1] - this.stride=[c0,c1] - this.offset=d|0} - var proto=View.prototype - proto.dtype=dtype - proto.dimension=2 - Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1] - }}) - Object.defineProperty(proto,'order',{get: - function order(){ - return (Math.abs(this.stride[0])>Math.abs(this.stride[1]))?[1,0]:[0,1]}}) - proto.set=function set(i0,i1,v){ - return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1]=v;}; - proto.get=function get(i0,i1){ - return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1];}; - proto.index=function index( - i0,i1 - ){return this.offset+this.stride[0]*i0+this.stride[1]*i1} - proto.hi=function hi(i0,i1){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,this.stride[0],this.stride[1],this.offset)} - proto.lo=function lo(i0,i1){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],c0=this.stride[0],c1=this.stride[1] - if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} - return new View(this.data,a0,a1,c0,c1,b)} - proto.step=function step(i0,i1){var a0=this.shape[0],a1=this.shape[1],b0=this.stride[0],b1=this.stride[1],c=this.offset,d=0,ceil=Math.ceil - if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} - return new View(this.data,a0,a1,b0,b1,c)} - proto.transpose=function transpose(i0,i1){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0) - var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],b[i0],b[i1],this.offset)} - proto.pick=function pick(i0,i1){var a=[],b=[],c=this.offset - if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} - if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} - var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],stride[0],stride[1],offset)} + 3: function (dtype, CTOR_LIST, ORDER) { + function View(a, b0, b1, b2, c0, c1, c2, d) { + this.data = a + this.shape = [b0, b1, b2] + this.stride = [c0, c1, c2] + this.offset = d | 0 + } + var proto = View.prototype + proto.dtype = dtype + proto.dimension = 3 + Object.defineProperty(proto, "size", { + get: function size() { + return this.shape[0] * this.shape[1] * this.shape[2] + }, + }) + Object.defineProperty(proto, "order", { + get: function order() { + 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] + } + }, + }) + proto.set = function set(i0, i1, i2, v) { + return dtype === "generic" + ? this.data.set(this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2, v) + : (this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2] = v) + } + proto.get = function get(i0, i1, i2) { + return dtype === "generic" + ? this.data.get(this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2) + : this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2] + } + proto.index = function index(i0, i1, i2) { + return this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + } + proto.hi = function hi(i0, i1, i2) { + return new View( + this.data, + typeof i0 !== "number" || i0 < 0 ? this.shape[0] : i0 | 0, + typeof i1 !== "number" || i1 < 0 ? this.shape[1] : i1 | 0, + typeof i2 !== "number" || i2 < 0 ? this.shape[2] : i2 | 0, + this.stride[0], + this.stride[1], + this.stride[2], + this.offset + ) + } + proto.lo = function lo(i0, i1, i2) { + var b = this.offset, + d = 0, + a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + c0 = this.stride[0], + c1 = this.stride[1], + c2 = this.stride[2] + if (typeof i0 === "number" && i0 >= 0) { + d = i0 | 0 + b += c0 * d + a0 -= d + } + if (typeof i1 === "number" && i1 >= 0) { + d = i1 | 0 + b += c1 * d + a1 -= d + } + if (typeof i2 === "number" && i2 >= 0) { + d = i2 | 0 + b += c2 * d + a2 -= d + } + return new View(this.data, a0, a1, a2, c0, c1, c2, b) + } + proto.step = function step(i0, i1, i2) { + var a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + b0 = this.stride[0], + b1 = this.stride[1], + b2 = this.stride[2], + c = this.offset, + d = 0, + ceil = Math.ceil + if (typeof i0 === "number") { + d = i0 | 0 + if (d < 0) { + c += b0 * (a0 - 1) + a0 = ceil(-a0 / d) + } else { + a0 = ceil(a0 / d) + } + b0 *= d + } + if (typeof i1 === "number") { + d = i1 | 0 + if (d < 0) { + c += b1 * (a1 - 1) + a1 = ceil(-a1 / d) + } else { + a1 = ceil(a1 / d) + } + b1 *= d + } + if (typeof i2 === "number") { + d = i2 | 0 + if (d < 0) { + c += b2 * (a2 - 1) + a2 = ceil(-a2 / d) + } else { + a2 = ceil(a2 / d) + } + b2 *= d + } + return new View(this.data, a0, a1, a2, b0, b1, b2, c) + } + proto.transpose = function transpose(i0, i1, i2) { + i0 = i0 === undefined ? 0 : i0 | 0 + i1 = i1 === undefined ? 1 : i1 | 0 + i2 = i2 === undefined ? 2 : i2 | 0 + var a = this.shape, + b = this.stride + return new View(this.data, a[i0], a[i1], a[i2], b[i0], b[i1], b[i2], this.offset) + } + proto.pick = function pick(i0, i1, i2) { + var a = [], + b = [], + c = this.offset + if (typeof i0 === "number" && i0 >= 0) { + c = (c + this.stride[0] * i0) | 0 + } else { + a.push(this.shape[0]) + b.push(this.stride[0]) + } + if (typeof i1 === "number" && i1 >= 0) { + c = (c + this.stride[1] * i1) | 0 + } else { + a.push(this.shape[1]) + b.push(this.stride[1]) + } + if (typeof i2 === "number" && i2 >= 0) { + c = (c + this.stride[2] * i2) | 0 + } else { + a.push(this.shape[2]) + b.push(this.stride[2]) + } + var ctor = CTOR_LIST[a.length + 1] + return ctor(this.data, a, b, c) + } + return function construct(data, shape, stride, offset) { + return new View(data, shape[0], shape[1], shape[2], stride[0], stride[1], stride[2], offset) + } }, - '3': function(dtype,CTOR_LIST,ORDER) { - function View(a,b0,b1,b2,c0,c1,c2,d){this.data=a - this.shape=[b0,b1,b2] - this.stride=[c0,c1,c2] - this.offset=d|0} - var proto=View.prototype - proto.dtype=dtype - proto.dimension=3 - Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2] - }}) - Object.defineProperty(proto,'order',{get: - function order(){ - 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];}}}) - proto.set=function set(i0,i1,i2,v){ - return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2]=v;}; - proto.get=function get(i0,i1,i2){ - return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2];}; - proto.index=function index( - i0,i1,i2 - ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2} - proto.hi=function hi(i0,i1,i2){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,this.stride[0],this.stride[1],this.stride[2],this.offset)} - proto.lo=function lo(i0,i1,i2){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2] - if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} - if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} - return new View(this.data,a0,a1,a2,c0,c1,c2,b)} - proto.step=function step(i0,i1,i2){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],c=this.offset,d=0,ceil=Math.ceil - if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} - if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} - return new View(this.data,a0,a1,a2,b0,b1,b2,c)} - proto.transpose=function transpose(i0,i1,i2){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0) - var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],b[i0],b[i1],b[i2],this.offset)} - proto.pick=function pick(i0,i1,i2){var a=[],b=[],c=this.offset - if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} - if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} - if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} - var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],stride[0],stride[1],stride[2],offset)} + 4: function (dtype, CTOR_LIST, ORDER) { + function View(a, b0, b1, b2, b3, c0, c1, c2, c3, d) { + this.data = a + this.shape = [b0, b1, b2, b3] + this.stride = [c0, c1, c2, c3] + this.offset = d | 0 + } + var proto = View.prototype + proto.dtype = dtype + proto.dimension = 4 + Object.defineProperty(proto, "size", { + get: function size() { + return this.shape[0] * this.shape[1] * this.shape[2] * this.shape[3] + }, + }) + Object.defineProperty(proto, "order", { get: ORDER }) + proto.set = function set(i0, i1, i2, i3, v) { + return dtype === "generic" + ? this.data.set(this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + this.stride[3] * i3, v) + : (this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + this.stride[3] * i3] = v) + } + proto.get = function get(i0, i1, i2, i3) { + return dtype === "generic" + ? this.data.get(this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + this.stride[3] * i3) + : this.data[this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + this.stride[3] * i3] + } + proto.index = function index(i0, i1, i2, i3) { + return this.offset + this.stride[0] * i0 + this.stride[1] * i1 + this.stride[2] * i2 + this.stride[3] * i3 + } + proto.hi = function hi(i0, i1, i2, i3) { + return new View( + this.data, + typeof i0 !== "number" || i0 < 0 ? this.shape[0] : i0 | 0, + typeof i1 !== "number" || i1 < 0 ? this.shape[1] : i1 | 0, + typeof i2 !== "number" || i2 < 0 ? this.shape[2] : i2 | 0, + typeof i3 !== "number" || i3 < 0 ? this.shape[3] : i3 | 0, + this.stride[0], + this.stride[1], + this.stride[2], + this.stride[3], + this.offset + ) + } + proto.lo = function lo(i0, i1, i2, i3) { + var b = this.offset, + d = 0, + a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + a3 = this.shape[3], + c0 = this.stride[0], + c1 = this.stride[1], + c2 = this.stride[2], + c3 = this.stride[3] + if (typeof i0 === "number" && i0 >= 0) { + d = i0 | 0 + b += c0 * d + a0 -= d + } + if (typeof i1 === "number" && i1 >= 0) { + d = i1 | 0 + b += c1 * d + a1 -= d + } + if (typeof i2 === "number" && i2 >= 0) { + d = i2 | 0 + b += c2 * d + a2 -= d + } + if (typeof i3 === "number" && i3 >= 0) { + d = i3 | 0 + b += c3 * d + a3 -= d + } + return new View(this.data, a0, a1, a2, a3, c0, c1, c2, c3, b) + } + proto.step = function step(i0, i1, i2, i3) { + var a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + a3 = this.shape[3], + b0 = this.stride[0], + b1 = this.stride[1], + b2 = this.stride[2], + b3 = this.stride[3], + c = this.offset, + d = 0, + ceil = Math.ceil + if (typeof i0 === "number") { + d = i0 | 0 + if (d < 0) { + c += b0 * (a0 - 1) + a0 = ceil(-a0 / d) + } else { + a0 = ceil(a0 / d) + } + b0 *= d + } + if (typeof i1 === "number") { + d = i1 | 0 + if (d < 0) { + c += b1 * (a1 - 1) + a1 = ceil(-a1 / d) + } else { + a1 = ceil(a1 / d) + } + b1 *= d + } + if (typeof i2 === "number") { + d = i2 | 0 + if (d < 0) { + c += b2 * (a2 - 1) + a2 = ceil(-a2 / d) + } else { + a2 = ceil(a2 / d) + } + b2 *= d + } + if (typeof i3 === "number") { + d = i3 | 0 + if (d < 0) { + c += b3 * (a3 - 1) + a3 = ceil(-a3 / d) + } else { + a3 = ceil(a3 / d) + } + b3 *= d + } + return new View(this.data, a0, a1, a2, a3, b0, b1, b2, b3, c) + } + proto.transpose = function transpose(i0, i1, i2, i3) { + i0 = i0 === undefined ? 0 : i0 | 0 + i1 = i1 === undefined ? 1 : i1 | 0 + i2 = i2 === undefined ? 2 : i2 | 0 + i3 = i3 === undefined ? 3 : i3 | 0 + var a = this.shape, + b = this.stride + return new View(this.data, a[i0], a[i1], a[i2], a[i3], b[i0], b[i1], b[i2], b[i3], this.offset) + } + proto.pick = function pick(i0, i1, i2, i3) { + var a = [], + b = [], + c = this.offset + if (typeof i0 === "number" && i0 >= 0) { + c = (c + this.stride[0] * i0) | 0 + } else { + a.push(this.shape[0]) + b.push(this.stride[0]) + } + if (typeof i1 === "number" && i1 >= 0) { + c = (c + this.stride[1] * i1) | 0 + } else { + a.push(this.shape[1]) + b.push(this.stride[1]) + } + if (typeof i2 === "number" && i2 >= 0) { + c = (c + this.stride[2] * i2) | 0 + } else { + a.push(this.shape[2]) + b.push(this.stride[2]) + } + if (typeof i3 === "number" && i3 >= 0) { + c = (c + this.stride[3] * i3) | 0 + } else { + a.push(this.shape[3]) + b.push(this.stride[3]) + } + var ctor = CTOR_LIST[a.length + 1] + return ctor(this.data, a, b, c) + } + return function construct(data, shape, stride, offset) { + return new View(data, shape[0], shape[1], shape[2], shape[3], stride[0], stride[1], stride[2], stride[3], offset) + } }, - '4': function(dtype,CTOR_LIST,ORDER) { - function View(a,b0,b1,b2,b3,c0,c1,c2,c3,d){this.data=a - this.shape=[b0,b1,b2,b3] - this.stride=[c0,c1,c2,c3] - this.offset=d|0} - var proto=View.prototype - proto.dtype=dtype - proto.dimension=4 - Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3] - }}) - Object.defineProperty(proto,'order',{get: - ORDER}) - proto.set=function set(i0,i1,i2,i3,v){ - return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3]=v;}; - proto.get=function get(i0,i1,i2,i3){ - return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3];}; - proto.index=function index( - i0,i1,i2,i3 - ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3} - proto.hi=function hi(i0,i1,i2,i3){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.offset)} - proto.lo=function lo(i0,i1,i2,i3){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3] - if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} - if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} - if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} - return new View(this.data,a0,a1,a2,a3,c0,c1,c2,c3,b)} - proto.step=function step(i0,i1,i2,i3){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],c=this.offset,d=0,ceil=Math.ceil - if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} - if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} - if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} - return new View(this.data,a0,a1,a2,a3,b0,b1,b2,b3,c)} - proto.transpose=function transpose(i0,i1,i2,i3){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0) - var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],a[i3],b[i0],b[i1],b[i2],b[i3],this.offset)} - proto.pick=function pick(i0,i1,i2,i3){var a=[],b=[],c=this.offset - if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} - if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} - if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} - if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} - var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],shape[3],stride[0],stride[1],stride[2],stride[3],offset)} + 5: function anonymous(dtype, CTOR_LIST, ORDER) { + function View(a, b0, b1, b2, b3, b4, c0, c1, c2, c3, c4, d) { + this.data = a + this.shape = [b0, b1, b2, b3, b4] + this.stride = [c0, c1, c2, c3, c4] + this.offset = d | 0 + } + var proto = View.prototype + proto.dtype = dtype + proto.dimension = 5 + Object.defineProperty(proto, "size", { + get: function size() { + return this.shape[0] * this.shape[1] * this.shape[2] * this.shape[3] * this.shape[4] + }, + }) + Object.defineProperty(proto, "order", { get: ORDER }) + proto.set = function set(i0, i1, i2, i3, i4, v) { + return dtype === "generic" + ? this.data.set( + this.offset + + this.stride[0] * i0 + + this.stride[1] * i1 + + this.stride[2] * i2 + + this.stride[3] * i3 + + this.stride[4] * i4, + v + ) + : (this.data[ + this.offset + + this.stride[0] * i0 + + this.stride[1] * i1 + + this.stride[2] * i2 + + this.stride[3] * i3 + + this.stride[4] * i4 + ] = v) + } + proto.get = function get(i0, i1, i2, i3, i4) { + return dtype === "generic" + ? this.data.get( + this.offset + + this.stride[0] * i0 + + this.stride[1] * i1 + + this.stride[2] * i2 + + this.stride[3] * i3 + + this.stride[4] * i4 + ) + : this.data[ + this.offset + + this.stride[0] * i0 + + this.stride[1] * i1 + + this.stride[2] * i2 + + this.stride[3] * i3 + + this.stride[4] * i4 + ] + } + proto.index = function index(i0, i1, i2, i3, i4) { + return ( + this.offset + + this.stride[0] * i0 + + this.stride[1] * i1 + + this.stride[2] * i2 + + this.stride[3] * i3 + + this.stride[4] * i4 + ) + } + proto.hi = function hi(i0, i1, i2, i3, i4) { + return new View( + this.data, + typeof i0 !== "number" || i0 < 0 ? this.shape[0] : i0 | 0, + typeof i1 !== "number" || i1 < 0 ? this.shape[1] : i1 | 0, + typeof i2 !== "number" || i2 < 0 ? this.shape[2] : i2 | 0, + typeof i3 !== "number" || i3 < 0 ? this.shape[3] : i3 | 0, + typeof i4 !== "number" || i4 < 0 ? this.shape[4] : i4 | 0, + this.stride[0], + this.stride[1], + this.stride[2], + this.stride[3], + this.stride[4], + this.offset + ) + } + proto.lo = function lo(i0, i1, i2, i3, i4) { + var b = this.offset, + d = 0, + a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + a3 = this.shape[3], + a4 = this.shape[4], + c0 = this.stride[0], + c1 = this.stride[1], + c2 = this.stride[2], + c3 = this.stride[3], + c4 = this.stride[4] + if (typeof i0 === "number" && i0 >= 0) { + d = i0 | 0 + b += c0 * d + a0 -= d + } + if (typeof i1 === "number" && i1 >= 0) { + d = i1 | 0 + b += c1 * d + a1 -= d + } + if (typeof i2 === "number" && i2 >= 0) { + d = i2 | 0 + b += c2 * d + a2 -= d + } + if (typeof i3 === "number" && i3 >= 0) { + d = i3 | 0 + b += c3 * d + a3 -= d + } + if (typeof i4 === "number" && i4 >= 0) { + d = i4 | 0 + b += c4 * d + a4 -= d + } + return new View(this.data, a0, a1, a2, a3, a4, c0, c1, c2, c3, c4, b) + } + proto.step = function step(i0, i1, i2, i3, i4) { + var a0 = this.shape[0], + a1 = this.shape[1], + a2 = this.shape[2], + a3 = this.shape[3], + a4 = this.shape[4], + b0 = this.stride[0], + b1 = this.stride[1], + b2 = this.stride[2], + b3 = this.stride[3], + b4 = this.stride[4], + c = this.offset, + d = 0, + ceil = Math.ceil + if (typeof i0 === "number") { + d = i0 | 0 + if (d < 0) { + c += b0 * (a0 - 1) + a0 = ceil(-a0 / d) + } else { + a0 = ceil(a0 / d) + } + b0 *= d + } + if (typeof i1 === "number") { + d = i1 | 0 + if (d < 0) { + c += b1 * (a1 - 1) + a1 = ceil(-a1 / d) + } else { + a1 = ceil(a1 / d) + } + b1 *= d + } + if (typeof i2 === "number") { + d = i2 | 0 + if (d < 0) { + c += b2 * (a2 - 1) + a2 = ceil(-a2 / d) + } else { + a2 = ceil(a2 / d) + } + b2 *= d + } + if (typeof i3 === "number") { + d = i3 | 0 + if (d < 0) { + c += b3 * (a3 - 1) + a3 = ceil(-a3 / d) + } else { + a3 = ceil(a3 / d) + } + b3 *= d + } + if (typeof i4 === "number") { + d = i4 | 0 + if (d < 0) { + c += b4 * (a4 - 1) + a4 = ceil(-a4 / d) + } else { + a4 = ceil(a4 / d) + } + b4 *= d + } + return new View(this.data, a0, a1, a2, a3, a4, b0, b1, b2, b3, b4, c) + } + proto.transpose = function transpose(i0, i1, i2, i3, i4) { + i0 = i0 === undefined ? 0 : i0 | 0 + i1 = i1 === undefined ? 1 : i1 | 0 + i2 = i2 === undefined ? 2 : i2 | 0 + i3 = i3 === undefined ? 3 : i3 | 0 + i4 = i4 === undefined ? 4 : i4 | 0 + var a = this.shape, + b = this.stride + return new View(this.data, a[i0], a[i1], a[i2], a[i3], a[i4], b[i0], b[i1], b[i2], b[i3], b[i4], this.offset) + } + proto.pick = function pick(i0, i1, i2, i3, i4) { + var a = [], + b = [], + c = this.offset + if (typeof i0 === "number" && i0 >= 0) { + c = (c + this.stride[0] * i0) | 0 + } else { + a.push(this.shape[0]) + b.push(this.stride[0]) + } + if (typeof i1 === "number" && i1 >= 0) { + c = (c + this.stride[1] * i1) | 0 + } else { + a.push(this.shape[1]) + b.push(this.stride[1]) + } + if (typeof i2 === "number" && i2 >= 0) { + c = (c + this.stride[2] * i2) | 0 + } else { + a.push(this.shape[2]) + b.push(this.stride[2]) + } + if (typeof i3 === "number" && i3 >= 0) { + c = (c + this.stride[3] * i3) | 0 + } else { + a.push(this.shape[3]) + b.push(this.stride[3]) + } + if (typeof i4 === "number" && i4 >= 0) { + c = (c + this.stride[4] * i4) | 0 + } else { + a.push(this.shape[4]) + b.push(this.stride[4]) + } + var ctor = CTOR_LIST[a.length + 1] + return ctor(this.data, a, b, c) + } + return function construct(data, shape, stride, offset) { + return new View( + data, + shape[0], + shape[1], + shape[2], + shape[3], + shape[4], + stride[0], + stride[1], + stride[2], + stride[3], + stride[4], + offset + ) + } }, - '5': function anonymous(dtype,CTOR_LIST,ORDER) { - function View(a,b0,b1,b2,b3,b4,c0,c1,c2,c3,c4,d){this.data=a - this.shape=[b0,b1,b2,b3,b4] - this.stride=[c0,c1,c2,c3,c4] - this.offset=d|0} - var proto=View.prototype - proto.dtype=dtype - proto.dimension=5 - Object.defineProperty(proto,'size',{get:function size(){return this.shape[0]*this.shape[1]*this.shape[2]*this.shape[3]*this.shape[4] - }}) - Object.defineProperty(proto,'order',{get: - ORDER}) - proto.set=function set(i0,i1,i2,i3,i4,v){ - return dtype === 'generic' ? this.data.set(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4,v) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4]=v;}; - proto.get=function get(i0,i1,i2,i3,i4){ - return dtype === 'generic' ? this.data.get(this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4) : this.data[this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4];}; - proto.index=function index( - i0,i1,i2,i3,i4 - ){return this.offset+this.stride[0]*i0+this.stride[1]*i1+this.stride[2]*i2+this.stride[3]*i3+this.stride[4]*i4} - proto.hi=function hi(i0,i1,i2,i3,i4){return new View(this.data,(typeof i0!=='number'||i0<0)?this.shape[0]:i0|0,(typeof i1!=='number'||i1<0)?this.shape[1]:i1|0,(typeof i2!=='number'||i2<0)?this.shape[2]:i2|0,(typeof i3!=='number'||i3<0)?this.shape[3]:i3|0,(typeof i4!=='number'||i4<0)?this.shape[4]:i4|0,this.stride[0],this.stride[1],this.stride[2],this.stride[3],this.stride[4],this.offset)} - proto.lo=function lo(i0,i1,i2,i3,i4){var b=this.offset,d=0,a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],c0=this.stride[0],c1=this.stride[1],c2=this.stride[2],c3=this.stride[3],c4=this.stride[4] - if(typeof i0==='number'&&i0>=0){d=i0|0;b+=c0*d;a0-=d} - if(typeof i1==='number'&&i1>=0){d=i1|0;b+=c1*d;a1-=d} - if(typeof i2==='number'&&i2>=0){d=i2|0;b+=c2*d;a2-=d} - if(typeof i3==='number'&&i3>=0){d=i3|0;b+=c3*d;a3-=d} - if(typeof i4==='number'&&i4>=0){d=i4|0;b+=c4*d;a4-=d} - return new View(this.data,a0,a1,a2,a3,a4,c0,c1,c2,c3,c4,b)} - proto.step=function step(i0,i1,i2,i3,i4){var a0=this.shape[0],a1=this.shape[1],a2=this.shape[2],a3=this.shape[3],a4=this.shape[4],b0=this.stride[0],b1=this.stride[1],b2=this.stride[2],b3=this.stride[3],b4=this.stride[4],c=this.offset,d=0,ceil=Math.ceil - if(typeof i0==='number'){d=i0|0;if(d<0){c+=b0*(a0-1);a0=ceil(-a0/d)}else{a0=ceil(a0/d)}b0*=d} - if(typeof i1==='number'){d=i1|0;if(d<0){c+=b1*(a1-1);a1=ceil(-a1/d)}else{a1=ceil(a1/d)}b1*=d} - if(typeof i2==='number'){d=i2|0;if(d<0){c+=b2*(a2-1);a2=ceil(-a2/d)}else{a2=ceil(a2/d)}b2*=d} - if(typeof i3==='number'){d=i3|0;if(d<0){c+=b3*(a3-1);a3=ceil(-a3/d)}else{a3=ceil(a3/d)}b3*=d} - if(typeof i4==='number'){d=i4|0;if(d<0){c+=b4*(a4-1);a4=ceil(-a4/d)}else{a4=ceil(a4/d)}b4*=d} - return new View(this.data,a0,a1,a2,a3,a4,b0,b1,b2,b3,b4,c)} - proto.transpose=function transpose(i0,i1,i2,i3,i4){i0=(i0===undefined?0:i0|0);i1=(i1===undefined?1:i1|0);i2=(i2===undefined?2:i2|0);i3=(i3===undefined?3:i3|0);i4=(i4===undefined?4:i4|0) - var a=this.shape,b=this.stride;return new View(this.data,a[i0],a[i1],a[i2],a[i3],a[i4],b[i0],b[i1],b[i2],b[i3],b[i4],this.offset)} - proto.pick=function pick(i0,i1,i2,i3,i4){var a=[],b=[],c=this.offset - if(typeof i0==='number'&&i0>=0){c=(c+this.stride[0]*i0)|0}else{a.push(this.shape[0]);b.push(this.stride[0])} - if(typeof i1==='number'&&i1>=0){c=(c+this.stride[1]*i1)|0}else{a.push(this.shape[1]);b.push(this.stride[1])} - if(typeof i2==='number'&&i2>=0){c=(c+this.stride[2]*i2)|0}else{a.push(this.shape[2]);b.push(this.stride[2])} - if(typeof i3==='number'&&i3>=0){c=(c+this.stride[3]*i3)|0}else{a.push(this.shape[3]);b.push(this.stride[3])} - if(typeof i4==='number'&&i4>=0){c=(c+this.stride[4]*i4)|0}else{a.push(this.shape[4]);b.push(this.stride[4])} - var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)} - return function construct(data,shape,stride,offset){return new View(data,shape[0],shape[1],shape[2],shape[3],shape[4],stride[0],stride[1],stride[2],stride[3],stride[4],offset)} - } } + function compileConstructor(inType, inDimension) { var dKey = inDimension === -1 ? 'G' : String(inDimension) From f1312db9142806e2a7fe9779c81a4e0e3c174b71 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 14:17:50 -0400 Subject: [PATCH 11/15] remove iota-array dependency --- ndarray.js | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/ndarray.js b/ndarray.js index 7332f62..9fb41c0 100644 --- a/ndarray.js +++ b/ndarray.js @@ -1,4 +1,3 @@ -var iota = require("iota-array") var isBuffer = require("is-buffer") var hasTypedArrays = ((typeof Float64Array) !== "undefined") diff --git a/package.json b/package.json index d5367b3..6b4bc2e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "test": "test" }, "dependencies": { - "iota-array": "^1.0.0", "is-buffer": "^1.0.2" }, "devDependencies": { From 210ccfbf32d085f40603a8b44f81d50ddf2b7d83 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 9 Aug 2021 14:56:59 -0400 Subject: [PATCH 12/15] refactoring and add comments --- ndarray.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ndarray.js b/ndarray.js index 9fb41c0..44bcbbc 100644 --- a/ndarray.js +++ b/ndarray.js @@ -22,7 +22,8 @@ function order() { } var allFns = { - G: function (dtype) { + // Special case for trivial arrays + T: function (dtype) { function View(a) { this.data = a } @@ -49,6 +50,8 @@ var allFns = { return new View(a) } }, + + // Special case for 0d arrays 0: function (dtype, TrivialArray) { function View(a, d) { this.data = a @@ -82,6 +85,7 @@ var allFns = { return new View(a, d) } }, + 1: function (dtype, CTOR_LIST, ORDER) { function View(a, b0, c0, d) { this.data = a @@ -885,7 +889,7 @@ var allFns = { function compileConstructor(inType, inDimension) { - var dKey = inDimension === -1 ? 'G' : String(inDimension) + var dKey = inDimension === -1 ? 'T' : String(inDimension) var procedure = allFns[dKey] if(inDimension === -1) { @@ -912,14 +916,14 @@ function arrayDType(data) { return "int16" case "[object Int32Array]": return "int32" + case "[object Uint8ClampedArray]": + return "uint8_clamped" 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]": @@ -933,20 +937,22 @@ function arrayDType(data) { } var CACHED_CONSTRUCTORS = { + "generic":[], + "buffer":[], + "array":[], + + // typed arrays "float32":[], "float64":[], "int8":[], "int16":[], "int32":[], + "uint8_clamped":[], "uint8":[], "uint16":[], "uint32":[], - "array":[], - "uint8_clamped":[], "bigint64": [], - "biguint64": [], - "buffer":[], - "generic":[] + "biguint64": [] } ;(function() { From 492214e63e1640fde3c671589fdc97d5925e086f Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 2 Sep 2021 12:50:02 -0400 Subject: [PATCH 13/15] Revert "bump version as a minor" This reverts commit 24777661dbecf1ceb5ac423b3a645436fa6960f9. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b4bc2e..a41693c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndarray", - "version": "1.1.0", + "version": "1.0.19", "description": "Multidimensional Arrays", "main": "ndarray.js", "directories": { From 70ec67233be65de444307a6916aba2655e28bd84 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 2 Sep 2021 12:50:11 -0400 Subject: [PATCH 14/15] 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a41693c..6b4bc2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndarray", - "version": "1.0.19", + "version": "1.1.0", "description": "Multidimensional Arrays", "main": "ndarray.js", "directories": { From 6d7a78bd63c49ef98cbb78f94c55a0bf6bc24f70 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Fri, 7 Jun 2024 13:04:13 -0400 Subject: [PATCH 15/15] Update README.md with "maintained by Plotly" badge --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 259fa0d..4be7064 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,13 @@ Modular multidimensional arrays for JavaScript. ##### Coming from MATLAB or numpy? See: [scijs/ndarray for MATLAB users](https://github.com/scijs/scijs-ndarray-for-matlab-users) ##### [Big list of ndarray modules](https://github.com/scijs/ndarray/wiki/ndarray-module-list#core-module) + + + Introduction ============ `ndarrays` provide higher dimensional views of 1D arrays. For example, here is how you can turn a length 4 typed array into an nd-array: