@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 9.67 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import e from"./../assert/is-nonnegative-integer.js";import r from"./../assert/is-array-like-object.js";import t from"./../assert/is-collection.js";import n from"./../assert/is-arraybuffer.js";import a from"./../assert/is-object.js";import i from"./../assert/is-array.js";import o from"./../assert/is-function.js";import l from"./../assert/is-complex-like.js";import u from"./../math/base/assert/is-even.js";import f from"./../math/base/assert/is-integer.js";import s from"./../assert/has-iterator-symbol-support.js";import m from"./../symbol/iterator.js";import g from"./../utils/define-property.js";import h from"./float64.js";import b from"./../complex/float64.js";import c from"./../complex/real.js";import w from"./../complex/imag.js";var y=r,p=l,v=c,d=w;function E(e){var r,t;for(r=[];;){if((t=e.next()).value)if(y(t.value))r.push(t.value[0],t.value[1]);else{if(!p(t.value))return new TypeError("invalid argument. An iterator must return either a two-element array containing real and imaginary components or a complex number. Value: `"+t.value+"`.");r.push(v(t.value),d(t.value))}if(t.done)break}return r}var T=r,j=l,_=c,x=w;function k(e,r,t){var n,a,i;for(n=[],i=0;;){if(i+=1,(a=e.next()).value)if(a=r.call(t,a.value,i),T(a))n.push(a[0],a[1]);else{if(!j(a))return new TypeError("invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `"+a+"`.");n.push(_(a),x(a))}if(a.done)break}return n}var V=l,L=c,R=w;function A(e,r){var t,n,a,i;for(t=r.length,i=0,a=0;a<t;a++){if(n=r[a],!V(n))return null;e[i]=L(n),e[i+1]=R(n),i+=2}return e}var B=e.isPrimitive,M=r,O=t,C=n,S=a,F=i,P=o,N=l,Y=u,I=f,q=s,z=m,D=g,G=h,H=b,J=c,K=w,Q=E,U=k,W=A,X=2*G.BYTES_PER_ELEMENT,Z=q();function $(e){return e instanceof re||"object"==typeof e&&null!==e&&("Complex64Array"===e.constructor.name||"Complex128Array"===e.constructor.name)&&"number"==typeof e._length&&"object"==typeof e._buffer}function ee(e){return e===re||"Complex64Array"===e.name}function re(){var e,r,t,n;if(r=arguments.length,!(this instanceof re))return 0===r?new re:1===r?new re(arguments[0]):2===r?new re(arguments[0],arguments[1]):new re(arguments[0],arguments[1],arguments[2]);if(0===r)t=new G(0);else if(1===r)if(B(arguments[0]))t=new G(2*arguments[0]);else if(O(arguments[0]))if((n=(t=arguments[0]).length)&&F(t)&&N(t[0])){if(null===(t=W(new G(2*n),t))){if(!Y(n))throw new RangeError("invalid argument. Array-like object input arguments must have a length which is a multiple of two. Length: `"+n+"`.");t=new G(arguments[0])}}else{if(!Y(n))throw new RangeError("invalid argument. Array-like object and typed array input arguments must have a length which is a multiple of two. Length: `"+n+"`.");t=new G(t)}else if(C(arguments[0])){if(!I((t=arguments[0]).byteLength/X))throw new RangeError("invalid argument. ArrayBuffer byte length must be a multiple of "+X+". Byte length: `"+t.byteLength+"`.");t=new G(t)}else{if(!S(arguments[0]))throw new TypeError("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `"+arguments[0]+"`.");if(t=arguments[0],!1===Z)throw new TypeError("invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `"+t+"`.");if(!P(t[z]))throw new TypeError("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `"+t+"`.");if(t=t[z](),!P(t.next))throw new TypeError("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable.");if((t=Q(t))instanceof Error)throw t;t=new G(t)}else{if(!C(t=arguments[0]))throw new TypeError("invalid argument. First argument must be an array buffer. Value: `"+t+"`.");if(!B(e=arguments[1]))throw new TypeError("invalid argument. Byte offset must be a nonnegative integer. Value: `"+e+"`.");if(!I(e/X))throw new RangeError("invalid argument. Byte offset must be a multiple of "+X+". Value: `"+e+"`.");if(2===r){if(n=t.byteLength-e,!I(n/X))throw new RangeError("invalid arguments. ArrayBuffer view byte length must be a multiple of "+X+". View byte length: `"+n+"`.");t=new G(t,e)}else{if(!B(n=arguments[2]))throw new TypeError("invalid argument. Length must be a nonnegative integer. Value: `"+n+"`.");if(n*X>t.byteLength-e)throw new RangeError("invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `"+n*X+"`.");t=new G(t,e,2*n)}}return D(this,"_buffer",{configurable:!1,enumerable:!1,writable:!1,value:t}),D(this,"_length",{configurable:!1,enumerable:!1,writable:!1,value:t.length/2}),this}D(re,"BYTES_PER_ELEMENT",{configurable:!1,enumerable:!1,writable:!1,value:X}),D(re,"name",{configurable:!1,enumerable:!1,writable:!1,value:"Complex128Array"}),D(re,"from",{configurable:!1,enumerable:!1,writable:!1,value:function(e){var r,t,n,a,i,o,l,u,f,s,m;if(!P(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!ee(this))throw new TypeError("invalid invocation. `this` is not a complex number array.");if((t=arguments.length)>1){if(!P(n=arguments[1]))throw new TypeError("invalid argument. Second argument must be a function. Value: `"+n+"`.");t>2&&(r=arguments[2])}if(O(e))if(n){for(l=e.length,s=0;s<l;s++)if(!N(e[s])){u=!0;break}if(u){if(!Y(l))throw new RangeError("invalid argument. First argument must have a length which is a multiple of two. Length: `"+l+"`.");for(i=(a=new this(l/2))._buffer,s=0;s<l;s++)i[s]=n.call(r,e[s],s)}else for(i=(a=new this(l))._buffer,m=0,s=0;s<l;s++){if(f=n.call(r,e[s],s),N(f))i[m]=J(f),i[m+1]=K(f);else{if(!M(f))throw new TypeError("invalid argument. Callback must return either a two-element array containing real and imaginary components or a complex number. Value: `"+f+"`.");i[m]=f[0],i[m+1]=f[1]}m+=2}}else a=new this(e);else{if(!(S(e)&&Z&&P(e[z])))throw new TypeError("invalid argument. First argument must be an array-like object or an iterable. Value: `"+e+"`.");if(i=e[z](),!P(i.next))throw new TypeError("invalid argument. First argument must be an array-like object or an iterable.");if((o=n?U(i,n,r):Q(i))instanceof Error)throw o;for(i=(a=new this(l=o.length/2))._buffer,s=0;s<l;s++)i[s]=o[s]}return a}}),D(re,"of",{configurable:!1,enumerable:!1,writable:!1,value:function(){var e,r;if(!P(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!ee(this))throw new TypeError("invalid invocation. `this` is not a complex number array.");for(e=[],r=0;r<arguments.length;r++)e.push(arguments[r]);return new this(e)}}),D(re.prototype,"buffer",{configurable:!1,enumerable:!1,get:function(){return this._buffer.buffer}}),D(re.prototype,"byteLength",{configurable:!1,enumerable:!1,get:function(){return this._buffer.byteLength}}),D(re.prototype,"byteOffset",{configurable:!1,enumerable:!1,get:function(){return this._buffer.byteOffset}}),D(re.prototype,"BYTES_PER_ELEMENT",{configurable:!1,enumerable:!1,writable:!1,value:re.BYTES_PER_ELEMENT}),D(re.prototype,"get",{configurable:!1,enumerable:!1,writable:!1,value:function(e){var r,t,n;if(!$(this))throw new TypeError("invalid invocation. `this` is not a complex number array.");if(n=this._buffer,arguments.length>1){if(r=arguments[1],!M(t=e)||t.length<2)throw new TypeError("invalid argument. Output argument must be an array-like object. Value: `"+t+"`.")}else r=e;if(!B(r))throw new TypeError("invalid argument. Index argument must be a nonnegative integer. Value: `"+r+"`.");if(!(r>=this._length))return r*=2,t?(t[0]=n[r],t[1]=n[r+1],t):new H(n[r],n[r+1])}}),D(re.prototype,"length",{configurable:!1,enumerable:!1,get:function(){return this._length}}),D(re.prototype,"set",{configurable:!1,enumerable:!1,writable:!1,value:function(e){var r,t,n,a,i,o,l,u,f;if(!$(this))throw new TypeError("invalid invocation. `this` is not a complex number array.");if(n=this._buffer,arguments.length>1){if(!B(t=arguments[1]))throw new TypeError("invalid argument. Index argument must be a nonnegative integer. Value: `"+t+"`.")}else t=0;if(N(e)){if(t>=this._length)throw new RangeError("invalid argument. Index argument is out-of-bounds. Value: `"+t+"`.");return n[t*=2]=J(e),void(n[t+1]=K(e))}if($(e)){if(t+(o=e._length)>this._length)throw new RangeError("invalid arguments. Target array lacks sufficient storage to accommodate source values.");if(r=e._buffer,f=n.byteOffset+t*X,r.buffer===n.buffer&&r.byteOffset<f&&r.byteOffset+r.byteLength>f){for(a=new G(r.length),u=0;u<r.length;u++)a[u]=r[u];r=a}for(t*=2,f=0,u=0;u<o;u++)n[t]=r[f],n[t+1]=r[f+1],t+=2,f+=2}else{if(!M(e))throw new TypeError("invalid argument. First argument must be either a complex number, an array-like object, or a complex number array. Value: `"+e+"`.");for(o=e.length,u=0;u<o;u++)if(!N(e[u])){i=!0;break}if(i){if(!Y(o))throw new RangeError("invalid argument. Array-like object arguments must have a length which is a multiple of two. Length: `"+o+"`.");if(t+o/2>this._length)throw new RangeError("invalid arguments. Target array lacks sufficient storage to accommodate source values.");if(r=e,f=n.byteOffset+t*X,r.buffer===n.buffer&&r.byteOffset<f&&r.byteOffset+r.byteLength>f){for(a=new G(o),u=0;u<o;u++)a[u]=r[u];r=a}for(t*=2,o/=2,f=0,u=0;u<o;u++)n[t]=r[f],n[t+1]=r[f+1],t+=2,f+=2;return}if(t+o>this._length)throw new RangeError("invalid arguments. Target array lacks sufficient storage to accommodate source values.");for(t*=2,u=0;u<o;u++)l=e[u],n[t]=J(l),n[t+1]=K(l),t+=2}}});var te=re;export default te;
//# sourceMappingURL=complex128.js.map