UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 5.3 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import t from"./../../utils/define-nonenumerable-read-only-property.js";import r from"./../../utils/define-nonenumerable-read-only-accessor.js";import e from"./bytes-per-element.js";import i from"./iteration-order.js";import s from"./strides2order.js";import n from"./minmax-view-buffer-index.js";import o from"./../../utils/define-read-only-property.js";import f from"./../../string/replace.js";function h(t,r){return r&&("column-major"===t||"both"===t)}function a(t,r){return r&&("row-major"===t||"both"===t)}var u=n,_=[0,0];function d(t,r,e,i,s){return 0!==t&&0!==s&&(u(_,r,e,i),t===_[1]-_[0]+1)}var p=o;function c(t){var r={};return p(r,"ROW_MAJOR_CONTIGUOUS",t.ROW_MAJOR_CONTIGUOUS),p(r,"COLUMN_MAJOR_CONTIGUOUS",t.COLUMN_MAJOR_CONTIGUOUS),r}function y(t){var r,e,i=t-1;for(r="return function set(",e=0;e<t;e++)r+="i"+e+",";for(r+="v){",r+="this._buffer[this._offset+",e=0;e<t;e++)r+="this._strides["+e+"]*i"+e,e<i&&(r+="+");return r+="]",r+="=v;",r+="return this;",r+="}",r+="//# sourceURL=ndarray.ctor.set.js",new Function(r)()}function l(t){var r,e,i=t-1;for(r="return function get(",e=0;e<t;e++)r+="i"+e,e<i&&(r+=",");for(r+="){",r+="return this._buffer[this._offset+",e=0;e<t;e++)r+="this._strides["+e+"]*i"+e,e<i&&(r+="+");return r+="];",r+="}",r+="//# sourceURL=ndarray.ctor.get.js",new Function(r)()}function g(t){var r,e,i,s,n,o;if(1===this._iterationOrder)return this._buffer[this._offset+t];if(-1===this._iterationOrder)return this._buffer[this._offset-t];if(e=this._shape,i=this._shape.length,r=this._strides,s=this._offset,"column-major"===this._order){for(o=0;o<i;o++)t-=n=t%e[o],t/=e[o],s+=n*r[o];return this._buffer[s]}for(o=i-1;o>=0;o--)t-=n=t%e[o],t/=e[o],s+=n*r[o];return this._buffer[s]}function m(t,r){var e,i,s,n,o,f;if(1===this._iterationOrder)return this._buffer[this._offset+t]=r,this;if(-1===this._iterationOrder)return this._buffer[this._offset-t]=r,this;if(i=this._shape,s=this._shape.length,e=this._strides,n=this._offset,"column-major"===this._order){for(f=0;f<s;f++)t-=o=t%i[f],t/=i[f],n+=o*e[f];return this._buffer[n]=r,this}for(f=s-1;f>=0;f--)t-=o=t%i[f],t/=i[f],n+=o*e[f];return this._buffer[n]=r,this}function O(){var t,r;for(t=this._offset,r=0;r<arguments.length-1;r++)t+=this._strides[r]*arguments[r];return this._buffer[t]=arguments[r],this}function E(){var t,r;for(t=this._offset,r=0;r<arguments.length;r++)t+=this._strides[r]*arguments[r];return this._buffer[t]}function b(){var t,r,e;for(r=this._length,(t={}).type="ndarray",t.dtype=this.dtype,t.flags={},t.order=this._order,t.shape=this._shape.slice(),t.strides=this._strides.slice(),e=0;e<r;e++)t.strides[e]<0&&(t.strides[e]*=-1);for(t.data=[],e=0;e<r;e++)t.data.push(this.iget(e));return t}var U=f,v={int8:"new Int8Array( [ {{data}} ] )",uint8:"new Uint8Array( [ {{data}} ] )",uint8c:"new Uint8ClampedArray( [ {{data}} ] )",int16:"new Int16Array( [ {{data}} ] )",uint16:"new Uint16Array( [ {{data}} ] )",int32:"new Int32Array( [ {{data}} ] )",uint32:"new Uint32Array( [ {{data}} ] )",float32:"new Float32Array( [ {{data}} ] )",float64:"new Float64Array( [ {{data}} ] )",generic:"[ {{data}} ]",binary:"new Buffer( [ {{data}} ] )"};function R(){var t,r,e,i,s;if(r=this._shape.length,i="ndarray( ",t="",this._length<=100)for(s=0;s<this._length;s++)t+=this.iget(s),s<this._length-1&&(t+=", ");else{for(s=0;s<3;s++)t+=this.iget(s),s<2&&(t+=", ");for(t+=", ..., ",s=2;s>=0;s--)t+=this.iget(this._length-1-s),s>0&&(t+=", ")}for(e=v[this.dtype],i+=U(e,"{{data}}",t),i+=", ",i+="[ "+this._shape.join(", ")+" ]",i+=", ",i+="[ ",s=0;s<r;s++)this._strides[s]<0?i+=-this._strides[s]:i+=this._strides[s],s<r-1&&(i+=", ");return i+=" ]",i+=", ",i+="0",i+=", ",i+="'"+this._order+"'",i+=" )"}var T=!0,j={codegen:T},w=t,A=r,N=e,M=i,L=s,S=h,C=a,I=d,J=c,B=y,G=l,P=g,Y=m,F=O,x=E,W=b,k=R,q=j;function z(t,r,e){var i={};function s(t,e,i,n,o){var f,h,a,u,_;if(!(this instanceof s))return new s(t,e,i,n,o);for(u=1,_=0;_<r;_++)u*=e[_];return h=s.BYTES_PER_ELEMENT?s.BYTES_PER_ELEMENT*u:null,this._byteLength=h,this._buffer=t,this._length=u,this._offset=n,this._order=o,this._shape=e,this._strides=i,this._iterationOrder=M(i),f=I(u,e,i,n,this._iterationOrder),a=L(i),this._flags={ROW_MAJOR_CONTIGUOUS:C(a,f),COLUMN_MAJOR_CONTIGUOUS:S(a,f)},this}return i.codegen=arguments.length>2?void 0===e.codegen?q.codegen:e.codegen:q.codegen,w(s,"BYTES_PER_ELEMENT",N(t)),w(s,"dtype",t),w(s,"ndims",r),A(s.prototype,"byteLength",(function(){return this._byteLength})),w(s.prototype,"BYTES_PER_ELEMENT",s.BYTES_PER_ELEMENT),A(s.prototype,"data",(function(){return this._buffer})),w(s.prototype,"dtype",s.dtype),A(s.prototype,"flags",(function(){return J(this._flags)})),A(s.prototype,"length",(function(){return this._length})),w(s.prototype,"ndims",r),A(s.prototype,"offset",(function(){return this._offset})),A(s.prototype,"order",(function(){return this._order})),A(s.prototype,"shape",(function(){return this._shape.slice()})),A(s.prototype,"strides",(function(){return this._strides.slice()})),w(s.prototype,"get",i.codegen?G(r):x),w(s.prototype,"iget",P),w(s.prototype,"set",i.codegen?B(r):F),w(s.prototype,"iset",Y),w(s.prototype,"toString",k),w(s.prototype,"toJSON",W),s}var D=z;export default D; //# sourceMappingURL=ctor.js.map