UNPKG

@stdlib/esm

Version:

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

3 lines 1.03 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import r from"./../../math/base/special/trunc.js";var e=r;function n(r,n,a,t,o,f,i){var u,l,m,s,c;for(u=n.length,l=1,c=0;c<u;c++)l*=n[c];if("clamp"===i)f<0?f=0:f>=l&&(f=l-1);else if("wrap"===i)f<0?(f+=l)<0&&0!==(f%=l)&&(f+=l):f>=l&&(f-=l)>=l&&(f%=l);else if(f<0||f>=l)throw new RangeError("invalid argument. Linear index must not exceed array dimensions. Number of array elements: "+l+". Value: `"+f+"`.");if(0===t){if("column-major"===o){for(c=0;c<u;c++)f-=s=f%n[c],f/=n[c],r[c]=s;return r}for(c=u-1;c>=0;c--)f-=s=f%n[c],f/=n[c],r[c]=s;return r}if("column-major"===o){for(c=u-1;c>=0;c--)(s=a[c])<0?(f-=(m=e(f/s))*s,r[c]=n[c]-1+m):(f-=(m=e(f/s))*s,r[c]=m);return r}for(c=0;c<u;c++)(s=a[c])<0?(f-=(m=e(f/s))*s,r[c]=n[c]-1+m):(f-=(m=e(f/s))*s,r[c]=m);return r}var a=n;function t(r,e,n,t,o,f,i){return 6===arguments.length?a(new Array(e.length),r,e,n,t,o,f):a(r,e,n,t,o,f,i)}var o=t;export default o; //# sourceMappingURL=ind2sub.js.map