1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 | this.j$ = this.jStat = (function(Math, undefined) {
|
3 |
|
4 |
|
5 | var concat = Array.prototype.concat;
|
6 | var slice = Array.prototype.slice;
|
7 | var toString = Object.prototype.toString;
|
8 |
|
9 |
|
10 |
|
11 | function calcRdx(n, m) {
|
12 | var val = n > m ? n : m;
|
13 | return Math.pow(10,
|
14 | 17 - ~~(Math.log(((val > 0) ? val : -val)) * Math.LOG10E));
|
15 | }
|
16 |
|
17 |
|
18 | var isArray = Array.isArray || function isArray(arg) {
|
19 | return toString.call(arg) === '[object Array]';
|
20 | };
|
21 |
|
22 |
|
23 | function isFunction(arg) {
|
24 | return toString.call(arg) === '[object Function]';
|
25 | }
|
26 |
|
27 |
|
28 | function isNumber(arg) {
|
29 | return typeof arg === 'number' && arg === arg;
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 | function toVector(arr) {
|
35 | return concat.apply([], arr);
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 | function jStat() {
|
41 | return new jStat._init(arguments);
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 | jStat.fn = jStat.prototype;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | jStat._init = function _init(args) {
|
52 | var i;
|
53 |
|
54 |
|
55 | if (isArray(args[0])) {
|
56 |
|
57 | if (isArray(args[0][0])) {
|
58 |
|
59 | if (isFunction(args[1]))
|
60 | args[0] = jStat.map(args[0], args[1]);
|
61 |
|
62 | for (i = 0; i < args[0].length; i++)
|
63 | this[i] = args[0][i];
|
64 | this.length = args[0].length;
|
65 |
|
66 |
|
67 | } else {
|
68 | this[0] = isFunction(args[1]) ? jStat.map(args[0], args[1]) : args[0];
|
69 | this.length = 1;
|
70 | }
|
71 |
|
72 |
|
73 | } else if (isNumber(args[0])) {
|
74 | this[0] = jStat.seq.apply(null, args);
|
75 | this.length = 1;
|
76 |
|
77 |
|
78 | } else if (args[0] instanceof jStat) {
|
79 |
|
80 | return jStat(args[0].toArray());
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | } else {
|
86 | this[0] = [];
|
87 | this.length = 1;
|
88 | }
|
89 |
|
90 | return this;
|
91 | };
|
92 | jStat._init.prototype = jStat.prototype;
|
93 | jStat._init.constructor = jStat;
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | jStat.utils = {
|
99 | calcRdx: calcRdx,
|
100 | isArray: isArray,
|
101 | isFunction: isFunction,
|
102 | isNumber: isNumber,
|
103 | toVector: toVector
|
104 | };
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | jStat.extend = function extend(obj) {
|
110 | var i, j;
|
111 |
|
112 | if (arguments.length === 1) {
|
113 | for (j in obj)
|
114 | jStat[j] = obj[j];
|
115 | return this;
|
116 | }
|
117 |
|
118 | for (i = 1; i < arguments.length; i++) {
|
119 | for (j in arguments[i])
|
120 | obj[j] = arguments[i][j];
|
121 | }
|
122 |
|
123 | return obj;
|
124 | };
|
125 |
|
126 |
|
127 |
|
128 | jStat.rows = function rows(arr) {
|
129 | return arr.length || 1;
|
130 | };
|
131 |
|
132 |
|
133 |
|
134 | jStat.cols = function cols(arr) {
|
135 | return arr[0].length || 1;
|
136 | };
|
137 |
|
138 |
|
139 |
|
140 | jStat.dimensions = function dimensions(arr) {
|
141 | return {
|
142 | rows: jStat.rows(arr),
|
143 | cols: jStat.cols(arr)
|
144 | };
|
145 | };
|
146 |
|
147 |
|
148 |
|
149 | jStat.row = function row(arr, index) {
|
150 | return arr[index];
|
151 | };
|
152 |
|
153 |
|
154 |
|
155 | jStat.col = function cols(arr, index) {
|
156 | var column = new Array(arr.length);
|
157 | for (var i = 0; i < arr.length; i++)
|
158 | column[i] = [arr[i][index]];
|
159 | return column;
|
160 | };
|
161 |
|
162 |
|
163 |
|
164 | jStat.diag = function diag(arr) {
|
165 | var nrow = jStat.rows(arr);
|
166 | var res = new Array(nrow);
|
167 | for (var row = 0; row < nrow; row++)
|
168 | res[row] = [arr[row][row]];
|
169 | return res;
|
170 | };
|
171 |
|
172 |
|
173 |
|
174 | jStat.antidiag = function antidiag(arr) {
|
175 | var nrow = jStat.rows(arr) - 1;
|
176 | var res = new Array(nrow);
|
177 | for (var i = 0; nrow >= 0; nrow--, i++)
|
178 | res[i] = [arr[i][nrow]];
|
179 | return res;
|
180 | };
|
181 |
|
182 |
|
183 | jStat.transpose = function transpose(arr) {
|
184 | var obj = [];
|
185 | var objArr, rows, cols, j, i;
|
186 |
|
187 |
|
188 | if (!isArray(arr[0]))
|
189 | arr = [arr];
|
190 |
|
191 | rows = arr.length;
|
192 | cols = arr[0].length;
|
193 |
|
194 | for (i = 0; i < cols; i++) {
|
195 | objArr = new Array(rows);
|
196 | for (j = 0; j < rows; j++)
|
197 | objArr[j] = arr[j][i];
|
198 | obj.push(objArr);
|
199 | }
|
200 |
|
201 |
|
202 | return obj.length === 1 ? obj[0] : obj;
|
203 | };
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | jStat.map = function map(arr, func, toAlter) {
|
209 | var row, nrow, ncol, res, col;
|
210 |
|
211 | if (!isArray(arr[0]))
|
212 | arr = [arr];
|
213 |
|
214 | nrow = arr.length;
|
215 | ncol = arr[0].length;
|
216 | res = toAlter ? arr : new Array(nrow);
|
217 |
|
218 | for (row = 0; row < nrow; row++) {
|
219 |
|
220 | if (!res[row])
|
221 | res[row] = new Array(ncol);
|
222 | for (col = 0; col < ncol; col++)
|
223 | res[row][col] = func(arr[row][col], row, col);
|
224 | }
|
225 |
|
226 | return res.length === 1 ? res[0] : res;
|
227 | };
|
228 |
|
229 |
|
230 |
|
231 | jStat.cumreduce = function cumreduce(arr, func, toAlter) {
|
232 | var row, nrow, ncol, res, col;
|
233 |
|
234 | if (!isArray(arr[0]))
|
235 | arr = [arr];
|
236 |
|
237 | nrow = arr.length;
|
238 | ncol = arr[0].length;
|
239 | res = toAlter ? arr : new Array(nrow);
|
240 |
|
241 | for (row = 0; row < nrow; row++) {
|
242 |
|
243 | if (!res[row])
|
244 | res[row] = new Array(ncol);
|
245 | if (ncol > 0)
|
246 | res[row][0] = arr[row][0];
|
247 | for (col = 1; col < ncol; col++)
|
248 | res[row][col] = func(res[row][col-1], arr[row][col]);
|
249 | }
|
250 | return res.length === 1 ? res[0] : res;
|
251 | };
|
252 |
|
253 |
|
254 |
|
255 | jStat.alter = function alter(arr, func) {
|
256 | return jStat.map(arr, func, true);
|
257 | };
|
258 |
|
259 |
|
260 |
|
261 | jStat.create = function create(rows, cols, func) {
|
262 | var res = new Array(rows);
|
263 | var i, j;
|
264 |
|
265 | if (isFunction(cols)) {
|
266 | func = cols;
|
267 | cols = rows;
|
268 | }
|
269 |
|
270 | for (i = 0; i < rows; i++) {
|
271 | res[i] = new Array(cols);
|
272 | for (j = 0; j < cols; j++)
|
273 | res[i][j] = func(i, j);
|
274 | }
|
275 |
|
276 | return res;
|
277 | };
|
278 |
|
279 |
|
280 | function retZero() { return 0; }
|
281 |
|
282 |
|
283 |
|
284 | jStat.zeros = function zeros(rows, cols) {
|
285 | if (!isNumber(cols))
|
286 | cols = rows;
|
287 | return jStat.create(rows, cols, retZero);
|
288 | };
|
289 |
|
290 |
|
291 | function retOne() { return 1; }
|
292 |
|
293 |
|
294 |
|
295 | jStat.ones = function ones(rows, cols) {
|
296 | if (!isNumber(cols))
|
297 | cols = rows;
|
298 | return jStat.create(rows, cols, retOne);
|
299 | };
|
300 |
|
301 |
|
302 |
|
303 | jStat.rand = function rand(rows, cols) {
|
304 | if (!isNumber(cols))
|
305 | cols = rows;
|
306 | return jStat.create(rows, cols, Math.random);
|
307 | };
|
308 |
|
309 |
|
310 | function retIdent(i, j) { return i === j ? 1 : 0; }
|
311 |
|
312 |
|
313 |
|
314 | jStat.identity = function identity(rows, cols) {
|
315 | if (!isNumber(cols))
|
316 | cols = rows;
|
317 | return jStat.create(rows, cols, retIdent);
|
318 | };
|
319 |
|
320 |
|
321 |
|
322 | jStat.symmetric = function symmetric(arr) {
|
323 | var issymmetric = true;
|
324 | var size = arr.length;
|
325 | var row, col;
|
326 |
|
327 | if (arr.length !== arr[0].length)
|
328 | return false;
|
329 |
|
330 | for (row = 0; row < size; row++) {
|
331 | for (col = 0; col < size; col++)
|
332 | if (arr[col][row] !== arr[row][col])
|
333 | return false;
|
334 | }
|
335 |
|
336 | return true;
|
337 | };
|
338 |
|
339 |
|
340 |
|
341 | jStat.clear = function clear(arr) {
|
342 | return jStat.alter(arr, retZero);
|
343 | };
|
344 |
|
345 |
|
346 |
|
347 | jStat.seq = function seq(min, max, length, func) {
|
348 | if (!isFunction(func))
|
349 | func = false;
|
350 |
|
351 | var arr = [];
|
352 | var hival = calcRdx(min, max);
|
353 | var step = (max * hival - min * hival) / ((length - 1) * hival);
|
354 | var current = min;
|
355 | var cnt;
|
356 |
|
357 |
|
358 |
|
359 | for (cnt = 0;
|
360 | current <= max;
|
361 | cnt++, current = (min * hival + step * hival * cnt) / hival) {
|
362 | arr.push((func ? func(current, cnt) : current));
|
363 | }
|
364 |
|
365 | return arr;
|
366 | };
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 | var jProto = jStat.prototype;
|
375 |
|
376 |
|
377 | jProto.length = 0;
|
378 |
|
379 |
|
380 |
|
381 |
|
382 | jProto.push = Array.prototype.push;
|
383 | jProto.sort = Array.prototype.sort;
|
384 | jProto.splice = Array.prototype.splice;
|
385 | jProto.slice = Array.prototype.slice;
|
386 |
|
387 |
|
388 |
|
389 | jProto.toArray = function toArray() {
|
390 | return this.length > 1 ? slice.call(this) : slice.call(this)[0];
|
391 | };
|
392 |
|
393 |
|
394 |
|
395 | jProto.map = function map(func, toAlter) {
|
396 | return jStat(jStat.map(this, func, toAlter));
|
397 | };
|
398 |
|
399 |
|
400 |
|
401 | jProto.cumreduce = function cumreduce(func, toAlter) {
|
402 | return jStat(jStat.cumreduce(this, func, toAlter));
|
403 | };
|
404 |
|
405 |
|
406 |
|
407 | jProto.alter = function alter(func) {
|
408 | jStat.alter(this, func);
|
409 | return this;
|
410 | };
|
411 |
|
412 |
|
413 |
|
414 | (function(funcs) {
|
415 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
416 | jProto[passfunc] = function(func) {
|
417 | var self = this,
|
418 | results;
|
419 |
|
420 | if (func) {
|
421 | setTimeout(function() {
|
422 | func.call(self, jProto[passfunc].call(self));
|
423 | });
|
424 | return this;
|
425 | }
|
426 | results = jStat[passfunc](this);
|
427 | return isArray(results) ? jStat(results) : results;
|
428 | };
|
429 | })(funcs[i]);
|
430 | })('transpose clear symmetric rows cols dimensions diag antidiag'.split(' '));
|
431 |
|
432 |
|
433 |
|
434 | (function(funcs) {
|
435 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
436 | jProto[passfunc] = function(index, func) {
|
437 | var self = this;
|
438 |
|
439 | if (func) {
|
440 | setTimeout(function() {
|
441 | func.call(self, jProto[passfunc].call(self, index));
|
442 | });
|
443 | return this;
|
444 | }
|
445 | return jStat(jStat[passfunc](this, index));
|
446 | };
|
447 | })(funcs[i]);
|
448 | })('row col'.split(' '));
|
449 |
|
450 |
|
451 |
|
452 | (function(funcs) {
|
453 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
454 | jProto[passfunc] = new Function(
|
455 | 'return jStat(jStat.' + passfunc + '.apply(null, arguments));');
|
456 | })(funcs[i]);
|
457 | })('create zeros ones rand identity'.split(' '));
|
458 |
|
459 |
|
460 |
|
461 | return jStat;
|
462 |
|
463 | }(Math));
|
464 | (function(jStat, Math) {
|
465 |
|
466 | var isFunction = jStat.utils.isFunction;
|
467 |
|
468 |
|
469 | function ascNum(a, b) { return a - b; }
|
470 |
|
471 | function clip(arg, min, max) {
|
472 | return Math.max(min, Math.min(arg, max));
|
473 | }
|
474 |
|
475 |
|
476 |
|
477 | jStat.sum = function sum(arr) {
|
478 | var sum = 0;
|
479 | var i = arr.length;
|
480 | while (--i >= 0)
|
481 | sum += arr[i];
|
482 | return sum;
|
483 | };
|
484 |
|
485 |
|
486 |
|
487 | jStat.sumsqrd = function sumsqrd(arr) {
|
488 | var sum = 0;
|
489 | var i = arr.length;
|
490 | while (--i >= 0)
|
491 | sum += arr[i] * arr[i];
|
492 | return sum;
|
493 | };
|
494 |
|
495 |
|
496 |
|
497 | jStat.sumsqerr = function sumsqerr(arr) {
|
498 | var mean = jStat.mean(arr);
|
499 | var sum = 0;
|
500 | var i = arr.length;
|
501 | var tmp;
|
502 | while (--i >= 0) {
|
503 | tmp = arr[i] - mean;
|
504 | sum += tmp * tmp;
|
505 | }
|
506 | return sum;
|
507 | };
|
508 |
|
509 |
|
510 | jStat.sumrow = function sumrow(arr) {
|
511 | var sum = 0;
|
512 | var i = arr.length;
|
513 | while (--i >= 0)
|
514 | sum += arr[i];
|
515 | return sum;
|
516 | };
|
517 |
|
518 |
|
519 | jStat.product = function product(arr) {
|
520 | var prod = 1;
|
521 | var i = arr.length;
|
522 | while (--i >= 0)
|
523 | prod *= arr[i];
|
524 | return prod;
|
525 | };
|
526 |
|
527 |
|
528 |
|
529 | jStat.min = function min(arr) {
|
530 | var low = arr[0];
|
531 | var i = 0;
|
532 | while (++i < arr.length)
|
533 | if (arr[i] < low)
|
534 | low = arr[i];
|
535 | return low;
|
536 | };
|
537 |
|
538 |
|
539 |
|
540 | jStat.max = function max(arr) {
|
541 | var high = arr[0];
|
542 | var i = 0;
|
543 | while (++i < arr.length)
|
544 | if (arr[i] > high)
|
545 | high = arr[i];
|
546 | return high;
|
547 | };
|
548 |
|
549 |
|
550 |
|
551 | jStat.unique = function unique(arr) {
|
552 | var hash = {}, _arr = [];
|
553 | for(var i = 0; i < arr.length; i++) {
|
554 | if (!hash[arr[i]]) {
|
555 | hash[arr[i]] = true;
|
556 | _arr.push(arr[i]);
|
557 | }
|
558 | }
|
559 | return _arr;
|
560 | };
|
561 |
|
562 |
|
563 |
|
564 | jStat.mean = function mean(arr) {
|
565 | return jStat.sum(arr) / arr.length;
|
566 | };
|
567 |
|
568 |
|
569 |
|
570 | jStat.meansqerr = function meansqerr(arr) {
|
571 | return jStat.sumsqerr(arr) / arr.length;
|
572 | };
|
573 |
|
574 |
|
575 |
|
576 | jStat.geomean = function geomean(arr) {
|
577 | return Math.pow(jStat.product(arr), 1 / arr.length);
|
578 | };
|
579 |
|
580 |
|
581 |
|
582 | jStat.median = function median(arr) {
|
583 | var arrlen = arr.length;
|
584 | var _arr = arr.slice().sort(ascNum);
|
585 |
|
586 | return !(arrlen & 1)
|
587 | ? (_arr[(arrlen / 2) - 1 ] + _arr[(arrlen / 2)]) / 2
|
588 | : _arr[(arrlen / 2) | 0 ];
|
589 | };
|
590 |
|
591 |
|
592 |
|
593 | jStat.cumsum = function cumsum(arr) {
|
594 | return jStat.cumreduce(arr, function (a, b) { return a + b; });
|
595 | };
|
596 |
|
597 |
|
598 |
|
599 | jStat.cumprod = function cumprod(arr) {
|
600 | return jStat.cumreduce(arr, function (a, b) { return a * b; });
|
601 | };
|
602 |
|
603 |
|
604 |
|
605 | jStat.diff = function diff(arr) {
|
606 | var diffs = [];
|
607 | var arrLen = arr.length;
|
608 | var i;
|
609 | for (i = 1; i < arrLen; i++)
|
610 | diffs.push(arr[i] - arr[i - 1]);
|
611 | return diffs;
|
612 | };
|
613 |
|
614 |
|
615 |
|
616 | jStat.rank = function (arr) {
|
617 | var arrlen = arr.length;
|
618 | var sorted = arr.slice().sort(ascNum);
|
619 | var ranks = new Array(arrlen);
|
620 | for (var i = 0; i < arrlen; i++) {
|
621 | var first = sorted.indexOf(arr[i]);
|
622 | var last = sorted.lastIndexOf(arr[i]);
|
623 | if (first === last) {
|
624 | var val = first;
|
625 | } else {
|
626 | var val = (first + last) / 2;
|
627 | }
|
628 | ranks[i] = val + 1;
|
629 | }
|
630 | return ranks;
|
631 | };
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 | jStat.mode = function mode(arr) {
|
638 | var arrLen = arr.length;
|
639 | var _arr = arr.slice().sort(ascNum);
|
640 | var count = 1;
|
641 | var maxCount = 0;
|
642 | var numMaxCount = 0;
|
643 | var mode_arr = [];
|
644 | var i;
|
645 |
|
646 | for (i = 0; i < arrLen; i++) {
|
647 | if (_arr[i] === _arr[i + 1]) {
|
648 | count++;
|
649 | } else {
|
650 | if (count > maxCount) {
|
651 | mode_arr = [_arr[i]];
|
652 | maxCount = count;
|
653 | numMaxCount = 0;
|
654 | }
|
655 |
|
656 | else if (count === maxCount) {
|
657 | mode_arr.push(_arr[i]);
|
658 | numMaxCount++;
|
659 | }
|
660 |
|
661 | count = 1;
|
662 | }
|
663 | }
|
664 |
|
665 | return numMaxCount === 0 ? mode_arr[0] : mode_arr;
|
666 | };
|
667 |
|
668 |
|
669 |
|
670 | jStat.range = function range(arr) {
|
671 | return jStat.max(arr) - jStat.min(arr);
|
672 | };
|
673 |
|
674 |
|
675 |
|
676 | jStat.variance = function variance(arr, flag) {
|
677 | return jStat.sumsqerr(arr) / (arr.length - (flag ? 1 : 0));
|
678 | };
|
679 |
|
680 |
|
681 | jStat.deviation = function (arr) {
|
682 | var mean = jStat.mean(arr);
|
683 | var arrlen = arr.length;
|
684 | var dev = new Array(arrlen);
|
685 | for (var i = 0; i < arrlen; i++) {
|
686 | dev[i] = arr[i] - mean;
|
687 | }
|
688 | return dev;
|
689 | };
|
690 |
|
691 |
|
692 |
|
693 | jStat.stdev = function stdev(arr, flag) {
|
694 | return Math.sqrt(jStat.variance(arr, flag));
|
695 | };
|
696 |
|
697 |
|
698 |
|
699 | jStat.meandev = function meandev(arr) {
|
700 | var devSum = 0;
|
701 | var mean = jStat.mean(arr);
|
702 | var i;
|
703 | for (i = arr.length - 1; i >= 0; i--)
|
704 | devSum += Math.abs(arr[i] - mean);
|
705 | return devSum / arr.length;
|
706 | };
|
707 |
|
708 |
|
709 |
|
710 | jStat.meddev = function meddev(arr) {
|
711 | var devSum = 0;
|
712 | var median = jStat.median(arr);
|
713 | var i;
|
714 | for (i = arr.length - 1; i >= 0; i--)
|
715 | devSum += Math.abs(arr[i] - median);
|
716 | return devSum / arr.length;
|
717 | };
|
718 |
|
719 |
|
720 |
|
721 | jStat.coeffvar = function coeffvar(arr) {
|
722 | return jStat.stdev(arr) / jStat.mean(arr);
|
723 | };
|
724 |
|
725 |
|
726 |
|
727 | jStat.quartiles = function quartiles(arr) {
|
728 | var arrlen = arr.length;
|
729 | var _arr = arr.slice().sort(ascNum);
|
730 | return [
|
731 | _arr[ Math.round((arrlen) / 4) - 1 ],
|
732 | _arr[ Math.round((arrlen) / 2) - 1 ],
|
733 | _arr[ Math.round((arrlen) * 3 / 4) - 1 ]
|
734 | ];
|
735 | };
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | jStat.quantiles = function quantiles(arr, quantilesArray, alphap, betap) {
|
741 | var sortedArray = arr.slice().sort(ascNum);
|
742 | var quantileVals = [quantilesArray.length];
|
743 | var n = arr.length;
|
744 | var i, p, m, aleph, k, gamma;
|
745 |
|
746 | if (typeof alphap === 'undefined')
|
747 | alphap = 3 / 8;
|
748 | if (typeof betap === 'undefined')
|
749 | betap = 3 / 8;
|
750 |
|
751 | for (i = 0; i < quantilesArray.length; i++) {
|
752 | p = quantilesArray[i];
|
753 | m = alphap + p * (1 - alphap - betap);
|
754 | aleph = n * p + m;
|
755 | k = Math.floor(clip(aleph, 1, n - 1));
|
756 | gamma = clip(aleph - k, 0, 1);
|
757 | quantileVals[i] = (1 - gamma) * sortedArray[k - 1] + gamma * sortedArray[k];
|
758 | }
|
759 |
|
760 | return quantileVals;
|
761 | };
|
762 |
|
763 |
|
764 |
|
765 | jStat.percentile = function percentile(arr, k) {
|
766 | var _arr = arr.slice().sort(ascNum);
|
767 | var realIndex = k * (_arr.length - 1);
|
768 | var index = parseInt(realIndex);
|
769 | var frac = realIndex - index;
|
770 |
|
771 | if (index + 1 < _arr.length) {
|
772 | return _arr[index] * (1 - frac) + _arr[index + 1] * frac;
|
773 | } else {
|
774 | return _arr[index];
|
775 | }
|
776 | }
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 | jStat.percentileOfScore = function percentileOfScore(arr, score, kind) {
|
783 | var counter = 0;
|
784 | var len = arr.length;
|
785 | var strict = false;
|
786 | var value, i;
|
787 |
|
788 | if (kind === 'strict')
|
789 | strict = true;
|
790 |
|
791 | for (i = 0; i < len; i++) {
|
792 | value = arr[i];
|
793 | if ((strict && value < score) ||
|
794 | (!strict && value <= score)) {
|
795 | counter++;
|
796 | }
|
797 | }
|
798 |
|
799 | return counter / len;
|
800 | };
|
801 |
|
802 |
|
803 |
|
804 | jStat.histogram = function histogram(arr, bins) {
|
805 | var first = jStat.min(arr);
|
806 | var binCnt = bins || 4;
|
807 | var binWidth = (jStat.max(arr) - first) / binCnt;
|
808 | var len = arr.length;
|
809 | var bins = [];
|
810 | var i;
|
811 |
|
812 | for (i = 0; i < binCnt; i++)
|
813 | bins[i] = 0;
|
814 | for (i = 0; i < len; i++)
|
815 | bins[Math.min(Math.floor(((arr[i] - first) / binWidth)), binCnt - 1)] += 1;
|
816 |
|
817 | return bins;
|
818 | };
|
819 |
|
820 |
|
821 |
|
822 | jStat.covariance = function covariance(arr1, arr2) {
|
823 | var u = jStat.mean(arr1);
|
824 | var v = jStat.mean(arr2);
|
825 | var arr1Len = arr1.length;
|
826 | var sq_dev = new Array(arr1Len);
|
827 | var i;
|
828 |
|
829 | for (i = 0; i < arr1Len; i++)
|
830 | sq_dev[i] = (arr1[i] - u) * (arr2[i] - v);
|
831 |
|
832 | return jStat.sum(sq_dev) / (arr1Len - 1);
|
833 | };
|
834 |
|
835 |
|
836 |
|
837 | jStat.corrcoeff = function corrcoeff(arr1, arr2) {
|
838 | return jStat.covariance(arr1, arr2) /
|
839 | jStat.stdev(arr1, 1) /
|
840 | jStat.stdev(arr2, 1);
|
841 | };
|
842 |
|
843 |
|
844 | jStat.spearmancoeff = function (arr1, arr2) {
|
845 | arr1 = jStat.rank(arr1);
|
846 | arr2 = jStat.rank(arr2);
|
847 | var arr1dev = jStat.deviation(arr1);
|
848 | var arr2dev = jStat.deviation(arr2);
|
849 | return jStat.sum(arr1dev.map(function (x, i) {
|
850 | return x * arr2dev[i];
|
851 | })) /
|
852 | Math.sqrt(jStat.sum(arr1dev.map(function (x) {
|
853 | return Math.pow(x, 2);
|
854 | })) * jStat.sum(arr2dev.map(function (x) {
|
855 | return Math.pow(x, 2);
|
856 | }))
|
857 | );
|
858 | }
|
859 |
|
860 |
|
861 |
|
862 | jStat.stanMoment = function stanMoment(arr, n) {
|
863 | var mu = jStat.mean(arr);
|
864 | var sigma = jStat.stdev(arr);
|
865 | var len = arr.length;
|
866 | var skewSum = 0;
|
867 |
|
868 | for (i = 0; i < len; i++)
|
869 | skewSum += Math.pow((arr[i] - mu) / sigma, n);
|
870 |
|
871 | return skewSum / arr.length;
|
872 | };
|
873 |
|
874 |
|
875 | jStat.skewness = function skewness(arr) {
|
876 | return jStat.stanMoment(arr, 3);
|
877 | };
|
878 |
|
879 |
|
880 | jStat.kurtosis = function kurtosis(arr) {
|
881 | return jStat.stanMoment(arr, 4) - 3;
|
882 | };
|
883 |
|
884 |
|
885 | var jProto = jStat.prototype;
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | (function(funcs) {
|
894 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
895 |
|
896 |
|
897 | jProto[passfunc] = function(fullbool, func) {
|
898 | var arr = [];
|
899 | var i = 0;
|
900 | var tmpthis = this;
|
901 |
|
902 | if (isFunction(fullbool)) {
|
903 | func = fullbool;
|
904 | fullbool = false;
|
905 | }
|
906 |
|
907 | if (func) {
|
908 | setTimeout(function() {
|
909 | func.call(tmpthis, jProto[passfunc].call(tmpthis, fullbool));
|
910 | });
|
911 | return this;
|
912 | }
|
913 |
|
914 | if (this.length > 1) {
|
915 | tmpthis = fullbool === true ? this : this.transpose();
|
916 | for (; i < tmpthis.length; i++)
|
917 | arr[i] = jStat[passfunc](tmpthis[i]);
|
918 | return arr;
|
919 | }
|
920 |
|
921 | return jStat[passfunc](this[0], fullbool);
|
922 | };
|
923 | })(funcs[i]);
|
924 | })(('cumsum cumprod').split(' '));
|
925 |
|
926 |
|
927 |
|
928 | (function(funcs) {
|
929 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
930 |
|
931 |
|
932 | jProto[passfunc] = function(fullbool, func) {
|
933 | var arr = [];
|
934 | var i = 0;
|
935 | var tmpthis = this;
|
936 |
|
937 | if (isFunction(fullbool)) {
|
938 | func = fullbool;
|
939 | fullbool = false;
|
940 | }
|
941 |
|
942 | if (func) {
|
943 | setTimeout(function() {
|
944 | func.call(tmpthis, jProto[passfunc].call(tmpthis, fullbool));
|
945 | });
|
946 | return this;
|
947 | }
|
948 |
|
949 | if (this.length > 1) {
|
950 | if (passfunc !== 'sumrow')
|
951 | tmpthis = fullbool === true ? this : this.transpose();
|
952 | for (; i < tmpthis.length; i++)
|
953 | arr[i] = jStat[passfunc](tmpthis[i]);
|
954 | return fullbool === true
|
955 | ? jStat[passfunc](jStat.utils.toVector(arr))
|
956 | : arr;
|
957 | }
|
958 |
|
959 | return jStat[passfunc](this[0], fullbool);
|
960 | };
|
961 | })(funcs[i]);
|
962 | })(('sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr ' +
|
963 | 'geomean median diff rank mode range variance deviation stdev meandev ' +
|
964 | 'meddev coeffvar quartiles histogram skewness kurtosis').split(' '));
|
965 |
|
966 |
|
967 |
|
968 |
|
969 | (function(funcs) {
|
970 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
971 | jProto[passfunc] = function() {
|
972 | var arr = [];
|
973 | var i = 0;
|
974 | var tmpthis = this;
|
975 | var args = Array.prototype.slice.call(arguments);
|
976 |
|
977 |
|
978 |
|
979 | if (isFunction(args[args.length - 1])) {
|
980 | var callbackFunction = args[args.length - 1];
|
981 | var argsToPass = args.slice(0, args.length - 1);
|
982 |
|
983 | setTimeout(function() {
|
984 | callbackFunction.call(tmpthis,
|
985 | jProto[passfunc].apply(tmpthis, argsToPass));
|
986 | });
|
987 | return this;
|
988 |
|
989 |
|
990 | } else {
|
991 | var callbackFunction = undefined;
|
992 | var curriedFunction = function curriedFunction(vector) {
|
993 | return jStat[passfunc].apply(tmpthis, [vector].concat(args));
|
994 | }
|
995 | }
|
996 |
|
997 |
|
998 | if (this.length > 1) {
|
999 | tmpthis = tmpthis.transpose();
|
1000 | for (; i < tmpthis.length; i++)
|
1001 | arr[i] = curriedFunction(tmpthis[i]);
|
1002 | return arr;
|
1003 | }
|
1004 |
|
1005 |
|
1006 | return curriedFunction(this[0]);
|
1007 | };
|
1008 | })(funcs[i]);
|
1009 | })('quantiles percentileOfScore'.split(' '));
|
1010 |
|
1011 | }(this.jStat, Math));
|
1012 |
|
1013 | (function(jStat, Math) {
|
1014 |
|
1015 |
|
1016 | jStat.gammaln = function gammaln(x) {
|
1017 | var j = 0;
|
1018 | var cof = [
|
1019 | 76.18009172947146, -86.50532032941677, 24.01409824083091,
|
1020 | -1.231739572450155, 0.1208650973866179e-2, -0.5395239384953e-5
|
1021 | ];
|
1022 | var ser = 1.000000000190015;
|
1023 | var xx, y, tmp;
|
1024 | tmp = (y = xx = x) + 5.5;
|
1025 | tmp -= (xx + 0.5) * Math.log(tmp);
|
1026 | for (; j < 6; j++)
|
1027 | ser += cof[j] / ++y;
|
1028 | return Math.log(2.5066282746310005 * ser / xx) - tmp;
|
1029 | };
|
1030 |
|
1031 |
|
1032 |
|
1033 | jStat.gammafn = function gammafn(x) {
|
1034 | var p = [-1.716185138865495, 24.76565080557592, -379.80425647094563,
|
1035 | 629.3311553128184, 866.9662027904133, -31451.272968848367,
|
1036 | -36144.413418691176, 66456.14382024054
|
1037 | ];
|
1038 | var q = [-30.8402300119739, 315.35062697960416, -1015.1563674902192,
|
1039 | -3107.771671572311, 22538.118420980151, 4755.8462775278811,
|
1040 | -134659.9598649693, -115132.2596755535];
|
1041 | var fact = false;
|
1042 | var n = 0;
|
1043 | var xden = 0;
|
1044 | var xnum = 0;
|
1045 | var y = x;
|
1046 | var i, z, yi, res, sum, ysq;
|
1047 | if (y <= 0) {
|
1048 | res = y % 1 + 3.6e-16;
|
1049 | if (res) {
|
1050 | fact = (!(y & 1) ? 1 : -1) * Math.PI / Math.sin(Math.PI * res);
|
1051 | y = 1 - y;
|
1052 | } else {
|
1053 | return Infinity;
|
1054 | }
|
1055 | }
|
1056 | yi = y;
|
1057 | if (y < 1) {
|
1058 | z = y++;
|
1059 | } else {
|
1060 | z = (y -= n = (y | 0) - 1) - 1;
|
1061 | }
|
1062 | for (i = 0; i < 8; ++i) {
|
1063 | xnum = (xnum + p[i]) * z;
|
1064 | xden = xden * z + q[i];
|
1065 | }
|
1066 | res = xnum / xden + 1;
|
1067 | if (yi < y) {
|
1068 | res /= yi;
|
1069 | } else if (yi > y) {
|
1070 | for (i = 0; i < n; ++i) {
|
1071 | res *= y;
|
1072 | y++;
|
1073 | }
|
1074 | }
|
1075 | if (fact) {
|
1076 | res = fact / res;
|
1077 | }
|
1078 | return res;
|
1079 | };
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 | jStat.gammap = function gammap(a, x) {
|
1085 | return jStat.lowRegGamma(a, x) * jStat.gammafn(a);
|
1086 | };
|
1087 |
|
1088 |
|
1089 |
|
1090 | jStat.lowRegGamma = function lowRegGamma(a, x) {
|
1091 | var aln = jStat.gammaln(a);
|
1092 | var ap = a;
|
1093 | var sum = 1 / a;
|
1094 | var del = sum;
|
1095 | var b = x + 1 - a;
|
1096 | var c = 1 / 1.0e-30;
|
1097 | var d = 1 / b;
|
1098 | var h = d;
|
1099 | var i = 1;
|
1100 |
|
1101 | var ITMAX = -~(Math.log((a >= 1) ? a : 1 / a) * 8.5 + a * 0.4 + 17);
|
1102 | var an, endval;
|
1103 |
|
1104 | if (x < 0 || a <= 0) {
|
1105 | return NaN;
|
1106 | } else if (x < a + 1) {
|
1107 | for (; i <= ITMAX; i++) {
|
1108 | sum += del *= x / ++ap;
|
1109 | }
|
1110 | return (sum * Math.exp(-x + a * Math.log(x) - (aln)));
|
1111 | }
|
1112 |
|
1113 | for (; i <= ITMAX; i++) {
|
1114 | an = -i * (i - a);
|
1115 | b += 2;
|
1116 | d = an * d + b;
|
1117 | c = b + an / c;
|
1118 | d = 1 / d;
|
1119 | h *= d * c;
|
1120 | }
|
1121 |
|
1122 | return (1 - h * Math.exp(-x + a * Math.log(x) - (aln)));
|
1123 | };
|
1124 |
|
1125 |
|
1126 | jStat.factorialln = function factorialln(n) {
|
1127 | return n < 0 ? NaN : jStat.gammaln(n + 1);
|
1128 | };
|
1129 |
|
1130 |
|
1131 | jStat.factorial = function factorial(n) {
|
1132 | return n < 0 ? NaN : jStat.gammafn(n + 1);
|
1133 | };
|
1134 |
|
1135 |
|
1136 | jStat.combination = function combination(n, m) {
|
1137 |
|
1138 | return (n > 170 || m > 170)
|
1139 | ? Math.exp(jStat.combinationln(n, m))
|
1140 | : (jStat.factorial(n) / jStat.factorial(m)) / jStat.factorial(n - m);
|
1141 | };
|
1142 |
|
1143 |
|
1144 | jStat.combinationln = function combinationln(n, m){
|
1145 | return jStat.factorialln(n) - jStat.factorialln(m) - jStat.factorialln(n - m);
|
1146 | };
|
1147 |
|
1148 |
|
1149 |
|
1150 | jStat.permutation = function permutation(n, m) {
|
1151 | return jStat.factorial(n) / jStat.factorial(n - m);
|
1152 | };
|
1153 |
|
1154 |
|
1155 |
|
1156 | jStat.betafn = function betafn(x, y) {
|
1157 |
|
1158 | if (x <= 0 || y <= 0)
|
1159 | return undefined;
|
1160 |
|
1161 | return (x + y > 170)
|
1162 | ? Math.exp(jStat.betaln(x, y))
|
1163 | : jStat.gammafn(x) * jStat.gammafn(y) / jStat.gammafn(x + y);
|
1164 | };
|
1165 |
|
1166 |
|
1167 |
|
1168 | jStat.betaln = function betaln(x, y) {
|
1169 | return jStat.gammaln(x) + jStat.gammaln(y) - jStat.gammaln(x + y);
|
1170 | };
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 | jStat.betacf = function betacf(x, a, b) {
|
1176 | var fpmin = 1e-30;
|
1177 | var m = 1;
|
1178 | var qab = a + b;
|
1179 | var qap = a + 1;
|
1180 | var qam = a - 1;
|
1181 | var c = 1;
|
1182 | var d = 1 - qab * x / qap;
|
1183 | var m2, aa, del, h;
|
1184 |
|
1185 |
|
1186 | if (Math.abs(d) < fpmin)
|
1187 | d = fpmin;
|
1188 | d = 1 / d;
|
1189 | h = d;
|
1190 |
|
1191 | for (; m <= 100; m++) {
|
1192 | m2 = 2 * m;
|
1193 | aa = m * (b - m) * x / ((qam + m2) * (a + m2));
|
1194 |
|
1195 | d = 1 + aa * d;
|
1196 | if (Math.abs(d) < fpmin)
|
1197 | d = fpmin;
|
1198 | c = 1 + aa / c;
|
1199 | if (Math.abs(c) < fpmin)
|
1200 | c = fpmin;
|
1201 | d = 1 / d;
|
1202 | h *= d * c;
|
1203 | aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2));
|
1204 |
|
1205 | d = 1 + aa * d;
|
1206 | if (Math.abs(d) < fpmin)
|
1207 | d = fpmin;
|
1208 | c = 1 + aa / c;
|
1209 | if (Math.abs(c) < fpmin)
|
1210 | c = fpmin;
|
1211 | d = 1 / d;
|
1212 | del = d * c;
|
1213 | h *= del;
|
1214 | if (Math.abs(del - 1.0) < 3e-7)
|
1215 | break;
|
1216 | }
|
1217 |
|
1218 | return h;
|
1219 | };
|
1220 |
|
1221 |
|
1222 |
|
1223 | jStat.gammapinv = function gammapinv(p, a) {
|
1224 | var j = 0;
|
1225 | var a1 = a - 1;
|
1226 | var EPS = 1e-8;
|
1227 | var gln = jStat.gammaln(a);
|
1228 | var x, err, t, u, pp, lna1, afac;
|
1229 |
|
1230 | if (p >= 1)
|
1231 | return Math.max(100, a + 100 * Math.sqrt(a));
|
1232 | if (p <= 0)
|
1233 | return 0;
|
1234 | if (a > 1) {
|
1235 | lna1 = Math.log(a1);
|
1236 | afac = Math.exp(a1 * (lna1 - 1) - gln);
|
1237 | pp = (p < 0.5) ? p : 1 - p;
|
1238 | t = Math.sqrt(-2 * Math.log(pp));
|
1239 | x = (2.30753 + t * 0.27061) / (1 + t * (0.99229 + t * 0.04481)) - t;
|
1240 | if (p < 0.5)
|
1241 | x = -x;
|
1242 | x = Math.max(1e-3,
|
1243 | a * Math.pow(1 - 1 / (9 * a) - x / (3 * Math.sqrt(a)), 3));
|
1244 | } else {
|
1245 | t = 1 - a * (0.253 + a * 0.12);
|
1246 | if (p < t)
|
1247 | x = Math.pow(p / t, 1 / a);
|
1248 | else
|
1249 | x = 1 - Math.log(1 - (p - t) / (1 - t));
|
1250 | }
|
1251 |
|
1252 | for(; j < 12; j++) {
|
1253 | if (x <= 0)
|
1254 | return 0;
|
1255 | err = jStat.lowRegGamma(a, x) - p;
|
1256 | if (a > 1)
|
1257 | t = afac * Math.exp(-(x - a1) + a1 * (Math.log(x) - lna1));
|
1258 | else
|
1259 | t = Math.exp(-x + a1 * Math.log(x) - gln);
|
1260 | u = err / t;
|
1261 | x -= (t = u / (1 - 0.5 * Math.min(1, u * ((a - 1) / x - 1))));
|
1262 | if (x <= 0)
|
1263 | x = 0.5 * (x + t);
|
1264 | if (Math.abs(t) < EPS * x)
|
1265 | break;
|
1266 | }
|
1267 |
|
1268 | return x;
|
1269 | };
|
1270 |
|
1271 |
|
1272 |
|
1273 | jStat.erf = function erf(x) {
|
1274 | var cof = [-1.3026537197817094, 6.4196979235649026e-1, 1.9476473204185836e-2,
|
1275 | -9.561514786808631e-3, -9.46595344482036e-4, 3.66839497852761e-4,
|
1276 | 4.2523324806907e-5, -2.0278578112534e-5, -1.624290004647e-6,
|
1277 | 1.303655835580e-6, 1.5626441722e-8, -8.5238095915e-8,
|
1278 | 6.529054439e-9, 5.059343495e-9, -9.91364156e-10,
|
1279 | -2.27365122e-10, 9.6467911e-11, 2.394038e-12,
|
1280 | -6.886027e-12, 8.94487e-13, 3.13092e-13,
|
1281 | -1.12708e-13, 3.81e-16, 7.106e-15,
|
1282 | -1.523e-15, -9.4e-17, 1.21e-16,
|
1283 | -2.8e-17];
|
1284 | var j = cof.length - 1;
|
1285 | var isneg = false;
|
1286 | var d = 0;
|
1287 | var dd = 0;
|
1288 | var t, ty, tmp, res;
|
1289 |
|
1290 | if (x < 0) {
|
1291 | x = -x;
|
1292 | isneg = true;
|
1293 | }
|
1294 |
|
1295 | t = 2 / (2 + x);
|
1296 | ty = 4 * t - 2;
|
1297 |
|
1298 | for(; j > 0; j--) {
|
1299 | tmp = d;
|
1300 | d = ty * d - dd + cof[j];
|
1301 | dd = tmp;
|
1302 | }
|
1303 |
|
1304 | res = t * Math.exp(-x * x + 0.5 * (cof[0] + ty * d) - dd);
|
1305 | return isneg ? res - 1 : 1 - res;
|
1306 | };
|
1307 |
|
1308 |
|
1309 |
|
1310 | jStat.erfc = function erfc(x) {
|
1311 | return 1 - jStat.erf(x);
|
1312 | };
|
1313 |
|
1314 |
|
1315 |
|
1316 | jStat.erfcinv = function erfcinv(p) {
|
1317 | var j = 0;
|
1318 | var x, err, t, pp;
|
1319 | if (p >= 2)
|
1320 | return -100;
|
1321 | if (p <= 0)
|
1322 | return 100;
|
1323 | pp = (p < 1) ? p : 2 - p;
|
1324 | t = Math.sqrt(-2 * Math.log(pp / 2));
|
1325 | x = -0.70711 * ((2.30753 + t * 0.27061) /
|
1326 | (1 + t * (0.99229 + t * 0.04481)) - t);
|
1327 | for (; j < 2; j++) {
|
1328 | err = jStat.erfc(x) - pp;
|
1329 | x += err / (1.12837916709551257 * Math.exp(-x * x) - x * err);
|
1330 | }
|
1331 | return (p < 1) ? x : -x;
|
1332 | };
|
1333 |
|
1334 |
|
1335 |
|
1336 | jStat.ibetainv = function ibetainv(p, a, b) {
|
1337 | var EPS = 1e-8;
|
1338 | var a1 = a - 1;
|
1339 | var b1 = b - 1;
|
1340 | var j = 0;
|
1341 | var lna, lnb, pp, t, u, err, x, al, h, w, afac;
|
1342 | if (p <= 0)
|
1343 | return 0;
|
1344 | if (p >= 1)
|
1345 | return 1;
|
1346 | if (a >= 1 && b >= 1) {
|
1347 | pp = (p < 0.5) ? p : 1 - p;
|
1348 | t = Math.sqrt(-2 * Math.log(pp));
|
1349 | x = (2.30753 + t * 0.27061) / (1 + t* (0.99229 + t * 0.04481)) - t;
|
1350 | if (p < 0.5)
|
1351 | x = -x;
|
1352 | al = (x * x - 3) / 6;
|
1353 | h = 2 / (1 / (2 * a - 1) + 1 / (2 * b - 1));
|
1354 | w = (x * Math.sqrt(al + h) / h) - (1 / (2 * b - 1) - 1 / (2 * a - 1)) *
|
1355 | (al + 5 / 6 - 2 / (3 * h));
|
1356 | x = a / (a + b * Math.exp(2 * w));
|
1357 | } else {
|
1358 | lna = Math.log(a / (a + b));
|
1359 | lnb = Math.log(b / (a + b));
|
1360 | t = Math.exp(a * lna) / a;
|
1361 | u = Math.exp(b * lnb) / b;
|
1362 | w = t + u;
|
1363 | if (p < t / w)
|
1364 | x = Math.pow(a * w * p, 1 / a);
|
1365 | else
|
1366 | x = 1 - Math.pow(b * w * (1 - p), 1 / b);
|
1367 | }
|
1368 | afac = -jStat.gammaln(a) - jStat.gammaln(b) + jStat.gammaln(a + b);
|
1369 | for(; j < 10; j++) {
|
1370 | if (x === 0 || x === 1)
|
1371 | return x;
|
1372 | err = jStat.ibeta(x, a, b) - p;
|
1373 | t = Math.exp(a1 * Math.log(x) + b1 * Math.log(1 - x) + afac);
|
1374 | u = err / t;
|
1375 | x -= (t = u / (1 - 0.5 * Math.min(1, u * (a1 / x - b1 / (1 - x)))));
|
1376 | if (x <= 0)
|
1377 | x = 0.5 * (x + t);
|
1378 | if (x >= 1)
|
1379 | x = 0.5 * (x + t + 1);
|
1380 | if (Math.abs(t) < EPS * x && j > 0)
|
1381 | break;
|
1382 | }
|
1383 | return x;
|
1384 | };
|
1385 |
|
1386 |
|
1387 |
|
1388 | jStat.ibeta = function ibeta(x, a, b) {
|
1389 |
|
1390 | var bt = (x === 0 || x === 1) ? 0 :
|
1391 | Math.exp(jStat.gammaln(a + b) - jStat.gammaln(a) -
|
1392 | jStat.gammaln(b) + a * Math.log(x) + b *
|
1393 | Math.log(1 - x));
|
1394 | if (x < 0 || x > 1)
|
1395 | return false;
|
1396 | if (x < (a + 1) / (a + b + 2))
|
1397 |
|
1398 | return bt * jStat.betacf(x, a, b) / a;
|
1399 |
|
1400 | return 1 - bt * jStat.betacf(1 - x, b, a) / b;
|
1401 | };
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 | jStat.randn = function randn(n, m) {
|
1407 | var u, v, x, y, q, mat;
|
1408 | if (!m)
|
1409 | m = n;
|
1410 | if (n)
|
1411 | return jStat.create(n, m, function() { return jStat.randn(); });
|
1412 | do {
|
1413 | u = Math.random();
|
1414 | v = 1.7156 * (Math.random() - 0.5);
|
1415 | x = u - 0.449871;
|
1416 | y = Math.abs(v) + 0.386595;
|
1417 | q = x * x + y * (0.19600 * y - 0.25472 * x);
|
1418 | } while (q > 0.27597 && (q > 0.27846 || v * v > -4 * Math.log(u) * u * u));
|
1419 | return v / u;
|
1420 | };
|
1421 |
|
1422 |
|
1423 |
|
1424 | jStat.randg = function randg(shape, n, m) {
|
1425 | var oalph = shape;
|
1426 | var a1, a2, u, v, x, mat;
|
1427 | if (!m)
|
1428 | m = n;
|
1429 | if (!shape)
|
1430 | shape = 1;
|
1431 | if (n) {
|
1432 | mat = jStat.zeros(n,m);
|
1433 | mat.alter(function() { return jStat.randg(shape); });
|
1434 | return mat;
|
1435 | }
|
1436 | if (shape < 1)
|
1437 | shape += 1;
|
1438 | a1 = shape - 1 / 3;
|
1439 | a2 = 1 / Math.sqrt(9 * a1);
|
1440 | do {
|
1441 | do {
|
1442 | x = jStat.randn();
|
1443 | v = 1 + a2 * x;
|
1444 | } while(v <= 0);
|
1445 | v = v * v * v;
|
1446 | u = Math.random();
|
1447 | } while(u > 1 - 0.331 * Math.pow(x, 4) &&
|
1448 | Math.log(u) > 0.5 * x*x + a1 * (1 - v + Math.log(v)));
|
1449 |
|
1450 | if (shape == oalph)
|
1451 | return a1 * v;
|
1452 |
|
1453 | do {
|
1454 | u = Math.random();
|
1455 | } while(u === 0);
|
1456 | return Math.pow(u, 1 / oalph) * a1 * v;
|
1457 | };
|
1458 |
|
1459 |
|
1460 |
|
1461 | (function(funcs) {
|
1462 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
1463 | jStat.fn[passfunc] = function() {
|
1464 | return jStat(
|
1465 | jStat.map(this, function(value) { return jStat[passfunc](value); }));
|
1466 | }
|
1467 | })(funcs[i]);
|
1468 | })('gammaln gammafn factorial factorialln'.split(' '));
|
1469 |
|
1470 |
|
1471 | (function(funcs) {
|
1472 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
1473 | jStat.fn[passfunc] = function() {
|
1474 | return jStat(jStat[passfunc].apply(null, arguments));
|
1475 | };
|
1476 | })(funcs[i]);
|
1477 | })('randn'.split(' '));
|
1478 |
|
1479 | }(this.jStat, Math));
|
1480 | (function(jStat, Math) {
|
1481 |
|
1482 |
|
1483 | (function(list) {
|
1484 | for (var i = 0; i < list.length; i++) (function(func) {
|
1485 |
|
1486 | jStat[func] = function(a, b, c) {
|
1487 | if (!(this instanceof arguments.callee))
|
1488 | return new arguments.callee(a, b, c);
|
1489 | this._a = a;
|
1490 | this._b = b;
|
1491 | this._c = c;
|
1492 | return this;
|
1493 | };
|
1494 |
|
1495 | jStat.fn[func] = function(a, b, c) {
|
1496 | var newthis = jStat[func](a, b, c);
|
1497 | newthis.data = this;
|
1498 | return newthis;
|
1499 | };
|
1500 |
|
1501 | jStat[func].prototype.sample = function(arr) {
|
1502 | var a = this._a;
|
1503 | var b = this._b;
|
1504 | var c = this._c;
|
1505 | if (arr)
|
1506 | return jStat.alter(arr, function() {
|
1507 | return jStat[func].sample(a, b, c);
|
1508 | });
|
1509 | else
|
1510 | return jStat[func].sample(a, b, c);
|
1511 | };
|
1512 |
|
1513 | (function(vals) {
|
1514 | for (var i = 0; i < vals.length; i++) (function(fnfunc) {
|
1515 | jStat[func].prototype[fnfunc] = function(x) {
|
1516 | var a = this._a;
|
1517 | var b = this._b;
|
1518 | var c = this._c;
|
1519 | if (!x && x !== 0)
|
1520 | x = this.data;
|
1521 | if (typeof x !== 'number') {
|
1522 | return jStat.fn.map.call(x, function(x) {
|
1523 | return jStat[func][fnfunc](x, a, b, c);
|
1524 | });
|
1525 | }
|
1526 | return jStat[func][fnfunc](x, a, b, c);
|
1527 | };
|
1528 | })(vals[i]);
|
1529 | })('pdf cdf inv'.split(' '));
|
1530 |
|
1531 | (function(vals) {
|
1532 | for (var i = 0; i < vals.length; i++) (function(fnfunc) {
|
1533 | jStat[func].prototype[fnfunc] = function() {
|
1534 | return jStat[func][fnfunc](this._a, this._b, this._c);
|
1535 | };
|
1536 | })(vals[i]);
|
1537 | })('mean median mode variance'.split(' '));
|
1538 | })(list[i]);
|
1539 | })((
|
1540 | 'beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy ' +
|
1541 | 'laplace lognormal noncentralt normal pareto studentt weibull uniform ' +
|
1542 | 'binomial negbin hypgeom poisson triangular'
|
1543 | ).split(' '));
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 | jStat.extend(jStat.beta, {
|
1549 | pdf: function pdf(x, alpha, beta) {
|
1550 |
|
1551 | if (x > 1 || x < 0)
|
1552 | return 0;
|
1553 |
|
1554 | if (alpha == 1 && beta == 1)
|
1555 | return 1;
|
1556 |
|
1557 | if (alpha < 512 && beta < 512) {
|
1558 | return (Math.pow(x, alpha - 1) * Math.pow(1 - x, beta - 1)) /
|
1559 | jStat.betafn(alpha, beta);
|
1560 | } else {
|
1561 | return Math.exp((alpha - 1) * Math.log(x) +
|
1562 | (beta - 1) * Math.log(1 - x) -
|
1563 | jStat.betaln(alpha, beta));
|
1564 | }
|
1565 | },
|
1566 |
|
1567 | cdf: function cdf(x, alpha, beta) {
|
1568 | return (x > 1 || x < 0) ? (x > 1) * 1 : jStat.ibeta(x, alpha, beta);
|
1569 | },
|
1570 |
|
1571 | inv: function inv(x, alpha, beta) {
|
1572 | return jStat.ibetainv(x, alpha, beta);
|
1573 | },
|
1574 |
|
1575 | mean: function mean(alpha, beta) {
|
1576 | return alpha / (alpha + beta);
|
1577 | },
|
1578 |
|
1579 | median: function median(alpha, beta) {
|
1580 | return jStat.ibetainv(0.5, alpha, beta);
|
1581 | },
|
1582 |
|
1583 | mode: function mode(alpha, beta) {
|
1584 | return (alpha - 1 ) / ( alpha + beta - 2);
|
1585 | },
|
1586 |
|
1587 |
|
1588 | sample: function sample(alpha, beta) {
|
1589 | var u = jStat.randg(alpha);
|
1590 | return u / (u + jStat.randg(beta));
|
1591 | },
|
1592 |
|
1593 | variance: function variance(alpha, beta) {
|
1594 | return (alpha * beta) / (Math.pow(alpha + beta, 2) * (alpha + beta + 1));
|
1595 | }
|
1596 | });
|
1597 |
|
1598 |
|
1599 | jStat.extend(jStat.centralF, {
|
1600 |
|
1601 |
|
1602 |
|
1603 | pdf: function pdf(x, df1, df2) {
|
1604 | var p, q, f;
|
1605 |
|
1606 | if (x < 0)
|
1607 | return 0;
|
1608 |
|
1609 | if (df1 <= 2) {
|
1610 | if (x === 0 && df1 < 2) {
|
1611 | return Infinity;
|
1612 | }
|
1613 | if (x === 0 && df1 === 2) {
|
1614 | return 1;
|
1615 | }
|
1616 | return Math.sqrt((Math.pow(df1 * x, df1) * Math.pow(df2, df2)) /
|
1617 | (Math.pow(df1 * x + df2, df1 + df2))) /
|
1618 | (x * jStat.betafn(df1/2, df2/2));
|
1619 | }
|
1620 |
|
1621 | p = (df1 * x) / (df2 + x * df1);
|
1622 | q = df2 / (df2 + x * df1);
|
1623 | f = df1 * q / 2.0;
|
1624 | return f * jStat.binomial.pdf((df1 - 2) / 2, (df1 + df2 - 2) / 2, p);
|
1625 | },
|
1626 |
|
1627 | cdf: function cdf(x, df1, df2) {
|
1628 | if (x < 0)
|
1629 | return 0;
|
1630 | return jStat.ibeta((df1 * x) / (df1 * x + df2), df1 / 2, df2 / 2);
|
1631 | },
|
1632 |
|
1633 | inv: function inv(x, df1, df2) {
|
1634 | return df2 / (df1 * (1 / jStat.ibetainv(x, df1 / 2, df2 / 2) - 1));
|
1635 | },
|
1636 |
|
1637 | mean: function mean(df1, df2) {
|
1638 | return (df2 > 2) ? df2 / (df2 - 2) : undefined;
|
1639 | },
|
1640 |
|
1641 | mode: function mode(df1, df2) {
|
1642 | return (df1 > 2) ? (df2 * (df1 - 2)) / (df1 * (df2 + 2)) : undefined;
|
1643 | },
|
1644 |
|
1645 |
|
1646 | sample: function sample(df1, df2) {
|
1647 | var x1 = jStat.randg(df1 / 2) * 2;
|
1648 | var x2 = jStat.randg(df2 / 2) * 2;
|
1649 | return (x1 / df1) / (x2 / df2);
|
1650 | },
|
1651 |
|
1652 | variance: function variance(df1, df2) {
|
1653 | if (df2 <= 4)
|
1654 | return undefined;
|
1655 | return 2 * df2 * df2 * (df1 + df2 - 2) /
|
1656 | (df1 * (df2 - 2) * (df2 - 2) * (df2 - 4));
|
1657 | }
|
1658 | });
|
1659 |
|
1660 |
|
1661 |
|
1662 | jStat.extend(jStat.cauchy, {
|
1663 | pdf: function pdf(x, local, scale) {
|
1664 | if (scale < 0) { return 0; }
|
1665 |
|
1666 | return (scale / (Math.pow(x - local, 2) + Math.pow(scale, 2))) / Math.PI;
|
1667 | },
|
1668 |
|
1669 | cdf: function cdf(x, local, scale) {
|
1670 | return Math.atan((x - local) / scale) / Math.PI + 0.5;
|
1671 | },
|
1672 |
|
1673 | inv: function(p, local, scale) {
|
1674 | return local + scale * Math.tan(Math.PI * (p - 0.5));
|
1675 | },
|
1676 |
|
1677 | median: function median(local, scale) {
|
1678 | return local;
|
1679 | },
|
1680 |
|
1681 | mode: function mode(local, scale) {
|
1682 | return local;
|
1683 | },
|
1684 |
|
1685 | sample: function sample(local, scale) {
|
1686 | return jStat.randn() *
|
1687 | Math.sqrt(1 / (2 * jStat.randg(0.5))) * scale + local;
|
1688 | }
|
1689 | });
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 | jStat.extend(jStat.chisquare, {
|
1695 | pdf: function pdf(x, dof) {
|
1696 | if (x < 0)
|
1697 | return 0;
|
1698 | return (x === 0 && dof === 2) ? 0.5 :
|
1699 | Math.exp((dof / 2 - 1) * Math.log(x) - x / 2 - (dof / 2) *
|
1700 | Math.log(2) - jStat.gammaln(dof / 2));
|
1701 | },
|
1702 |
|
1703 | cdf: function cdf(x, dof) {
|
1704 | if (x < 0)
|
1705 | return 0;
|
1706 | return jStat.lowRegGamma(dof / 2, x / 2);
|
1707 | },
|
1708 |
|
1709 | inv: function(p, dof) {
|
1710 | return 2 * jStat.gammapinv(p, 0.5 * dof);
|
1711 | },
|
1712 |
|
1713 | mean : function(dof) {
|
1714 | return dof;
|
1715 | },
|
1716 |
|
1717 |
|
1718 | median: function median(dof) {
|
1719 | return dof * Math.pow(1 - (2 / (9 * dof)), 3);
|
1720 | },
|
1721 |
|
1722 | mode: function mode(dof) {
|
1723 | return (dof - 2 > 0) ? dof - 2 : 0;
|
1724 | },
|
1725 |
|
1726 | sample: function sample(dof) {
|
1727 | return jStat.randg(dof / 2) * 2;
|
1728 | },
|
1729 |
|
1730 | variance: function variance(dof) {
|
1731 | return 2 * dof;
|
1732 | }
|
1733 | });
|
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 | jStat.extend(jStat.exponential, {
|
1739 | pdf: function pdf(x, rate) {
|
1740 | return x < 0 ? 0 : rate * Math.exp(-rate * x);
|
1741 | },
|
1742 |
|
1743 | cdf: function cdf(x, rate) {
|
1744 | return x < 0 ? 0 : 1 - Math.exp(-rate * x);
|
1745 | },
|
1746 |
|
1747 | inv: function(p, rate) {
|
1748 | return -Math.log(1 - p) / rate;
|
1749 | },
|
1750 |
|
1751 | mean : function(rate) {
|
1752 | return 1 / rate;
|
1753 | },
|
1754 |
|
1755 | median: function (rate) {
|
1756 | return (1 / rate) * Math.log(2);
|
1757 | },
|
1758 |
|
1759 | mode: function mode(rate) {
|
1760 | return 0;
|
1761 | },
|
1762 |
|
1763 | sample: function sample(rate) {
|
1764 | return -1 / rate * Math.log(Math.random());
|
1765 | },
|
1766 |
|
1767 | variance : function(rate) {
|
1768 | return Math.pow(rate, -2);
|
1769 | }
|
1770 | });
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 | jStat.extend(jStat.gamma, {
|
1776 | pdf: function pdf(x, shape, scale) {
|
1777 | if (x < 0)
|
1778 | return 0;
|
1779 | return (x === 0 && shape === 1) ? 1 / scale :
|
1780 | Math.exp((shape - 1) * Math.log(x) - x / scale -
|
1781 | jStat.gammaln(shape) - shape * Math.log(scale));
|
1782 | },
|
1783 |
|
1784 | cdf: function cdf(x, shape, scale) {
|
1785 | if (x < 0)
|
1786 | return 0;
|
1787 | return jStat.lowRegGamma(shape, x / scale);
|
1788 | },
|
1789 |
|
1790 | inv: function(p, shape, scale) {
|
1791 | return jStat.gammapinv(p, shape) * scale;
|
1792 | },
|
1793 |
|
1794 | mean : function(shape, scale) {
|
1795 | return shape * scale;
|
1796 | },
|
1797 |
|
1798 | mode: function mode(shape, scale) {
|
1799 | if(shape > 1) return (shape - 1) * scale;
|
1800 | return undefined;
|
1801 | },
|
1802 |
|
1803 | sample: function sample(shape, scale) {
|
1804 | return jStat.randg(shape) * scale;
|
1805 | },
|
1806 |
|
1807 | variance: function variance(shape, scale) {
|
1808 | return shape * scale * scale;
|
1809 | }
|
1810 | });
|
1811 |
|
1812 |
|
1813 | jStat.extend(jStat.invgamma, {
|
1814 | pdf: function pdf(x, shape, scale) {
|
1815 | if (x <= 0)
|
1816 | return 0;
|
1817 | return Math.exp(-(shape + 1) * Math.log(x) - scale / x -
|
1818 | jStat.gammaln(shape) + shape * Math.log(scale));
|
1819 | },
|
1820 |
|
1821 | cdf: function cdf(x, shape, scale) {
|
1822 | if (x <= 0)
|
1823 | return 0;
|
1824 | return 1 - jStat.lowRegGamma(shape, scale / x);
|
1825 | },
|
1826 |
|
1827 | inv: function(p, shape, scale) {
|
1828 | return scale / jStat.gammapinv(1 - p, shape);
|
1829 | },
|
1830 |
|
1831 | mean : function(shape, scale) {
|
1832 | return (shape > 1) ? scale / (shape - 1) : undefined;
|
1833 | },
|
1834 |
|
1835 | mode: function mode(shape, scale) {
|
1836 | return scale / (shape + 1);
|
1837 | },
|
1838 |
|
1839 | sample: function sample(shape, scale) {
|
1840 | return scale / jStat.randg(shape);
|
1841 | },
|
1842 |
|
1843 | variance: function variance(shape, scale) {
|
1844 | if (shape <= 2)
|
1845 | return undefined;
|
1846 | return scale * scale / ((shape - 1) * (shape - 1) * (shape - 2));
|
1847 | }
|
1848 | });
|
1849 |
|
1850 |
|
1851 |
|
1852 | jStat.extend(jStat.kumaraswamy, {
|
1853 | pdf: function pdf(x, alpha, beta) {
|
1854 | if (x === 0 && alpha === 1)
|
1855 | return beta;
|
1856 | else if (x === 1 && beta === 1)
|
1857 | return alpha;
|
1858 | return Math.exp(Math.log(alpha) + Math.log(beta) + (alpha - 1) *
|
1859 | Math.log(x) + (beta - 1) *
|
1860 | Math.log(1 - Math.pow(x, alpha)));
|
1861 | },
|
1862 |
|
1863 | cdf: function cdf(x, alpha, beta) {
|
1864 | if (x < 0)
|
1865 | return 0;
|
1866 | else if (x > 1)
|
1867 | return 1;
|
1868 | return (1 - Math.pow(1 - Math.pow(x, alpha), beta));
|
1869 | },
|
1870 |
|
1871 | inv: function inv(p, alpha, beta) {
|
1872 | return Math.pow(1 - Math.pow(1 - p, 1 / beta), 1 / alpha);
|
1873 | },
|
1874 |
|
1875 | mean : function(alpha, beta) {
|
1876 | return (beta * jStat.gammafn(1 + 1 / alpha) *
|
1877 | jStat.gammafn(beta)) / (jStat.gammafn(1 + 1 / alpha + beta));
|
1878 | },
|
1879 |
|
1880 | median: function median(alpha, beta) {
|
1881 | return Math.pow(1 - Math.pow(2, -1 / beta), 1 / alpha);
|
1882 | },
|
1883 |
|
1884 | mode: function mode(alpha, beta) {
|
1885 | if (!(alpha >= 1 && beta >= 1 && (alpha !== 1 && beta !== 1)))
|
1886 | return undefined;
|
1887 | return Math.pow((alpha - 1) / (alpha * beta - 1), 1 / alpha);
|
1888 | },
|
1889 |
|
1890 | variance: function variance(alpha, beta) {
|
1891 | throw new Error('variance not yet implemented');
|
1892 |
|
1893 | }
|
1894 | });
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 | jStat.extend(jStat.lognormal, {
|
1900 | pdf: function pdf(x, mu, sigma) {
|
1901 | if (x <= 0)
|
1902 | return 0;
|
1903 | return Math.exp(-Math.log(x) - 0.5 * Math.log(2 * Math.PI) -
|
1904 | Math.log(sigma) - Math.pow(Math.log(x) - mu, 2) /
|
1905 | (2 * sigma * sigma));
|
1906 | },
|
1907 |
|
1908 | cdf: function cdf(x, mu, sigma) {
|
1909 | if (x < 0)
|
1910 | return 0;
|
1911 | return 0.5 +
|
1912 | (0.5 * jStat.erf((Math.log(x) - mu) / Math.sqrt(2 * sigma * sigma)));
|
1913 | },
|
1914 |
|
1915 | inv: function(p, mu, sigma) {
|
1916 | return Math.exp(-1.41421356237309505 * sigma * jStat.erfcinv(2 * p) + mu);
|
1917 | },
|
1918 |
|
1919 | mean: function mean(mu, sigma) {
|
1920 | return Math.exp(mu + sigma * sigma / 2);
|
1921 | },
|
1922 |
|
1923 | median: function median(mu, sigma) {
|
1924 | return Math.exp(mu);
|
1925 | },
|
1926 |
|
1927 | mode: function mode(mu, sigma) {
|
1928 | return Math.exp(mu - sigma * sigma);
|
1929 | },
|
1930 |
|
1931 | sample: function sample(mu, sigma) {
|
1932 | return Math.exp(jStat.randn() * sigma + mu);
|
1933 | },
|
1934 |
|
1935 | variance: function variance(mu, sigma) {
|
1936 | return (Math.exp(sigma * sigma) - 1) * Math.exp(2 * mu + sigma * sigma);
|
1937 | }
|
1938 | });
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 | jStat.extend(jStat.noncentralt, {
|
1944 | pdf: function pdf(x, dof, ncp) {
|
1945 | var tol = 1e-14;
|
1946 | if (Math.abs(ncp) < tol)
|
1947 | return jStat.studentt.pdf(x, dof)
|
1948 |
|
1949 | if (Math.abs(x) < tol) {
|
1950 | return Math.exp(jStat.gammaln((dof + 1) / 2) - ncp * ncp / 2 -
|
1951 | 0.5 * Math.log(Math.PI * dof) - jStat.gammaln(dof / 2));
|
1952 | }
|
1953 |
|
1954 |
|
1955 | return dof / x *
|
1956 | (jStat.noncentralt.cdf(x * Math.sqrt(1 + 2 / dof), dof+2, ncp) -
|
1957 | jStat.noncentralt.cdf(x, dof, ncp));
|
1958 | },
|
1959 |
|
1960 | cdf: function cdf(x, dof, ncp) {
|
1961 | var tol = 1e-14;
|
1962 | var min_iterations = 200;
|
1963 |
|
1964 | if (Math.abs(ncp) < tol)
|
1965 | return jStat.studentt.cdf(x, dof);
|
1966 |
|
1967 |
|
1968 | var flip = false;
|
1969 | if (x < 0) {
|
1970 | flip = true;
|
1971 | ncp = -ncp;
|
1972 | }
|
1973 |
|
1974 | var prob = jStat.normal.cdf(-ncp, 0, 1);
|
1975 | var value = tol + 1;
|
1976 |
|
1977 | var lastvalue = value;
|
1978 | var y = x * x / (x * x + dof);
|
1979 | var j = 0;
|
1980 | var p = Math.exp(-ncp * ncp / 2);
|
1981 | var q = Math.exp(-ncp * ncp / 2 - 0.5 * Math.log(2) -
|
1982 | jStat.gammaln(3 / 2)) * ncp;
|
1983 | while (j < min_iterations || lastvalue > tol || value > tol) {
|
1984 | lastvalue = value;
|
1985 | if (j > 0) {
|
1986 | p *= (ncp * ncp) / (2 * j);
|
1987 | q *= (ncp * ncp) / (2 * (j + 1 / 2));
|
1988 | }
|
1989 | value = p * jStat.beta.cdf(y, j + 0.5, dof / 2) +
|
1990 | q * jStat.beta.cdf(y, j+1, dof/2);
|
1991 | prob += 0.5 * value;
|
1992 | j++;
|
1993 | }
|
1994 |
|
1995 | return flip ? (1 - prob) : prob;
|
1996 | }
|
1997 | });
|
1998 |
|
1999 |
|
2000 |
|
2001 | jStat.extend(jStat.normal, {
|
2002 | pdf: function pdf(x, mean, std) {
|
2003 | return Math.exp(-0.5 * Math.log(2 * Math.PI) -
|
2004 | Math.log(std) - Math.pow(x - mean, 2) / (2 * std * std));
|
2005 | },
|
2006 |
|
2007 | cdf: function cdf(x, mean, std) {
|
2008 | return 0.5 * (1 + jStat.erf((x - mean) / Math.sqrt(2 * std * std)));
|
2009 | },
|
2010 |
|
2011 | inv: function(p, mean, std) {
|
2012 | return -1.41421356237309505 * std * jStat.erfcinv(2 * p) + mean;
|
2013 | },
|
2014 |
|
2015 | mean : function(mean, std) {
|
2016 | return mean;
|
2017 | },
|
2018 |
|
2019 | median: function median(mean, std) {
|
2020 | return mean;
|
2021 | },
|
2022 |
|
2023 | mode: function (mean, std) {
|
2024 | return mean;
|
2025 | },
|
2026 |
|
2027 | sample: function sample(mean, std) {
|
2028 | return jStat.randn() * std + mean;
|
2029 | },
|
2030 |
|
2031 | variance : function(mean, std) {
|
2032 | return std * std;
|
2033 | }
|
2034 | });
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 | jStat.extend(jStat.pareto, {
|
2040 | pdf: function pdf(x, scale, shape) {
|
2041 | if (x < scale)
|
2042 | return 0;
|
2043 | return (shape * Math.pow(scale, shape)) / Math.pow(x, shape + 1);
|
2044 | },
|
2045 |
|
2046 | cdf: function cdf(x, scale, shape) {
|
2047 | if (x < scale)
|
2048 | return 0;
|
2049 | return 1 - Math.pow(scale / x, shape);
|
2050 | },
|
2051 |
|
2052 | inv: function inv(p, scale, shape) {
|
2053 | return scale / Math.pow(1 - p, 1 / shape);
|
2054 | },
|
2055 |
|
2056 | mean: function mean(scale, shape) {
|
2057 | if (shape <= 1)
|
2058 | return undefined;
|
2059 | return (shape * Math.pow(scale, shape)) / (shape - 1);
|
2060 | },
|
2061 |
|
2062 | median: function median(scale, shape) {
|
2063 | return scale * (shape * Math.SQRT2);
|
2064 | },
|
2065 |
|
2066 | mode: function mode(scale, shape) {
|
2067 | return scale;
|
2068 | },
|
2069 |
|
2070 | variance : function(scale, shape) {
|
2071 | if (shape <= 2)
|
2072 | return undefined;
|
2073 | return (scale*scale * shape) / (Math.pow(shape - 1, 2) * (shape - 2));
|
2074 | }
|
2075 | });
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 | jStat.extend(jStat.studentt, {
|
2081 | pdf: function pdf(x, dof) {
|
2082 | dof = dof > 1e100 ? 1e100 : dof;
|
2083 | return (1/(Math.sqrt(dof) * jStat.betafn(0.5, dof/2))) *
|
2084 | Math.pow(1 + ((x * x) / dof), -((dof + 1) / 2));
|
2085 | },
|
2086 |
|
2087 | cdf: function cdf(x, dof) {
|
2088 | var dof2 = dof / 2;
|
2089 | return jStat.ibeta((x + Math.sqrt(x * x + dof)) /
|
2090 | (2 * Math.sqrt(x * x + dof)), dof2, dof2);
|
2091 | },
|
2092 |
|
2093 | inv: function(p, dof) {
|
2094 | var x = jStat.ibetainv(2 * Math.min(p, 1 - p), 0.5 * dof, 0.5);
|
2095 | x = Math.sqrt(dof * (1 - x) / x);
|
2096 | return (p > 0.5) ? x : -x;
|
2097 | },
|
2098 |
|
2099 | mean: function mean(dof) {
|
2100 | return (dof > 1) ? 0 : undefined;
|
2101 | },
|
2102 |
|
2103 | median: function median(dof) {
|
2104 | return 0;
|
2105 | },
|
2106 |
|
2107 | mode: function mode(dof) {
|
2108 | return 0;
|
2109 | },
|
2110 |
|
2111 | sample: function sample(dof) {
|
2112 | return jStat.randn() * Math.sqrt(dof / (2 * jStat.randg(dof / 2)));
|
2113 | },
|
2114 |
|
2115 | variance: function variance(dof) {
|
2116 | return (dof > 2) ? dof / (dof - 2) : (dof > 1) ? Infinity : undefined;
|
2117 | }
|
2118 | });
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 | jStat.extend(jStat.weibull, {
|
2124 | pdf: function pdf(x, scale, shape) {
|
2125 | if (x < 0 || scale < 0 || shape < 0)
|
2126 | return 0;
|
2127 | return (shape / scale) * Math.pow((x / scale), (shape - 1)) *
|
2128 | Math.exp(-(Math.pow((x / scale), shape)));
|
2129 | },
|
2130 |
|
2131 | cdf: function cdf(x, scale, shape) {
|
2132 | return x < 0 ? 0 : 1 - Math.exp(-Math.pow((x / scale), shape));
|
2133 | },
|
2134 |
|
2135 | inv: function(p, scale, shape) {
|
2136 | return scale * Math.pow(-Math.log(1 - p), 1 / shape);
|
2137 | },
|
2138 |
|
2139 | mean : function(scale, shape) {
|
2140 | return scale * jStat.gammafn(1 + 1 / shape);
|
2141 | },
|
2142 |
|
2143 | median: function median(scale, shape) {
|
2144 | return scale * Math.pow(Math.log(2), 1 / shape);
|
2145 | },
|
2146 |
|
2147 | mode: function mode(scale, shape) {
|
2148 | if (shape <= 1)
|
2149 | return 0;
|
2150 | return scale * Math.pow((shape - 1) / shape, 1 / shape);
|
2151 | },
|
2152 |
|
2153 | sample: function sample(scale, shape) {
|
2154 | return scale * Math.pow(-Math.log(Math.random()), 1 / shape);
|
2155 | },
|
2156 |
|
2157 | variance: function variance(scale, shape) {
|
2158 | return scale * scale * jStat.gammafn(1 + 2 / shape) -
|
2159 | Math.pow(jStat.weibull.mean(scale, shape), 2);
|
2160 | }
|
2161 | });
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 | jStat.extend(jStat.uniform, {
|
2167 | pdf: function pdf(x, a, b) {
|
2168 | return (x < a || x > b) ? 0 : 1 / (b - a);
|
2169 | },
|
2170 |
|
2171 | cdf: function cdf(x, a, b) {
|
2172 | if (x < a)
|
2173 | return 0;
|
2174 | else if (x < b)
|
2175 | return (x - a) / (b - a);
|
2176 | return 1;
|
2177 | },
|
2178 |
|
2179 | inv: function(p, a, b) {
|
2180 | return a + (p * (b - a));
|
2181 | },
|
2182 |
|
2183 | mean: function mean(a, b) {
|
2184 | return 0.5 * (a + b);
|
2185 | },
|
2186 |
|
2187 | median: function median(a, b) {
|
2188 | return jStat.mean(a, b);
|
2189 | },
|
2190 |
|
2191 | mode: function mode(a, b) {
|
2192 | throw new Error('mode is not yet implemented');
|
2193 | },
|
2194 |
|
2195 | sample: function sample(a, b) {
|
2196 | return (a / 2 + b / 2) + (b / 2 - a / 2) * (2 * Math.random() - 1);
|
2197 | },
|
2198 |
|
2199 | variance: function variance(a, b) {
|
2200 | return Math.pow(b - a, 2) / 12;
|
2201 | }
|
2202 | });
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 | jStat.extend(jStat.binomial, {
|
2208 | pdf: function pdf(k, n, p) {
|
2209 | return (p === 0 || p === 1) ?
|
2210 | ((n * p) === k ? 1 : 0) :
|
2211 | jStat.combination(n, k) * Math.pow(p, k) * Math.pow(1 - p, n - k);
|
2212 | },
|
2213 |
|
2214 | cdf: function cdf(x, n, p) {
|
2215 | var binomarr = [],
|
2216 | k = 0;
|
2217 | if (x < 0) {
|
2218 | return 0;
|
2219 | }
|
2220 | if (x < n) {
|
2221 | for (; k <= x; k++) {
|
2222 | binomarr[ k ] = jStat.binomial.pdf(k, n, p);
|
2223 | }
|
2224 | return jStat.sum(binomarr);
|
2225 | }
|
2226 | return 1;
|
2227 | }
|
2228 | });
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 | jStat.extend(jStat.negbin, {
|
2234 | pdf: function pdf(k, r, p) {
|
2235 | if (k !== k >>> 0)
|
2236 | return false;
|
2237 | if (k < 0)
|
2238 | return 0;
|
2239 | return jStat.combination(k + r - 1, r - 1) *
|
2240 | Math.pow(1 - p, k) * Math.pow(p, r);
|
2241 | },
|
2242 |
|
2243 | cdf: function cdf(x, r, p) {
|
2244 | var sum = 0,
|
2245 | k = 0;
|
2246 | if (x < 0) return 0;
|
2247 | for (; k <= x; k++) {
|
2248 | sum += jStat.negbin.pdf(k, r, p);
|
2249 | }
|
2250 | return sum;
|
2251 | }
|
2252 | });
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 | jStat.extend(jStat.hypgeom, {
|
2258 | pdf: function pdf(k, N, m, n) {
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 | if(k !== k | 0) {
|
2269 | return false;
|
2270 | } else if(k < 0 || k < m - (N - n)) {
|
2271 |
|
2272 | return 0;
|
2273 | } else if(k > n || k > m) {
|
2274 |
|
2275 | return 0;
|
2276 | } else if (m * 2 > N) {
|
2277 |
|
2278 |
|
2279 | if(n * 2 > N) {
|
2280 |
|
2281 |
|
2282 | return jStat.hypgeom.pdf(N - m - n + k, N, N - m, N - n)
|
2283 | } else {
|
2284 |
|
2285 |
|
2286 | return jStat.hypgeom.pdf(n - k, N, N - m, n);
|
2287 | }
|
2288 |
|
2289 | } else if(n * 2 > N) {
|
2290 |
|
2291 |
|
2292 | return jStat.hypgeom.pdf(m - k, N, m, N - n);
|
2293 |
|
2294 | } else if(m < n) {
|
2295 |
|
2296 |
|
2297 | return jStat.hypgeom.pdf(k, N, n, m);
|
2298 | } else {
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 | var scaledPDF = 1;
|
2311 |
|
2312 |
|
2313 | var samplesDone = 0;
|
2314 |
|
2315 | for(var i = 0; i < k; i++) {
|
2316 |
|
2317 |
|
2318 | while(scaledPDF > 1 && samplesDone < n) {
|
2319 |
|
2320 |
|
2321 |
|
2322 | scaledPDF *= 1 - (m / (N - samplesDone));
|
2323 |
|
2324 |
|
2325 | samplesDone++;
|
2326 | }
|
2327 |
|
2328 |
|
2329 |
|
2330 | scaledPDF *= (n - i) * (m - i) / ((i + 1) * (N - m - n + i + 1));
|
2331 | }
|
2332 |
|
2333 | for(; samplesDone < n; samplesDone++) {
|
2334 |
|
2335 | scaledPDF *= 1 - (m / (N - samplesDone));
|
2336 | }
|
2337 |
|
2338 |
|
2339 | return Math.min(1, Math.max(0, scaledPDF));
|
2340 | }
|
2341 | },
|
2342 |
|
2343 | cdf: function cdf(x, N, m, n) {
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 | if(x < 0 || x < m - (N - n)) {
|
2356 |
|
2357 | return 0;
|
2358 | } else if(x >= n || x >= m) {
|
2359 |
|
2360 | return 1;
|
2361 | } else if (m * 2 > N) {
|
2362 |
|
2363 |
|
2364 | if(n * 2 > N) {
|
2365 |
|
2366 |
|
2367 | return jStat.hypgeom.cdf(N - m - n + x, N, N - m, N - n)
|
2368 | } else {
|
2369 |
|
2370 |
|
2371 | return 1 - jStat.hypgeom.cdf(n - x - 1, N, N - m, n);
|
2372 | }
|
2373 |
|
2374 | } else if(n * 2 > N) {
|
2375 |
|
2376 |
|
2377 | return 1 - jStat.hypgeom.cdf(m - x - 1, N, m, N - n);
|
2378 |
|
2379 | } else if(m < n) {
|
2380 |
|
2381 |
|
2382 | return jStat.hypgeom.cdf(x, N, n, m);
|
2383 | } else {
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 | var scaledCDF = 1;
|
2395 |
|
2396 |
|
2397 |
|
2398 | var scaledPDF = 1;
|
2399 |
|
2400 |
|
2401 | var samplesDone = 0;
|
2402 |
|
2403 | for(var i = 0; i < x; i++) {
|
2404 |
|
2405 |
|
2406 | while(scaledCDF > 1 && samplesDone < n) {
|
2407 |
|
2408 |
|
2409 |
|
2410 | var factor = 1 - (m / (N - samplesDone));
|
2411 |
|
2412 | scaledPDF *= factor;
|
2413 | scaledCDF *= factor;
|
2414 |
|
2415 |
|
2416 | samplesDone++;
|
2417 | }
|
2418 |
|
2419 |
|
2420 |
|
2421 | scaledPDF *= (n - i) * (m - i) / ((i + 1) * (N - m - n + i + 1));
|
2422 |
|
2423 |
|
2424 | scaledCDF += scaledPDF;
|
2425 | }
|
2426 |
|
2427 | for(; samplesDone < n; samplesDone++) {
|
2428 |
|
2429 | scaledCDF *= 1 - (m / (N - samplesDone));
|
2430 | }
|
2431 |
|
2432 |
|
2433 | return Math.min(1, Math.max(0, scaledCDF));
|
2434 | }
|
2435 | }
|
2436 | });
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 | jStat.extend(jStat.poisson, {
|
2442 | pdf: function pdf(k, l) {
|
2443 | if (l < 0 || (k % 1) !== 0 || k < 0) {
|
2444 | return 0;
|
2445 | }
|
2446 |
|
2447 | return Math.pow(l, k) * Math.exp(-l) / jStat.factorial(k);
|
2448 | },
|
2449 |
|
2450 | cdf: function cdf(x, l) {
|
2451 | var sumarr = [],
|
2452 | k = 0;
|
2453 | if (x < 0) return 0;
|
2454 | for (; k <= x; k++) {
|
2455 | sumarr.push(jStat.poisson.pdf(k, l));
|
2456 | }
|
2457 | return jStat.sum(sumarr);
|
2458 | },
|
2459 |
|
2460 | mean : function(l) {
|
2461 | return l;
|
2462 | },
|
2463 |
|
2464 | variance : function(l) {
|
2465 | return l;
|
2466 | },
|
2467 |
|
2468 | sample: function sample(l) {
|
2469 | var p = 1, k = 0, L = Math.exp(-l);
|
2470 | do {
|
2471 | k++;
|
2472 | p *= Math.random();
|
2473 | } while (p > L);
|
2474 | return k - 1;
|
2475 | }
|
2476 | });
|
2477 |
|
2478 |
|
2479 | jStat.extend(jStat.triangular, {
|
2480 | pdf: function pdf(x, a, b, c) {
|
2481 | if (b <= a || c < a || c > b) {
|
2482 | return NaN;
|
2483 | } else {
|
2484 | if (x < a || x > b) {
|
2485 | return 0;
|
2486 | } else if (x < c) {
|
2487 | return (2 * (x - a)) / ((b - a) * (c - a));
|
2488 | } else if (x === c) {
|
2489 | return (2 / (b - a));
|
2490 | } else {
|
2491 | return (2 * (b - x)) / ((b - a) * (b - c));
|
2492 | }
|
2493 | }
|
2494 | },
|
2495 |
|
2496 | cdf: function cdf(x, a, b, c) {
|
2497 | if (b <= a || c < a || c > b)
|
2498 | return NaN;
|
2499 | if (x <= a)
|
2500 | return 0;
|
2501 | else if (x >= b)
|
2502 | return 1;
|
2503 | if (x <= c)
|
2504 | return Math.pow(x - a, 2) / ((b - a) * (c - a));
|
2505 | else
|
2506 | return 1 - Math.pow(b - x, 2) / ((b - a) * (b - c));
|
2507 | },
|
2508 |
|
2509 | inv: function inv(p, a, b, c) {
|
2510 | if (b <= a || c < a || c > b) {
|
2511 | return NaN;
|
2512 | } else {
|
2513 | if (p <= ((c - a) / (b - a))) {
|
2514 | return a + (b - a) * Math.sqrt(p * ((c - a) / (b - a)));
|
2515 | } else {
|
2516 | return a + (b - a) * (1 - Math.sqrt((1 - p) * (1 - ((c - a) / (b - a)))));
|
2517 | }
|
2518 | }
|
2519 | },
|
2520 |
|
2521 | mean: function mean(a, b, c) {
|
2522 | return (a + b + c) / 3;
|
2523 | },
|
2524 |
|
2525 | median: function median(a, b, c) {
|
2526 | if (c <= (a + b) / 2) {
|
2527 | return b - Math.sqrt((b - a) * (b - c)) / Math.sqrt(2);
|
2528 | } else if (c > (a + b) / 2) {
|
2529 | return a + Math.sqrt((b - a) * (c - a)) / Math.sqrt(2);
|
2530 | }
|
2531 | },
|
2532 |
|
2533 | mode: function mode(a, b, c) {
|
2534 | return c;
|
2535 | },
|
2536 |
|
2537 | sample: function sample(a, b, c) {
|
2538 | var u = Math.random();
|
2539 | if (u < ((c - a) / (b - a)))
|
2540 | return a + Math.sqrt(u * (b - a) * (c - a))
|
2541 | return b - Math.sqrt((1 - u) * (b - a) * (b - c));
|
2542 | },
|
2543 |
|
2544 | variance: function variance(a, b, c) {
|
2545 | return (a * a + b * b + c * c - a * b - a * c - b * c) / 18;
|
2546 | }
|
2547 | });
|
2548 |
|
2549 | function laplaceSign(x) { return x / Math.abs(x); }
|
2550 |
|
2551 | jStat.extend(jStat.laplace, {
|
2552 | pdf: function pdf(x, mu, b) {
|
2553 | return (b <= 0) ? 0 : (Math.exp(-Math.abs(x - mu) / b)) / (2 * b);
|
2554 | },
|
2555 |
|
2556 | cdf: function cdf(x, mu, b) {
|
2557 | if (b <= 0) { return 0; }
|
2558 |
|
2559 | if(x < mu) {
|
2560 | return 0.5 * Math.exp((x - mu) / b);
|
2561 | } else {
|
2562 | return 1 - 0.5 * Math.exp(- (x - mu) / b);
|
2563 | }
|
2564 | },
|
2565 |
|
2566 | mean: function(mu, b) {
|
2567 | return mu;
|
2568 | },
|
2569 |
|
2570 | median: function(mu, b) {
|
2571 | return mu;
|
2572 | },
|
2573 |
|
2574 | mode: function(mu, b) {
|
2575 | return mu;
|
2576 | },
|
2577 |
|
2578 | variance: function(mu, b) {
|
2579 | return 2 * b * b;
|
2580 | },
|
2581 |
|
2582 | sample: function sample(mu, b) {
|
2583 | var u = Math.random() - 0.5;
|
2584 |
|
2585 | return mu - (b * laplaceSign(u) * Math.log(1 - (2 * Math.abs(u))));
|
2586 | }
|
2587 | });
|
2588 |
|
2589 | }(this.jStat, Math));
|
2590 |
|
2591 |
|
2592 |
|
2593 | (function(jStat, Math) {
|
2594 |
|
2595 | var push = Array.prototype.push;
|
2596 | var isArray = jStat.utils.isArray;
|
2597 |
|
2598 | function isUsable(arg) {
|
2599 | return isArray(arg) || arg instanceof jStat;
|
2600 | }
|
2601 |
|
2602 | jStat.extend({
|
2603 |
|
2604 |
|
2605 | add: function add(arr, arg) {
|
2606 |
|
2607 | if (isUsable(arg)) {
|
2608 | if (!isUsable(arg[0])) arg = [ arg ];
|
2609 | return jStat.map(arr, function(value, row, col) {
|
2610 | return value + arg[row][col];
|
2611 | });
|
2612 | }
|
2613 | return jStat.map(arr, function(value) { return value + arg; });
|
2614 | },
|
2615 |
|
2616 |
|
2617 | subtract: function subtract(arr, arg) {
|
2618 |
|
2619 | if (isUsable(arg)) {
|
2620 | if (!isUsable(arg[0])) arg = [ arg ];
|
2621 | return jStat.map(arr, function(value, row, col) {
|
2622 | return value - arg[row][col] || 0;
|
2623 | });
|
2624 | }
|
2625 | return jStat.map(arr, function(value) { return value - arg; });
|
2626 | },
|
2627 |
|
2628 |
|
2629 | divide: function divide(arr, arg) {
|
2630 | if (isUsable(arg)) {
|
2631 | if (!isUsable(arg[0])) arg = [ arg ];
|
2632 | return jStat.multiply(arr, jStat.inv(arg));
|
2633 | }
|
2634 | return jStat.map(arr, function(value) { return value / arg; });
|
2635 | },
|
2636 |
|
2637 |
|
2638 | multiply: function multiply(arr, arg) {
|
2639 | var row, col, nrescols, sum,
|
2640 | nrow = arr.length,
|
2641 | ncol = arr[0].length,
|
2642 | res = jStat.zeros(nrow, nrescols = (isUsable(arg)) ? arg[0].length : ncol),
|
2643 | rescols = 0;
|
2644 | if (isUsable(arg)) {
|
2645 | for (; rescols < nrescols; rescols++) {
|
2646 | for (row = 0; row < nrow; row++) {
|
2647 | sum = 0;
|
2648 | for (col = 0; col < ncol; col++)
|
2649 | sum += arr[row][col] * arg[col][rescols];
|
2650 | res[row][rescols] = sum;
|
2651 | }
|
2652 | }
|
2653 | return (nrow === 1 && rescols === 1) ? res[0][0] : res;
|
2654 | }
|
2655 | return jStat.map(arr, function(value) { return value * arg; });
|
2656 | },
|
2657 |
|
2658 |
|
2659 | dot: function dot(arr, arg) {
|
2660 | if (!isUsable(arr[0])) arr = [ arr ];
|
2661 | if (!isUsable(arg[0])) arg = [ arg ];
|
2662 |
|
2663 | var left = (arr[0].length === 1 && arr.length !== 1) ? jStat.transpose(arr) : arr,
|
2664 | right = (arg[0].length === 1 && arg.length !== 1) ? jStat.transpose(arg) : arg,
|
2665 | res = [],
|
2666 | row = 0,
|
2667 | nrow = left.length,
|
2668 | ncol = left[0].length,
|
2669 | sum, col;
|
2670 | for (; row < nrow; row++) {
|
2671 | res[row] = [];
|
2672 | sum = 0;
|
2673 | for (col = 0; col < ncol; col++)
|
2674 | sum += left[row][col] * right[row][col];
|
2675 | res[row] = sum;
|
2676 | }
|
2677 | return (res.length === 1) ? res[0] : res;
|
2678 | },
|
2679 |
|
2680 |
|
2681 | pow: function pow(arr, arg) {
|
2682 | return jStat.map(arr, function(value) { return Math.pow(value, arg); });
|
2683 | },
|
2684 |
|
2685 |
|
2686 | exp: function exp(arr) {
|
2687 | return jStat.map(arr, function(value) { return Math.exp(value); });
|
2688 | },
|
2689 |
|
2690 |
|
2691 | log: function exp(arr) {
|
2692 | return jStat.map(arr, function(value) { return Math.log(value); });
|
2693 | },
|
2694 |
|
2695 |
|
2696 | abs: function abs(arr) {
|
2697 | return jStat.map(arr, function(value) { return Math.abs(value); });
|
2698 | },
|
2699 |
|
2700 |
|
2701 |
|
2702 | norm: function norm(arr, p) {
|
2703 | var nnorm = 0,
|
2704 | i = 0;
|
2705 |
|
2706 | if (isNaN(p)) p = 2;
|
2707 |
|
2708 | if (isUsable(arr[0])) arr = arr[0];
|
2709 |
|
2710 | for (; i < arr.length; i++) {
|
2711 | nnorm += Math.pow(Math.abs(arr[i]), p);
|
2712 | }
|
2713 | return Math.pow(nnorm, 1 / p);
|
2714 | },
|
2715 |
|
2716 |
|
2717 |
|
2718 | angle: function angle(arr, arg) {
|
2719 | return Math.acos(jStat.dot(arr, arg) / (jStat.norm(arr) * jStat.norm(arg)));
|
2720 | },
|
2721 |
|
2722 |
|
2723 |
|
2724 | aug: function aug(a, b) {
|
2725 | var newarr = [];
|
2726 | for (var i = 0; i < a.length; i++) {
|
2727 | newarr.push(a[i].slice());
|
2728 | }
|
2729 | for (var i = 0; i < newarr.length; i++) {
|
2730 | push.apply(newarr[i], b[i]);
|
2731 | }
|
2732 | return newarr;
|
2733 | },
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 | inv: function inv(a) {
|
2739 | var rows = a.length;
|
2740 | var cols = a[0].length;
|
2741 | var b = jStat.identity(rows, cols);
|
2742 | var c = jStat.gauss_jordan(a, b);
|
2743 | var result = [];
|
2744 | var i = 0;
|
2745 | var j;
|
2746 |
|
2747 |
|
2748 | for (; i < rows; i++) {
|
2749 | result[i] = [];
|
2750 | for (j = cols; j < c[0].length; j++)
|
2751 | result[i][j - cols] = c[i][j];
|
2752 | }
|
2753 | return result;
|
2754 | },
|
2755 |
|
2756 |
|
2757 | det: function det(a) {
|
2758 | var alen = a.length,
|
2759 | alend = alen * 2,
|
2760 | vals = new Array(alend),
|
2761 | rowshift = alen - 1,
|
2762 | colshift = alend - 1,
|
2763 | mrow = rowshift - alen + 1,
|
2764 | mcol = colshift,
|
2765 | i = 0,
|
2766 | result = 0,
|
2767 | j;
|
2768 |
|
2769 | if (alen === 2) {
|
2770 | return a[0][0] * a[1][1] - a[0][1] * a[1][0];
|
2771 | }
|
2772 | for (; i < alend; i++) {
|
2773 | vals[i] = 1;
|
2774 | }
|
2775 | for (i = 0; i < alen; i++) {
|
2776 | for (j = 0; j < alen; j++) {
|
2777 | vals[(mrow < 0) ? mrow + alen : mrow ] *= a[i][j];
|
2778 | vals[(mcol < alen) ? mcol + alen : mcol ] *= a[i][j];
|
2779 | mrow++;
|
2780 | mcol--;
|
2781 | }
|
2782 | mrow = --rowshift - alen + 1;
|
2783 | mcol = --colshift;
|
2784 | }
|
2785 | for (i = 0; i < alen; i++) {
|
2786 | result += vals[i];
|
2787 | }
|
2788 | for (; i < alend; i++) {
|
2789 | result -= vals[i];
|
2790 | }
|
2791 | return result;
|
2792 | },
|
2793 |
|
2794 | gauss_elimination: function gauss_elimination(a, b) {
|
2795 | var i = 0,
|
2796 | j = 0,
|
2797 | n = a.length,
|
2798 | m = a[0].length,
|
2799 | factor = 1,
|
2800 | sum = 0,
|
2801 | x = [],
|
2802 | maug, pivot, temp, k;
|
2803 | a = jStat.aug(a, b);
|
2804 | maug = a[0].length;
|
2805 | for(i = 0; i < n; i++) {
|
2806 | pivot = a[i][i];
|
2807 | j = i;
|
2808 | for (k = i + 1; k < m; k++) {
|
2809 | if (pivot < Math.abs(a[k][i])) {
|
2810 | pivot = a[k][i];
|
2811 | j = k;
|
2812 | }
|
2813 | }
|
2814 | if (j != i) {
|
2815 | for(k = 0; k < maug; k++) {
|
2816 | temp = a[i][k];
|
2817 | a[i][k] = a[j][k];
|
2818 | a[j][k] = temp;
|
2819 | }
|
2820 | }
|
2821 | for (j = i + 1; j < n; j++) {
|
2822 | factor = a[j][i] / a[i][i];
|
2823 | for(k = i; k < maug; k++) {
|
2824 | a[j][k] = a[j][k] - factor * a[i][k];
|
2825 | }
|
2826 | }
|
2827 | }
|
2828 | for (i = n - 1; i >= 0; i--) {
|
2829 | sum = 0;
|
2830 | for (j = i + 1; j<= n - 1; j++) {
|
2831 | sum = sum + x[j] * a[i][j];
|
2832 | }
|
2833 | x[i] =(a[i][maug - 1] - sum) / a[i][i];
|
2834 | }
|
2835 | return x;
|
2836 | },
|
2837 |
|
2838 | gauss_jordan: function gauss_jordan(a, b) {
|
2839 | var m = jStat.aug(a, b),
|
2840 | h = m.length,
|
2841 | w = m[0].length;
|
2842 |
|
2843 | for (var y = 0; y < h; y++) {
|
2844 | var maxrow = y;
|
2845 | for (var y2 = y+1; y2 < h; y2++) {
|
2846 | if (Math.abs(m[y2][y]) > Math.abs(m[maxrow][y]))
|
2847 | maxrow = y2;
|
2848 | }
|
2849 | var tmp = m[y];
|
2850 | m[y] = m[maxrow];
|
2851 | m[maxrow] = tmp
|
2852 | for (var y2 = y+1; y2 < h; y2++) {
|
2853 | c = m[y2][y] / m[y][y];
|
2854 | for (var x = y; x < w; x++) {
|
2855 | m[y2][x] -= m[y][x] * c;
|
2856 | }
|
2857 | }
|
2858 | }
|
2859 |
|
2860 | for (var y = h-1; y >= 0; y--) {
|
2861 | c = m[y][y];
|
2862 | for (var y2 = 0; y2 < y; y2++) {
|
2863 | for (var x = w-1; x > y-1; x--) {
|
2864 | m[y2][x] -= m[y][x] * m[y2][y] / c;
|
2865 | }
|
2866 | }
|
2867 | m[y][y] /= c;
|
2868 | for (var x = h; x < w; x++) {
|
2869 | m[y][x] /= c;
|
2870 | }
|
2871 | }
|
2872 | return m;
|
2873 | },
|
2874 |
|
2875 | lu: function lu(a, b) {
|
2876 | throw new Error('lu not yet implemented');
|
2877 | },
|
2878 |
|
2879 | cholesky: function cholesky(a, b) {
|
2880 | throw new Error('cholesky not yet implemented');
|
2881 | },
|
2882 |
|
2883 | gauss_jacobi: function gauss_jacobi(a, b, x, r) {
|
2884 | var i = 0;
|
2885 | var j = 0;
|
2886 | var n = a.length;
|
2887 | var l = [];
|
2888 | var u = [];
|
2889 | var d = [];
|
2890 | var xv, c, h, xk;
|
2891 | for (; i < n; i++) {
|
2892 | l[i] = [];
|
2893 | u[i] = [];
|
2894 | d[i] = [];
|
2895 | for (j = 0; j < n; j++) {
|
2896 | if (i > j) {
|
2897 | l[i][j] = a[i][j];
|
2898 | u[i][j] = d[i][j] = 0;
|
2899 | } else if (i < j) {
|
2900 | u[i][j] = a[i][j];
|
2901 | l[i][j] = d[i][j] = 0;
|
2902 | } else {
|
2903 | d[i][j] = a[i][j];
|
2904 | l[i][j] = u[i][j] = 0;
|
2905 | }
|
2906 | }
|
2907 | }
|
2908 | h = jStat.multiply(jStat.multiply(jStat.inv(d), jStat.add(l, u)), -1);
|
2909 | c = jStat.multiply(jStat.inv(d), b);
|
2910 | xv = x;
|
2911 | xk = jStat.add(jStat.multiply(h, x), c);
|
2912 | i = 2;
|
2913 | while (Math.abs(jStat.norm(jStat.subtract(xk,xv))) > r) {
|
2914 | xv = xk;
|
2915 | xk = jStat.add(jStat.multiply(h, xv), c);
|
2916 | i++;
|
2917 | }
|
2918 | return xk;
|
2919 | },
|
2920 |
|
2921 | gauss_seidel: function gauss_seidel(a, b, x, r) {
|
2922 | var i = 0;
|
2923 | var n = a.length;
|
2924 | var l = [];
|
2925 | var u = [];
|
2926 | var d = [];
|
2927 | var j, xv, c, h, xk;
|
2928 | for (; i < n; i++) {
|
2929 | l[i] = [];
|
2930 | u[i] = [];
|
2931 | d[i] = [];
|
2932 | for (j = 0; j < n; j++) {
|
2933 | if (i > j) {
|
2934 | l[i][j] = a[i][j];
|
2935 | u[i][j] = d[i][j] = 0;
|
2936 | } else if (i < j) {
|
2937 | u[i][j] = a[i][j];
|
2938 | l[i][j] = d[i][j] = 0;
|
2939 | } else {
|
2940 | d[i][j] = a[i][j];
|
2941 | l[i][j] = u[i][j] = 0;
|
2942 | }
|
2943 | }
|
2944 | }
|
2945 | h = jStat.multiply(jStat.multiply(jStat.inv(jStat.add(d, l)), u), -1);
|
2946 | c = jStat.multiply(jStat.inv(jStat.add(d, l)), b);
|
2947 | xv = x;
|
2948 | xk = jStat.add(jStat.multiply(h, x), c);
|
2949 | i = 2;
|
2950 | while (Math.abs(jStat.norm(jStat.subtract(xk, xv))) > r) {
|
2951 | xv = xk;
|
2952 | xk = jStat.add(jStat.multiply(h, xv), c);
|
2953 | i = i + 1;
|
2954 | }
|
2955 | return xk;
|
2956 | },
|
2957 |
|
2958 | SOR: function SOR(a, b, x, r, w) {
|
2959 | var i = 0;
|
2960 | var n = a.length;
|
2961 | var l = [];
|
2962 | var u = [];
|
2963 | var d = [];
|
2964 | var j, xv, c, h, xk;
|
2965 | for (; i < n; i++) {
|
2966 | l[i] = [];
|
2967 | u[i] = [];
|
2968 | d[i] = [];
|
2969 | for (j = 0; j < n; j++) {
|
2970 | if (i > j) {
|
2971 | l[i][j] = a[i][j];
|
2972 | u[i][j] = d[i][j] = 0;
|
2973 | } else if (i < j) {
|
2974 | u[i][j] = a[i][j];
|
2975 | l[i][j] = d[i][j] = 0;
|
2976 | } else {
|
2977 | d[i][j] = a[i][j];
|
2978 | l[i][j] = u[i][j] = 0;
|
2979 | }
|
2980 | }
|
2981 | }
|
2982 | h = jStat.multiply(jStat.inv(jStat.add(d, jStat.multiply(l, w))),
|
2983 | jStat.subtract(jStat.multiply(d, 1 - w),
|
2984 | jStat.multiply(u, w)));
|
2985 | c = jStat.multiply(jStat.multiply(jStat.inv(jStat.add(d,
|
2986 | jStat.multiply(l, w))), b), w);
|
2987 | xv = x;
|
2988 | xk = jStat.add(jStat.multiply(h, x), c);
|
2989 | i = 2;
|
2990 | while (Math.abs(jStat.norm(jStat.subtract(xk, xv))) > r) {
|
2991 | xv = xk;
|
2992 | xk = jStat.add(jStat.multiply(h, xv), c);
|
2993 | i++;
|
2994 | }
|
2995 | return xk;
|
2996 | },
|
2997 |
|
2998 | householder: function householder(a) {
|
2999 | var m = a.length;
|
3000 | var n = a[0].length;
|
3001 | var i = 0;
|
3002 | var w = [];
|
3003 | var p = [];
|
3004 | var alpha, r, k, j, factor;
|
3005 | for (; i < m - 1; i++) {
|
3006 | alpha = 0;
|
3007 | for (j = i + 1; j < n; j++)
|
3008 | alpha += (a[j][i] * a[j][i]);
|
3009 | factor = (a[i + 1][i] > 0) ? -1 : 1;
|
3010 | alpha = factor * Math.sqrt(alpha);
|
3011 | r = Math.sqrt((((alpha * alpha) - a[i + 1][i] * alpha) / 2));
|
3012 | w = jStat.zeros(m, 1);
|
3013 | w[i + 1][0] = (a[i + 1][i] - alpha) / (2 * r);
|
3014 | for (k = i + 2; k < m; k++) w[k][0] = a[k][i] / (2 * r);
|
3015 | p = jStat.subtract(jStat.identity(m, n),
|
3016 | jStat.multiply(jStat.multiply(w, jStat.transpose(w)), 2));
|
3017 | a = jStat.multiply(p, jStat.multiply(a, p));
|
3018 | }
|
3019 | return a;
|
3020 | },
|
3021 |
|
3022 |
|
3023 | QR: function QR(a, b) {
|
3024 | var m = a.length;
|
3025 | var n = a[0].length;
|
3026 | var i = 0;
|
3027 | var w = [];
|
3028 | var p = [];
|
3029 | var x = [];
|
3030 | var j, alpha, r, k, factor, sum;
|
3031 | for (; i < m - 1; i++) {
|
3032 | alpha = 0;
|
3033 | for (j = i + 1; j < n; j++)
|
3034 | alpha += (a[j][i] * a[j][i]);
|
3035 | factor = (a[i + 1][i] > 0) ? -1 : 1;
|
3036 | alpha = factor * Math.sqrt(alpha);
|
3037 | r = Math.sqrt((((alpha * alpha) - a[i + 1][i] * alpha) / 2));
|
3038 | w = jStat.zeros(m, 1);
|
3039 | w[i + 1][0] = (a[i + 1][i] - alpha) / (2 * r);
|
3040 | for (k = i + 2; k < m; k++)
|
3041 | w[k][0] = a[k][i] / (2 * r);
|
3042 | p = jStat.subtract(jStat.identity(m, n),
|
3043 | jStat.multiply(jStat.multiply(w, jStat.transpose(w)), 2));
|
3044 | a = jStat.multiply(p, a);
|
3045 | b = jStat.multiply(p, b);
|
3046 | }
|
3047 | for (i = m - 1; i >= 0; i--) {
|
3048 | sum = 0;
|
3049 | for (j = i + 1; j <= n - 1; j++)
|
3050 | sum = x[j] * a[i][j];
|
3051 | x[i] = b[i][0] / a[i][i];
|
3052 | }
|
3053 | return x;
|
3054 | },
|
3055 |
|
3056 | jacobi: function jacobi(a) {
|
3057 | var condition = 1;
|
3058 | var count = 0;
|
3059 | var n = a.length;
|
3060 | var e = jStat.identity(n, n);
|
3061 | var ev = [];
|
3062 | var b, i, j, p, q, maxim, theta, s;
|
3063 |
|
3064 | while (condition === 1) {
|
3065 | count++;
|
3066 | maxim = a[0][1];
|
3067 | p = 0;
|
3068 | q = 1;
|
3069 | for (i = 0; i < n; i++) {
|
3070 | for (j = 0; j < n; j++) {
|
3071 | if (i != j) {
|
3072 | if (maxim < Math.abs(a[i][j])) {
|
3073 | maxim = Math.abs(a[i][j]);
|
3074 | p = i;
|
3075 | q = j;
|
3076 | }
|
3077 | }
|
3078 | }
|
3079 | }
|
3080 | if (a[p][p] === a[q][q])
|
3081 | theta = (a[p][q] > 0) ? Math.PI / 4 : -Math.PI / 4;
|
3082 | else
|
3083 | theta = Math.atan(2 * a[p][q] / (a[p][p] - a[q][q])) / 2;
|
3084 | s = jStat.identity(n, n);
|
3085 | s[p][p] = Math.cos(theta);
|
3086 | s[p][q] = -Math.sin(theta);
|
3087 | s[q][p] = Math.sin(theta);
|
3088 | s[q][q] = Math.cos(theta);
|
3089 |
|
3090 | e = jStat.multiply(e, s);
|
3091 | b = jStat.multiply(jStat.multiply(jStat.inv(s), a), s);
|
3092 | a = b;
|
3093 | condition = 0;
|
3094 | for (i = 1; i < n; i++) {
|
3095 | for (j = 1; j < n; j++) {
|
3096 | if (i != j && Math.abs(a[i][j]) > 0.001) {
|
3097 | condition = 1;
|
3098 | }
|
3099 | }
|
3100 | }
|
3101 | }
|
3102 | for (i = 0; i < n; i++) ev.push(a[i][i]);
|
3103 |
|
3104 | return [e, ev];
|
3105 | },
|
3106 |
|
3107 | rungekutta: function rungekutta(f, h, p, t_j, u_j, order) {
|
3108 | var k1, k2, u_j1, k3, k4;
|
3109 | if (order === 2) {
|
3110 | while (t_j <= p) {
|
3111 | k1 = h * f(t_j, u_j);
|
3112 | k2 = h * f(t_j + h, u_j + k1);
|
3113 | u_j1 = u_j + (k1 + k2) / 2;
|
3114 | u_j = u_j1;
|
3115 | t_j = t_j + h;
|
3116 | }
|
3117 | }
|
3118 | if (order === 4) {
|
3119 | while (t_j <= p) {
|
3120 | k1 = h * f(t_j, u_j);
|
3121 | k2 = h * f(t_j + h / 2, u_j + k1 / 2);
|
3122 | k3 = h * f(t_j + h / 2, u_j + k2 / 2);
|
3123 | k4 = h * f(t_j +h, u_j + k3);
|
3124 | u_j1 = u_j + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
|
3125 | u_j = u_j1;
|
3126 | t_j = t_j + h;
|
3127 | }
|
3128 | }
|
3129 | return u_j;
|
3130 | },
|
3131 |
|
3132 | romberg: function romberg(f, a, b, order) {
|
3133 | var i = 0;
|
3134 | var h = (b - a) / 2;
|
3135 | var x = [];
|
3136 | var h1 = [];
|
3137 | var g = [];
|
3138 | var m, a1, j, k, I, d;
|
3139 | while (i < order / 2) {
|
3140 | I = f(a);
|
3141 | for (j = a, k = 0; j <= b; j = j + h, k++) x[k] = j;
|
3142 | m = x.length;
|
3143 | for (j = 1; j < m - 1; j++) {
|
3144 | I += (((j % 2) !== 0) ? 4 : 2) * f(x[j]);
|
3145 | }
|
3146 | I = (h / 3) * (I + f(b));
|
3147 | g[i] = I;
|
3148 | h /= 2;
|
3149 | i++;
|
3150 | }
|
3151 | a1 = g.length;
|
3152 | m = 1;
|
3153 | while (a1 !== 1) {
|
3154 | for (j = 0; j < a1 - 1; j++)
|
3155 | h1[j] = ((Math.pow(4, m)) * g[j + 1] - g[j]) / (Math.pow(4, m) - 1);
|
3156 | a1 = h1.length;
|
3157 | g = h1;
|
3158 | h1 = [];
|
3159 | m++;
|
3160 | }
|
3161 | return g;
|
3162 | },
|
3163 |
|
3164 | richardson: function richardson(X, f, x, h) {
|
3165 | function pos(X, x) {
|
3166 | var i = 0;
|
3167 | var n = X.length;
|
3168 | var p;
|
3169 | for (; i < n; i++)
|
3170 | if (X[i] === x) p = i;
|
3171 | return p;
|
3172 | }
|
3173 | var n = X.length,
|
3174 | h_min = Math.abs(x - X[pos(X, x) + 1]),
|
3175 | i = 0,
|
3176 | g = [],
|
3177 | h1 = [],
|
3178 | y1, y2, m, a, j;
|
3179 | while (h >= h_min) {
|
3180 | y1 = pos(X, x + h);
|
3181 | y2 = pos(X, x);
|
3182 | g[i] = (f[y1] - 2 * f[y2] + f[2 * y2 - y1]) / (h * h);
|
3183 | h /= 2;
|
3184 | i++;
|
3185 | }
|
3186 | a = g.length;
|
3187 | m = 1;
|
3188 | while (a != 1) {
|
3189 | for (j = 0; j < a - 1; j++)
|
3190 | h1[j] = ((Math.pow(4, m)) * g[j + 1] - g[j]) / (Math.pow(4, m) - 1);
|
3191 | a = h1.length;
|
3192 | g = h1;
|
3193 | h1 = [];
|
3194 | m++;
|
3195 | }
|
3196 | return g;
|
3197 | },
|
3198 |
|
3199 | simpson: function simpson(f, a, b, n) {
|
3200 | var h = (b - a) / n;
|
3201 | var I = f(a);
|
3202 | var x = [];
|
3203 | var j = a;
|
3204 | var k = 0;
|
3205 | var i = 1;
|
3206 | var m;
|
3207 | for (; j <= b; j = j + h, k++)
|
3208 | x[k] = j;
|
3209 | m = x.length;
|
3210 | for (; i < m - 1; i++) {
|
3211 | I += ((i % 2 !== 0) ? 4 : 2) * f(x[i]);
|
3212 | }
|
3213 | return (h / 3) * (I + f(b));
|
3214 | },
|
3215 |
|
3216 | hermite: function hermite(X, F, dF, value) {
|
3217 | var n = X.length;
|
3218 | var p = 0;
|
3219 | var i = 0;
|
3220 | var l = [];
|
3221 | var dl = [];
|
3222 | var A = [];
|
3223 | var B = [];
|
3224 | var j;
|
3225 | for (; i < n; i++) {
|
3226 | l[i] = 1;
|
3227 | for (j = 0; j < n; j++) {
|
3228 | if (i != j) l[i] *= (value - X[j]) / (X[i] - X[j]);
|
3229 | }
|
3230 | dl[i] = 0;
|
3231 | for (j = 0; j < n; j++) {
|
3232 | if (i != j) dl[i] += 1 / (X [i] - X[j]);
|
3233 | }
|
3234 | A[i] = (1 - 2 * (value - X[i]) * dl[i]) * (l[i] * l[i]);
|
3235 | B[i] = (value - X[i]) * (l[i] * l[i]);
|
3236 | p += (A[i] * F[i] + B[i] * dF[i]);
|
3237 | }
|
3238 | return p;
|
3239 | },
|
3240 |
|
3241 | lagrange: function lagrange(X, F, value) {
|
3242 | var p = 0;
|
3243 | var i = 0;
|
3244 | var j, l;
|
3245 | var n = X.length;
|
3246 | for (; i < n; i++) {
|
3247 | l = F[i];
|
3248 | for (j = 0; j < n; j++) {
|
3249 |
|
3250 | if (i != j) l *= (value - X[j]) / (X[i] - X[j]);
|
3251 | }
|
3252 |
|
3253 | p += l;
|
3254 | }
|
3255 | return p;
|
3256 | },
|
3257 |
|
3258 | cubic_spline: function cubic_spline(X, F, value) {
|
3259 | var n = X.length;
|
3260 | var i = 0, j;
|
3261 | var A = [];
|
3262 | var B = [];
|
3263 | var alpha = [];
|
3264 | var c = [];
|
3265 | var h = [];
|
3266 | var b = [];
|
3267 | var d = [];
|
3268 | for (; i < n - 1; i++)
|
3269 | h[i] = X[i + 1] - X[i];
|
3270 | alpha[0] = 0;
|
3271 | for (i = 1; i < n - 1; i++) {
|
3272 | alpha[i] = (3 / h[i]) * (F[i + 1] - F[i]) -
|
3273 | (3 / h[i-1]) * (F[i] - F[i-1]);
|
3274 | }
|
3275 | for (i = 1; i < n - 1; i++) {
|
3276 | A[i] = [];
|
3277 | B[i] = [];
|
3278 | A[i][i-1] = h[i-1];
|
3279 | A[i][i] = 2 * (h[i - 1] + h[i]);
|
3280 | A[i][i+1] = h[i];
|
3281 | B[i][0] = alpha[i];
|
3282 | }
|
3283 | c = jStat.multiply(jStat.inv(A), B);
|
3284 | for (j = 0; j < n - 1; j++) {
|
3285 | b[j] = (F[j + 1] - F[j]) / h[j] - h[j] * (c[j + 1][0] + 2 * c[j][0]) / 3;
|
3286 | d[j] = (c[j + 1][0] - c[j][0]) / (3 * h[j]);
|
3287 | }
|
3288 | for (j = 0; j < n; j++) {
|
3289 | if (X[j] > value) break;
|
3290 | }
|
3291 | j -= 1;
|
3292 | return F[j] + (value - X[j]) * b[j] + jStat.sq(value-X[j]) *
|
3293 | c[j] + (value - X[j]) * jStat.sq(value - X[j]) * d[j];
|
3294 | },
|
3295 |
|
3296 | gauss_quadrature: function gauss_quadrature() {
|
3297 | throw new Error('gauss_quadrature not yet implemented');
|
3298 | },
|
3299 |
|
3300 | PCA: function PCA(X) {
|
3301 | var m = X.length;
|
3302 | var n = X[0].length;
|
3303 | var flag = false;
|
3304 | var i = 0;
|
3305 | var j, temp1;
|
3306 | var u = [];
|
3307 | var D = [];
|
3308 | var result = [];
|
3309 | var temp2 = [];
|
3310 | var Y = [];
|
3311 | var Bt = [];
|
3312 | var B = [];
|
3313 | var C = [];
|
3314 | var V = [];
|
3315 | var Vt = [];
|
3316 | for (i = 0; i < m; i++) {
|
3317 | u[i] = jStat.sum(X[i]) / n;
|
3318 | }
|
3319 | for (i = 0; i < n; i++) {
|
3320 | B[i] = [];
|
3321 | for(j = 0; j < m; j++) {
|
3322 | B[i][j] = X[j][i] - u[j];
|
3323 | }
|
3324 | }
|
3325 | B = jStat.transpose(B);
|
3326 | for (i = 0; i < m; i++) {
|
3327 | C[i] = [];
|
3328 | for (j = 0; j < m; j++) {
|
3329 | C[i][j] = (jStat.dot([B[i]], [B[j]])) / (n - 1);
|
3330 | }
|
3331 | }
|
3332 | result = jStat.jacobi(C);
|
3333 | V = result[0];
|
3334 | D = result[1];
|
3335 | Vt = jStat.transpose(V);
|
3336 | for (i = 0; i < D.length; i++) {
|
3337 | for (j = i; j < D.length; j++) {
|
3338 | if(D[i] < D[j]) {
|
3339 | temp1 = D[i];
|
3340 | D[i] = D[j];
|
3341 | D[j] = temp1;
|
3342 | temp2 = Vt[i];
|
3343 | Vt[i] = Vt[j];
|
3344 | Vt[j] = temp2;
|
3345 | }
|
3346 | }
|
3347 | }
|
3348 | Bt = jStat.transpose(B);
|
3349 | for (i = 0; i < m; i++) {
|
3350 | Y[i] = [];
|
3351 | for (j = 0; j < Bt.length; j++) {
|
3352 | Y[i][j] = jStat.dot([Vt[i]], [Bt[j]]);
|
3353 | }
|
3354 | }
|
3355 | return [X, D, Vt, Y];
|
3356 | }
|
3357 | });
|
3358 |
|
3359 |
|
3360 | (function(funcs) {
|
3361 | for (var i = 0; i < funcs.length; i++) (function(passfunc) {
|
3362 | jStat.fn[passfunc] = function(arg, func) {
|
3363 | var tmpthis = this;
|
3364 |
|
3365 | if (func) {
|
3366 | setTimeout(function() {
|
3367 | func.call(tmpthis, jStat.fn[passfunc].call(tmpthis, arg));
|
3368 | }, 15);
|
3369 | return this;
|
3370 | }
|
3371 | if (typeof jStat[passfunc](this, arg) === 'number')
|
3372 | return jStat[passfunc](this, arg);
|
3373 | else
|
3374 | return jStat(jStat[passfunc](this, arg));
|
3375 | };
|
3376 | }(funcs[i]));
|
3377 | }('add divide multiply subtract dot pow exp log abs norm angle'.split(' ')));
|
3378 |
|
3379 | }(this.jStat, Math));
|
3380 | (function(jStat, Math) {
|
3381 |
|
3382 | var slice = [].slice;
|
3383 | var isNumber = jStat.utils.isNumber;
|
3384 | var isArray = jStat.utils.isArray;
|
3385 |
|
3386 |
|
3387 |
|
3388 | jStat.extend({
|
3389 |
|
3390 |
|
3391 |
|
3392 | zscore: function zscore() {
|
3393 | var args = slice.call(arguments);
|
3394 | if (isNumber(args[1])) {
|
3395 | return (args[0] - args[1]) / args[2];
|
3396 | }
|
3397 | return (args[0] - jStat.mean(args[1])) / jStat.stdev(args[1], args[2]);
|
3398 | },
|
3399 |
|
3400 |
|
3401 |
|
3402 |
|
3403 |
|
3404 | ztest: function ztest() {
|
3405 | var args = slice.call(arguments);
|
3406 | var z;
|
3407 | if (isArray(args[1])) {
|
3408 |
|
3409 | z = jStat.zscore(args[0],args[1],args[3]);
|
3410 | return (args[2] === 1) ?
|
3411 | (jStat.normal.cdf(-Math.abs(z), 0, 1)) :
|
3412 | (jStat.normal.cdf(-Math.abs(z), 0, 1)*2);
|
3413 | } else {
|
3414 | if (args.length > 2) {
|
3415 |
|
3416 | z = jStat.zscore(args[0],args[1],args[2]);
|
3417 | return (args[3] === 1) ?
|
3418 | (jStat.normal.cdf(-Math.abs(z),0,1)) :
|
3419 | (jStat.normal.cdf(-Math.abs(z),0,1)* 2);
|
3420 | } else {
|
3421 |
|
3422 | z = args[0];
|
3423 | return (args[1] === 1) ?
|
3424 | (jStat.normal.cdf(-Math.abs(z),0,1)) :
|
3425 | (jStat.normal.cdf(-Math.abs(z),0,1)*2);
|
3426 | }
|
3427 | }
|
3428 | }
|
3429 | });
|
3430 |
|
3431 | jStat.extend(jStat.fn, {
|
3432 | zscore: function zscore(value, flag) {
|
3433 | return (value - this.mean()) / this.stdev(flag);
|
3434 | },
|
3435 |
|
3436 | ztest: function ztest(value, sides, flag) {
|
3437 | var zscore = Math.abs(this.zscore(value, flag));
|
3438 | return (sides === 1) ?
|
3439 | (jStat.normal.cdf(-zscore, 0, 1)) :
|
3440 | (jStat.normal.cdf(-zscore, 0, 1) * 2);
|
3441 | }
|
3442 | });
|
3443 |
|
3444 |
|
3445 | jStat.extend({
|
3446 |
|
3447 |
|
3448 |
|
3449 | tscore: function tscore() {
|
3450 | var args = slice.call(arguments);
|
3451 | return (args.length === 4) ?
|
3452 | ((args[0] - args[1]) / (args[2] / Math.sqrt(args[3]))) :
|
3453 | ((args[0] - jStat.mean(args[1])) /
|
3454 | (jStat.stdev(args[1], true) / Math.sqrt(args[1].length)));
|
3455 | },
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 | ttest: function ttest() {
|
3462 | var args = slice.call(arguments);
|
3463 | var tscore;
|
3464 | if (args.length === 5) {
|
3465 | tscore = Math.abs(jStat.tscore(args[0], args[1], args[2], args[3]));
|
3466 | return (args[4] === 1) ?
|
3467 | (jStat.studentt.cdf(-tscore, args[3]-1)) :
|
3468 | (jStat.studentt.cdf(-tscore, args[3]-1)*2);
|
3469 | }
|
3470 | if (isNumber(args[1])) {
|
3471 | tscore = Math.abs(args[0])
|
3472 | return (args[2] == 1) ?
|
3473 | (jStat.studentt.cdf(-tscore, args[1]-1)) :
|
3474 | (jStat.studentt.cdf(-tscore, args[1]-1) * 2);
|
3475 | }
|
3476 | tscore = Math.abs(jStat.tscore(args[0], args[1]))
|
3477 | return (args[2] == 1) ?
|
3478 | (jStat.studentt.cdf(-tscore, args[1].length-1)) :
|
3479 | (jStat.studentt.cdf(-tscore, args[1].length-1) * 2);
|
3480 | }
|
3481 | });
|
3482 |
|
3483 | jStat.extend(jStat.fn, {
|
3484 | tscore: function tscore(value) {
|
3485 | return (value - this.mean()) / (this.stdev(true) / Math.sqrt(this.cols()));
|
3486 | },
|
3487 |
|
3488 | ttest: function ttest(value, sides) {
|
3489 | return (sides === 1) ?
|
3490 | (1 - jStat.studentt.cdf(Math.abs(this.tscore(value)), this.cols()-1)) :
|
3491 | (jStat.studentt.cdf(-Math.abs(this.tscore(value)), this.cols()-1)*2);
|
3492 | }
|
3493 | });
|
3494 |
|
3495 |
|
3496 | jStat.extend({
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 | anovafscore: function anovafscore() {
|
3502 | var args = slice.call(arguments),
|
3503 | expVar, sample, sampMean, sampSampMean, tmpargs, unexpVar, i, j;
|
3504 | if (args.length === 1) {
|
3505 | tmpargs = new Array(args[0].length);
|
3506 | for (i = 0; i < args[0].length; i++) {
|
3507 | tmpargs[i] = args[0][i];
|
3508 | }
|
3509 | args = tmpargs;
|
3510 | }
|
3511 |
|
3512 | if (args.length === 2) {
|
3513 | return jStat.variance(args[0]) / jStat.variance(args[1]);
|
3514 | }
|
3515 |
|
3516 | sample = new Array();
|
3517 | for (i = 0; i < args.length; i++) {
|
3518 | sample = sample.concat(args[i]);
|
3519 | }
|
3520 | sampMean = jStat.mean(sample);
|
3521 |
|
3522 | expVar = 0;
|
3523 | for (i = 0; i < args.length; i++) {
|
3524 | expVar = expVar + args[i].length * Math.pow(jStat.mean(args[i]) - sampMean, 2);
|
3525 | }
|
3526 | expVar /= (args.length - 1);
|
3527 |
|
3528 | unexpVar = 0;
|
3529 | for (i = 0; i < args.length; i++) {
|
3530 | sampSampMean = jStat.mean(args[i]);
|
3531 | for (j = 0; j < args[i].length; j++) {
|
3532 | unexpVar += Math.pow(args[i][j] - sampSampMean, 2);
|
3533 | }
|
3534 | }
|
3535 | unexpVar /= (sample.length - args.length);
|
3536 | return expVar / unexpVar;
|
3537 | },
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 | anovaftest: function anovaftest() {
|
3543 | var args = slice.call(arguments),
|
3544 | df1, df2, n, i;
|
3545 | if (isNumber(args[0])) {
|
3546 | return 1 - jStat.centralF.cdf(args[0], args[1], args[2]);
|
3547 | }
|
3548 | anovafscore = jStat.anovafscore(args);
|
3549 | df1 = args.length - 1;
|
3550 | n = 0;
|
3551 | for (i = 0; i < args.length; i++) {
|
3552 | n = n + args[i].length;
|
3553 | }
|
3554 | df2 = n - df1 - 1;
|
3555 | return 1 - jStat.centralF.cdf(anovafscore, df1, df2);
|
3556 | },
|
3557 |
|
3558 | ftest: function ftest(fscore, df1, df2) {
|
3559 | return 1 - jStat.centralF.cdf(fscore, df1, df2);
|
3560 | }
|
3561 | });
|
3562 |
|
3563 | jStat.extend(jStat.fn, {
|
3564 | anovafscore: function anovafscore() {
|
3565 | return jStat.anovafscore(this.toArray());
|
3566 | },
|
3567 |
|
3568 | anovaftes: function anovaftes() {
|
3569 | var n = 0;
|
3570 | var i;
|
3571 | for (i = 0; i < this.length; i++) {
|
3572 | n = n + this[i].length;
|
3573 | }
|
3574 | return jStat.ftest(this.anovafscore(), this.length - 1, n - this.length);
|
3575 | }
|
3576 | });
|
3577 |
|
3578 |
|
3579 | jStat.extend({
|
3580 |
|
3581 |
|
3582 |
|
3583 | normalci: function normalci() {
|
3584 | var args = slice.call(arguments),
|
3585 | ans = new Array(2),
|
3586 | change;
|
3587 | if (args.length === 4) {
|
3588 | change = Math.abs(jStat.normal.inv(args[1] / 2, 0, 1) *
|
3589 | args[2] / Math.sqrt(args[3]));
|
3590 | } else {
|
3591 | change = Math.abs(jStat.normal.inv(args[1] / 2, 0, 1) *
|
3592 | jStat.stdev(args[2]) / Math.sqrt(args[2].length));
|
3593 | }
|
3594 | ans[0] = args[0] - change;
|
3595 | ans[1] = args[0] + change;
|
3596 | return ans;
|
3597 | },
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 | tci: function tci() {
|
3603 | var args = slice.call(arguments),
|
3604 | ans = new Array(2),
|
3605 | change;
|
3606 | if (args.length === 4) {
|
3607 | change = Math.abs(jStat.studentt.inv(args[1] / 2, args[3] - 1) *
|
3608 | args[2] / Math.sqrt(args[3]));
|
3609 | } else {
|
3610 | change = Math.abs(jStat.studentt.inv(args[1] / 2, args[2].length - 1) *
|
3611 | jStat.stdev(args[2], true) / Math.sqrt(args[2].length));
|
3612 | }
|
3613 | ans[0] = args[0] - change;
|
3614 | ans[1] = args[0] + change;
|
3615 | return ans;
|
3616 | },
|
3617 |
|
3618 | significant: function significant(pvalue, alpha) {
|
3619 | return pvalue < alpha;
|
3620 | }
|
3621 | });
|
3622 |
|
3623 | jStat.extend(jStat.fn, {
|
3624 | normalci: function normalci(value, alpha) {
|
3625 | return jStat.normalci(value, alpha, this.toArray());
|
3626 | },
|
3627 |
|
3628 | tci: function tci(value, alpha) {
|
3629 | return jStat.tci(value, alpha, this.toArray());
|
3630 | }
|
3631 | });
|
3632 |
|
3633 |
|
3634 | function differenceOfProportions(p1, n1, p2, n2) {
|
3635 | if (p1 > 1 || p2 > 1 || p1 <= 0 || p2 <= 0) {
|
3636 | throw new Error("Proportions should be greater than 0 and less than 1")
|
3637 | }
|
3638 | var pooled = (p1 * n1 + p2 * n2) / (n1 + n2);
|
3639 | var se = Math.sqrt(pooled * (1 - pooled) * ((1/n1) + (1/n2)));
|
3640 | return (p1 - p2) / se;
|
3641 | }
|
3642 |
|
3643 |
|
3644 | jStat.extend(jStat.fn, {
|
3645 | oneSidedDifferenceOfProportions: function oneSidedDifferenceOfProportions(p1, n1, p2, n2) {
|
3646 | var z = differenceOfProportions(p1, n1, p2, n2);
|
3647 | return jStat.ztest(z, 1);
|
3648 | },
|
3649 |
|
3650 | twoSidedDifferenceOfProportions: function twoSidedDifferenceOfProportions(p1, n1, p2, n2) {
|
3651 | var z = differenceOfProportions(p1, n1, p2, n2);
|
3652 | return jStat.ztest(z, 2);
|
3653 | }
|
3654 | });
|
3655 |
|
3656 | }(this.jStat, Math));
|
3657 |
|
3658 | },{}],2:[function(require,module,exports){
|
3659 | (function (global){
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 | ;(function() {
|
3670 |
|
3671 |
|
3672 | var undefined;
|
3673 |
|
3674 |
|
3675 | var VERSION = '4.6.1';
|
3676 |
|
3677 |
|
3678 | var LARGE_ARRAY_SIZE = 200;
|
3679 |
|
3680 |
|
3681 | var FUNC_ERROR_TEXT = 'Expected a function';
|
3682 |
|
3683 |
|
3684 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
3685 |
|
3686 |
|
3687 | var PLACEHOLDER = '__lodash_placeholder__';
|
3688 |
|
3689 |
|
3690 | var BIND_FLAG = 1,
|
3691 | BIND_KEY_FLAG = 2,
|
3692 | CURRY_BOUND_FLAG = 4,
|
3693 | CURRY_FLAG = 8,
|
3694 | CURRY_RIGHT_FLAG = 16,
|
3695 | PARTIAL_FLAG = 32,
|
3696 | PARTIAL_RIGHT_FLAG = 64,
|
3697 | ARY_FLAG = 128,
|
3698 | REARG_FLAG = 256,
|
3699 | FLIP_FLAG = 512;
|
3700 |
|
3701 |
|
3702 | var UNORDERED_COMPARE_FLAG = 1,
|
3703 | PARTIAL_COMPARE_FLAG = 2;
|
3704 |
|
3705 |
|
3706 | var DEFAULT_TRUNC_LENGTH = 30,
|
3707 | DEFAULT_TRUNC_OMISSION = '...';
|
3708 |
|
3709 |
|
3710 | var HOT_COUNT = 150,
|
3711 | HOT_SPAN = 16;
|
3712 |
|
3713 |
|
3714 | var LAZY_FILTER_FLAG = 1,
|
3715 | LAZY_MAP_FLAG = 2,
|
3716 | LAZY_WHILE_FLAG = 3;
|
3717 |
|
3718 |
|
3719 | var INFINITY = 1 / 0,
|
3720 | MAX_SAFE_INTEGER = 9007199254740991,
|
3721 | MAX_INTEGER = 1.7976931348623157e+308,
|
3722 | NAN = 0 / 0;
|
3723 |
|
3724 |
|
3725 | var MAX_ARRAY_LENGTH = 4294967295,
|
3726 | MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
3727 | HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
3728 |
|
3729 |
|
3730 | var argsTag = '[object Arguments]',
|
3731 | arrayTag = '[object Array]',
|
3732 | boolTag = '[object Boolean]',
|
3733 | dateTag = '[object Date]',
|
3734 | errorTag = '[object Error]',
|
3735 | funcTag = '[object Function]',
|
3736 | genTag = '[object GeneratorFunction]',
|
3737 | mapTag = '[object Map]',
|
3738 | numberTag = '[object Number]',
|
3739 | objectTag = '[object Object]',
|
3740 | regexpTag = '[object RegExp]',
|
3741 | setTag = '[object Set]',
|
3742 | stringTag = '[object String]',
|
3743 | symbolTag = '[object Symbol]',
|
3744 | weakMapTag = '[object WeakMap]',
|
3745 | weakSetTag = '[object WeakSet]';
|
3746 |
|
3747 | var arrayBufferTag = '[object ArrayBuffer]',
|
3748 | float32Tag = '[object Float32Array]',
|
3749 | float64Tag = '[object Float64Array]',
|
3750 | int8Tag = '[object Int8Array]',
|
3751 | int16Tag = '[object Int16Array]',
|
3752 | int32Tag = '[object Int32Array]',
|
3753 | uint8Tag = '[object Uint8Array]',
|
3754 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
3755 | uint16Tag = '[object Uint16Array]',
|
3756 | uint32Tag = '[object Uint32Array]';
|
3757 |
|
3758 |
|
3759 | var reEmptyStringLeading = /\b__p \+= '';/g,
|
3760 | reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
3761 | reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
3762 |
|
3763 |
|
3764 | var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
|
3765 | reUnescapedHtml = /[&<>"'`]/g,
|
3766 | reHasEscapedHtml = RegExp(reEscapedHtml.source),
|
3767 | reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
3768 |
|
3769 |
|
3770 | var reEscape = /<%-([\s\S]+?)%>/g,
|
3771 | reEvaluate = /<%([\s\S]+?)%>/g,
|
3772 | reInterpolate = /<%=([\s\S]+?)%>/g;
|
3773 |
|
3774 |
|
3775 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
3776 | reIsPlainProp = /^\w*$/,
|
3777 | rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g;
|
3778 |
|
3779 |
|
3780 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
|
3781 | reHasRegExpChar = RegExp(reRegExpChar.source);
|
3782 |
|
3783 |
|
3784 | var reTrim = /^\s+|\s+$/g,
|
3785 | reTrimStart = /^\s+/,
|
3786 | reTrimEnd = /\s+$/;
|
3787 |
|
3788 |
|
3789 | var reEscapeChar = /\\(\\)?/g;
|
3790 |
|
3791 |
|
3792 | var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
|
3793 |
|
3794 |
|
3795 | var reFlags = /\w*$/;
|
3796 |
|
3797 |
|
3798 | var reHasHexPrefix = /^0x/i;
|
3799 |
|
3800 |
|
3801 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
3802 |
|
3803 |
|
3804 | var reIsBinary = /^0b[01]+$/i;
|
3805 |
|
3806 |
|
3807 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
3808 |
|
3809 |
|
3810 | var reIsOctal = /^0o[0-7]+$/i;
|
3811 |
|
3812 |
|
3813 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
3814 |
|
3815 |
|
3816 | var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
|
3817 |
|
3818 |
|
3819 | var reNoMatch = /($^)/;
|
3820 |
|
3821 |
|
3822 | var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
3823 |
|
3824 |
|
3825 | var rsAstralRange = '\\ud800-\\udfff',
|
3826 | rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
3827 | rsComboSymbolsRange = '\\u20d0-\\u20f0',
|
3828 | rsDingbatRange = '\\u2700-\\u27bf',
|
3829 | rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
|
3830 | rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
|
3831 | rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
|
3832 | rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
|
3833 | rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
|
3834 | rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
|
3835 | rsVarRange = '\\ufe0e\\ufe0f',
|
3836 | rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange;
|
3837 |
|
3838 |
|
3839 | var rsAstral = '[' + rsAstralRange + ']',
|
3840 | rsBreak = '[' + rsBreakRange + ']',
|
3841 | rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
|
3842 | rsDigits = '\\d+',
|
3843 | rsDingbat = '[' + rsDingbatRange + ']',
|
3844 | rsLower = '[' + rsLowerRange + ']',
|
3845 | rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
|
3846 | rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
3847 | rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
|
3848 | rsNonAstral = '[^' + rsAstralRange + ']',
|
3849 | rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
3850 | rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
3851 | rsUpper = '[' + rsUpperRange + ']',
|
3852 | rsZWJ = '\\u200d';
|
3853 |
|
3854 |
|
3855 | var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
|
3856 | rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
|
3857 | reOptMod = rsModifier + '?',
|
3858 | rsOptVar = '[' + rsVarRange + ']?',
|
3859 | rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
|
3860 | rsSeq = rsOptVar + reOptMod + rsOptJoin,
|
3861 | rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
|
3862 | rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
|
3863 |
|
3864 | |
3865 |
|
3866 |
|
3867 |
|
3868 | var reComboMark = RegExp(rsCombo, 'g');
|
3869 |
|
3870 |
|
3871 | var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
|
3872 |
|
3873 |
|
3874 | var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
|
3875 |
|
3876 |
|
3877 | var reBasicWord = /[a-zA-Z0-9]+/g;
|
3878 |
|
3879 |
|
3880 | var reComplexWord = RegExp([
|
3881 | rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
|
3882 | rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
|
3883 | rsUpper + '?' + rsLowerMisc + '+',
|
3884 | rsUpper + '+',
|
3885 | rsDigits,
|
3886 | rsEmoji
|
3887 | ].join('|'), 'g');
|
3888 |
|
3889 |
|
3890 | var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
3891 |
|
3892 |
|
3893 | var contextProps = [
|
3894 | 'Array', 'Buffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
|
3895 | 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
|
3896 | 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
|
3897 | 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
|
3898 | 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
|
3899 | ];
|
3900 |
|
3901 |
|
3902 | var templateCounter = -1;
|
3903 |
|
3904 |
|
3905 | var typedArrayTags = {};
|
3906 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
3907 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
3908 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
3909 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
3910 | typedArrayTags[uint32Tag] = true;
|
3911 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
3912 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
3913 | typedArrayTags[dateTag] = typedArrayTags[errorTag] =
|
3914 | typedArrayTags[funcTag] = typedArrayTags[mapTag] =
|
3915 | typedArrayTags[numberTag] = typedArrayTags[objectTag] =
|
3916 | typedArrayTags[regexpTag] = typedArrayTags[setTag] =
|
3917 | typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
3918 |
|
3919 |
|
3920 | var cloneableTags = {};
|
3921 | cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
3922 | cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
|
3923 | cloneableTags[dateTag] = cloneableTags[float32Tag] =
|
3924 | cloneableTags[float64Tag] = cloneableTags[int8Tag] =
|
3925 | cloneableTags[int16Tag] = cloneableTags[int32Tag] =
|
3926 | cloneableTags[mapTag] = cloneableTags[numberTag] =
|
3927 | cloneableTags[objectTag] = cloneableTags[regexpTag] =
|
3928 | cloneableTags[setTag] = cloneableTags[stringTag] =
|
3929 | cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
|
3930 | cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
|
3931 | cloneableTags[uint32Tag] = true;
|
3932 | cloneableTags[errorTag] = cloneableTags[funcTag] =
|
3933 | cloneableTags[weakMapTag] = false;
|
3934 |
|
3935 |
|
3936 | var deburredLetters = {
|
3937 | '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
|
3938 | '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
|
3939 | '\xc7': 'C', '\xe7': 'c',
|
3940 | '\xd0': 'D', '\xf0': 'd',
|
3941 | '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
|
3942 | '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
|
3943 | '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
|
3944 | '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
|
3945 | '\xd1': 'N', '\xf1': 'n',
|
3946 | '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
|
3947 | '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
|
3948 | '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
|
3949 | '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
|
3950 | '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
|
3951 | '\xc6': 'Ae', '\xe6': 'ae',
|
3952 | '\xde': 'Th', '\xfe': 'th',
|
3953 | '\xdf': 'ss'
|
3954 | };
|
3955 |
|
3956 |
|
3957 | var htmlEscapes = {
|
3958 | '&': '&',
|
3959 | '<': '<',
|
3960 | '>': '>',
|
3961 | '"': '"',
|
3962 | "'": ''',
|
3963 | '`': '`'
|
3964 | };
|
3965 |
|
3966 |
|
3967 | var htmlUnescapes = {
|
3968 | '&': '&',
|
3969 | '<': '<',
|
3970 | '>': '>',
|
3971 | '"': '"',
|
3972 | ''': "'",
|
3973 | '`': '`'
|
3974 | };
|
3975 |
|
3976 |
|
3977 | var objectTypes = {
|
3978 | 'function': true,
|
3979 | 'object': true
|
3980 | };
|
3981 |
|
3982 |
|
3983 | var stringEscapes = {
|
3984 | '\\': '\\',
|
3985 | "'": "'",
|
3986 | '\n': 'n',
|
3987 | '\r': 'r',
|
3988 | '\u2028': 'u2028',
|
3989 | '\u2029': 'u2029'
|
3990 | };
|
3991 |
|
3992 |
|
3993 | var freeParseFloat = parseFloat,
|
3994 | freeParseInt = parseInt;
|
3995 |
|
3996 |
|
3997 | var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
|
3998 | ? exports
|
3999 | : undefined;
|
4000 |
|
4001 |
|
4002 | var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
|
4003 | ? module
|
4004 | : undefined;
|
4005 |
|
4006 |
|
4007 | var moduleExports = (freeModule && freeModule.exports === freeExports)
|
4008 | ? freeExports
|
4009 | : undefined;
|
4010 |
|
4011 |
|
4012 | var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
|
4013 |
|
4014 |
|
4015 | var freeSelf = checkGlobal(objectTypes[typeof self] && self);
|
4016 |
|
4017 |
|
4018 | var freeWindow = checkGlobal(objectTypes[typeof window] && window);
|
4019 |
|
4020 |
|
4021 | var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
|
4022 |
|
4023 | |
4024 |
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 | var root = freeGlobal ||
|
4030 | ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
|
4031 | freeSelf || thisGlobal || Function('return this')();
|
4032 |
|
4033 |
|
4034 |
|
4035 | |
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 | function addMapEntry(map, pair) {
|
4044 |
|
4045 | map.set(pair[0], pair[1]);
|
4046 | return map;
|
4047 | }
|
4048 |
|
4049 | |
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 |
|
4055 |
|
4056 |
|
4057 | function addSetEntry(set, value) {
|
4058 | set.add(value);
|
4059 | return set;
|
4060 | }
|
4061 |
|
4062 | /**
|
4063 | * A faster alternative to `Function#apply`, this function invokes `func`
|
4064 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
4065 | *
|
4066 | * @private
|
4067 | * @param {Function} func The function to invoke.
|
4068 | * @param {*} thisArg The `this` binding of `func`.
|
4069 | * @param {...*} args The arguments to invoke `func` with.
|
4070 | * @returns {*} Returns the result of `func`.
|
4071 | */
|
4072 | function apply(func, thisArg, args) {
|
4073 | var length = args.length;
|
4074 | switch (length) {
|
4075 | case 0: return func.call(thisArg);
|
4076 | case 1: return func.call(thisArg, args[0]);
|
4077 | case 2: return func.call(thisArg, args[0], args[1]);
|
4078 | case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
4079 | }
|
4080 | return func.apply(thisArg, args);
|
4081 | }
|
4082 |
|
4083 | |
4084 |
|
4085 |
|
4086 |
|
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 | function arrayAggregator(array, setter, iteratee, accumulator) {
|
4094 | var index = -1,
|
4095 | length = array.length;
|
4096 |
|
4097 | while (++index < length) {
|
4098 | var value = array[index];
|
4099 | setter(accumulator, value, iteratee(value), array);
|
4100 | }
|
4101 | return accumulator;
|
4102 | }
|
4103 |
|
4104 | |
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 | function arrayConcat(array, other) {
|
4113 | var index = -1,
|
4114 | length = array.length,
|
4115 | othIndex = -1,
|
4116 | othLength = other.length,
|
4117 | result = Array(length + othLength);
|
4118 |
|
4119 | while (++index < length) {
|
4120 | result[index] = array[index];
|
4121 | }
|
4122 | while (++othIndex < othLength) {
|
4123 | result[index++] = other[othIndex];
|
4124 | }
|
4125 | return result;
|
4126 | }
|
4127 |
|
4128 | |
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 | function arrayEach(array, iteratee) {
|
4138 | var index = -1,
|
4139 | length = array.length;
|
4140 |
|
4141 | while (++index < length) {
|
4142 | if (iteratee(array[index], index, array) === false) {
|
4143 | break;
|
4144 | }
|
4145 | }
|
4146 | return array;
|
4147 | }
|
4148 |
|
4149 | |
4150 |
|
4151 |
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 | function arrayEachRight(array, iteratee) {
|
4159 | var length = array.length;
|
4160 |
|
4161 | while (length--) {
|
4162 | if (iteratee(array[length], length, array) === false) {
|
4163 | break;
|
4164 | }
|
4165 | }
|
4166 | return array;
|
4167 | }
|
4168 |
|
4169 | |
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 | function arrayEvery(array, predicate) {
|
4179 | var index = -1,
|
4180 | length = array.length;
|
4181 |
|
4182 | while (++index < length) {
|
4183 | if (!predicate(array[index], index, array)) {
|
4184 | return false;
|
4185 | }
|
4186 | }
|
4187 | return true;
|
4188 | }
|
4189 |
|
4190 | |
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 | function arrayFilter(array, predicate) {
|
4200 | var index = -1,
|
4201 | length = array.length,
|
4202 | resIndex = 0,
|
4203 | result = [];
|
4204 |
|
4205 | while (++index < length) {
|
4206 | var value = array[index];
|
4207 | if (predicate(value, index, array)) {
|
4208 | result[resIndex++] = value;
|
4209 | }
|
4210 | }
|
4211 | return result;
|
4212 | }
|
4213 |
|
4214 | |
4215 |
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 |
|
4223 | function arrayIncludes(array, value) {
|
4224 | return !!array.length && baseIndexOf(array, value, 0) > -1;
|
4225 | }
|
4226 |
|
4227 | |
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 | function arrayIncludesWith(array, value, comparator) {
|
4237 | var index = -1,
|
4238 | length = array.length;
|
4239 |
|
4240 | while (++index < length) {
|
4241 | if (comparator(value, array[index])) {
|
4242 | return true;
|
4243 | }
|
4244 | }
|
4245 | return false;
|
4246 | }
|
4247 |
|
4248 | |
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 | function arrayMap(array, iteratee) {
|
4258 | var index = -1,
|
4259 | length = array.length,
|
4260 | result = Array(length);
|
4261 |
|
4262 | while (++index < length) {
|
4263 | result[index] = iteratee(array[index], index, array);
|
4264 | }
|
4265 | return result;
|
4266 | }
|
4267 |
|
4268 | |
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 | function arrayPush(array, values) {
|
4277 | var index = -1,
|
4278 | length = values.length,
|
4279 | offset = array.length;
|
4280 |
|
4281 | while (++index < length) {
|
4282 | array[offset + index] = values[index];
|
4283 | }
|
4284 | return array;
|
4285 | }
|
4286 |
|
4287 | |
4288 |
|
4289 |
|
4290 |
|
4291 |
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 |
|
4298 | function arrayReduce(array, iteratee, accumulator, initAccum) {
|
4299 | var index = -1,
|
4300 | length = array.length;
|
4301 |
|
4302 | if (initAccum && length) {
|
4303 | accumulator = array[++index];
|
4304 | }
|
4305 | while (++index < length) {
|
4306 | accumulator = iteratee(accumulator, array[index], index, array);
|
4307 | }
|
4308 | return accumulator;
|
4309 | }
|
4310 |
|
4311 | |
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 | function arrayReduceRight(array, iteratee, accumulator, initAccum) {
|
4323 | var length = array.length;
|
4324 | if (initAccum && length) {
|
4325 | accumulator = array[--length];
|
4326 | }
|
4327 | while (length--) {
|
4328 | accumulator = iteratee(accumulator, array[length], length, array);
|
4329 | }
|
4330 | return accumulator;
|
4331 | }
|
4332 |
|
4333 | |
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 | function arraySome(array, predicate) {
|
4343 | var index = -1,
|
4344 | length = array.length;
|
4345 |
|
4346 | while (++index < length) {
|
4347 | if (predicate(array[index], index, array)) {
|
4348 | return true;
|
4349 | }
|
4350 | }
|
4351 | return false;
|
4352 | }
|
4353 |
|
4354 | |
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 |
|
4364 | function baseExtremum(array, iteratee, comparator) {
|
4365 | var index = -1,
|
4366 | length = array.length;
|
4367 |
|
4368 | while (++index < length) {
|
4369 | var value = array[index],
|
4370 | current = iteratee(value);
|
4371 |
|
4372 | if (current != null && (computed === undefined
|
4373 | ? current === current
|
4374 | : comparator(current, computed)
|
4375 | )) {
|
4376 | var computed = current,
|
4377 | result = value;
|
4378 | }
|
4379 | }
|
4380 | return result;
|
4381 | }
|
4382 |
|
4383 | |
4384 |
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 | function baseFind(collection, predicate, eachFunc, retKey) {
|
4396 | var result;
|
4397 | eachFunc(collection, function(value, key, collection) {
|
4398 | if (predicate(value, key, collection)) {
|
4399 | result = retKey ? key : value;
|
4400 | return false;
|
4401 | }
|
4402 | });
|
4403 | return result;
|
4404 | }
|
4405 |
|
4406 | |
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 |
|
4416 | function baseFindIndex(array, predicate, fromRight) {
|
4417 | var length = array.length,
|
4418 | index = fromRight ? length : -1;
|
4419 |
|
4420 | while ((fromRight ? index-- : ++index < length)) {
|
4421 | if (predicate(array[index], index, array)) {
|
4422 | return index;
|
4423 | }
|
4424 | }
|
4425 | return -1;
|
4426 | }
|
4427 |
|
4428 | |
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 | function baseIndexOf(array, value, fromIndex) {
|
4438 | if (value !== value) {
|
4439 | return indexOfNaN(array, fromIndex);
|
4440 | }
|
4441 | var index = fromIndex - 1,
|
4442 | length = array.length;
|
4443 |
|
4444 | while (++index < length) {
|
4445 | if (array[index] === value) {
|
4446 | return index;
|
4447 | }
|
4448 | }
|
4449 | return -1;
|
4450 | }
|
4451 |
|
4452 | |
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 | function baseIndexOfWith(array, value, fromIndex, comparator) {
|
4463 | var index = fromIndex - 1,
|
4464 | length = array.length;
|
4465 |
|
4466 | while (++index < length) {
|
4467 | if (comparator(array[index], value)) {
|
4468 | return index;
|
4469 | }
|
4470 | }
|
4471 | return -1;
|
4472 | }
|
4473 |
|
4474 | |
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
|
4487 | eachFunc(collection, function(value, index, collection) {
|
4488 | accumulator = initAccum
|
4489 | ? (initAccum = false, value)
|
4490 | : iteratee(accumulator, value, index, collection);
|
4491 | });
|
4492 | return accumulator;
|
4493 | }
|
4494 |
|
4495 | |
4496 |
|
4497 |
|
4498 |
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 | function baseSortBy(array, comparer) {
|
4506 | var length = array.length;
|
4507 |
|
4508 | array.sort(comparer);
|
4509 | while (length--) {
|
4510 | array[length] = array[length].value;
|
4511 | }
|
4512 | return array;
|
4513 | }
|
4514 |
|
4515 | |
4516 |
|
4517 |
|
4518 |
|
4519 |
|
4520 |
|
4521 |
|
4522 |
|
4523 | function baseSum(array, iteratee) {
|
4524 | var result,
|
4525 | index = -1,
|
4526 | length = array.length;
|
4527 |
|
4528 | while (++index < length) {
|
4529 | var current = iteratee(array[index]);
|
4530 | if (current !== undefined) {
|
4531 | result = result === undefined ? current : (result + current);
|
4532 | }
|
4533 | }
|
4534 | return result;
|
4535 | }
|
4536 |
|
4537 | |
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 |
|
4544 |
|
4545 |
|
4546 | function baseTimes(n, iteratee) {
|
4547 | var index = -1,
|
4548 | result = Array(n);
|
4549 |
|
4550 | while (++index < n) {
|
4551 | result[index] = iteratee(index);
|
4552 | }
|
4553 | return result;
|
4554 | }
|
4555 |
|
4556 | |
4557 |
|
4558 |
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 | function baseToPairs(object, props) {
|
4566 | return arrayMap(props, function(key) {
|
4567 | return [key, object[key]];
|
4568 | });
|
4569 | }
|
4570 |
|
4571 | |
4572 |
|
4573 |
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 | function baseUnary(func) {
|
4579 | return function(value) {
|
4580 | return func(value);
|
4581 | };
|
4582 | }
|
4583 |
|
4584 | |
4585 |
|
4586 |
|
4587 |
|
4588 |
|
4589 |
|
4590 |
|
4591 |
|
4592 |
|
4593 |
|
4594 | function baseValues(object, props) {
|
4595 | return arrayMap(props, function(key) {
|
4596 | return object[key];
|
4597 | });
|
4598 | }
|
4599 |
|
4600 | |
4601 |
|
4602 |
|
4603 |
|
4604 |
|
4605 |
|
4606 |
|
4607 |
|
4608 |
|
4609 | function charsStartIndex(strSymbols, chrSymbols) {
|
4610 | var index = -1,
|
4611 | length = strSymbols.length;
|
4612 |
|
4613 | while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
4614 | return index;
|
4615 | }
|
4616 |
|
4617 | |
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 |
|
4626 | function charsEndIndex(strSymbols, chrSymbols) {
|
4627 | var index = strSymbols.length;
|
4628 |
|
4629 | while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
4630 | return index;
|
4631 | }
|
4632 |
|
4633 | |
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 |
|
4639 |
|
4640 | function checkGlobal(value) {
|
4641 | return (value && value.Object === Object) ? value : null;
|
4642 | }
|
4643 |
|
4644 | |
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 | function compareAscending(value, other) {
|
4653 | if (value !== other) {
|
4654 | var valIsNull = value === null,
|
4655 | valIsUndef = value === undefined,
|
4656 | valIsReflexive = value === value;
|
4657 |
|
4658 | var othIsNull = other === null,
|
4659 | othIsUndef = other === undefined,
|
4660 | othIsReflexive = other === other;
|
4661 |
|
4662 | if ((value > other && !othIsNull) || !valIsReflexive ||
|
4663 | (valIsNull && !othIsUndef && othIsReflexive) ||
|
4664 | (valIsUndef && othIsReflexive)) {
|
4665 | return 1;
|
4666 | }
|
4667 | if ((value < other && !valIsNull) || !othIsReflexive ||
|
4668 | (othIsNull && !valIsUndef && valIsReflexive) ||
|
4669 | (othIsUndef && valIsReflexive)) {
|
4670 | return -1;
|
4671 | }
|
4672 | }
|
4673 | return 0;
|
4674 | }
|
4675 |
|
4676 | |
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 | function compareMultiple(object, other, orders) {
|
4691 | var index = -1,
|
4692 | objCriteria = object.criteria,
|
4693 | othCriteria = other.criteria,
|
4694 | length = objCriteria.length,
|
4695 | ordersLength = orders.length;
|
4696 |
|
4697 | while (++index < length) {
|
4698 | var result = compareAscending(objCriteria[index], othCriteria[index]);
|
4699 | if (result) {
|
4700 | if (index >= ordersLength) {
|
4701 | return result;
|
4702 | }
|
4703 | var order = orders[index];
|
4704 | return result * (order == 'desc' ? -1 : 1);
|
4705 | }
|
4706 | }
|
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 | return object.index - other.index;
|
4715 | }
|
4716 |
|
4717 | |
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 | function countHolders(array, placeholder) {
|
4726 | var length = array.length,
|
4727 | result = 0;
|
4728 |
|
4729 | while (length--) {
|
4730 | if (array[length] === placeholder) {
|
4731 | result++;
|
4732 | }
|
4733 | }
|
4734 | return result;
|
4735 | }
|
4736 |
|
4737 | |
4738 |
|
4739 |
|
4740 |
|
4741 |
|
4742 |
|
4743 |
|
4744 | function deburrLetter(letter) {
|
4745 | return deburredLetters[letter];
|
4746 | }
|
4747 |
|
4748 | |
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 |
|
4754 |
|
4755 | function escapeHtmlChar(chr) {
|
4756 | return htmlEscapes[chr];
|
4757 | }
|
4758 |
|
4759 | |
4760 |
|
4761 |
|
4762 |
|
4763 |
|
4764 |
|
4765 |
|
4766 | function escapeStringChar(chr) {
|
4767 | return '\\' + stringEscapes[chr];
|
4768 | }
|
4769 |
|
4770 | |
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 | function indexOfNaN(array, fromIndex, fromRight) {
|
4780 | var length = array.length,
|
4781 | index = fromIndex + (fromRight ? 0 : -1);
|
4782 |
|
4783 | while ((fromRight ? index-- : ++index < length)) {
|
4784 | var other = array[index];
|
4785 | if (other !== other) {
|
4786 | return index;
|
4787 | }
|
4788 | }
|
4789 | return -1;
|
4790 | }
|
4791 |
|
4792 | |
4793 |
|
4794 |
|
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 | function isHostObject(value) {
|
4800 |
|
4801 |
|
4802 | var result = false;
|
4803 | if (value != null && typeof value.toString != 'function') {
|
4804 | try {
|
4805 | result = !!(value + '');
|
4806 | } catch (e) {}
|
4807 | }
|
4808 | return result;
|
4809 | }
|
4810 |
|
4811 | |
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 | function isIndex(value, length) {
|
4820 | value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
4821 | length = length == null ? MAX_SAFE_INTEGER : length;
|
4822 | return value > -1 && value % 1 == 0 && value < length;
|
4823 | }
|
4824 |
|
4825 | |
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 | function iteratorToArray(iterator) {
|
4833 | var data,
|
4834 | result = [];
|
4835 |
|
4836 | while (!(data = iterator.next()).done) {
|
4837 | result.push(data.value);
|
4838 | }
|
4839 | return result;
|
4840 | }
|
4841 |
|
4842 | |
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 | function mapToArray(map) {
|
4850 | var index = -1,
|
4851 | result = Array(map.size);
|
4852 |
|
4853 | map.forEach(function(value, key) {
|
4854 | result[++index] = [key, value];
|
4855 | });
|
4856 | return result;
|
4857 | }
|
4858 |
|
4859 | |
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 |
|
4868 | function replaceHolders(array, placeholder) {
|
4869 | var index = -1,
|
4870 | length = array.length,
|
4871 | resIndex = 0,
|
4872 | result = [];
|
4873 |
|
4874 | while (++index < length) {
|
4875 | var value = array[index];
|
4876 | if (value === placeholder || value === PLACEHOLDER) {
|
4877 | array[index] = PLACEHOLDER;
|
4878 | result[resIndex++] = index;
|
4879 | }
|
4880 | }
|
4881 | return result;
|
4882 | }
|
4883 |
|
4884 | |
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 | function setToArray(set) {
|
4892 | var index = -1,
|
4893 | result = Array(set.size);
|
4894 |
|
4895 | set.forEach(function(value) {
|
4896 | result[++index] = value;
|
4897 | });
|
4898 | return result;
|
4899 | }
|
4900 |
|
4901 | |
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 | function stringSize(string) {
|
4909 | if (!(string && reHasComplexSymbol.test(string))) {
|
4910 | return string.length;
|
4911 | }
|
4912 | var result = reComplexSymbol.lastIndex = 0;
|
4913 | while (reComplexSymbol.test(string)) {
|
4914 | result++;
|
4915 | }
|
4916 | return result;
|
4917 | }
|
4918 |
|
4919 | |
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 | function stringToArray(string) {
|
4927 | return string.match(reComplexSymbol);
|
4928 | }
|
4929 |
|
4930 | |
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 | function unescapeHtmlChar(chr) {
|
4938 | return htmlUnescapes[chr];
|
4939 | }
|
4940 |
|
4941 |
|
4942 |
|
4943 | |
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 |
|
4976 |
|
4977 |
|
4978 | function runInContext(context) {
|
4979 | context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
|
4980 |
|
4981 |
|
4982 | var Date = context.Date,
|
4983 | Error = context.Error,
|
4984 | Math = context.Math,
|
4985 | RegExp = context.RegExp,
|
4986 | TypeError = context.TypeError;
|
4987 |
|
4988 |
|
4989 | var arrayProto = context.Array.prototype,
|
4990 | objectProto = context.Object.prototype;
|
4991 |
|
4992 |
|
4993 | var funcToString = context.Function.prototype.toString;
|
4994 |
|
4995 |
|
4996 | var hasOwnProperty = objectProto.hasOwnProperty;
|
4997 |
|
4998 |
|
4999 | var idCounter = 0;
|
5000 |
|
5001 |
|
5002 | var objectCtorString = funcToString.call(Object);
|
5003 |
|
5004 | |
5005 |
|
5006 |
|
5007 |
|
5008 | var objectToString = objectProto.toString;
|
5009 |
|
5010 |
|
5011 | var oldDash = root._;
|
5012 |
|
5013 |
|
5014 | var reIsNative = RegExp('^' +
|
5015 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
5016 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
5017 | );
|
5018 |
|
5019 |
|
5020 | var Buffer = moduleExports ? context.Buffer : undefined,
|
5021 | Reflect = context.Reflect,
|
5022 | Symbol = context.Symbol,
|
5023 | Uint8Array = context.Uint8Array,
|
5024 | clearTimeout = context.clearTimeout,
|
5025 | enumerate = Reflect ? Reflect.enumerate : undefined,
|
5026 | getPrototypeOf = Object.getPrototypeOf,
|
5027 | getOwnPropertySymbols = Object.getOwnPropertySymbols,
|
5028 | iteratorSymbol = typeof (iteratorSymbol = Symbol && Symbol.iterator) == 'symbol' ? iteratorSymbol : undefined,
|
5029 | objectCreate = Object.create,
|
5030 | propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
5031 | setTimeout = context.setTimeout,
|
5032 | splice = arrayProto.splice;
|
5033 |
|
5034 |
|
5035 | var nativeCeil = Math.ceil,
|
5036 | nativeFloor = Math.floor,
|
5037 | nativeIsFinite = context.isFinite,
|
5038 | nativeJoin = arrayProto.join,
|
5039 | nativeKeys = Object.keys,
|
5040 | nativeMax = Math.max,
|
5041 | nativeMin = Math.min,
|
5042 | nativeParseInt = context.parseInt,
|
5043 | nativeRandom = Math.random,
|
5044 | nativeReverse = arrayProto.reverse;
|
5045 |
|
5046 |
|
5047 | var Map = getNative(context, 'Map'),
|
5048 | Set = getNative(context, 'Set'),
|
5049 | WeakMap = getNative(context, 'WeakMap'),
|
5050 | nativeCreate = getNative(Object, 'create');
|
5051 |
|
5052 |
|
5053 | var metaMap = WeakMap && new WeakMap;
|
5054 |
|
5055 |
|
5056 | var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
|
5057 |
|
5058 |
|
5059 | var realNames = {};
|
5060 |
|
5061 |
|
5062 | var mapCtorString = Map ? funcToString.call(Map) : '',
|
5063 | setCtorString = Set ? funcToString.call(Set) : '',
|
5064 | weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
|
5065 |
|
5066 |
|
5067 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
5068 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
|
5069 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
5070 |
|
5071 |
|
5072 |
|
5073 | |
5074 |
|
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 |
|
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 |
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 |
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 |
|
5145 |
|
5146 |
|
5147 |
|
5148 |
|
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 |
|
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 |
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 |
|
5170 |
|
5171 |
|
5172 |
|
5173 |
|
5174 |
|
5175 |
|
5176 |
|
5177 |
|
5178 |
|
5179 |
|
5180 |
|
5181 |
|
5182 |
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 | function lodash(value) {
|
5188 | if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
|
5189 | if (value instanceof LodashWrapper) {
|
5190 | return value;
|
5191 | }
|
5192 | if (hasOwnProperty.call(value, '__wrapped__')) {
|
5193 | return wrapperClone(value);
|
5194 | }
|
5195 | }
|
5196 | return new LodashWrapper(value);
|
5197 | }
|
5198 |
|
5199 | |
5200 |
|
5201 |
|
5202 |
|
5203 |
|
5204 | function baseLodash() {
|
5205 |
|
5206 | }
|
5207 |
|
5208 | |
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 | function LodashWrapper(value, chainAll) {
|
5216 | this.__wrapped__ = value;
|
5217 | this.__actions__ = [];
|
5218 | this.__chain__ = !!chainAll;
|
5219 | this.__index__ = 0;
|
5220 | this.__values__ = undefined;
|
5221 | }
|
5222 |
|
5223 | |
5224 |
|
5225 |
|
5226 |
|
5227 |
|
5228 |
|
5229 |
|
5230 |
|
5231 |
|
5232 | lodash.templateSettings = {
|
5233 |
|
5234 | |
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 | 'escape': reEscape,
|
5241 |
|
5242 | |
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 |
|
5248 | 'evaluate': reEvaluate,
|
5249 |
|
5250 | |
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 | 'interpolate': reInterpolate,
|
5257 |
|
5258 | |
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 | 'variable': '',
|
5265 |
|
5266 | |
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 | 'imports': {
|
5273 |
|
5274 | |
5275 |
|
5276 |
|
5277 |
|
5278 |
|
5279 |
|
5280 | '_': lodash
|
5281 | }
|
5282 | };
|
5283 |
|
5284 |
|
5285 |
|
5286 | |
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 | function LazyWrapper(value) {
|
5294 | this.__wrapped__ = value;
|
5295 | this.__actions__ = [];
|
5296 | this.__dir__ = 1;
|
5297 | this.__filtered__ = false;
|
5298 | this.__iteratees__ = [];
|
5299 | this.__takeCount__ = MAX_ARRAY_LENGTH;
|
5300 | this.__views__ = [];
|
5301 | }
|
5302 |
|
5303 | |
5304 |
|
5305 |
|
5306 |
|
5307 |
|
5308 |
|
5309 |
|
5310 |
|
5311 | function lazyClone() {
|
5312 | var result = new LazyWrapper(this.__wrapped__);
|
5313 | result.__actions__ = copyArray(this.__actions__);
|
5314 | result.__dir__ = this.__dir__;
|
5315 | result.__filtered__ = this.__filtered__;
|
5316 | result.__iteratees__ = copyArray(this.__iteratees__);
|
5317 | result.__takeCount__ = this.__takeCount__;
|
5318 | result.__views__ = copyArray(this.__views__);
|
5319 | return result;
|
5320 | }
|
5321 |
|
5322 | |
5323 |
|
5324 |
|
5325 |
|
5326 |
|
5327 |
|
5328 |
|
5329 |
|
5330 | function lazyReverse() {
|
5331 | if (this.__filtered__) {
|
5332 | var result = new LazyWrapper(this);
|
5333 | result.__dir__ = -1;
|
5334 | result.__filtered__ = true;
|
5335 | } else {
|
5336 | result = this.clone();
|
5337 | result.__dir__ *= -1;
|
5338 | }
|
5339 | return result;
|
5340 | }
|
5341 |
|
5342 | |
5343 |
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 | function lazyValue() {
|
5351 | var array = this.__wrapped__.value(),
|
5352 | dir = this.__dir__,
|
5353 | isArr = isArray(array),
|
5354 | isRight = dir < 0,
|
5355 | arrLength = isArr ? array.length : 0,
|
5356 | view = getView(0, arrLength, this.__views__),
|
5357 | start = view.start,
|
5358 | end = view.end,
|
5359 | length = end - start,
|
5360 | index = isRight ? end : (start - 1),
|
5361 | iteratees = this.__iteratees__,
|
5362 | iterLength = iteratees.length,
|
5363 | resIndex = 0,
|
5364 | takeCount = nativeMin(length, this.__takeCount__);
|
5365 |
|
5366 | if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
|
5367 | (arrLength == length && takeCount == length)) {
|
5368 | return baseWrapperValue(array, this.__actions__);
|
5369 | }
|
5370 | var result = [];
|
5371 |
|
5372 | outer:
|
5373 | while (length-- && resIndex < takeCount) {
|
5374 | index += dir;
|
5375 |
|
5376 | var iterIndex = -1,
|
5377 | value = array[index];
|
5378 |
|
5379 | while (++iterIndex < iterLength) {
|
5380 | var data = iteratees[iterIndex],
|
5381 | iteratee = data.iteratee,
|
5382 | type = data.type,
|
5383 | computed = iteratee(value);
|
5384 |
|
5385 | if (type == LAZY_MAP_FLAG) {
|
5386 | value = computed;
|
5387 | } else if (!computed) {
|
5388 | if (type == LAZY_FILTER_FLAG) {
|
5389 | continue outer;
|
5390 | } else {
|
5391 | break outer;
|
5392 | }
|
5393 | }
|
5394 | }
|
5395 | result[resIndex++] = value;
|
5396 | }
|
5397 | return result;
|
5398 | }
|
5399 |
|
5400 |
|
5401 |
|
5402 | |
5403 |
|
5404 |
|
5405 |
|
5406 |
|
5407 |
|
5408 |
|
5409 | function Hash() {}
|
5410 |
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 | function hashDelete(hash, key) {
|
5420 | return hashHas(hash, key) && delete hash[key];
|
5421 | }
|
5422 |
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 | function hashGet(hash, key) {
|
5432 | if (nativeCreate) {
|
5433 | var result = hash[key];
|
5434 | return result === HASH_UNDEFINED ? undefined : result;
|
5435 | }
|
5436 | return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
|
5437 | }
|
5438 |
|
5439 | |
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 | function hashHas(hash, key) {
|
5448 | return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash, key);
|
5449 | }
|
5450 |
|
5451 | |
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 |
|
5459 | function hashSet(hash, key, value) {
|
5460 | hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
5461 | }
|
5462 |
|
5463 |
|
5464 |
|
5465 | |
5466 |
|
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 | function MapCache(values) {
|
5473 | var index = -1,
|
5474 | length = values ? values.length : 0;
|
5475 |
|
5476 | this.clear();
|
5477 | while (++index < length) {
|
5478 | var entry = values[index];
|
5479 | this.set(entry[0], entry[1]);
|
5480 | }
|
5481 | }
|
5482 |
|
5483 | |
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 | function mapClear() {
|
5491 | this.__data__ = {
|
5492 | 'hash': new Hash,
|
5493 | 'map': Map ? new Map : [],
|
5494 | 'string': new Hash
|
5495 | };
|
5496 | }
|
5497 |
|
5498 | |
5499 |
|
5500 |
|
5501 |
|
5502 |
|
5503 |
|
5504 |
|
5505 |
|
5506 |
|
5507 | function mapDelete(key) {
|
5508 | var data = this.__data__;
|
5509 | if (isKeyable(key)) {
|
5510 | return hashDelete(typeof key == 'string' ? data.string : data.hash, key);
|
5511 | }
|
5512 | return Map ? data.map['delete'](key) : assocDelete(data.map, key);
|
5513 | }
|
5514 |
|
5515 | |
5516 |
|
5517 |
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 | function mapGet(key) {
|
5525 | var data = this.__data__;
|
5526 | if (isKeyable(key)) {
|
5527 | return hashGet(typeof key == 'string' ? data.string : data.hash, key);
|
5528 | }
|
5529 | return Map ? data.map.get(key) : assocGet(data.map, key);
|
5530 | }
|
5531 |
|
5532 | |
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 | function mapHas(key) {
|
5542 | var data = this.__data__;
|
5543 | if (isKeyable(key)) {
|
5544 | return hashHas(typeof key == 'string' ? data.string : data.hash, key);
|
5545 | }
|
5546 | return Map ? data.map.has(key) : assocHas(data.map, key);
|
5547 | }
|
5548 |
|
5549 | |
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 |
|
5558 |
|
5559 | function mapSet(key, value) {
|
5560 | var data = this.__data__;
|
5561 | if (isKeyable(key)) {
|
5562 | hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
|
5563 | } else if (Map) {
|
5564 | data.map.set(key, value);
|
5565 | } else {
|
5566 | assocSet(data.map, key, value);
|
5567 | }
|
5568 | return this;
|
5569 | }
|
5570 |
|
5571 |
|
5572 |
|
5573 | |
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 | function SetCache(values) {
|
5582 | var index = -1,
|
5583 | length = values ? values.length : 0;
|
5584 |
|
5585 | this.__data__ = new MapCache;
|
5586 | while (++index < length) {
|
5587 | this.push(values[index]);
|
5588 | }
|
5589 | }
|
5590 |
|
5591 | |
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 |
|
5598 |
|
5599 | function cacheHas(cache, value) {
|
5600 | var map = cache.__data__;
|
5601 | if (isKeyable(value)) {
|
5602 | var data = map.__data__,
|
5603 | hash = typeof value == 'string' ? data.string : data.hash;
|
5604 |
|
5605 | return hash[value] === HASH_UNDEFINED;
|
5606 | }
|
5607 | return map.has(value);
|
5608 | }
|
5609 |
|
5610 | |
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 | function cachePush(value) {
|
5619 | var map = this.__data__;
|
5620 | if (isKeyable(value)) {
|
5621 | var data = map.__data__,
|
5622 | hash = typeof value == 'string' ? data.string : data.hash;
|
5623 |
|
5624 | hash[value] = HASH_UNDEFINED;
|
5625 | }
|
5626 | else {
|
5627 | map.set(value, HASH_UNDEFINED);
|
5628 | }
|
5629 | }
|
5630 |
|
5631 |
|
5632 |
|
5633 | |
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 | function Stack(values) {
|
5641 | var index = -1,
|
5642 | length = values ? values.length : 0;
|
5643 |
|
5644 | this.clear();
|
5645 | while (++index < length) {
|
5646 | var entry = values[index];
|
5647 | this.set(entry[0], entry[1]);
|
5648 | }
|
5649 | }
|
5650 |
|
5651 | |
5652 |
|
5653 |
|
5654 |
|
5655 |
|
5656 |
|
5657 |
|
5658 | function stackClear() {
|
5659 | this.__data__ = { 'array': [], 'map': null };
|
5660 | }
|
5661 |
|
5662 | |
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 | function stackDelete(key) {
|
5672 | var data = this.__data__,
|
5673 | array = data.array;
|
5674 |
|
5675 | return array ? assocDelete(array, key) : data.map['delete'](key);
|
5676 | }
|
5677 |
|
5678 | |
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 | function stackGet(key) {
|
5688 | var data = this.__data__,
|
5689 | array = data.array;
|
5690 |
|
5691 | return array ? assocGet(array, key) : data.map.get(key);
|
5692 | }
|
5693 |
|
5694 | |
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 | function stackHas(key) {
|
5704 | var data = this.__data__,
|
5705 | array = data.array;
|
5706 |
|
5707 | return array ? assocHas(array, key) : data.map.has(key);
|
5708 | }
|
5709 |
|
5710 | |
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 | function stackSet(key, value) {
|
5721 | var data = this.__data__,
|
5722 | array = data.array;
|
5723 |
|
5724 | if (array) {
|
5725 | if (array.length < (LARGE_ARRAY_SIZE - 1)) {
|
5726 | assocSet(array, key, value);
|
5727 | } else {
|
5728 | data.array = null;
|
5729 | data.map = new MapCache(array);
|
5730 | }
|
5731 | }
|
5732 | var map = data.map;
|
5733 | if (map) {
|
5734 | map.set(key, value);
|
5735 | }
|
5736 | return this;
|
5737 | }
|
5738 |
|
5739 |
|
5740 |
|
5741 | |
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 | function assocDelete(array, key) {
|
5750 | var index = assocIndexOf(array, key);
|
5751 | if (index < 0) {
|
5752 | return false;
|
5753 | }
|
5754 | var lastIndex = array.length - 1;
|
5755 | if (index == lastIndex) {
|
5756 | array.pop();
|
5757 | } else {
|
5758 | splice.call(array, index, 1);
|
5759 | }
|
5760 | return true;
|
5761 | }
|
5762 |
|
5763 | |
5764 |
|
5765 |
|
5766 |
|
5767 |
|
5768 |
|
5769 |
|
5770 |
|
5771 | function assocGet(array, key) {
|
5772 | var index = assocIndexOf(array, key);
|
5773 | return index < 0 ? undefined : array[index][1];
|
5774 | }
|
5775 |
|
5776 | |
5777 |
|
5778 |
|
5779 |
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 | function assocHas(array, key) {
|
5785 | return assocIndexOf(array, key) > -1;
|
5786 | }
|
5787 |
|
5788 | |
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 |
|
5797 | function assocIndexOf(array, key) {
|
5798 | var length = array.length;
|
5799 | while (length--) {
|
5800 | if (eq(array[length][0], key)) {
|
5801 | return length;
|
5802 | }
|
5803 | }
|
5804 | return -1;
|
5805 | }
|
5806 |
|
5807 | |
5808 |
|
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 | function assocSet(array, key, value) {
|
5816 | var index = assocIndexOf(array, key);
|
5817 | if (index < 0) {
|
5818 | array.push([key, value]);
|
5819 | } else {
|
5820 | array[index][1] = value;
|
5821 | }
|
5822 | }
|
5823 |
|
5824 |
|
5825 |
|
5826 | |
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 | function assignInDefaults(objValue, srcValue, key, object) {
|
5837 | if (objValue === undefined ||
|
5838 | (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
5839 | return srcValue;
|
5840 | }
|
5841 | return objValue;
|
5842 | }
|
5843 |
|
5844 | |
5845 |
|
5846 |
|
5847 |
|
5848 |
|
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 | function assignMergeValue(object, key, value) {
|
5854 | if ((value !== undefined && !eq(object[key], value)) ||
|
5855 | (typeof key == 'number' && value === undefined && !(key in object))) {
|
5856 | object[key] = value;
|
5857 | }
|
5858 | }
|
5859 |
|
5860 | |
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 | function assignValue(object, key, value) {
|
5871 | var objValue = object[key];
|
5872 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
5873 | (value === undefined && !(key in object))) {
|
5874 | object[key] = value;
|
5875 | }
|
5876 | }
|
5877 |
|
5878 | |
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 | function baseAggregator(collection, setter, iteratee, accumulator) {
|
5890 | baseEach(collection, function(value, key, collection) {
|
5891 | setter(accumulator, value, iteratee(value), collection);
|
5892 | });
|
5893 | return accumulator;
|
5894 | }
|
5895 |
|
5896 | |
5897 |
|
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 | function baseAssign(object, source) {
|
5906 | return object && copyObject(source, keys(source), object);
|
5907 | }
|
5908 |
|
5909 | |
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 | function baseAt(object, paths) {
|
5918 | var index = -1,
|
5919 | isNil = object == null,
|
5920 | length = paths.length,
|
5921 | result = Array(length);
|
5922 |
|
5923 | while (++index < length) {
|
5924 | result[index] = isNil ? undefined : get(object, paths[index]);
|
5925 | }
|
5926 | return result;
|
5927 | }
|
5928 |
|
5929 | /**
|
5930 | * Casts `value` to an empty array if it's not an array like object.
|
5931 | *
|
5932 | * @private
|
5933 | * @param {*} value The value to inspect.
|
5934 | * @returns {Array} Returns the array-like object.
|
5935 | */
|
5936 | function baseCastArrayLikeObject(value) {
|
5937 | return isArrayLikeObject(value) ? value : [];
|
5938 | }
|
5939 |
|
5940 | |
5941 |
|
5942 |
|
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 | function baseCastFunction(value) {
|
5948 | return typeof value == 'function' ? value : identity;
|
5949 | }
|
5950 |
|
5951 | |
5952 |
|
5953 |
|
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 | function baseCastPath(value) {
|
5959 | return isArray(value) ? value : stringToPath(value);
|
5960 | }
|
5961 |
|
5962 | |
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 |
|
5969 |
|
5970 |
|
5971 | function baseClamp(number, lower, upper) {
|
5972 | if (number === number) {
|
5973 | if (upper !== undefined) {
|
5974 | number = number <= upper ? number : upper;
|
5975 | }
|
5976 | if (lower !== undefined) {
|
5977 | number = number >= lower ? number : lower;
|
5978 | }
|
5979 | }
|
5980 | return number;
|
5981 | }
|
5982 |
|
5983 | |
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 |
|
5989 |
|
5990 |
|
5991 |
|
5992 |
|
5993 |
|
5994 |
|
5995 |
|
5996 |
|
5997 | function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
5998 | var result;
|
5999 | if (customizer) {
|
6000 | result = object ? customizer(value, key, object, stack) : customizer(value);
|
6001 | }
|
6002 | if (result !== undefined) {
|
6003 | return result;
|
6004 | }
|
6005 | if (!isObject(value)) {
|
6006 | return value;
|
6007 | }
|
6008 | var isArr = isArray(value);
|
6009 | if (isArr) {
|
6010 | result = initCloneArray(value);
|
6011 | if (!isDeep) {
|
6012 | return copyArray(value, result);
|
6013 | }
|
6014 | } else {
|
6015 | var tag = getTag(value),
|
6016 | isFunc = tag == funcTag || tag == genTag;
|
6017 |
|
6018 | if (isBuffer(value)) {
|
6019 | return cloneBuffer(value, isDeep);
|
6020 | }
|
6021 | if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
6022 | if (isHostObject(value)) {
|
6023 | return object ? value : {};
|
6024 | }
|
6025 | result = initCloneObject(isFunc ? {} : value);
|
6026 | if (!isDeep) {
|
6027 | result = baseAssign(result, value);
|
6028 | return isFull ? copySymbols(value, result) : result;
|
6029 | }
|
6030 | } else {
|
6031 | if (!cloneableTags[tag]) {
|
6032 | return object ? value : {};
|
6033 | }
|
6034 | result = initCloneByTag(value, tag, isDeep);
|
6035 | }
|
6036 | }
|
6037 |
|
6038 | stack || (stack = new Stack);
|
6039 | var stacked = stack.get(value);
|
6040 | if (stacked) {
|
6041 | return stacked;
|
6042 | }
|
6043 | stack.set(value, result);
|
6044 |
|
6045 |
|
6046 | (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
6047 | assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
6048 | });
|
6049 | return (isFull && !isArr) ? copySymbols(value, result) : result;
|
6050 | }
|
6051 |
|
6052 | |
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 | function baseConforms(source) {
|
6060 | var props = keys(source),
|
6061 | length = props.length;
|
6062 |
|
6063 | return function(object) {
|
6064 | if (object == null) {
|
6065 | return !length;
|
6066 | }
|
6067 | var index = length;
|
6068 | while (index--) {
|
6069 | var key = props[index],
|
6070 | predicate = source[key],
|
6071 | value = object[key];
|
6072 |
|
6073 | if ((value === undefined && !(key in Object(object))) || !predicate(value)) {
|
6074 | return false;
|
6075 | }
|
6076 | }
|
6077 | return true;
|
6078 | };
|
6079 | }
|
6080 |
|
6081 | |
6082 |
|
6083 |
|
6084 |
|
6085 |
|
6086 |
|
6087 |
|
6088 |
|
6089 | function baseCreate(proto) {
|
6090 | return isObject(proto) ? objectCreate(proto) : {};
|
6091 | }
|
6092 |
|
6093 | |
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 | function baseDelay(func, wait, args) {
|
6104 | if (typeof func != 'function') {
|
6105 | throw new TypeError(FUNC_ERROR_TEXT);
|
6106 | }
|
6107 | return setTimeout(function() { func.apply(undefined, args); }, wait);
|
6108 | }
|
6109 |
|
6110 | |
6111 |
|
6112 |
|
6113 |
|
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 | function baseDifference(array, values, iteratee, comparator) {
|
6122 | var index = -1,
|
6123 | includes = arrayIncludes,
|
6124 | isCommon = true,
|
6125 | length = array.length,
|
6126 | result = [],
|
6127 | valuesLength = values.length;
|
6128 |
|
6129 | if (!length) {
|
6130 | return result;
|
6131 | }
|
6132 | if (iteratee) {
|
6133 | values = arrayMap(values, baseUnary(iteratee));
|
6134 | }
|
6135 | if (comparator) {
|
6136 | includes = arrayIncludesWith;
|
6137 | isCommon = false;
|
6138 | }
|
6139 | else if (values.length >= LARGE_ARRAY_SIZE) {
|
6140 | includes = cacheHas;
|
6141 | isCommon = false;
|
6142 | values = new SetCache(values);
|
6143 | }
|
6144 | outer:
|
6145 | while (++index < length) {
|
6146 | var value = array[index],
|
6147 | computed = iteratee ? iteratee(value) : value;
|
6148 |
|
6149 | if (isCommon && computed === computed) {
|
6150 | var valuesIndex = valuesLength;
|
6151 | while (valuesIndex--) {
|
6152 | if (values[valuesIndex] === computed) {
|
6153 | continue outer;
|
6154 | }
|
6155 | }
|
6156 | result.push(value);
|
6157 | }
|
6158 | else if (!includes(values, computed, comparator)) {
|
6159 | result.push(value);
|
6160 | }
|
6161 | }
|
6162 | return result;
|
6163 | }
|
6164 |
|
6165 | |
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 | var baseEach = createBaseEach(baseForOwn);
|
6174 |
|
6175 | |
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 | var baseEachRight = createBaseEach(baseForOwnRight, true);
|
6184 |
|
6185 | |
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 | function baseEvery(collection, predicate) {
|
6194 | var result = true;
|
6195 | baseEach(collection, function(value, index, collection) {
|
6196 | result = !!predicate(value, index, collection);
|
6197 | return result;
|
6198 | });
|
6199 | return result;
|
6200 | }
|
6201 |
|
6202 | |
6203 |
|
6204 |
|
6205 |
|
6206 |
|
6207 |
|
6208 |
|
6209 |
|
6210 |
|
6211 |
|
6212 | function baseFill(array, value, start, end) {
|
6213 | var length = array.length;
|
6214 |
|
6215 | start = toInteger(start);
|
6216 | if (start < 0) {
|
6217 | start = -start > length ? 0 : (length + start);
|
6218 | }
|
6219 | end = (end === undefined || end > length) ? length : toInteger(end);
|
6220 | if (end < 0) {
|
6221 | end += length;
|
6222 | }
|
6223 | end = start > end ? 0 : toLength(end);
|
6224 | while (start < end) {
|
6225 | array[start++] = value;
|
6226 | }
|
6227 | return array;
|
6228 | }
|
6229 |
|
6230 | |
6231 |
|
6232 |
|
6233 |
|
6234 |
|
6235 |
|
6236 |
|
6237 |
|
6238 | function baseFilter(collection, predicate) {
|
6239 | var result = [];
|
6240 | baseEach(collection, function(value, index, collection) {
|
6241 | if (predicate(value, index, collection)) {
|
6242 | result.push(value);
|
6243 | }
|
6244 | });
|
6245 | return result;
|
6246 | }
|
6247 |
|
6248 | |
6249 |
|
6250 |
|
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 | function baseFlatten(array, depth, isStrict, result) {
|
6259 | result || (result = []);
|
6260 |
|
6261 | var index = -1,
|
6262 | length = array.length;
|
6263 |
|
6264 | while (++index < length) {
|
6265 | var value = array[index];
|
6266 | if (depth > 0 && isArrayLikeObject(value) &&
|
6267 | (isStrict || isArray(value) || isArguments(value))) {
|
6268 | if (depth > 1) {
|
6269 |
|
6270 | baseFlatten(value, depth - 1, isStrict, result);
|
6271 | } else {
|
6272 | arrayPush(result, value);
|
6273 | }
|
6274 | } else if (!isStrict) {
|
6275 | result[result.length] = value;
|
6276 | }
|
6277 | }
|
6278 | return result;
|
6279 | }
|
6280 |
|
6281 | |
6282 |
|
6283 |
|
6284 |
|
6285 |
|
6286 |
|
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 | var baseFor = createBaseFor();
|
6294 |
|
6295 | |
6296 |
|
6297 |
|
6298 |
|
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 |
|
6305 | var baseForRight = createBaseFor(true);
|
6306 |
|
6307 | |
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 |
|
6314 |
|
6315 | function baseForIn(object, iteratee) {
|
6316 | return object == null ? object : baseFor(object, iteratee, keysIn);
|
6317 | }
|
6318 |
|
6319 | |
6320 |
|
6321 |
|
6322 |
|
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 | function baseForOwn(object, iteratee) {
|
6328 | return object && baseFor(object, iteratee, keys);
|
6329 | }
|
6330 |
|
6331 | |
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 |
|
6339 | function baseForOwnRight(object, iteratee) {
|
6340 | return object && baseForRight(object, iteratee, keys);
|
6341 | }
|
6342 |
|
6343 | |
6344 |
|
6345 |
|
6346 |
|
6347 |
|
6348 |
|
6349 |
|
6350 |
|
6351 |
|
6352 | function baseFunctions(object, props) {
|
6353 | return arrayFilter(props, function(key) {
|
6354 | return isFunction(object[key]);
|
6355 | });
|
6356 | }
|
6357 |
|
6358 | |
6359 |
|
6360 |
|
6361 |
|
6362 |
|
6363 |
|
6364 |
|
6365 |
|
6366 | function baseGet(object, path) {
|
6367 | path = isKey(path, object) ? [path + ''] : baseCastPath(path);
|
6368 |
|
6369 | var index = 0,
|
6370 | length = path.length;
|
6371 |
|
6372 | while (object != null && index < length) {
|
6373 | object = object[path[index++]];
|
6374 | }
|
6375 | return (index && index == length) ? object : undefined;
|
6376 | }
|
6377 |
|
6378 | |
6379 |
|
6380 |
|
6381 |
|
6382 |
|
6383 |
|
6384 |
|
6385 |
|
6386 | function baseHas(object, key) {
|
6387 |
|
6388 |
|
6389 |
|
6390 | return hasOwnProperty.call(object, key) ||
|
6391 | (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
|
6392 | }
|
6393 |
|
6394 | |
6395 |
|
6396 |
|
6397 |
|
6398 |
|
6399 |
|
6400 |
|
6401 |
|
6402 | function baseHasIn(object, key) {
|
6403 | return key in Object(object);
|
6404 | }
|
6405 |
|
6406 | |
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 | function baseInRange(number, start, end) {
|
6416 | return number >= nativeMin(start, end) && number < nativeMax(start, end);
|
6417 | }
|
6418 |
|
6419 | |
6420 |
|
6421 |
|
6422 |
|
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 | function baseIntersection(arrays, iteratee, comparator) {
|
6430 | var includes = comparator ? arrayIncludesWith : arrayIncludes,
|
6431 | length = arrays[0].length,
|
6432 | othLength = arrays.length,
|
6433 | othIndex = othLength,
|
6434 | caches = Array(othLength),
|
6435 | maxLength = Infinity,
|
6436 | result = [];
|
6437 |
|
6438 | while (othIndex--) {
|
6439 | var array = arrays[othIndex];
|
6440 | if (othIndex && iteratee) {
|
6441 | array = arrayMap(array, baseUnary(iteratee));
|
6442 | }
|
6443 | maxLength = nativeMin(array.length, maxLength);
|
6444 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
|
6445 | ? new SetCache(othIndex && array)
|
6446 | : undefined;
|
6447 | }
|
6448 | array = arrays[0];
|
6449 |
|
6450 | var index = -1,
|
6451 | seen = caches[0];
|
6452 |
|
6453 | outer:
|
6454 | while (++index < length && result.length < maxLength) {
|
6455 | var value = array[index],
|
6456 | computed = iteratee ? iteratee(value) : value;
|
6457 |
|
6458 | if (!(seen
|
6459 | ? cacheHas(seen, computed)
|
6460 | : includes(result, computed, comparator)
|
6461 | )) {
|
6462 | othIndex = othLength;
|
6463 | while (--othIndex) {
|
6464 | var cache = caches[othIndex];
|
6465 | if (!(cache
|
6466 | ? cacheHas(cache, computed)
|
6467 | : includes(arrays[othIndex], computed, comparator))
|
6468 | ) {
|
6469 | continue outer;
|
6470 | }
|
6471 | }
|
6472 | if (seen) {
|
6473 | seen.push(computed);
|
6474 | }
|
6475 | result.push(value);
|
6476 | }
|
6477 | }
|
6478 | return result;
|
6479 | }
|
6480 |
|
6481 | |
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 | function baseInverter(object, setter, iteratee, accumulator) {
|
6493 | baseForOwn(object, function(value, key, object) {
|
6494 | setter(accumulator, iteratee(value), key, object);
|
6495 | });
|
6496 | return accumulator;
|
6497 | }
|
6498 |
|
6499 | |
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 | function baseInvoke(object, path, args) {
|
6510 | if (!isKey(path, object)) {
|
6511 | path = baseCastPath(path);
|
6512 | object = parent(object, path);
|
6513 | path = last(path);
|
6514 | }
|
6515 | var func = object == null ? object : object[path];
|
6516 | return func == null ? undefined : apply(func, object, args);
|
6517 | }
|
6518 |
|
6519 | |
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 |
|
6527 |
|
6528 |
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 | function baseIsEqual(value, other, customizer, bitmask, stack) {
|
6535 | if (value === other) {
|
6536 | return true;
|
6537 | }
|
6538 | if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
6539 | return value !== value && other !== other;
|
6540 | }
|
6541 | return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
|
6542 | }
|
6543 |
|
6544 | |
6545 |
|
6546 |
|
6547 |
|
6548 |
|
6549 |
|
6550 |
|
6551 |
|
6552 |
|
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 | function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
|
6559 | var objIsArr = isArray(object),
|
6560 | othIsArr = isArray(other),
|
6561 | objTag = arrayTag,
|
6562 | othTag = arrayTag;
|
6563 |
|
6564 | if (!objIsArr) {
|
6565 | objTag = getTag(object);
|
6566 | objTag = objTag == argsTag ? objectTag : objTag;
|
6567 | }
|
6568 | if (!othIsArr) {
|
6569 | othTag = getTag(other);
|
6570 | othTag = othTag == argsTag ? objectTag : othTag;
|
6571 | }
|
6572 | var objIsObj = objTag == objectTag && !isHostObject(object),
|
6573 | othIsObj = othTag == objectTag && !isHostObject(other),
|
6574 | isSameTag = objTag == othTag;
|
6575 |
|
6576 | if (isSameTag && !objIsObj) {
|
6577 | stack || (stack = new Stack);
|
6578 | return (objIsArr || isTypedArray(object))
|
6579 | ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
|
6580 | : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
|
6581 | }
|
6582 | if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
|
6583 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
6584 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
6585 |
|
6586 | if (objIsWrapped || othIsWrapped) {
|
6587 | stack || (stack = new Stack);
|
6588 | return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
|
6589 | }
|
6590 | }
|
6591 | if (!isSameTag) {
|
6592 | return false;
|
6593 | }
|
6594 | stack || (stack = new Stack);
|
6595 | return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
|
6596 | }
|
6597 |
|
6598 | |
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 | function baseIsMatch(object, source, matchData, customizer) {
|
6609 | var index = matchData.length,
|
6610 | length = index,
|
6611 | noCustomizer = !customizer;
|
6612 |
|
6613 | if (object == null) {
|
6614 | return !length;
|
6615 | }
|
6616 | object = Object(object);
|
6617 | while (index--) {
|
6618 | var data = matchData[index];
|
6619 | if ((noCustomizer && data[2])
|
6620 | ? data[1] !== object[data[0]]
|
6621 | : !(data[0] in object)
|
6622 | ) {
|
6623 | return false;
|
6624 | }
|
6625 | }
|
6626 | while (++index < length) {
|
6627 | data = matchData[index];
|
6628 | var key = data[0],
|
6629 | objValue = object[key],
|
6630 | srcValue = data[1];
|
6631 |
|
6632 | if (noCustomizer && data[2]) {
|
6633 | if (objValue === undefined && !(key in object)) {
|
6634 | return false;
|
6635 | }
|
6636 | } else {
|
6637 | var stack = new Stack,
|
6638 | result = customizer ? customizer(objValue, srcValue, key, object, source, stack) : undefined;
|
6639 |
|
6640 | if (!(result === undefined
|
6641 | ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
|
6642 | : result
|
6643 | )) {
|
6644 | return false;
|
6645 | }
|
6646 | }
|
6647 | }
|
6648 | return true;
|
6649 | }
|
6650 |
|
6651 | |
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 | function baseIteratee(value) {
|
6659 | var type = typeof value;
|
6660 | if (type == 'function') {
|
6661 | return value;
|
6662 | }
|
6663 | if (value == null) {
|
6664 | return identity;
|
6665 | }
|
6666 | if (type == 'object') {
|
6667 | return isArray(value)
|
6668 | ? baseMatchesProperty(value[0], value[1])
|
6669 | : baseMatches(value);
|
6670 | }
|
6671 | return property(value);
|
6672 | }
|
6673 |
|
6674 | |
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 | function baseKeys(object) {
|
6683 | return nativeKeys(Object(object));
|
6684 | }
|
6685 |
|
6686 | |
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 | function baseKeysIn(object) {
|
6695 | object = object == null ? object : Object(object);
|
6696 |
|
6697 | var result = [];
|
6698 | for (var key in object) {
|
6699 | result.push(key);
|
6700 | }
|
6701 | return result;
|
6702 | }
|
6703 |
|
6704 |
|
6705 | if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
|
6706 | baseKeysIn = function(object) {
|
6707 | return iteratorToArray(enumerate(object));
|
6708 | };
|
6709 | }
|
6710 |
|
6711 | |
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 | function baseMap(collection, iteratee) {
|
6720 | var index = -1,
|
6721 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
6722 |
|
6723 | baseEach(collection, function(value, key, collection) {
|
6724 | result[++index] = iteratee(value, key, collection);
|
6725 | });
|
6726 | return result;
|
6727 | }
|
6728 |
|
6729 | |
6730 |
|
6731 |
|
6732 |
|
6733 |
|
6734 |
|
6735 |
|
6736 | function baseMatches(source) {
|
6737 | var matchData = getMatchData(source);
|
6738 | if (matchData.length == 1 && matchData[0][2]) {
|
6739 | var key = matchData[0][0],
|
6740 | value = matchData[0][1];
|
6741 |
|
6742 | return function(object) {
|
6743 | if (object == null) {
|
6744 | return false;
|
6745 | }
|
6746 | return object[key] === value &&
|
6747 | (value !== undefined || (key in Object(object)));
|
6748 | };
|
6749 | }
|
6750 | return function(object) {
|
6751 | return object === source || baseIsMatch(object, source, matchData);
|
6752 | };
|
6753 | }
|
6754 |
|
6755 | |
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 |
|
6761 |
|
6762 |
|
6763 | function baseMatchesProperty(path, srcValue) {
|
6764 | return function(object) {
|
6765 | var objValue = get(object, path);
|
6766 | return (objValue === undefined && objValue === srcValue)
|
6767 | ? hasIn(object, path)
|
6768 | : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
|
6769 | };
|
6770 | }
|
6771 |
|
6772 | /**
|
6773 | * The base implementation of `_.merge` without support for multiple sources.
|
6774 | *
|
6775 | * @private
|
6776 | * @param {Object} object The destination object.
|
6777 | * @param {Object} source The source object.
|
6778 | * @param {number} srcIndex The index of `source`.
|
6779 | * @param {Function} [customizer] The function to customize merged values.
|
6780 | * @param {Object} [stack] Tracks traversed source values and their merged counterparts.
|
6781 | */
|
6782 | function baseMerge(object, source, srcIndex, customizer, stack) {
|
6783 | if (object === source) {
|
6784 | return;
|
6785 | }
|
6786 | var props = (isArray(source) || isTypedArray(source))
|
6787 | ? undefined
|
6788 | : keysIn(source);
|
6789 |
|
6790 | arrayEach(props || source, function(srcValue, key) {
|
6791 | if (props) {
|
6792 | key = srcValue;
|
6793 | srcValue = source[key];
|
6794 | }
|
6795 | if (isObject(srcValue)) {
|
6796 | stack || (stack = new Stack);
|
6797 | baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
6798 | }
|
6799 | else {
|
6800 | var newValue = customizer
|
6801 | ? customizer(object[key], srcValue, (key + ''), object, source, stack)
|
6802 | : undefined;
|
6803 |
|
6804 | if (newValue === undefined) {
|
6805 | newValue = srcValue;
|
6806 | }
|
6807 | assignMergeValue(object, key, newValue);
|
6808 | }
|
6809 | });
|
6810 | }
|
6811 |
|
6812 | |
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
6827 | var objValue = object[key],
|
6828 | srcValue = source[key],
|
6829 | stacked = stack.get(srcValue);
|
6830 |
|
6831 | if (stacked) {
|
6832 | assignMergeValue(object, key, stacked);
|
6833 | return;
|
6834 | }
|
6835 | var newValue = customizer
|
6836 | ? customizer(objValue, srcValue, (key + ''), object, source, stack)
|
6837 | : undefined;
|
6838 |
|
6839 | var isCommon = newValue === undefined;
|
6840 |
|
6841 | if (isCommon) {
|
6842 | newValue = srcValue;
|
6843 | if (isArray(srcValue) || isTypedArray(srcValue)) {
|
6844 | if (isArray(objValue)) {
|
6845 | newValue = objValue;
|
6846 | }
|
6847 | else if (isArrayLikeObject(objValue)) {
|
6848 | newValue = copyArray(objValue);
|
6849 | }
|
6850 | else {
|
6851 | isCommon = false;
|
6852 | newValue = baseClone(srcValue, !customizer);
|
6853 | }
|
6854 | }
|
6855 | else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
6856 | if (isArguments(objValue)) {
|
6857 | newValue = toPlainObject(objValue);
|
6858 | }
|
6859 | else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
6860 | isCommon = false;
|
6861 | newValue = baseClone(srcValue, !customizer);
|
6862 | }
|
6863 | else {
|
6864 | newValue = objValue;
|
6865 | }
|
6866 | }
|
6867 | else {
|
6868 | isCommon = false;
|
6869 | }
|
6870 | }
|
6871 | stack.set(srcValue, newValue);
|
6872 |
|
6873 | if (isCommon) {
|
6874 |
|
6875 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
|
6876 | }
|
6877 | stack['delete'](srcValue);
|
6878 | assignMergeValue(object, key, newValue);
|
6879 | }
|
6880 |
|
6881 | |
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 |
|
6888 |
|
6889 |
|
6890 | function baseOrderBy(collection, iteratees, orders) {
|
6891 | var index = -1;
|
6892 | iteratees = arrayMap(iteratees.length ? iteratees : Array(1), getIteratee());
|
6893 |
|
6894 | var result = baseMap(collection, function(value, key, collection) {
|
6895 | var criteria = arrayMap(iteratees, function(iteratee) {
|
6896 | return iteratee(value);
|
6897 | });
|
6898 | return { 'criteria': criteria, 'index': ++index, 'value': value };
|
6899 | });
|
6900 |
|
6901 | return baseSortBy(result, function(object, other) {
|
6902 | return compareMultiple(object, other, orders);
|
6903 | });
|
6904 | }
|
6905 |
|
6906 | |
6907 |
|
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 |
|
6914 |
|
6915 | function basePick(object, props) {
|
6916 | object = Object(object);
|
6917 | return arrayReduce(props, function(result, key) {
|
6918 | if (key in object) {
|
6919 | result[key] = object[key];
|
6920 | }
|
6921 | return result;
|
6922 | }, {});
|
6923 | }
|
6924 |
|
6925 | |
6926 |
|
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 |
|
6932 |
|
6933 | function basePickBy(object, predicate) {
|
6934 | var result = {};
|
6935 | baseForIn(object, function(value, key) {
|
6936 | if (predicate(value, key)) {
|
6937 | result[key] = value;
|
6938 | }
|
6939 | });
|
6940 | return result;
|
6941 | }
|
6942 |
|
6943 | |
6944 |
|
6945 |
|
6946 |
|
6947 |
|
6948 |
|
6949 |
|
6950 | function baseProperty(key) {
|
6951 | return function(object) {
|
6952 | return object == null ? undefined : object[key];
|
6953 | };
|
6954 | }
|
6955 |
|
6956 | |
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 | function basePropertyDeep(path) {
|
6964 | return function(object) {
|
6965 | return baseGet(object, path);
|
6966 | };
|
6967 | }
|
6968 |
|
6969 | |
6970 |
|
6971 |
|
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 | function basePullAll(array, values, iteratee, comparator) {
|
6981 | var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
|
6982 | index = -1,
|
6983 | length = values.length,
|
6984 | seen = array;
|
6985 |
|
6986 | if (iteratee) {
|
6987 | seen = arrayMap(array, baseUnary(iteratee));
|
6988 | }
|
6989 | while (++index < length) {
|
6990 | var fromIndex = 0,
|
6991 | value = values[index],
|
6992 | computed = iteratee ? iteratee(value) : value;
|
6993 |
|
6994 | while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
|
6995 | if (seen !== array) {
|
6996 | splice.call(seen, fromIndex, 1);
|
6997 | }
|
6998 | splice.call(array, fromIndex, 1);
|
6999 | }
|
7000 | }
|
7001 | return array;
|
7002 | }
|
7003 |
|
7004 | |
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 | function basePullAt(array, indexes) {
|
7014 | var length = array ? indexes.length : 0,
|
7015 | lastIndex = length - 1;
|
7016 |
|
7017 | while (length--) {
|
7018 | var index = indexes[length];
|
7019 | if (lastIndex == length || index != previous) {
|
7020 | var previous = index;
|
7021 | if (isIndex(index)) {
|
7022 | splice.call(array, index, 1);
|
7023 | }
|
7024 | else if (!isKey(index, array)) {
|
7025 | var path = baseCastPath(index),
|
7026 | object = parent(array, path);
|
7027 |
|
7028 | if (object != null) {
|
7029 | delete object[last(path)];
|
7030 | }
|
7031 | }
|
7032 | else {
|
7033 | delete array[index];
|
7034 | }
|
7035 | }
|
7036 | }
|
7037 | return array;
|
7038 | }
|
7039 |
|
7040 | |
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 |
|
7049 | function baseRandom(lower, upper) {
|
7050 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
|
7051 | }
|
7052 |
|
7053 | |
7054 |
|
7055 |
|
7056 |
|
7057 |
|
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 | function baseRange(start, end, step, fromRight) {
|
7065 | var index = -1,
|
7066 | length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
|
7067 | result = Array(length);
|
7068 |
|
7069 | while (length--) {
|
7070 | result[fromRight ? length : ++index] = start;
|
7071 | start += step;
|
7072 | }
|
7073 | return result;
|
7074 | }
|
7075 |
|
7076 | |
7077 |
|
7078 |
|
7079 |
|
7080 |
|
7081 |
|
7082 |
|
7083 |
|
7084 |
|
7085 |
|
7086 | function baseSet(object, path, value, customizer) {
|
7087 | path = isKey(path, object) ? [path + ''] : baseCastPath(path);
|
7088 |
|
7089 | var index = -1,
|
7090 | length = path.length,
|
7091 | lastIndex = length - 1,
|
7092 | nested = object;
|
7093 |
|
7094 | while (nested != null && ++index < length) {
|
7095 | var key = path[index];
|
7096 | if (isObject(nested)) {
|
7097 | var newValue = value;
|
7098 | if (index != lastIndex) {
|
7099 | var objValue = nested[key];
|
7100 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
7101 | if (newValue === undefined) {
|
7102 | newValue = objValue == null
|
7103 | ? (isIndex(path[index + 1]) ? [] : {})
|
7104 | : objValue;
|
7105 | }
|
7106 | }
|
7107 | assignValue(nested, key, newValue);
|
7108 | }
|
7109 | nested = nested[key];
|
7110 | }
|
7111 | return object;
|
7112 | }
|
7113 |
|
7114 | |
7115 |
|
7116 |
|
7117 |
|
7118 |
|
7119 |
|
7120 |
|
7121 |
|
7122 | var baseSetData = !metaMap ? identity : function(func, data) {
|
7123 | metaMap.set(func, data);
|
7124 | return func;
|
7125 | };
|
7126 |
|
7127 | |
7128 |
|
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 | function baseSlice(array, start, end) {
|
7137 | var index = -1,
|
7138 | length = array.length;
|
7139 |
|
7140 | if (start < 0) {
|
7141 | start = -start > length ? 0 : (length + start);
|
7142 | }
|
7143 | end = end > length ? length : end;
|
7144 | if (end < 0) {
|
7145 | end += length;
|
7146 | }
|
7147 | length = start > end ? 0 : ((end - start) >>> 0);
|
7148 | start >>>= 0;
|
7149 |
|
7150 | var result = Array(length);
|
7151 | while (++index < length) {
|
7152 | result[index] = array[index + start];
|
7153 | }
|
7154 | return result;
|
7155 | }
|
7156 |
|
7157 | |
7158 |
|
7159 |
|
7160 |
|
7161 |
|
7162 |
|
7163 |
|
7164 |
|
7165 | function baseSome(collection, predicate) {
|
7166 | var result;
|
7167 |
|
7168 | baseEach(collection, function(value, index, collection) {
|
7169 | result = predicate(value, index, collection);
|
7170 | return !result;
|
7171 | });
|
7172 | return !!result;
|
7173 | }
|
7174 |
|
7175 | |
7176 |
|
7177 |
|
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 |
|
7183 |
|
7184 |
|
7185 |
|
7186 |
|
7187 | function baseSortedIndex(array, value, retHighest) {
|
7188 | var low = 0,
|
7189 | high = array ? array.length : low;
|
7190 |
|
7191 | if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
|
7192 | while (low < high) {
|
7193 | var mid = (low + high) >>> 1,
|
7194 | computed = array[mid];
|
7195 |
|
7196 | if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
|
7197 | low = mid + 1;
|
7198 | } else {
|
7199 | high = mid;
|
7200 | }
|
7201 | }
|
7202 | return high;
|
7203 | }
|
7204 | return baseSortedIndexBy(array, value, identity, retHighest);
|
7205 | }
|
7206 |
|
7207 | |
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 | function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
7220 | value = iteratee(value);
|
7221 |
|
7222 | var low = 0,
|
7223 | high = array ? array.length : 0,
|
7224 | valIsNaN = value !== value,
|
7225 | valIsNull = value === null,
|
7226 | valIsUndef = value === undefined;
|
7227 |
|
7228 | while (low < high) {
|
7229 | var mid = nativeFloor((low + high) / 2),
|
7230 | computed = iteratee(array[mid]),
|
7231 | isDef = computed !== undefined,
|
7232 | isReflexive = computed === computed;
|
7233 |
|
7234 | if (valIsNaN) {
|
7235 | var setLow = isReflexive || retHighest;
|
7236 | } else if (valIsNull) {
|
7237 | setLow = isReflexive && isDef && (retHighest || computed != null);
|
7238 | } else if (valIsUndef) {
|
7239 | setLow = isReflexive && (retHighest || isDef);
|
7240 | } else if (computed == null) {
|
7241 | setLow = false;
|
7242 | } else {
|
7243 | setLow = retHighest ? (computed <= value) : (computed < value);
|
7244 | }
|
7245 | if (setLow) {
|
7246 | low = mid + 1;
|
7247 | } else {
|
7248 | high = mid;
|
7249 | }
|
7250 | }
|
7251 | return nativeMin(high, MAX_ARRAY_INDEX);
|
7252 | }
|
7253 |
|
7254 | |
7255 |
|
7256 |
|
7257 |
|
7258 |
|
7259 |
|
7260 |
|
7261 | function baseSortedUniq(array) {
|
7262 | return baseSortedUniqBy(array);
|
7263 | }
|
7264 |
|
7265 | |
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 | function baseSortedUniqBy(array, iteratee) {
|
7275 | var index = 0,
|
7276 | length = array.length,
|
7277 | value = array[0],
|
7278 | computed = iteratee ? iteratee(value) : value,
|
7279 | seen = computed,
|
7280 | resIndex = 1,
|
7281 | result = [value];
|
7282 |
|
7283 | while (++index < length) {
|
7284 | value = array[index],
|
7285 | computed = iteratee ? iteratee(value) : value;
|
7286 |
|
7287 | if (!eq(computed, seen)) {
|
7288 | seen = computed;
|
7289 | result[resIndex++] = value;
|
7290 | }
|
7291 | }
|
7292 | return result;
|
7293 | }
|
7294 |
|
7295 | |
7296 |
|
7297 |
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 |
|
7303 |
|
7304 | function baseUniq(array, iteratee, comparator) {
|
7305 | var index = -1,
|
7306 | includes = arrayIncludes,
|
7307 | length = array.length,
|
7308 | isCommon = true,
|
7309 | result = [],
|
7310 | seen = result;
|
7311 |
|
7312 | if (comparator) {
|
7313 | isCommon = false;
|
7314 | includes = arrayIncludesWith;
|
7315 | }
|
7316 | else if (length >= LARGE_ARRAY_SIZE) {
|
7317 | var set = iteratee ? null : createSet(array);
|
7318 | if (set) {
|
7319 | return setToArray(set);
|
7320 | }
|
7321 | isCommon = false;
|
7322 | includes = cacheHas;
|
7323 | seen = new SetCache;
|
7324 | }
|
7325 | else {
|
7326 | seen = iteratee ? [] : result;
|
7327 | }
|
7328 | outer:
|
7329 | while (++index < length) {
|
7330 | var value = array[index],
|
7331 | computed = iteratee ? iteratee(value) : value;
|
7332 |
|
7333 | if (isCommon && computed === computed) {
|
7334 | var seenIndex = seen.length;
|
7335 | while (seenIndex--) {
|
7336 | if (seen[seenIndex] === computed) {
|
7337 | continue outer;
|
7338 | }
|
7339 | }
|
7340 | if (iteratee) {
|
7341 | seen.push(computed);
|
7342 | }
|
7343 | result.push(value);
|
7344 | }
|
7345 | else if (!includes(seen, computed, comparator)) {
|
7346 | if (seen !== result) {
|
7347 | seen.push(computed);
|
7348 | }
|
7349 | result.push(value);
|
7350 | }
|
7351 | }
|
7352 | return result;
|
7353 | }
|
7354 |
|
7355 | |
7356 |
|
7357 |
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 | function baseUnset(object, path) {
|
7364 | path = isKey(path, object) ? [path + ''] : baseCastPath(path);
|
7365 | object = parent(object, path);
|
7366 | var key = last(path);
|
7367 | return (object != null && has(object, key)) ? delete object[key] : true;
|
7368 | }
|
7369 |
|
7370 | |
7371 |
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 | function baseUpdate(object, path, updater, customizer) {
|
7381 | return baseSet(object, path, updater(baseGet(object, path)), customizer);
|
7382 | }
|
7383 |
|
7384 | |
7385 |
|
7386 |
|
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 | function baseWhile(array, predicate, isDrop, fromRight) {
|
7396 | var length = array.length,
|
7397 | index = fromRight ? length : -1;
|
7398 |
|
7399 | while ((fromRight ? index-- : ++index < length) &&
|
7400 | predicate(array[index], index, array)) {}
|
7401 |
|
7402 | return isDrop
|
7403 | ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
7404 | : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
|
7405 | }
|
7406 |
|
7407 | |
7408 |
|
7409 |
|
7410 |
|
7411 |
|
7412 |
|
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 | function baseWrapperValue(value, actions) {
|
7418 | var result = value;
|
7419 | if (result instanceof LazyWrapper) {
|
7420 | result = result.value();
|
7421 | }
|
7422 | return arrayReduce(actions, function(result, action) {
|
7423 | return action.func.apply(action.thisArg, arrayPush([result], action.args));
|
7424 | }, result);
|
7425 | }
|
7426 |
|
7427 | |
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 |
|
7433 |
|
7434 |
|
7435 |
|
7436 |
|
7437 | function baseXor(arrays, iteratee, comparator) {
|
7438 | var index = -1,
|
7439 | length = arrays.length;
|
7440 |
|
7441 | while (++index < length) {
|
7442 | var result = result
|
7443 | ? arrayPush(
|
7444 | baseDifference(result, arrays[index], iteratee, comparator),
|
7445 | baseDifference(arrays[index], result, iteratee, comparator)
|
7446 | )
|
7447 | : arrays[index];
|
7448 | }
|
7449 | return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
|
7450 | }
|
7451 |
|
7452 | |
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 | function baseZipObject(props, values, assignFunc) {
|
7462 | var index = -1,
|
7463 | length = props.length,
|
7464 | valsLength = values.length,
|
7465 | result = {};
|
7466 |
|
7467 | while (++index < length) {
|
7468 | assignFunc(result, props[index], index < valsLength ? values[index] : undefined);
|
7469 | }
|
7470 | return result;
|
7471 | }
|
7472 |
|
7473 | |
7474 |
|
7475 |
|
7476 |
|
7477 |
|
7478 |
|
7479 |
|
7480 |
|
7481 | function cloneBuffer(buffer, isDeep) {
|
7482 | if (isDeep) {
|
7483 | return buffer.slice();
|
7484 | }
|
7485 | var result = new buffer.constructor(buffer.length);
|
7486 | buffer.copy(result);
|
7487 | return result;
|
7488 | }
|
7489 |
|
7490 | |
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 | function cloneArrayBuffer(arrayBuffer) {
|
7498 | var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
7499 | new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
7500 | return result;
|
7501 | }
|
7502 |
|
7503 | |
7504 |
|
7505 |
|
7506 |
|
7507 |
|
7508 |
|
7509 |
|
7510 | function cloneMap(map) {
|
7511 | return arrayReduce(mapToArray(map), addMapEntry, new map.constructor);
|
7512 | }
|
7513 |
|
7514 | |
7515 |
|
7516 |
|
7517 |
|
7518 |
|
7519 |
|
7520 |
|
7521 | function cloneRegExp(regexp) {
|
7522 | var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
7523 | result.lastIndex = regexp.lastIndex;
|
7524 | return result;
|
7525 | }
|
7526 |
|
7527 | |
7528 |
|
7529 |
|
7530 |
|
7531 |
|
7532 |
|
7533 |
|
7534 | function cloneSet(set) {
|
7535 | return arrayReduce(setToArray(set), addSetEntry, new set.constructor);
|
7536 | }
|
7537 |
|
7538 | /**
|
7539 | * Creates a clone of the `symbol` object.
|
7540 | *
|
7541 | * @private
|
7542 | * @param {Object} symbol The symbol object to clone.
|
7543 | * @returns {Object} Returns the cloned symbol object.
|
7544 | */
|
7545 | function cloneSymbol(symbol) {
|
7546 | return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
7547 | }
|
7548 |
|
7549 | |
7550 |
|
7551 |
|
7552 |
|
7553 |
|
7554 |
|
7555 |
|
7556 |
|
7557 | function cloneTypedArray(typedArray, isDeep) {
|
7558 | var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
7559 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
7560 | }
|
7561 |
|
7562 | |
7563 |
|
7564 |
|
7565 |
|
7566 |
|
7567 |
|
7568 |
|
7569 |
|
7570 |
|
7571 |
|
7572 |
|
7573 | function composeArgs(args, partials, holders, isCurried) {
|
7574 | var argsIndex = -1,
|
7575 | argsLength = args.length,
|
7576 | holdersLength = holders.length,
|
7577 | leftIndex = -1,
|
7578 | leftLength = partials.length,
|
7579 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
7580 | result = Array(leftLength + rangeLength),
|
7581 | isUncurried = !isCurried;
|
7582 |
|
7583 | while (++leftIndex < leftLength) {
|
7584 | result[leftIndex] = partials[leftIndex];
|
7585 | }
|
7586 | while (++argsIndex < holdersLength) {
|
7587 | if (isUncurried || argsIndex < argsLength) {
|
7588 | result[holders[argsIndex]] = args[argsIndex];
|
7589 | }
|
7590 | }
|
7591 | while (rangeLength--) {
|
7592 | result[leftIndex++] = args[argsIndex++];
|
7593 | }
|
7594 | return result;
|
7595 | }
|
7596 |
|
7597 | |
7598 |
|
7599 |
|
7600 |
|
7601 |
|
7602 |
|
7603 |
|
7604 |
|
7605 |
|
7606 |
|
7607 |
|
7608 | function composeArgsRight(args, partials, holders, isCurried) {
|
7609 | var argsIndex = -1,
|
7610 | argsLength = args.length,
|
7611 | holdersIndex = -1,
|
7612 | holdersLength = holders.length,
|
7613 | rightIndex = -1,
|
7614 | rightLength = partials.length,
|
7615 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
7616 | result = Array(rangeLength + rightLength),
|
7617 | isUncurried = !isCurried;
|
7618 |
|
7619 | while (++argsIndex < rangeLength) {
|
7620 | result[argsIndex] = args[argsIndex];
|
7621 | }
|
7622 | var offset = argsIndex;
|
7623 | while (++rightIndex < rightLength) {
|
7624 | result[offset + rightIndex] = partials[rightIndex];
|
7625 | }
|
7626 | while (++holdersIndex < holdersLength) {
|
7627 | if (isUncurried || argsIndex < argsLength) {
|
7628 | result[offset + holders[holdersIndex]] = args[argsIndex++];
|
7629 | }
|
7630 | }
|
7631 | return result;
|
7632 | }
|
7633 |
|
7634 | |
7635 |
|
7636 |
|
7637 |
|
7638 |
|
7639 |
|
7640 |
|
7641 |
|
7642 | function copyArray(source, array) {
|
7643 | var index = -1,
|
7644 | length = source.length;
|
7645 |
|
7646 | array || (array = Array(length));
|
7647 | while (++index < length) {
|
7648 | array[index] = source[index];
|
7649 | }
|
7650 | return array;
|
7651 | }
|
7652 |
|
7653 | |
7654 |
|
7655 |
|
7656 |
|
7657 |
|
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 | function copyObject(source, props, object) {
|
7663 | return copyObjectWith(source, props, object);
|
7664 | }
|
7665 |
|
7666 | |
7667 |
|
7668 |
|
7669 |
|
7670 |
|
7671 |
|
7672 |
|
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 | function copyObjectWith(source, props, object, customizer) {
|
7678 | object || (object = {});
|
7679 |
|
7680 | var index = -1,
|
7681 | length = props.length;
|
7682 |
|
7683 | while (++index < length) {
|
7684 | var key = props[index];
|
7685 |
|
7686 | var newValue = customizer
|
7687 | ? customizer(object[key], source[key], key, object, source)
|
7688 | : source[key];
|
7689 |
|
7690 | assignValue(object, key, newValue);
|
7691 | }
|
7692 | return object;
|
7693 | }
|
7694 |
|
7695 | |
7696 |
|
7697 |
|
7698 |
|
7699 |
|
7700 |
|
7701 |
|
7702 |
|
7703 | function copySymbols(source, object) {
|
7704 | return copyObject(source, getSymbols(source), object);
|
7705 | }
|
7706 |
|
7707 | |
7708 |
|
7709 |
|
7710 |
|
7711 |
|
7712 |
|
7713 |
|
7714 |
|
7715 | function createAggregator(setter, initializer) {
|
7716 | return function(collection, iteratee) {
|
7717 | var func = isArray(collection) ? arrayAggregator : baseAggregator,
|
7718 | accumulator = initializer ? initializer() : {};
|
7719 |
|
7720 | return func(collection, setter, getIteratee(iteratee), accumulator);
|
7721 | };
|
7722 | }
|
7723 |
|
7724 | |
7725 |
|
7726 |
|
7727 |
|
7728 |
|
7729 |
|
7730 |
|
7731 | function createAssigner(assigner) {
|
7732 | return rest(function(object, sources) {
|
7733 | var index = -1,
|
7734 | length = sources.length,
|
7735 | customizer = length > 1 ? sources[length - 1] : undefined,
|
7736 | guard = length > 2 ? sources[2] : undefined;
|
7737 |
|
7738 | customizer = typeof customizer == 'function'
|
7739 | ? (length--, customizer)
|
7740 | : undefined;
|
7741 |
|
7742 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
7743 | customizer = length < 3 ? undefined : customizer;
|
7744 | length = 1;
|
7745 | }
|
7746 | object = Object(object);
|
7747 | while (++index < length) {
|
7748 | var source = sources[index];
|
7749 | if (source) {
|
7750 | assigner(object, source, index, customizer);
|
7751 | }
|
7752 | }
|
7753 | return object;
|
7754 | });
|
7755 | }
|
7756 |
|
7757 | |
7758 |
|
7759 |
|
7760 |
|
7761 |
|
7762 |
|
7763 |
|
7764 |
|
7765 | function createBaseEach(eachFunc, fromRight) {
|
7766 | return function(collection, iteratee) {
|
7767 | if (collection == null) {
|
7768 | return collection;
|
7769 | }
|
7770 | if (!isArrayLike(collection)) {
|
7771 | return eachFunc(collection, iteratee);
|
7772 | }
|
7773 | var length = collection.length,
|
7774 | index = fromRight ? length : -1,
|
7775 | iterable = Object(collection);
|
7776 |
|
7777 | while ((fromRight ? index-- : ++index < length)) {
|
7778 | if (iteratee(iterable[index], index, iterable) === false) {
|
7779 | break;
|
7780 | }
|
7781 | }
|
7782 | return collection;
|
7783 | };
|
7784 | }
|
7785 |
|
7786 | |
7787 |
|
7788 |
|
7789 |
|
7790 |
|
7791 |
|
7792 |
|
7793 | function createBaseFor(fromRight) {
|
7794 | return function(object, iteratee, keysFunc) {
|
7795 | var index = -1,
|
7796 | iterable = Object(object),
|
7797 | props = keysFunc(object),
|
7798 | length = props.length;
|
7799 |
|
7800 | while (length--) {
|
7801 | var key = props[fromRight ? length : ++index];
|
7802 | if (iteratee(iterable[key], key, iterable) === false) {
|
7803 | break;
|
7804 | }
|
7805 | }
|
7806 | return object;
|
7807 | };
|
7808 | }
|
7809 |
|
7810 | |
7811 |
|
7812 |
|
7813 |
|
7814 |
|
7815 |
|
7816 |
|
7817 |
|
7818 |
|
7819 |
|
7820 | function createBaseWrapper(func, bitmask, thisArg) {
|
7821 | var isBind = bitmask & BIND_FLAG,
|
7822 | Ctor = createCtorWrapper(func);
|
7823 |
|
7824 | function wrapper() {
|
7825 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
7826 | return fn.apply(isBind ? thisArg : this, arguments);
|
7827 | }
|
7828 | return wrapper;
|
7829 | }
|
7830 |
|
7831 | |
7832 |
|
7833 |
|
7834 |
|
7835 |
|
7836 |
|
7837 |
|
7838 | function createCaseFirst(methodName) {
|
7839 | return function(string) {
|
7840 | string = toString(string);
|
7841 |
|
7842 | var strSymbols = reHasComplexSymbol.test(string)
|
7843 | ? stringToArray(string)
|
7844 | : undefined;
|
7845 |
|
7846 | var chr = strSymbols ? strSymbols[0] : string.charAt(0),
|
7847 | trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1);
|
7848 |
|
7849 | return chr[methodName]() + trailing;
|
7850 | };
|
7851 | }
|
7852 |
|
7853 | |
7854 |
|
7855 |
|
7856 |
|
7857 |
|
7858 |
|
7859 |
|
7860 | function createCompounder(callback) {
|
7861 | return function(string) {
|
7862 | return arrayReduce(words(deburr(string)), callback, '');
|
7863 | };
|
7864 | }
|
7865 |
|
7866 | |
7867 |
|
7868 |
|
7869 |
|
7870 |
|
7871 |
|
7872 |
|
7873 |
|
7874 | function createCtorWrapper(Ctor) {
|
7875 | return function() {
|
7876 |
|
7877 |
|
7878 |
|
7879 | var args = arguments;
|
7880 | switch (args.length) {
|
7881 | case 0: return new Ctor;
|
7882 | case 1: return new Ctor(args[0]);
|
7883 | case 2: return new Ctor(args[0], args[1]);
|
7884 | case 3: return new Ctor(args[0], args[1], args[2]);
|
7885 | case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
7886 | case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
7887 | case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
7888 | case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
7889 | }
|
7890 | var thisBinding = baseCreate(Ctor.prototype),
|
7891 | result = Ctor.apply(thisBinding, args);
|
7892 |
|
7893 |
|
7894 |
|
7895 | return isObject(result) ? result : thisBinding;
|
7896 | };
|
7897 | }
|
7898 |
|
7899 | |
7900 |
|
7901 |
|
7902 |
|
7903 |
|
7904 |
|
7905 |
|
7906 |
|
7907 |
|
7908 | function createCurryWrapper(func, bitmask, arity) {
|
7909 | var Ctor = createCtorWrapper(func);
|
7910 |
|
7911 | function wrapper() {
|
7912 | var length = arguments.length,
|
7913 | args = Array(length),
|
7914 | index = length,
|
7915 | placeholder = getPlaceholder(wrapper);
|
7916 |
|
7917 | while (index--) {
|
7918 | args[index] = arguments[index];
|
7919 | }
|
7920 | var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
7921 | ? []
|
7922 | : replaceHolders(args, placeholder);
|
7923 |
|
7924 | length -= holders.length;
|
7925 | if (length < arity) {
|
7926 | return createRecurryWrapper(
|
7927 | func, bitmask, createHybridWrapper, wrapper.placeholder, undefined,
|
7928 | args, holders, undefined, undefined, arity - length);
|
7929 | }
|
7930 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
7931 | return apply(fn, this, args);
|
7932 | }
|
7933 | return wrapper;
|
7934 | }
|
7935 |
|
7936 | |
7937 |
|
7938 |
|
7939 |
|
7940 |
|
7941 |
|
7942 |
|
7943 | function createFlow(fromRight) {
|
7944 | return rest(function(funcs) {
|
7945 | funcs = baseFlatten(funcs, 1);
|
7946 |
|
7947 | var length = funcs.length,
|
7948 | index = length,
|
7949 | prereq = LodashWrapper.prototype.thru;
|
7950 |
|
7951 | if (fromRight) {
|
7952 | funcs.reverse();
|
7953 | }
|
7954 | while (index--) {
|
7955 | var func = funcs[index];
|
7956 | if (typeof func != 'function') {
|
7957 | throw new TypeError(FUNC_ERROR_TEXT);
|
7958 | }
|
7959 | if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
|
7960 | var wrapper = new LodashWrapper([], true);
|
7961 | }
|
7962 | }
|
7963 | index = wrapper ? index : length;
|
7964 | while (++index < length) {
|
7965 | func = funcs[index];
|
7966 |
|
7967 | var funcName = getFuncName(func),
|
7968 | data = funcName == 'wrapper' ? getData(func) : undefined;
|
7969 |
|
7970 | if (data && isLaziable(data[0]) &&
|
7971 | data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
|
7972 | !data[4].length && data[9] == 1
|
7973 | ) {
|
7974 | wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
7975 | } else {
|
7976 | wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
|
7977 | }
|
7978 | }
|
7979 | return function() {
|
7980 | var args = arguments,
|
7981 | value = args[0];
|
7982 |
|
7983 | if (wrapper && args.length == 1 &&
|
7984 | isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
|
7985 | return wrapper.plant(value).value();
|
7986 | }
|
7987 | var index = 0,
|
7988 | result = length ? funcs[index].apply(this, args) : value;
|
7989 |
|
7990 | while (++index < length) {
|
7991 | result = funcs[index].call(this, result);
|
7992 | }
|
7993 | return result;
|
7994 | };
|
7995 | });
|
7996 | }
|
7997 |
|
7998 | |
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 |
|
8005 |
|
8006 |
|
8007 |
|
8008 |
|
8009 |
|
8010 |
|
8011 |
|
8012 |
|
8013 |
|
8014 |
|
8015 | function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
|
8016 | var isAry = bitmask & ARY_FLAG,
|
8017 | isBind = bitmask & BIND_FLAG,
|
8018 | isBindKey = bitmask & BIND_KEY_FLAG,
|
8019 | isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
|
8020 | isFlip = bitmask & FLIP_FLAG,
|
8021 | Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
8022 |
|
8023 | function wrapper() {
|
8024 | var length = arguments.length,
|
8025 | index = length,
|
8026 | args = Array(length);
|
8027 |
|
8028 | while (index--) {
|
8029 | args[index] = arguments[index];
|
8030 | }
|
8031 | if (isCurried) {
|
8032 | var placeholder = getPlaceholder(wrapper),
|
8033 | holdersCount = countHolders(args, placeholder);
|
8034 | }
|
8035 | if (partials) {
|
8036 | args = composeArgs(args, partials, holders, isCurried);
|
8037 | }
|
8038 | if (partialsRight) {
|
8039 | args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
|
8040 | }
|
8041 | length -= holdersCount;
|
8042 | if (isCurried && length < arity) {
|
8043 | var newHolders = replaceHolders(args, placeholder);
|
8044 | return createRecurryWrapper(
|
8045 | func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg,
|
8046 | args, newHolders, argPos, ary, arity - length
|
8047 | );
|
8048 | }
|
8049 | var thisBinding = isBind ? thisArg : this,
|
8050 | fn = isBindKey ? thisBinding[func] : func;
|
8051 |
|
8052 | length = args.length;
|
8053 | if (argPos) {
|
8054 | args = reorder(args, argPos);
|
8055 | } else if (isFlip && length > 1) {
|
8056 | args.reverse();
|
8057 | }
|
8058 | if (isAry && ary < length) {
|
8059 | args.length = ary;
|
8060 | }
|
8061 | if (this && this !== root && this instanceof wrapper) {
|
8062 | fn = Ctor || createCtorWrapper(fn);
|
8063 | }
|
8064 | return fn.apply(thisBinding, args);
|
8065 | }
|
8066 | return wrapper;
|
8067 | }
|
8068 |
|
8069 | |
8070 |
|
8071 |
|
8072 |
|
8073 |
|
8074 |
|
8075 |
|
8076 |
|
8077 | function createInverter(setter, toIteratee) {
|
8078 | return function(object, iteratee) {
|
8079 | return baseInverter(object, setter, toIteratee(iteratee), {});
|
8080 | };
|
8081 | }
|
8082 |
|
8083 | |
8084 |
|
8085 |
|
8086 |
|
8087 |
|
8088 |
|
8089 |
|
8090 | function createOver(arrayFunc) {
|
8091 | return rest(function(iteratees) {
|
8092 | iteratees = arrayMap(baseFlatten(iteratees, 1), getIteratee());
|
8093 | return rest(function(args) {
|
8094 | var thisArg = this;
|
8095 | return arrayFunc(iteratees, function(iteratee) {
|
8096 | return apply(iteratee, thisArg, args);
|
8097 | });
|
8098 | });
|
8099 | });
|
8100 | }
|
8101 |
|
8102 | |
8103 |
|
8104 |
|
8105 |
|
8106 |
|
8107 |
|
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 | function createPadding(string, length, chars) {
|
8113 | length = toInteger(length);
|
8114 |
|
8115 | var strLength = stringSize(string);
|
8116 | if (!length || strLength >= length) {
|
8117 | return '';
|
8118 | }
|
8119 | var padLength = length - strLength;
|
8120 | chars = chars === undefined ? ' ' : (chars + '');
|
8121 |
|
8122 | var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
|
8123 | return reHasComplexSymbol.test(chars)
|
8124 | ? stringToArray(result).slice(0, padLength).join('')
|
8125 | : result.slice(0, padLength);
|
8126 | }
|
8127 |
|
8128 | |
8129 |
|
8130 |
|
8131 |
|
8132 |
|
8133 |
|
8134 |
|
8135 |
|
8136 |
|
8137 |
|
8138 |
|
8139 |
|
8140 | function createPartialWrapper(func, bitmask, thisArg, partials) {
|
8141 | var isBind = bitmask & BIND_FLAG,
|
8142 | Ctor = createCtorWrapper(func);
|
8143 |
|
8144 | function wrapper() {
|
8145 | var argsIndex = -1,
|
8146 | argsLength = arguments.length,
|
8147 | leftIndex = -1,
|
8148 | leftLength = partials.length,
|
8149 | args = Array(leftLength + argsLength),
|
8150 | fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
8151 |
|
8152 | while (++leftIndex < leftLength) {
|
8153 | args[leftIndex] = partials[leftIndex];
|
8154 | }
|
8155 | while (argsLength--) {
|
8156 | args[leftIndex++] = arguments[++argsIndex];
|
8157 | }
|
8158 | return apply(fn, isBind ? thisArg : this, args);
|
8159 | }
|
8160 | return wrapper;
|
8161 | }
|
8162 |
|
8163 | |
8164 |
|
8165 |
|
8166 |
|
8167 |
|
8168 |
|
8169 |
|
8170 | function createRange(fromRight) {
|
8171 | return function(start, end, step) {
|
8172 | if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
8173 | end = step = undefined;
|
8174 | }
|
8175 |
|
8176 | start = toNumber(start);
|
8177 | start = start === start ? start : 0;
|
8178 | if (end === undefined) {
|
8179 | end = start;
|
8180 | start = 0;
|
8181 | } else {
|
8182 | end = toNumber(end) || 0;
|
8183 | }
|
8184 | step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
|
8185 | return baseRange(start, end, step, fromRight);
|
8186 | };
|
8187 | }
|
8188 |
|
8189 | |
8190 |
|
8191 |
|
8192 |
|
8193 |
|
8194 |
|
8195 |
|
8196 |
|
8197 |
|
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 |
|
8203 |
|
8204 |
|
8205 | function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
|
8206 | var isCurry = bitmask & CURRY_FLAG,
|
8207 | newArgPos = argPos ? copyArray(argPos) : undefined,
|
8208 | newHolders = isCurry ? holders : undefined,
|
8209 | newHoldersRight = isCurry ? undefined : holders,
|
8210 | newPartials = isCurry ? partials : undefined,
|
8211 | newPartialsRight = isCurry ? undefined : partials;
|
8212 |
|
8213 | bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
|
8214 | bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
|
8215 |
|
8216 | if (!(bitmask & CURRY_BOUND_FLAG)) {
|
8217 | bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
|
8218 | }
|
8219 | var newData = [
|
8220 | func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
|
8221 | newHoldersRight, newArgPos, ary, arity
|
8222 | ];
|
8223 |
|
8224 | var result = wrapFunc.apply(undefined, newData);
|
8225 | if (isLaziable(func)) {
|
8226 | setData(result, newData);
|
8227 | }
|
8228 | result.placeholder = placeholder;
|
8229 | return result;
|
8230 | }
|
8231 |
|
8232 | |
8233 |
|
8234 |
|
8235 |
|
8236 |
|
8237 |
|
8238 |
|
8239 | function createRound(methodName) {
|
8240 | var func = Math[methodName];
|
8241 | return function(number, precision) {
|
8242 | number = toNumber(number);
|
8243 | precision = toInteger(precision);
|
8244 | if (precision) {
|
8245 |
|
8246 |
|
8247 | var pair = (toString(number) + 'e').split('e'),
|
8248 | value = func(pair[0] + 'e' + (+pair[1] + precision));
|
8249 |
|
8250 | pair = (toString(value) + 'e').split('e');
|
8251 | return +(pair[0] + 'e' + (+pair[1] - precision));
|
8252 | }
|
8253 | return func(number);
|
8254 | };
|
8255 | }
|
8256 |
|
8257 | |
8258 |
|
8259 |
|
8260 |
|
8261 |
|
8262 |
|
8263 |
|
8264 | var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) {
|
8265 | return new Set(values);
|
8266 | };
|
8267 |
|
8268 | |
8269 |
|
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 |
|
8275 |
|
8276 |
|
8277 |
|
8278 |
|
8279 |
|
8280 |
|
8281 |
|
8282 |
|
8283 |
|
8284 |
|
8285 |
|
8286 |
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 |
|
8293 | function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
8294 | var isBindKey = bitmask & BIND_KEY_FLAG;
|
8295 | if (!isBindKey && typeof func != 'function') {
|
8296 | throw new TypeError(FUNC_ERROR_TEXT);
|
8297 | }
|
8298 | var length = partials ? partials.length : 0;
|
8299 | if (!length) {
|
8300 | bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
8301 | partials = holders = undefined;
|
8302 | }
|
8303 | ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
|
8304 | arity = arity === undefined ? arity : toInteger(arity);
|
8305 | length -= holders ? holders.length : 0;
|
8306 |
|
8307 | if (bitmask & PARTIAL_RIGHT_FLAG) {
|
8308 | var partialsRight = partials,
|
8309 | holdersRight = holders;
|
8310 |
|
8311 | partials = holders = undefined;
|
8312 | }
|
8313 | var data = isBindKey ? undefined : getData(func);
|
8314 |
|
8315 | var newData = [
|
8316 | func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
|
8317 | argPos, ary, arity
|
8318 | ];
|
8319 |
|
8320 | if (data) {
|
8321 | mergeData(newData, data);
|
8322 | }
|
8323 | func = newData[0];
|
8324 | bitmask = newData[1];
|
8325 | thisArg = newData[2];
|
8326 | partials = newData[3];
|
8327 | holders = newData[4];
|
8328 | arity = newData[9] = newData[9] == null
|
8329 | ? (isBindKey ? 0 : func.length)
|
8330 | : nativeMax(newData[9] - length, 0);
|
8331 |
|
8332 | if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
|
8333 | bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
|
8334 | }
|
8335 | if (!bitmask || bitmask == BIND_FLAG) {
|
8336 | var result = createBaseWrapper(func, bitmask, thisArg);
|
8337 | } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
|
8338 | result = createCurryWrapper(func, bitmask, arity);
|
8339 | } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
|
8340 | result = createPartialWrapper(func, bitmask, thisArg, partials);
|
8341 | } else {
|
8342 | result = createHybridWrapper.apply(undefined, newData);
|
8343 | }
|
8344 | var setter = data ? baseSetData : setData;
|
8345 | return setter(result, newData);
|
8346 | }
|
8347 |
|
8348 | |
8349 |
|
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 |
|
8357 |
|
8358 |
|
8359 |
|
8360 |
|
8361 | function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
|
8362 | var index = -1,
|
8363 | isPartial = bitmask & PARTIAL_COMPARE_FLAG,
|
8364 | isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
|
8365 | arrLength = array.length,
|
8366 | othLength = other.length;
|
8367 |
|
8368 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
8369 | return false;
|
8370 | }
|
8371 |
|
8372 | var stacked = stack.get(array);
|
8373 | if (stacked) {
|
8374 | return stacked == other;
|
8375 | }
|
8376 | var result = true;
|
8377 | stack.set(array, other);
|
8378 |
|
8379 |
|
8380 | while (++index < arrLength) {
|
8381 | var arrValue = array[index],
|
8382 | othValue = other[index];
|
8383 |
|
8384 | if (customizer) {
|
8385 | var compared = isPartial
|
8386 | ? customizer(othValue, arrValue, index, other, array, stack)
|
8387 | : customizer(arrValue, othValue, index, array, other, stack);
|
8388 | }
|
8389 | if (compared !== undefined) {
|
8390 | if (compared) {
|
8391 | continue;
|
8392 | }
|
8393 | result = false;
|
8394 | break;
|
8395 | }
|
8396 |
|
8397 | if (isUnordered) {
|
8398 | if (!arraySome(other, function(othValue) {
|
8399 | return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
|
8400 | })) {
|
8401 | result = false;
|
8402 | break;
|
8403 | }
|
8404 | } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
|
8405 | result = false;
|
8406 | break;
|
8407 | }
|
8408 | }
|
8409 | stack['delete'](array);
|
8410 | return result;
|
8411 | }
|
8412 |
|
8413 | |
8414 |
|
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 |
|
8429 |
|
8430 | function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
|
8431 | switch (tag) {
|
8432 | case arrayBufferTag:
|
8433 | if ((object.byteLength != other.byteLength) ||
|
8434 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
8435 | return false;
|
8436 | }
|
8437 | return true;
|
8438 |
|
8439 | case boolTag:
|
8440 | case dateTag:
|
8441 |
|
8442 |
|
8443 | return +object == +other;
|
8444 |
|
8445 | case errorTag:
|
8446 | return object.name == other.name && object.message == other.message;
|
8447 |
|
8448 | case numberTag:
|
8449 |
|
8450 | return (object != +object) ? other != +other : object == +other;
|
8451 |
|
8452 | case regexpTag:
|
8453 | case stringTag:
|
8454 |
|
8455 |
|
8456 | return object == (other + '');
|
8457 |
|
8458 | case mapTag:
|
8459 | var convert = mapToArray;
|
8460 |
|
8461 | case setTag:
|
8462 | var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
|
8463 | convert || (convert = setToArray);
|
8464 |
|
8465 | if (object.size != other.size && !isPartial) {
|
8466 | return false;
|
8467 | }
|
8468 |
|
8469 | var stacked = stack.get(object);
|
8470 | if (stacked) {
|
8471 | return stacked == other;
|
8472 | }
|
8473 |
|
8474 | return equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask | UNORDERED_COMPARE_FLAG, stack.set(object, other));
|
8475 |
|
8476 | case symbolTag:
|
8477 | if (symbolValueOf) {
|
8478 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
8479 | }
|
8480 | }
|
8481 | return false;
|
8482 | }
|
8483 |
|
8484 | |
8485 |
|
8486 |
|
8487 |
|
8488 |
|
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 |
|
8495 |
|
8496 |
|
8497 | function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
|
8498 | var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
|
8499 | objProps = keys(object),
|
8500 | objLength = objProps.length,
|
8501 | othProps = keys(other),
|
8502 | othLength = othProps.length;
|
8503 |
|
8504 | if (objLength != othLength && !isPartial) {
|
8505 | return false;
|
8506 | }
|
8507 | var index = objLength;
|
8508 | while (index--) {
|
8509 | var key = objProps[index];
|
8510 | if (!(isPartial ? key in other : baseHas(other, key))) {
|
8511 | return false;
|
8512 | }
|
8513 | }
|
8514 |
|
8515 | var stacked = stack.get(object);
|
8516 | if (stacked) {
|
8517 | return stacked == other;
|
8518 | }
|
8519 | var result = true;
|
8520 | stack.set(object, other);
|
8521 |
|
8522 | var skipCtor = isPartial;
|
8523 | while (++index < objLength) {
|
8524 | key = objProps[index];
|
8525 | var objValue = object[key],
|
8526 | othValue = other[key];
|
8527 |
|
8528 | if (customizer) {
|
8529 | var compared = isPartial
|
8530 | ? customizer(othValue, objValue, key, other, object, stack)
|
8531 | : customizer(objValue, othValue, key, object, other, stack);
|
8532 | }
|
8533 |
|
8534 | if (!(compared === undefined
|
8535 | ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
|
8536 | : compared
|
8537 | )) {
|
8538 | result = false;
|
8539 | break;
|
8540 | }
|
8541 | skipCtor || (skipCtor = key == 'constructor');
|
8542 | }
|
8543 | if (result && !skipCtor) {
|
8544 | var objCtor = object.constructor,
|
8545 | othCtor = other.constructor;
|
8546 |
|
8547 |
|
8548 | if (objCtor != othCtor &&
|
8549 | ('constructor' in object && 'constructor' in other) &&
|
8550 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
8551 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
8552 | result = false;
|
8553 | }
|
8554 | }
|
8555 | stack['delete'](object);
|
8556 | return result;
|
8557 | }
|
8558 |
|
8559 | |
8560 |
|
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 | var getData = !metaMap ? noop : function(func) {
|
8567 | return metaMap.get(func);
|
8568 | };
|
8569 |
|
8570 | |
8571 |
|
8572 |
|
8573 |
|
8574 |
|
8575 |
|
8576 |
|
8577 | function getFuncName(func) {
|
8578 | var result = (func.name + ''),
|
8579 | array = realNames[result],
|
8580 | length = hasOwnProperty.call(realNames, result) ? array.length : 0;
|
8581 |
|
8582 | while (length--) {
|
8583 | var data = array[length],
|
8584 | otherFunc = data.func;
|
8585 | if (otherFunc == null || otherFunc == func) {
|
8586 | return data.name;
|
8587 | }
|
8588 | }
|
8589 | return result;
|
8590 | }
|
8591 |
|
8592 | |
8593 |
|
8594 |
|
8595 |
|
8596 |
|
8597 |
|
8598 |
|
8599 |
|
8600 |
|
8601 |
|
8602 |
|
8603 | function getIteratee() {
|
8604 | var result = lodash.iteratee || iteratee;
|
8605 | result = result === iteratee ? baseIteratee : result;
|
8606 | return arguments.length ? result(arguments[0], arguments[1]) : result;
|
8607 | }
|
8608 |
|
8609 | |
8610 |
|
8611 |
|
8612 |
|
8613 |
|
8614 |
|
8615 |
|
8616 |
|
8617 |
|
8618 |
|
8619 | var getLength = baseProperty('length');
|
8620 |
|
8621 | |
8622 |
|
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 | function getMatchData(object) {
|
8629 | var result = toPairs(object),
|
8630 | length = result.length;
|
8631 |
|
8632 | while (length--) {
|
8633 | result[length][2] = isStrictComparable(result[length][1]);
|
8634 | }
|
8635 | return result;
|
8636 | }
|
8637 |
|
8638 | |
8639 |
|
8640 |
|
8641 |
|
8642 |
|
8643 |
|
8644 |
|
8645 |
|
8646 | function getNative(object, key) {
|
8647 | var value = object[key];
|
8648 | return isNative(value) ? value : undefined;
|
8649 | }
|
8650 |
|
8651 | |
8652 |
|
8653 |
|
8654 |
|
8655 |
|
8656 |
|
8657 |
|
8658 | function getPlaceholder(func) {
|
8659 | var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
|
8660 | return object.placeholder;
|
8661 | }
|
8662 |
|
8663 | |
8664 |
|
8665 |
|
8666 |
|
8667 |
|
8668 |
|
8669 |
|
8670 | var getSymbols = getOwnPropertySymbols || function() {
|
8671 | return [];
|
8672 | };
|
8673 |
|
8674 | |
8675 |
|
8676 |
|
8677 |
|
8678 |
|
8679 |
|
8680 |
|
8681 | function getTag(value) {
|
8682 | return objectToString.call(value);
|
8683 | }
|
8684 |
|
8685 |
|
8686 | if ((Map && getTag(new Map) != mapTag) ||
|
8687 | (Set && getTag(new Set) != setTag) ||
|
8688 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
8689 | getTag = function(value) {
|
8690 | var result = objectToString.call(value),
|
8691 | Ctor = result == objectTag ? value.constructor : null,
|
8692 | ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
|
8693 |
|
8694 | if (ctorString) {
|
8695 | switch (ctorString) {
|
8696 | case mapCtorString: return mapTag;
|
8697 | case setCtorString: return setTag;
|
8698 | case weakMapCtorString: return weakMapTag;
|
8699 | }
|
8700 | }
|
8701 | return result;
|
8702 | };
|
8703 | }
|
8704 |
|
8705 | |
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 |
|
8712 |
|
8713 |
|
8714 |
|
8715 | function getView(start, end, transforms) {
|
8716 | var index = -1,
|
8717 | length = transforms.length;
|
8718 |
|
8719 | while (++index < length) {
|
8720 | var data = transforms[index],
|
8721 | size = data.size;
|
8722 |
|
8723 | switch (data.type) {
|
8724 | case 'drop': start += size; break;
|
8725 | case 'dropRight': end -= size; break;
|
8726 | case 'take': end = nativeMin(end, start + size); break;
|
8727 | case 'takeRight': start = nativeMax(start, end - size); break;
|
8728 | }
|
8729 | }
|
8730 | return { 'start': start, 'end': end };
|
8731 | }
|
8732 |
|
8733 | |
8734 |
|
8735 |
|
8736 |
|
8737 |
|
8738 |
|
8739 |
|
8740 |
|
8741 |
|
8742 | function hasPath(object, path, hasFunc) {
|
8743 | if (object == null) {
|
8744 | return false;
|
8745 | }
|
8746 | var result = hasFunc(object, path);
|
8747 | if (!result && !isKey(path)) {
|
8748 | path = baseCastPath(path);
|
8749 | object = parent(object, path);
|
8750 | if (object != null) {
|
8751 | path = last(path);
|
8752 | result = hasFunc(object, path);
|
8753 | }
|
8754 | }
|
8755 | var length = object ? object.length : undefined;
|
8756 | return result || (
|
8757 | !!length && isLength(length) && isIndex(path, length) &&
|
8758 | (isArray(object) || isString(object) || isArguments(object))
|
8759 | );
|
8760 | }
|
8761 |
|
8762 | |
8763 |
|
8764 |
|
8765 |
|
8766 |
|
8767 |
|
8768 |
|
8769 | function initCloneArray(array) {
|
8770 | var length = array.length,
|
8771 | result = array.constructor(length);
|
8772 |
|
8773 |
|
8774 | if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
8775 | result.index = array.index;
|
8776 | result.input = array.input;
|
8777 | }
|
8778 | return result;
|
8779 | }
|
8780 |
|
8781 | |
8782 |
|
8783 |
|
8784 |
|
8785 |
|
8786 |
|
8787 |
|
8788 | function initCloneObject(object) {
|
8789 | return (typeof object.constructor == 'function' && !isPrototype(object))
|
8790 | ? baseCreate(getPrototypeOf(object))
|
8791 | : {};
|
8792 | }
|
8793 |
|
8794 | |
8795 |
|
8796 |
|
8797 |
|
8798 |
|
8799 |
|
8800 |
|
8801 |
|
8802 |
|
8803 |
|
8804 |
|
8805 |
|
8806 | function initCloneByTag(object, tag, isDeep) {
|
8807 | var Ctor = object.constructor;
|
8808 | switch (tag) {
|
8809 | case arrayBufferTag:
|
8810 | return cloneArrayBuffer(object);
|
8811 |
|
8812 | case boolTag:
|
8813 | case dateTag:
|
8814 | return new Ctor(+object);
|
8815 |
|
8816 | case float32Tag: case float64Tag:
|
8817 | case int8Tag: case int16Tag: case int32Tag:
|
8818 | case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
8819 | return cloneTypedArray(object, isDeep);
|
8820 |
|
8821 | case mapTag:
|
8822 | return cloneMap(object);
|
8823 |
|
8824 | case numberTag:
|
8825 | case stringTag:
|
8826 | return new Ctor(object);
|
8827 |
|
8828 | case regexpTag:
|
8829 | return cloneRegExp(object);
|
8830 |
|
8831 | case setTag:
|
8832 | return cloneSet(object);
|
8833 |
|
8834 | case symbolTag:
|
8835 | return cloneSymbol(object);
|
8836 | }
|
8837 | }
|
8838 |
|
8839 | |
8840 |
|
8841 |
|
8842 |
|
8843 |
|
8844 |
|
8845 |
|
8846 |
|
8847 | function indexKeys(object) {
|
8848 | var length = object ? object.length : undefined;
|
8849 | if (isLength(length) &&
|
8850 | (isArray(object) || isString(object) || isArguments(object))) {
|
8851 | return baseTimes(length, String);
|
8852 | }
|
8853 | return null;
|
8854 | }
|
8855 |
|
8856 | |
8857 |
|
8858 |
|
8859 |
|
8860 |
|
8861 |
|
8862 |
|
8863 |
|
8864 |
|
8865 | function isIterateeCall(value, index, object) {
|
8866 | if (!isObject(object)) {
|
8867 | return false;
|
8868 | }
|
8869 | var type = typeof index;
|
8870 | if (type == 'number'
|
8871 | ? (isArrayLike(object) && isIndex(index, object.length))
|
8872 | : (type == 'string' && index in object)) {
|
8873 | return eq(object[index], value);
|
8874 | }
|
8875 | return false;
|
8876 | }
|
8877 |
|
8878 | |
8879 |
|
8880 |
|
8881 |
|
8882 |
|
8883 |
|
8884 |
|
8885 |
|
8886 | function isKey(value, object) {
|
8887 | if (typeof value == 'number') {
|
8888 | return true;
|
8889 | }
|
8890 | return !isArray(value) &&
|
8891 | (reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
8892 | (object != null && value in Object(object)));
|
8893 | }
|
8894 |
|
8895 | |
8896 |
|
8897 |
|
8898 |
|
8899 |
|
8900 |
|
8901 |
|
8902 | function isKeyable(value) {
|
8903 | var type = typeof value;
|
8904 | return type == 'number' || type == 'boolean' ||
|
8905 | (type == 'string' && value != '__proto__') || value == null;
|
8906 | }
|
8907 |
|
8908 | |
8909 |
|
8910 |
|
8911 |
|
8912 |
|
8913 |
|
8914 |
|
8915 | function isLaziable(func) {
|
8916 | var funcName = getFuncName(func),
|
8917 | other = lodash[funcName];
|
8918 |
|
8919 | if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
|
8920 | return false;
|
8921 | }
|
8922 | if (func === other) {
|
8923 | return true;
|
8924 | }
|
8925 | var data = getData(other);
|
8926 | return !!data && func === data[0];
|
8927 | }
|
8928 |
|
8929 | |
8930 |
|
8931 |
|
8932 |
|
8933 |
|
8934 |
|
8935 |
|
8936 | function isPrototype(value) {
|
8937 | var Ctor = value && value.constructor,
|
8938 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
8939 |
|
8940 | return value === proto;
|
8941 | }
|
8942 |
|
8943 | |
8944 |
|
8945 |
|
8946 |
|
8947 |
|
8948 |
|
8949 |
|
8950 |
|
8951 | function isStrictComparable(value) {
|
8952 | return value === value && !isObject(value);
|
8953 | }
|
8954 |
|
8955 | |
8956 |
|
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 |
|
8963 |
|
8964 |
|
8965 |
|
8966 |
|
8967 |
|
8968 |
|
8969 |
|
8970 | function mergeData(data, source) {
|
8971 | var bitmask = data[1],
|
8972 | srcBitmask = source[1],
|
8973 | newBitmask = bitmask | srcBitmask,
|
8974 | isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
|
8975 |
|
8976 | var isCombo =
|
8977 | ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
|
8978 | ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
|
8979 | ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
|
8980 |
|
8981 |
|
8982 | if (!(isCommon || isCombo)) {
|
8983 | return data;
|
8984 | }
|
8985 |
|
8986 | if (srcBitmask & BIND_FLAG) {
|
8987 | data[2] = source[2];
|
8988 |
|
8989 | newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
|
8990 | }
|
8991 |
|
8992 | var value = source[3];
|
8993 | if (value) {
|
8994 | var partials = data[3];
|
8995 | data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value);
|
8996 | data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]);
|
8997 | }
|
8998 |
|
8999 | value = source[5];
|
9000 | if (value) {
|
9001 | partials = data[5];
|
9002 | data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value);
|
9003 | data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]);
|
9004 | }
|
9005 |
|
9006 | value = source[7];
|
9007 | if (value) {
|
9008 | data[7] = copyArray(value);
|
9009 | }
|
9010 |
|
9011 | if (srcBitmask & ARY_FLAG) {
|
9012 | data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
|
9013 | }
|
9014 |
|
9015 | if (data[9] == null) {
|
9016 | data[9] = source[9];
|
9017 | }
|
9018 |
|
9019 | data[0] = source[0];
|
9020 | data[1] = newBitmask;
|
9021 |
|
9022 | return data;
|
9023 | }
|
9024 |
|
9025 | |
9026 |
|
9027 |
|
9028 |
|
9029 |
|
9030 |
|
9031 |
|
9032 |
|
9033 |
|
9034 |
|
9035 |
|
9036 |
|
9037 | function mergeDefaults(objValue, srcValue, key, object, source, stack) {
|
9038 | if (isObject(objValue) && isObject(srcValue)) {
|
9039 | baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
|
9040 | }
|
9041 | return objValue;
|
9042 | }
|
9043 |
|
9044 | |
9045 |
|
9046 |
|
9047 |
|
9048 |
|
9049 |
|
9050 |
|
9051 |
|
9052 | function parent(object, path) {
|
9053 | return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
|
9054 | }
|
9055 |
|
9056 | /**
|
9057 | * Reorder `array` according to the specified indexes where the element at
|
9058 | * the first index is assigned as the first element, the element at
|
9059 | * the second index is assigned as the second element, and so on.
|
9060 | *
|
9061 | * @private
|
9062 | * @param {Array} array The array to reorder.
|
9063 | * @param {Array} indexes The arranged array indexes.
|
9064 | * @returns {Array} Returns `array`.
|
9065 | */
|
9066 | function reorder(array, indexes) {
|
9067 | var arrLength = array.length,
|
9068 | length = nativeMin(indexes.length, arrLength),
|
9069 | oldArray = copyArray(array);
|
9070 |
|
9071 | while (length--) {
|
9072 | var index = indexes[length];
|
9073 | array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
|
9074 | }
|
9075 | return array;
|
9076 | }
|
9077 |
|
9078 | |
9079 |
|
9080 |
|
9081 |
|
9082 |
|
9083 |
|
9084 |
|
9085 |
|
9086 |
|
9087 |
|
9088 |
|
9089 |
|
9090 |
|
9091 | var setData = (function() {
|
9092 | var count = 0,
|
9093 | lastCalled = 0;
|
9094 |
|
9095 | return function(key, value) {
|
9096 | var stamp = now(),
|
9097 | remaining = HOT_SPAN - (stamp - lastCalled);
|
9098 |
|
9099 | lastCalled = stamp;
|
9100 | if (remaining > 0) {
|
9101 | if (++count >= HOT_COUNT) {
|
9102 | return key;
|
9103 | }
|
9104 | } else {
|
9105 | count = 0;
|
9106 | }
|
9107 | return baseSetData(key, value);
|
9108 | };
|
9109 | }());
|
9110 |
|
9111 | |
9112 |
|
9113 |
|
9114 |
|
9115 |
|
9116 |
|
9117 |
|
9118 | function stringToPath(string) {
|
9119 | var result = [];
|
9120 | toString(string).replace(rePropName, function(match, number, quote, string) {
|
9121 | result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
9122 | });
|
9123 | return result;
|
9124 | }
|
9125 |
|
9126 | |
9127 |
|
9128 |
|
9129 |
|
9130 |
|
9131 |
|
9132 |
|
9133 | function wrapperClone(wrapper) {
|
9134 | if (wrapper instanceof LazyWrapper) {
|
9135 | return wrapper.clone();
|
9136 | }
|
9137 | var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
|
9138 | result.__actions__ = copyArray(wrapper.__actions__);
|
9139 | result.__index__ = wrapper.__index__;
|
9140 | result.__values__ = wrapper.__values__;
|
9141 | return result;
|
9142 | }
|
9143 |
|
9144 |
|
9145 |
|
9146 | |
9147 |
|
9148 |
|
9149 |
|
9150 |
|
9151 |
|
9152 |
|
9153 |
|
9154 |
|
9155 |
|
9156 |
|
9157 |
|
9158 |
|
9159 |
|
9160 |
|
9161 |
|
9162 |
|
9163 |
|
9164 |
|
9165 | function chunk(array, size) {
|
9166 | size = nativeMax(toInteger(size), 0);
|
9167 |
|
9168 | var length = array ? array.length : 0;
|
9169 | if (!length || size < 1) {
|
9170 | return [];
|
9171 | }
|
9172 | var index = 0,
|
9173 | resIndex = 0,
|
9174 | result = Array(nativeCeil(length / size));
|
9175 |
|
9176 | while (index < length) {
|
9177 | result[resIndex++] = baseSlice(array, index, (index += size));
|
9178 | }
|
9179 | return result;
|
9180 | }
|
9181 |
|
9182 | |
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 | function compact(array) {
|
9197 | var index = -1,
|
9198 | length = array ? array.length : 0,
|
9199 | resIndex = 0,
|
9200 | result = [];
|
9201 |
|
9202 | while (++index < length) {
|
9203 | var value = array[index];
|
9204 | if (value) {
|
9205 | result[resIndex++] = value;
|
9206 | }
|
9207 | }
|
9208 | return result;
|
9209 | }
|
9210 |
|
9211 | |
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 |
|
9227 |
|
9228 |
|
9229 |
|
9230 |
|
9231 |
|
9232 | var concat = rest(function(array, values) {
|
9233 | if (!isArray(array)) {
|
9234 | array = array == null ? [] : [Object(array)];
|
9235 | }
|
9236 | values = baseFlatten(values, 1);
|
9237 | return arrayConcat(array, values);
|
9238 | });
|
9239 |
|
9240 | |
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 |
|
9247 |
|
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 |
|
9255 |
|
9256 |
|
9257 | var difference = rest(function(array, values) {
|
9258 | return isArrayLikeObject(array)
|
9259 | ? baseDifference(array, baseFlatten(values, 1, true))
|
9260 | : [];
|
9261 | });
|
9262 |
|
9263 | |
9264 |
|
9265 |
|
9266 |
|
9267 |
|
9268 |
|
9269 |
|
9270 |
|
9271 |
|
9272 |
|
9273 |
|
9274 |
|
9275 |
|
9276 |
|
9277 |
|
9278 |
|
9279 |
|
9280 |
|
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 | var differenceBy = rest(function(array, values) {
|
9286 | var iteratee = last(values);
|
9287 | if (isArrayLikeObject(iteratee)) {
|
9288 | iteratee = undefined;
|
9289 | }
|
9290 | return isArrayLikeObject(array)
|
9291 | ? baseDifference(array, baseFlatten(values, 1, true), getIteratee(iteratee))
|
9292 | : [];
|
9293 | });
|
9294 |
|
9295 | |
9296 |
|
9297 |
|
9298 |
|
9299 |
|
9300 |
|
9301 |
|
9302 |
|
9303 |
|
9304 |
|
9305 |
|
9306 |
|
9307 |
|
9308 |
|
9309 |
|
9310 |
|
9311 |
|
9312 |
|
9313 |
|
9314 |
|
9315 | var differenceWith = rest(function(array, values) {
|
9316 | var comparator = last(values);
|
9317 | if (isArrayLikeObject(comparator)) {
|
9318 | comparator = undefined;
|
9319 | }
|
9320 | return isArrayLikeObject(array)
|
9321 | ? baseDifference(array, baseFlatten(values, 1, true), undefined, comparator)
|
9322 | : [];
|
9323 | });
|
9324 |
|
9325 | |
9326 |
|
9327 |
|
9328 |
|
9329 |
|
9330 |
|
9331 |
|
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 |
|
9344 |
|
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 | function drop(array, n, guard) {
|
9350 | var length = array ? array.length : 0;
|
9351 | if (!length) {
|
9352 | return [];
|
9353 | }
|
9354 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
9355 | return baseSlice(array, n < 0 ? 0 : n, length);
|
9356 | }
|
9357 |
|
9358 | |
9359 |
|
9360 |
|
9361 |
|
9362 |
|
9363 |
|
9364 |
|
9365 |
|
9366 |
|
9367 |
|
9368 |
|
9369 |
|
9370 |
|
9371 |
|
9372 |
|
9373 |
|
9374 |
|
9375 |
|
9376 |
|
9377 |
|
9378 |
|
9379 |
|
9380 |
|
9381 |
|
9382 | function dropRight(array, n, guard) {
|
9383 | var length = array ? array.length : 0;
|
9384 | if (!length) {
|
9385 | return [];
|
9386 | }
|
9387 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
9388 | n = length - n;
|
9389 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
9390 | }
|
9391 |
|
9392 | |
9393 |
|
9394 |
|
9395 |
|
9396 |
|
9397 |
|
9398 |
|
9399 |
|
9400 |
|
9401 |
|
9402 |
|
9403 |
|
9404 |
|
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 |
|
9410 |
|
9411 |
|
9412 |
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 |
|
9420 |
|
9421 |
|
9422 |
|
9423 |
|
9424 |
|
9425 |
|
9426 | function dropRightWhile(array, predicate) {
|
9427 | return (array && array.length)
|
9428 | ? baseWhile(array, getIteratee(predicate, 3), true, true)
|
9429 | : [];
|
9430 | }
|
9431 |
|
9432 | |
9433 |
|
9434 |
|
9435 |
|
9436 |
|
9437 |
|
9438 |
|
9439 |
|
9440 |
|
9441 |
|
9442 |
|
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 |
|
9454 |
|
9455 |
|
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 |
|
9461 |
|
9462 |
|
9463 |
|
9464 |
|
9465 |
|
9466 | function dropWhile(array, predicate) {
|
9467 | return (array && array.length)
|
9468 | ? baseWhile(array, getIteratee(predicate, 3), true)
|
9469 | : [];
|
9470 | }
|
9471 |
|
9472 | |
9473 |
|
9474 |
|
9475 |
|
9476 |
|
9477 |
|
9478 |
|
9479 |
|
9480 |
|
9481 |
|
9482 |
|
9483 |
|
9484 |
|
9485 |
|
9486 |
|
9487 |
|
9488 |
|
9489 |
|
9490 |
|
9491 |
|
9492 |
|
9493 |
|
9494 |
|
9495 |
|
9496 |
|
9497 |
|
9498 |
|
9499 |
|
9500 | function fill(array, value, start, end) {
|
9501 | var length = array ? array.length : 0;
|
9502 | if (!length) {
|
9503 | return [];
|
9504 | }
|
9505 | if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
9506 | start = 0;
|
9507 | end = length;
|
9508 | }
|
9509 | return baseFill(array, value, start, end);
|
9510 | }
|
9511 |
|
9512 | |
9513 |
|
9514 |
|
9515 |
|
9516 |
|
9517 |
|
9518 |
|
9519 |
|
9520 |
|
9521 |
|
9522 |
|
9523 |
|
9524 |
|
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 |
|
9530 |
|
9531 |
|
9532 |
|
9533 |
|
9534 |
|
9535 |
|
9536 |
|
9537 |
|
9538 |
|
9539 |
|
9540 |
|
9541 |
|
9542 |
|
9543 |
|
9544 |
|
9545 | function findIndex(array, predicate) {
|
9546 | return (array && array.length)
|
9547 | ? baseFindIndex(array, getIteratee(predicate, 3))
|
9548 | : -1;
|
9549 | }
|
9550 |
|
9551 | |
9552 |
|
9553 |
|
9554 |
|
9555 |
|
9556 |
|
9557 |
|
9558 |
|
9559 |
|
9560 |
|
9561 |
|
9562 |
|
9563 |
|
9564 |
|
9565 |
|
9566 |
|
9567 |
|
9568 |
|
9569 |
|
9570 |
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 | function findLastIndex(array, predicate) {
|
9585 | return (array && array.length)
|
9586 | ? baseFindIndex(array, getIteratee(predicate, 3), true)
|
9587 | : -1;
|
9588 | }
|
9589 |
|
9590 | |
9591 |
|
9592 |
|
9593 |
|
9594 |
|
9595 |
|
9596 |
|
9597 |
|
9598 |
|
9599 |
|
9600 |
|
9601 |
|
9602 |
|
9603 | function flatten(array) {
|
9604 | var length = array ? array.length : 0;
|
9605 | return length ? baseFlatten(array, 1) : [];
|
9606 | }
|
9607 |
|
9608 | |
9609 |
|
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 | function flattenDeep(array) {
|
9622 | var length = array ? array.length : 0;
|
9623 | return length ? baseFlatten(array, INFINITY) : [];
|
9624 | }
|
9625 |
|
9626 | |
9627 |
|
9628 |
|
9629 |
|
9630 |
|
9631 |
|
9632 |
|
9633 |
|
9634 |
|
9635 |
|
9636 |
|
9637 |
|
9638 |
|
9639 |
|
9640 |
|
9641 |
|
9642 |
|
9643 |
|
9644 |
|
9645 | function flattenDepth(array, depth) {
|
9646 | var length = array ? array.length : 0;
|
9647 | if (!length) {
|
9648 | return [];
|
9649 | }
|
9650 | depth = depth === undefined ? 1 : toInteger(depth);
|
9651 | return baseFlatten(array, depth);
|
9652 | }
|
9653 |
|
9654 | |
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 |
|
9660 |
|
9661 |
|
9662 |
|
9663 |
|
9664 |
|
9665 |
|
9666 |
|
9667 |
|
9668 | function fromPairs(pairs) {
|
9669 | var index = -1,
|
9670 | length = pairs ? pairs.length : 0,
|
9671 | result = {};
|
9672 |
|
9673 | while (++index < length) {
|
9674 | var pair = pairs[index];
|
9675 | result[pair[0]] = pair[1];
|
9676 | }
|
9677 | return result;
|
9678 | }
|
9679 |
|
9680 | |
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 |
|
9686 |
|
9687 |
|
9688 |
|
9689 |
|
9690 |
|
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 |
|
9696 |
|
9697 | function head(array) {
|
9698 | return array ? array[0] : undefined;
|
9699 | }
|
9700 |
|
9701 | |
9702 |
|
9703 |
|
9704 |
|
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 |
|
9710 |
|
9711 |
|
9712 |
|
9713 |
|
9714 |
|
9715 |
|
9716 |
|
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 |
|
9722 |
|
9723 | function indexOf(array, value, fromIndex) {
|
9724 | var length = array ? array.length : 0;
|
9725 | if (!length) {
|
9726 | return -1;
|
9727 | }
|
9728 | fromIndex = toInteger(fromIndex);
|
9729 | if (fromIndex < 0) {
|
9730 | fromIndex = nativeMax(length + fromIndex, 0);
|
9731 | }
|
9732 | return baseIndexOf(array, value, fromIndex);
|
9733 | }
|
9734 |
|
9735 | |
9736 |
|
9737 |
|
9738 |
|
9739 |
|
9740 |
|
9741 |
|
9742 |
|
9743 |
|
9744 |
|
9745 |
|
9746 |
|
9747 |
|
9748 | function initial(array) {
|
9749 | return dropRight(array, 1);
|
9750 | }
|
9751 |
|
9752 | |
9753 |
|
9754 |
|
9755 |
|
9756 |
|
9757 |
|
9758 |
|
9759 |
|
9760 |
|
9761 |
|
9762 |
|
9763 |
|
9764 |
|
9765 |
|
9766 |
|
9767 |
|
9768 | var intersection = rest(function(arrays) {
|
9769 | var mapped = arrayMap(arrays, baseCastArrayLikeObject);
|
9770 | return (mapped.length && mapped[0] === arrays[0])
|
9771 | ? baseIntersection(mapped)
|
9772 | : [];
|
9773 | });
|
9774 |
|
9775 | |
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 |
|
9786 |
|
9787 |
|
9788 |
|
9789 |
|
9790 |
|
9791 |
|
9792 |
|
9793 |
|
9794 |
|
9795 |
|
9796 | var intersectionBy = rest(function(arrays) {
|
9797 | var iteratee = last(arrays),
|
9798 | mapped = arrayMap(arrays, baseCastArrayLikeObject);
|
9799 |
|
9800 | if (iteratee === last(mapped)) {
|
9801 | iteratee = undefined;
|
9802 | } else {
|
9803 | mapped.pop();
|
9804 | }
|
9805 | return (mapped.length && mapped[0] === arrays[0])
|
9806 | ? baseIntersection(mapped, getIteratee(iteratee))
|
9807 | : [];
|
9808 | });
|
9809 |
|
9810 | |
9811 |
|
9812 |
|
9813 |
|
9814 |
|
9815 |
|
9816 |
|
9817 |
|
9818 |
|
9819 |
|
9820 |
|
9821 |
|
9822 |
|
9823 |
|
9824 |
|
9825 |
|
9826 |
|
9827 |
|
9828 |
|
9829 |
|
9830 | var intersectionWith = rest(function(arrays) {
|
9831 | var comparator = last(arrays),
|
9832 | mapped = arrayMap(arrays, baseCastArrayLikeObject);
|
9833 |
|
9834 | if (comparator === last(mapped)) {
|
9835 | comparator = undefined;
|
9836 | } else {
|
9837 | mapped.pop();
|
9838 | }
|
9839 | return (mapped.length && mapped[0] === arrays[0])
|
9840 | ? baseIntersection(mapped, undefined, comparator)
|
9841 | : [];
|
9842 | });
|
9843 |
|
9844 | |
9845 |
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 | function join(array, separator) {
|
9859 | return array ? nativeJoin.call(array, separator) : '';
|
9860 | }
|
9861 |
|
9862 | |
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 |
|
9872 |
|
9873 |
|
9874 |
|
9875 | function last(array) {
|
9876 | var length = array ? array.length : 0;
|
9877 | return length ? array[length - 1] : undefined;
|
9878 | }
|
9879 |
|
9880 | |
9881 |
|
9882 |
|
9883 |
|
9884 |
|
9885 |
|
9886 |
|
9887 |
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 |
|
9893 |
|
9894 |
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 |
|
9900 | function lastIndexOf(array, value, fromIndex) {
|
9901 | var length = array ? array.length : 0;
|
9902 | if (!length) {
|
9903 | return -1;
|
9904 | }
|
9905 | var index = length;
|
9906 | if (fromIndex !== undefined) {
|
9907 | index = toInteger(fromIndex);
|
9908 | index = (index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1)) + 1;
|
9909 | }
|
9910 | if (value !== value) {
|
9911 | return indexOfNaN(array, index, true);
|
9912 | }
|
9913 | while (index--) {
|
9914 | if (array[index] === value) {
|
9915 | return index;
|
9916 | }
|
9917 | }
|
9918 | return -1;
|
9919 | }
|
9920 |
|
9921 | |
9922 |
|
9923 |
|
9924 |
|
9925 |
|
9926 |
|
9927 |
|
9928 |
|
9929 |
|
9930 |
|
9931 |
|
9932 |
|
9933 |
|
9934 |
|
9935 |
|
9936 |
|
9937 |
|
9938 |
|
9939 |
|
9940 |
|
9941 |
|
9942 |
|
9943 | var pull = rest(pullAll);
|
9944 |
|
9945 | |
9946 |
|
9947 |
|
9948 |
|
9949 |
|
9950 |
|
9951 |
|
9952 |
|
9953 |
|
9954 |
|
9955 |
|
9956 |
|
9957 |
|
9958 |
|
9959 |
|
9960 |
|
9961 |
|
9962 |
|
9963 |
|
9964 | function pullAll(array, values) {
|
9965 | return (array && array.length && values && values.length)
|
9966 | ? basePullAll(array, values)
|
9967 | : array;
|
9968 | }
|
9969 |
|
9970 | |
9971 |
|
9972 |
|
9973 |
|
9974 |
|
9975 |
|
9976 |
|
9977 |
|
9978 |
|
9979 |
|
9980 |
|
9981 |
|
9982 |
|
9983 |
|
9984 |
|
9985 |
|
9986 |
|
9987 |
|
9988 |
|
9989 |
|
9990 |
|
9991 |
|
9992 | function pullAllBy(array, values, iteratee) {
|
9993 | return (array && array.length && values && values.length)
|
9994 | ? basePullAll(array, values, getIteratee(iteratee))
|
9995 | : array;
|
9996 | }
|
9997 |
|
9998 | |
9999 |
|
10000 |
|
10001 |
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 |
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 |
|
10014 |
|
10015 |
|
10016 |
|
10017 |
|
10018 |
|
10019 |
|
10020 | function pullAllWith(array, values, comparator) {
|
10021 | return (array && array.length && values && values.length)
|
10022 | ? basePullAll(array, values, undefined, comparator)
|
10023 | : array;
|
10024 | }
|
10025 |
|
10026 | |
10027 |
|
10028 |
|
10029 |
|
10030 |
|
10031 |
|
10032 |
|
10033 |
|
10034 |
|
10035 |
|
10036 |
|
10037 |
|
10038 |
|
10039 |
|
10040 |
|
10041 |
|
10042 |
|
10043 |
|
10044 |
|
10045 |
|
10046 |
|
10047 |
|
10048 |
|
10049 |
|
10050 | var pullAt = rest(function(array, indexes) {
|
10051 | indexes = arrayMap(baseFlatten(indexes, 1), String);
|
10052 |
|
10053 | var result = baseAt(array, indexes);
|
10054 | basePullAt(array, indexes.sort(compareAscending));
|
10055 | return result;
|
10056 | });
|
10057 |
|
10058 | |
10059 |
|
10060 |
|
10061 |
|
10062 |
|
10063 |
|
10064 |
|
10065 |
|
10066 |
|
10067 |
|
10068 |
|
10069 |
|
10070 |
|
10071 |
|
10072 |
|
10073 |
|
10074 |
|
10075 |
|
10076 |
|
10077 |
|
10078 |
|
10079 |
|
10080 |
|
10081 |
|
10082 |
|
10083 |
|
10084 |
|
10085 | function remove(array, predicate) {
|
10086 | var result = [];
|
10087 | if (!(array && array.length)) {
|
10088 | return result;
|
10089 | }
|
10090 | var index = -1,
|
10091 | indexes = [],
|
10092 | length = array.length;
|
10093 |
|
10094 | predicate = getIteratee(predicate, 3);
|
10095 | while (++index < length) {
|
10096 | var value = array[index];
|
10097 | if (predicate(value, index, array)) {
|
10098 | result.push(value);
|
10099 | indexes.push(index);
|
10100 | }
|
10101 | }
|
10102 | basePullAt(array, indexes);
|
10103 | return result;
|
10104 | }
|
10105 |
|
10106 | |
10107 |
|
10108 |
|
10109 |
|
10110 |
|
10111 |
|
10112 |
|
10113 |
|
10114 |
|
10115 |
|
10116 |
|
10117 |
|
10118 |
|
10119 |
|
10120 |
|
10121 |
|
10122 |
|
10123 |
|
10124 |
|
10125 |
|
10126 |
|
10127 | function reverse(array) {
|
10128 | return array ? nativeReverse.call(array) : array;
|
10129 | }
|
10130 |
|
10131 | |
10132 |
|
10133 |
|
10134 |
|
10135 |
|
10136 |
|
10137 |
|
10138 |
|
10139 |
|
10140 |
|
10141 |
|
10142 |
|
10143 |
|
10144 |
|
10145 | function slice(array, start, end) {
|
10146 | var length = array ? array.length : 0;
|
10147 | if (!length) {
|
10148 | return [];
|
10149 | }
|
10150 | if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
|
10151 | start = 0;
|
10152 | end = length;
|
10153 | }
|
10154 | else {
|
10155 | start = start == null ? 0 : toInteger(start);
|
10156 | end = end === undefined ? length : toInteger(end);
|
10157 | }
|
10158 | return baseSlice(array, start, end);
|
10159 | }
|
10160 |
|
10161 | |
10162 |
|
10163 |
|
10164 |
|
10165 |
|
10166 |
|
10167 |
|
10168 |
|
10169 |
|
10170 |
|
10171 |
|
10172 |
|
10173 |
|
10174 |
|
10175 |
|
10176 |
|
10177 |
|
10178 |
|
10179 | function sortedIndex(array, value) {
|
10180 | return baseSortedIndex(array, value);
|
10181 | }
|
10182 |
|
10183 | |
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 |
|
10189 |
|
10190 |
|
10191 |
|
10192 |
|
10193 |
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 |
|
10201 |
|
10202 |
|
10203 |
|
10204 |
|
10205 |
|
10206 | function sortedIndexBy(array, value, iteratee) {
|
10207 | return baseSortedIndexBy(array, value, getIteratee(iteratee));
|
10208 | }
|
10209 |
|
10210 | |
10211 |
|
10212 |
|
10213 |
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 |
|
10220 |
|
10221 |
|
10222 |
|
10223 |
|
10224 |
|
10225 | function sortedIndexOf(array, value) {
|
10226 | var length = array ? array.length : 0;
|
10227 | if (length) {
|
10228 | var index = baseSortedIndex(array, value);
|
10229 | if (index < length && eq(array[index], value)) {
|
10230 | return index;
|
10231 | }
|
10232 | }
|
10233 | return -1;
|
10234 | }
|
10235 |
|
10236 | |
10237 |
|
10238 |
|
10239 |
|
10240 |
|
10241 |
|
10242 |
|
10243 |
|
10244 |
|
10245 |
|
10246 |
|
10247 |
|
10248 |
|
10249 |
|
10250 |
|
10251 |
|
10252 | function sortedLastIndex(array, value) {
|
10253 | return baseSortedIndex(array, value, true);
|
10254 | }
|
10255 |
|
10256 | |
10257 |
|
10258 |
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 |
|
10264 |
|
10265 |
|
10266 |
|
10267 |
|
10268 |
|
10269 |
|
10270 |
|
10271 |
|
10272 |
|
10273 |
|
10274 | function sortedLastIndexBy(array, value, iteratee) {
|
10275 | return baseSortedIndexBy(array, value, getIteratee(iteratee), true);
|
10276 | }
|
10277 |
|
10278 | |
10279 |
|
10280 |
|
10281 |
|
10282 |
|
10283 |
|
10284 |
|
10285 |
|
10286 |
|
10287 |
|
10288 |
|
10289 |
|
10290 |
|
10291 |
|
10292 |
|
10293 | function sortedLastIndexOf(array, value) {
|
10294 | var length = array ? array.length : 0;
|
10295 | if (length) {
|
10296 | var index = baseSortedIndex(array, value, true) - 1;
|
10297 | if (eq(array[index], value)) {
|
10298 | return index;
|
10299 | }
|
10300 | }
|
10301 | return -1;
|
10302 | }
|
10303 |
|
10304 | |
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 | function sortedUniq(array) {
|
10319 | return (array && array.length)
|
10320 | ? baseSortedUniq(array)
|
10321 | : [];
|
10322 | }
|
10323 |
|
10324 | |
10325 |
|
10326 |
|
10327 |
|
10328 |
|
10329 |
|
10330 |
|
10331 |
|
10332 |
|
10333 |
|
10334 |
|
10335 |
|
10336 |
|
10337 |
|
10338 |
|
10339 | function sortedUniqBy(array, iteratee) {
|
10340 | return (array && array.length)
|
10341 | ? baseSortedUniqBy(array, getIteratee(iteratee))
|
10342 | : [];
|
10343 | }
|
10344 |
|
10345 | |
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 |
|
10357 |
|
10358 | function tail(array) {
|
10359 | return drop(array, 1);
|
10360 | }
|
10361 |
|
10362 | |
10363 |
|
10364 |
|
10365 |
|
10366 |
|
10367 |
|
10368 |
|
10369 |
|
10370 |
|
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 |
|
10376 |
|
10377 |
|
10378 |
|
10379 |
|
10380 |
|
10381 |
|
10382 |
|
10383 |
|
10384 |
|
10385 |
|
10386 | function take(array, n, guard) {
|
10387 | if (!(array && array.length)) {
|
10388 | return [];
|
10389 | }
|
10390 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
10391 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
10392 | }
|
10393 |
|
10394 | |
10395 |
|
10396 |
|
10397 |
|
10398 |
|
10399 |
|
10400 |
|
10401 |
|
10402 |
|
10403 |
|
10404 |
|
10405 |
|
10406 |
|
10407 |
|
10408 |
|
10409 |
|
10410 |
|
10411 |
|
10412 |
|
10413 |
|
10414 |
|
10415 |
|
10416 |
|
10417 |
|
10418 | function takeRight(array, n, guard) {
|
10419 | var length = array ? array.length : 0;
|
10420 | if (!length) {
|
10421 | return [];
|
10422 | }
|
10423 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
10424 | n = length - n;
|
10425 | return baseSlice(array, n < 0 ? 0 : n, length);
|
10426 | }
|
10427 |
|
10428 | |
10429 |
|
10430 |
|
10431 |
|
10432 |
|
10433 |
|
10434 |
|
10435 |
|
10436 |
|
10437 |
|
10438 |
|
10439 |
|
10440 |
|
10441 |
|
10442 |
|
10443 |
|
10444 |
|
10445 |
|
10446 |
|
10447 |
|
10448 |
|
10449 |
|
10450 |
|
10451 |
|
10452 |
|
10453 |
|
10454 |
|
10455 |
|
10456 |
|
10457 |
|
10458 |
|
10459 |
|
10460 |
|
10461 |
|
10462 | function takeRightWhile(array, predicate) {
|
10463 | return (array && array.length)
|
10464 | ? baseWhile(array, getIteratee(predicate, 3), false, true)
|
10465 | : [];
|
10466 | }
|
10467 |
|
10468 | |
10469 |
|
10470 |
|
10471 |
|
10472 |
|
10473 |
|
10474 |
|
10475 |
|
10476 |
|
10477 |
|
10478 |
|
10479 |
|
10480 |
|
10481 |
|
10482 |
|
10483 |
|
10484 |
|
10485 |
|
10486 |
|
10487 |
|
10488 |
|
10489 |
|
10490 |
|
10491 |
|
10492 |
|
10493 |
|
10494 |
|
10495 |
|
10496 |
|
10497 |
|
10498 |
|
10499 |
|
10500 |
|
10501 |
|
10502 | function takeWhile(array, predicate) {
|
10503 | return (array && array.length)
|
10504 | ? baseWhile(array, getIteratee(predicate, 3))
|
10505 | : [];
|
10506 | }
|
10507 |
|
10508 | |
10509 |
|
10510 |
|
10511 |
|
10512 |
|
10513 |
|
10514 |
|
10515 |
|
10516 |
|
10517 |
|
10518 |
|
10519 |
|
10520 |
|
10521 |
|
10522 |
|
10523 | var union = rest(function(arrays) {
|
10524 | return baseUniq(baseFlatten(arrays, 1, true));
|
10525 | });
|
10526 |
|
10527 | |
10528 |
|
10529 |
|
10530 |
|
10531 |
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 |
|
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 |
|
10542 |
|
10543 |
|
10544 |
|
10545 |
|
10546 |
|
10547 | var unionBy = rest(function(arrays) {
|
10548 | var iteratee = last(arrays);
|
10549 | if (isArrayLikeObject(iteratee)) {
|
10550 | iteratee = undefined;
|
10551 | }
|
10552 | return baseUniq(baseFlatten(arrays, 1, true), getIteratee(iteratee));
|
10553 | });
|
10554 |
|
10555 | |
10556 |
|
10557 |
|
10558 |
|
10559 |
|
10560 |
|
10561 |
|
10562 |
|
10563 |
|
10564 |
|
10565 |
|
10566 |
|
10567 |
|
10568 |
|
10569 |
|
10570 |
|
10571 |
|
10572 |
|
10573 |
|
10574 | var unionWith = rest(function(arrays) {
|
10575 | var comparator = last(arrays);
|
10576 | if (isArrayLikeObject(comparator)) {
|
10577 | comparator = undefined;
|
10578 | }
|
10579 | return baseUniq(baseFlatten(arrays, 1, true), undefined, comparator);
|
10580 | });
|
10581 |
|
10582 | |
10583 |
|
10584 |
|
10585 |
|
10586 |
|
10587 |
|
10588 |
|
10589 |
|
10590 |
|
10591 |
|
10592 |
|
10593 |
|
10594 |
|
10595 |
|
10596 |
|
10597 |
|
10598 | function uniq(array) {
|
10599 | return (array && array.length)
|
10600 | ? baseUniq(array)
|
10601 | : [];
|
10602 | }
|
10603 |
|
10604 | |
10605 |
|
10606 |
|
10607 |
|
10608 |
|
10609 |
|
10610 |
|
10611 |
|
10612 |
|
10613 |
|
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 |
|
10622 |
|
10623 |
|
10624 | function uniqBy(array, iteratee) {
|
10625 | return (array && array.length)
|
10626 | ? baseUniq(array, getIteratee(iteratee))
|
10627 | : [];
|
10628 | }
|
10629 |
|
10630 | |
10631 |
|
10632 |
|
10633 |
|
10634 |
|
10635 |
|
10636 |
|
10637 |
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 |
|
10643 |
|
10644 |
|
10645 |
|
10646 |
|
10647 |
|
10648 | function uniqWith(array, comparator) {
|
10649 | return (array && array.length)
|
10650 | ? baseUniq(array, undefined, comparator)
|
10651 | : [];
|
10652 | }
|
10653 |
|
10654 | |
10655 |
|
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 |
|
10668 |
|
10669 |
|
10670 |
|
10671 |
|
10672 | function unzip(array) {
|
10673 | if (!(array && array.length)) {
|
10674 | return [];
|
10675 | }
|
10676 | var length = 0;
|
10677 | array = arrayFilter(array, function(group) {
|
10678 | if (isArrayLikeObject(group)) {
|
10679 | length = nativeMax(group.length, length);
|
10680 | return true;
|
10681 | }
|
10682 | });
|
10683 | return baseTimes(length, function(index) {
|
10684 | return arrayMap(array, baseProperty(index));
|
10685 | });
|
10686 | }
|
10687 |
|
10688 | |
10689 |
|
10690 |
|
10691 |
|
10692 |
|
10693 |
|
10694 |
|
10695 |
|
10696 |
|
10697 |
|
10698 |
|
10699 |
|
10700 |
|
10701 |
|
10702 |
|
10703 |
|
10704 |
|
10705 |
|
10706 |
|
10707 | function unzipWith(array, iteratee) {
|
10708 | if (!(array && array.length)) {
|
10709 | return [];
|
10710 | }
|
10711 | var result = unzip(array);
|
10712 | if (iteratee == null) {
|
10713 | return result;
|
10714 | }
|
10715 | return arrayMap(result, function(group) {
|
10716 | return apply(iteratee, undefined, group);
|
10717 | });
|
10718 | }
|
10719 |
|
10720 | |
10721 |
|
10722 |
|
10723 |
|
10724 |
|
10725 |
|
10726 |
|
10727 |
|
10728 |
|
10729 |
|
10730 |
|
10731 |
|
10732 |
|
10733 |
|
10734 |
|
10735 |
|
10736 | var without = rest(function(array, values) {
|
10737 | return isArrayLikeObject(array)
|
10738 | ? baseDifference(array, values)
|
10739 | : [];
|
10740 | });
|
10741 |
|
10742 | |
10743 |
|
10744 |
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 |
|
10751 |
|
10752 |
|
10753 |
|
10754 |
|
10755 |
|
10756 |
|
10757 | var xor = rest(function(arrays) {
|
10758 | return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
10759 | });
|
10760 |
|
10761 | |
10762 |
|
10763 |
|
10764 |
|
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 |
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 |
|
10781 | var xorBy = rest(function(arrays) {
|
10782 | var iteratee = last(arrays);
|
10783 | if (isArrayLikeObject(iteratee)) {
|
10784 | iteratee = undefined;
|
10785 | }
|
10786 | return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee));
|
10787 | });
|
10788 |
|
10789 | |
10790 |
|
10791 |
|
10792 |
|
10793 |
|
10794 |
|
10795 |
|
10796 |
|
10797 |
|
10798 |
|
10799 |
|
10800 |
|
10801 |
|
10802 |
|
10803 |
|
10804 |
|
10805 |
|
10806 |
|
10807 |
|
10808 | var xorWith = rest(function(arrays) {
|
10809 | var comparator = last(arrays);
|
10810 | if (isArrayLikeObject(comparator)) {
|
10811 | comparator = undefined;
|
10812 | }
|
10813 | return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
|
10814 | });
|
10815 |
|
10816 | |
10817 |
|
10818 |
|
10819 |
|
10820 |
|
10821 |
|
10822 |
|
10823 |
|
10824 |
|
10825 |
|
10826 |
|
10827 |
|
10828 |
|
10829 |
|
10830 |
|
10831 | var zip = rest(unzip);
|
10832 |
|
10833 | |
10834 |
|
10835 |
|
10836 |
|
10837 |
|
10838 |
|
10839 |
|
10840 |
|
10841 |
|
10842 |
|
10843 |
|
10844 |
|
10845 |
|
10846 |
|
10847 |
|
10848 | function zipObject(props, values) {
|
10849 | return baseZipObject(props || [], values || [], assignValue);
|
10850 | }
|
10851 |
|
10852 | |
10853 |
|
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 |
|
10862 |
|
10863 |
|
10864 |
|
10865 |
|
10866 | function zipObjectDeep(props, values) {
|
10867 | return baseZipObject(props || [], values || [], baseSet);
|
10868 | }
|
10869 |
|
10870 | |
10871 |
|
10872 |
|
10873 |
|
10874 |
|
10875 |
|
10876 |
|
10877 |
|
10878 |
|
10879 |
|
10880 |
|
10881 |
|
10882 |
|
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 | var zipWith = rest(function(arrays) {
|
10889 | var length = arrays.length,
|
10890 | iteratee = length > 1 ? arrays[length - 1] : undefined;
|
10891 |
|
10892 | iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
|
10893 | return unzipWith(arrays, iteratee);
|
10894 | });
|
10895 |
|
10896 |
|
10897 |
|
10898 | |
10899 |
|
10900 |
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 |
|
10913 |
|
10914 |
|
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 |
|
10925 | function chain(value) {
|
10926 | var result = lodash(value);
|
10927 | result.__chain__ = true;
|
10928 | return result;
|
10929 | }
|
10930 |
|
10931 | |
10932 |
|
10933 |
|
10934 |
|
10935 |
|
10936 |
|
10937 |
|
10938 |
|
10939 |
|
10940 |
|
10941 |
|
10942 |
|
10943 |
|
10944 |
|
10945 |
|
10946 |
|
10947 |
|
10948 |
|
10949 |
|
10950 |
|
10951 |
|
10952 |
|
10953 | function tap(value, interceptor) {
|
10954 | interceptor(value);
|
10955 | return value;
|
10956 | }
|
10957 |
|
10958 | |
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 |
|
10966 |
|
10967 |
|
10968 |
|
10969 |
|
10970 |
|
10971 |
|
10972 |
|
10973 |
|
10974 |
|
10975 |
|
10976 |
|
10977 |
|
10978 |
|
10979 |
|
10980 | function thru(value, interceptor) {
|
10981 | return interceptor(value);
|
10982 | }
|
10983 |
|
10984 | |
10985 |
|
10986 |
|
10987 |
|
10988 |
|
10989 |
|
10990 |
|
10991 |
|
10992 |
|
10993 |
|
10994 |
|
10995 |
|
10996 |
|
10997 |
|
10998 |
|
10999 |
|
11000 |
|
11001 |
|
11002 |
|
11003 | var wrapperAt = rest(function(paths) {
|
11004 | paths = baseFlatten(paths, 1);
|
11005 | var length = paths.length,
|
11006 | start = length ? paths[0] : 0,
|
11007 | value = this.__wrapped__,
|
11008 | interceptor = function(object) { return baseAt(object, paths); };
|
11009 |
|
11010 | if (length > 1 || this.__actions__.length ||
|
11011 | !(value instanceof LazyWrapper) || !isIndex(start)) {
|
11012 | return this.thru(interceptor);
|
11013 | }
|
11014 | value = value.slice(start, +start + (length ? 1 : 0));
|
11015 | value.__actions__.push({
|
11016 | 'func': thru,
|
11017 | 'args': [interceptor],
|
11018 | 'thisArg': undefined
|
11019 | });
|
11020 | return new LodashWrapper(value, this.__chain__).thru(function(array) {
|
11021 | if (length && !array.length) {
|
11022 | array.push(undefined);
|
11023 | }
|
11024 | return array;
|
11025 | });
|
11026 | });
|
11027 |
|
11028 | |
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 |
|
11037 |
|
11038 |
|
11039 |
|
11040 |
|
11041 |
|
11042 |
|
11043 |
|
11044 |
|
11045 |
|
11046 |
|
11047 |
|
11048 |
|
11049 |
|
11050 |
|
11051 |
|
11052 |
|
11053 |
|
11054 | function wrapperChain() {
|
11055 | return chain(this);
|
11056 | }
|
11057 |
|
11058 | |
11059 |
|
11060 |
|
11061 |
|
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 |
|
11082 |
|
11083 | function wrapperCommit() {
|
11084 | return new LodashWrapper(this.value(), this.__chain__);
|
11085 | }
|
11086 |
|
11087 | |
11088 |
|
11089 |
|
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 |
|
11095 |
|
11096 |
|
11097 |
|
11098 |
|
11099 |
|
11100 |
|
11101 |
|
11102 |
|
11103 |
|
11104 | function wrapperFlatMap(iteratee) {
|
11105 | return this.map(iteratee).flatten();
|
11106 | }
|
11107 |
|
11108 | |
11109 |
|
11110 |
|
11111 |
|
11112 |
|
11113 |
|
11114 |
|
11115 |
|
11116 |
|
11117 |
|
11118 |
|
11119 |
|
11120 |
|
11121 |
|
11122 |
|
11123 |
|
11124 |
|
11125 |
|
11126 |
|
11127 |
|
11128 |
|
11129 | function wrapperNext() {
|
11130 | if (this.__values__ === undefined) {
|
11131 | this.__values__ = toArray(this.value());
|
11132 | }
|
11133 | var done = this.__index__ >= this.__values__.length,
|
11134 | value = done ? undefined : this.__values__[this.__index__++];
|
11135 |
|
11136 | return { 'done': done, 'value': value };
|
11137 | }
|
11138 |
|
11139 | |
11140 |
|
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 | function wrapperToIterator() {
|
11157 | return this;
|
11158 | }
|
11159 |
|
11160 | |
11161 |
|
11162 |
|
11163 |
|
11164 |
|
11165 |
|
11166 |
|
11167 |
|
11168 |
|
11169 |
|
11170 |
|
11171 |
|
11172 |
|
11173 |
|
11174 |
|
11175 |
|
11176 |
|
11177 |
|
11178 |
|
11179 |
|
11180 |
|
11181 |
|
11182 |
|
11183 | function wrapperPlant(value) {
|
11184 | var result,
|
11185 | parent = this;
|
11186 |
|
11187 | while (parent instanceof baseLodash) {
|
11188 | var clone = wrapperClone(parent);
|
11189 | clone.__index__ = 0;
|
11190 | clone.__values__ = undefined;
|
11191 | if (result) {
|
11192 | previous.__wrapped__ = clone;
|
11193 | } else {
|
11194 | result = clone;
|
11195 | }
|
11196 | var previous = clone;
|
11197 | parent = parent.__wrapped__;
|
11198 | }
|
11199 | previous.__wrapped__ = value;
|
11200 | return result;
|
11201 | }
|
11202 |
|
11203 | |
11204 |
|
11205 |
|
11206 |
|
11207 |
|
11208 |
|
11209 |
|
11210 |
|
11211 |
|
11212 |
|
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 |
|
11220 |
|
11221 |
|
11222 | function wrapperReverse() {
|
11223 | var value = this.__wrapped__;
|
11224 | if (value instanceof LazyWrapper) {
|
11225 | var wrapped = value;
|
11226 | if (this.__actions__.length) {
|
11227 | wrapped = new LazyWrapper(this);
|
11228 | }
|
11229 | wrapped = wrapped.reverse();
|
11230 | wrapped.__actions__.push({
|
11231 | 'func': thru,
|
11232 | 'args': [reverse],
|
11233 | 'thisArg': undefined
|
11234 | });
|
11235 | return new LodashWrapper(wrapped, this.__chain__);
|
11236 | }
|
11237 | return this.thru(reverse);
|
11238 | }
|
11239 |
|
11240 | |
11241 |
|
11242 |
|
11243 |
|
11244 |
|
11245 |
|
11246 |
|
11247 |
|
11248 |
|
11249 |
|
11250 |
|
11251 |
|
11252 |
|
11253 | function wrapperValue() {
|
11254 | return baseWrapperValue(this.__wrapped__, this.__actions__);
|
11255 | }
|
11256 |
|
11257 |
|
11258 |
|
11259 | |
11260 |
|
11261 |
|
11262 |
|
11263 |
|
11264 |
|
11265 |
|
11266 |
|
11267 |
|
11268 |
|
11269 |
|
11270 |
|
11271 |
|
11272 |
|
11273 |
|
11274 |
|
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 | var countBy = createAggregator(function(result, value, key) {
|
11280 | hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
|
11281 | });
|
11282 |
|
11283 | |
11284 |
|
11285 |
|
11286 |
|
11287 |
|
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 |
|
11297 |
|
11298 |
|
11299 |
|
11300 |
|
11301 |
|
11302 |
|
11303 |
|
11304 |
|
11305 |
|
11306 |
|
11307 |
|
11308 |
|
11309 |
|
11310 |
|
11311 |
|
11312 |
|
11313 |
|
11314 |
|
11315 |
|
11316 |
|
11317 | function every(collection, predicate, guard) {
|
11318 | var func = isArray(collection) ? arrayEvery : baseEvery;
|
11319 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
11320 | predicate = undefined;
|
11321 | }
|
11322 | return func(collection, getIteratee(predicate, 3));
|
11323 | }
|
11324 |
|
11325 | |
11326 |
|
11327 |
|
11328 |
|
11329 |
|
11330 |
|
11331 |
|
11332 |
|
11333 |
|
11334 |
|
11335 |
|
11336 |
|
11337 |
|
11338 |
|
11339 |
|
11340 |
|
11341 |
|
11342 |
|
11343 |
|
11344 |
|
11345 |
|
11346 |
|
11347 |
|
11348 |
|
11349 |
|
11350 |
|
11351 |
|
11352 |
|
11353 |
|
11354 |
|
11355 |
|
11356 |
|
11357 |
|
11358 | function filter(collection, predicate) {
|
11359 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
11360 | return func(collection, getIteratee(predicate, 3));
|
11361 | }
|
11362 |
|
11363 | |
11364 |
|
11365 |
|
11366 |
|
11367 |
|
11368 |
|
11369 |
|
11370 |
|
11371 |
|
11372 |
|
11373 |
|
11374 |
|
11375 |
|
11376 |
|
11377 |
|
11378 |
|
11379 |
|
11380 |
|
11381 |
|
11382 |
|
11383 |
|
11384 |
|
11385 |
|
11386 |
|
11387 |
|
11388 |
|
11389 |
|
11390 |
|
11391 |
|
11392 |
|
11393 |
|
11394 |
|
11395 |
|
11396 |
|
11397 | function find(collection, predicate) {
|
11398 | predicate = getIteratee(predicate, 3);
|
11399 | if (isArray(collection)) {
|
11400 | var index = baseFindIndex(collection, predicate);
|
11401 | return index > -1 ? collection[index] : undefined;
|
11402 | }
|
11403 | return baseFind(collection, predicate, baseEach);
|
11404 | }
|
11405 |
|
11406 | |
11407 |
|
11408 |
|
11409 |
|
11410 |
|
11411 |
|
11412 |
|
11413 |
|
11414 |
|
11415 |
|
11416 |
|
11417 |
|
11418 |
|
11419 |
|
11420 |
|
11421 |
|
11422 |
|
11423 | function findLast(collection, predicate) {
|
11424 | predicate = getIteratee(predicate, 3);
|
11425 | if (isArray(collection)) {
|
11426 | var index = baseFindIndex(collection, predicate, true);
|
11427 | return index > -1 ? collection[index] : undefined;
|
11428 | }
|
11429 | return baseFind(collection, predicate, baseEachRight);
|
11430 | }
|
11431 |
|
11432 | |
11433 |
|
11434 |
|
11435 |
|
11436 |
|
11437 |
|
11438 |
|
11439 |
|
11440 |
|
11441 |
|
11442 |
|
11443 |
|
11444 |
|
11445 |
|
11446 |
|
11447 |
|
11448 |
|
11449 |
|
11450 |
|
11451 |
|
11452 | function flatMap(collection, iteratee) {
|
11453 | return baseFlatten(map(collection, iteratee), 1);
|
11454 | }
|
11455 |
|
11456 | |
11457 |
|
11458 |
|
11459 |
|
11460 |
|
11461 |
|
11462 |
|
11463 |
|
11464 |
|
11465 |
|
11466 |
|
11467 |
|
11468 |
|
11469 |
|
11470 |
|
11471 |
|
11472 |
|
11473 |
|
11474 |
|
11475 |
|
11476 |
|
11477 |
|
11478 |
|
11479 |
|
11480 |
|
11481 |
|
11482 |
|
11483 |
|
11484 | function forEach(collection, iteratee) {
|
11485 | return (typeof iteratee == 'function' && isArray(collection))
|
11486 | ? arrayEach(collection, iteratee)
|
11487 | : baseEach(collection, baseCastFunction(iteratee));
|
11488 | }
|
11489 |
|
11490 | |
11491 |
|
11492 |
|
11493 |
|
11494 |
|
11495 |
|
11496 |
|
11497 |
|
11498 |
|
11499 |
|
11500 |
|
11501 |
|
11502 |
|
11503 |
|
11504 |
|
11505 |
|
11506 |
|
11507 |
|
11508 | function forEachRight(collection, iteratee) {
|
11509 | return (typeof iteratee == 'function' && isArray(collection))
|
11510 | ? arrayEachRight(collection, iteratee)
|
11511 | : baseEachRight(collection, baseCastFunction(iteratee));
|
11512 | }
|
11513 |
|
11514 | |
11515 |
|
11516 |
|
11517 |
|
11518 |
|
11519 |
|
11520 |
|
11521 |
|
11522 |
|
11523 |
|
11524 |
|
11525 |
|
11526 |
|
11527 |
|
11528 |
|
11529 |
|
11530 |
|
11531 |
|
11532 |
|
11533 |
|
11534 |
|
11535 | var groupBy = createAggregator(function(result, value, key) {
|
11536 | if (hasOwnProperty.call(result, key)) {
|
11537 | result[key].push(value);
|
11538 | } else {
|
11539 | result[key] = [value];
|
11540 | }
|
11541 | });
|
11542 |
|
11543 | |
11544 |
|
11545 |
|
11546 |
|
11547 |
|
11548 |
|
11549 |
|
11550 |
|
11551 |
|
11552 |
|
11553 |
|
11554 |
|
11555 |
|
11556 |
|
11557 |
|
11558 |
|
11559 |
|
11560 |
|
11561 |
|
11562 |
|
11563 |
|
11564 |
|
11565 |
|
11566 |
|
11567 |
|
11568 |
|
11569 |
|
11570 |
|
11571 | function includes(collection, value, fromIndex, guard) {
|
11572 | collection = isArrayLike(collection) ? collection : values(collection);
|
11573 | fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
|
11574 |
|
11575 | var length = collection.length;
|
11576 | if (fromIndex < 0) {
|
11577 | fromIndex = nativeMax(length + fromIndex, 0);
|
11578 | }
|
11579 | return isString(collection)
|
11580 | ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
|
11581 | : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
|
11582 | }
|
11583 |
|
11584 | |
11585 |
|
11586 |
|
11587 |
|
11588 |
|
11589 |
|
11590 |
|
11591 |
|
11592 |
|
11593 |
|
11594 |
|
11595 |
|
11596 |
|
11597 |
|
11598 |
|
11599 |
|
11600 |
|
11601 |
|
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 | var invokeMap = rest(function(collection, path, args) {
|
11607 | var index = -1,
|
11608 | isFunc = typeof path == 'function',
|
11609 | isProp = isKey(path),
|
11610 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
11611 |
|
11612 | baseEach(collection, function(value) {
|
11613 | var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
|
11614 | result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
|
11615 | });
|
11616 | return result;
|
11617 | });
|
11618 |
|
11619 | |
11620 |
|
11621 |
|
11622 |
|
11623 |
|
11624 |
|
11625 |
|
11626 |
|
11627 |
|
11628 |
|
11629 |
|
11630 |
|
11631 |
|
11632 |
|
11633 |
|
11634 |
|
11635 |
|
11636 |
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 |
|
11643 |
|
11644 |
|
11645 |
|
11646 | var keyBy = createAggregator(function(result, value, key) {
|
11647 | result[key] = value;
|
11648 | });
|
11649 |
|
11650 | |
11651 |
|
11652 |
|
11653 |
|
11654 |
|
11655 |
|
11656 |
|
11657 |
|
11658 |
|
11659 |
|
11660 |
|
11661 |
|
11662 |
|
11663 |
|
11664 |
|
11665 |
|
11666 |
|
11667 |
|
11668 |
|
11669 |
|
11670 |
|
11671 |
|
11672 |
|
11673 |
|
11674 |
|
11675 |
|
11676 |
|
11677 |
|
11678 |
|
11679 |
|
11680 |
|
11681 |
|
11682 |
|
11683 |
|
11684 |
|
11685 |
|
11686 |
|
11687 |
|
11688 |
|
11689 |
|
11690 |
|
11691 | function map(collection, iteratee) {
|
11692 | var func = isArray(collection) ? arrayMap : baseMap;
|
11693 | return func(collection, getIteratee(iteratee, 3));
|
11694 | }
|
11695 |
|
11696 | |
11697 |
|
11698 |
|
11699 |
|
11700 |
|
11701 |
|
11702 |
|
11703 |
|
11704 |
|
11705 |
|
11706 |
|
11707 |
|
11708 |
|
11709 |
|
11710 |
|
11711 |
|
11712 |
|
11713 |
|
11714 |
|
11715 |
|
11716 |
|
11717 |
|
11718 |
|
11719 |
|
11720 |
|
11721 |
|
11722 |
|
11723 | function orderBy(collection, iteratees, orders, guard) {
|
11724 | if (collection == null) {
|
11725 | return [];
|
11726 | }
|
11727 | if (!isArray(iteratees)) {
|
11728 | iteratees = iteratees == null ? [] : [iteratees];
|
11729 | }
|
11730 | orders = guard ? undefined : orders;
|
11731 | if (!isArray(orders)) {
|
11732 | orders = orders == null ? [] : [orders];
|
11733 | }
|
11734 | return baseOrderBy(collection, iteratees, orders);
|
11735 | }
|
11736 |
|
11737 | |
11738 |
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 |
|
11747 |
|
11748 |
|
11749 |
|
11750 |
|
11751 |
|
11752 |
|
11753 |
|
11754 |
|
11755 |
|
11756 |
|
11757 |
|
11758 |
|
11759 |
|
11760 |
|
11761 |
|
11762 |
|
11763 |
|
11764 |
|
11765 |
|
11766 |
|
11767 |
|
11768 |
|
11769 |
|
11770 |
|
11771 |
|
11772 | var partition = createAggregator(function(result, value, key) {
|
11773 | result[key ? 0 : 1].push(value);
|
11774 | }, function() { return [[], []]; });
|
11775 |
|
11776 | |
11777 |
|
11778 |
|
11779 |
|
11780 |
|
11781 |
|
11782 |
|
11783 |
|
11784 |
|
11785 |
|
11786 |
|
11787 |
|
11788 |
|
11789 |
|
11790 |
|
11791 |
|
11792 |
|
11793 |
|
11794 |
|
11795 |
|
11796 |
|
11797 |
|
11798 |
|
11799 |
|
11800 |
|
11801 |
|
11802 |
|
11803 |
|
11804 |
|
11805 |
|
11806 |
|
11807 |
|
11808 |
|
11809 |
|
11810 |
|
11811 | function reduce(collection, iteratee, accumulator) {
|
11812 | var func = isArray(collection) ? arrayReduce : baseReduce,
|
11813 | initAccum = arguments.length < 3;
|
11814 |
|
11815 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
|
11816 | }
|
11817 |
|
11818 | |
11819 |
|
11820 |
|
11821 |
|
11822 |
|
11823 |
|
11824 |
|
11825 |
|
11826 |
|
11827 |
|
11828 |
|
11829 |
|
11830 |
|
11831 |
|
11832 |
|
11833 |
|
11834 |
|
11835 |
|
11836 |
|
11837 |
|
11838 | function reduceRight(collection, iteratee, accumulator) {
|
11839 | var func = isArray(collection) ? arrayReduceRight : baseReduce,
|
11840 | initAccum = arguments.length < 3;
|
11841 |
|
11842 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
|
11843 | }
|
11844 |
|
11845 | |
11846 |
|
11847 |
|
11848 |
|
11849 |
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 |
|
11856 |
|
11857 |
|
11858 |
|
11859 |
|
11860 |
|
11861 |
|
11862 |
|
11863 |
|
11864 |
|
11865 |
|
11866 |
|
11867 |
|
11868 |
|
11869 |
|
11870 |
|
11871 |
|
11872 |
|
11873 |
|
11874 |
|
11875 |
|
11876 |
|
11877 | function reject(collection, predicate) {
|
11878 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
11879 | predicate = getIteratee(predicate, 3);
|
11880 | return func(collection, function(value, index, collection) {
|
11881 | return !predicate(value, index, collection);
|
11882 | });
|
11883 | }
|
11884 |
|
11885 | |
11886 |
|
11887 |
|
11888 |
|
11889 |
|
11890 |
|
11891 |
|
11892 |
|
11893 |
|
11894 |
|
11895 |
|
11896 |
|
11897 |
|
11898 | function sample(collection) {
|
11899 | var array = isArrayLike(collection) ? collection : values(collection),
|
11900 | length = array.length;
|
11901 |
|
11902 | return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
|
11903 | }
|
11904 |
|
11905 | |
11906 |
|
11907 |
|
11908 |
|
11909 |
|
11910 |
|
11911 |
|
11912 |
|
11913 |
|
11914 |
|
11915 |
|
11916 |
|
11917 |
|
11918 |
|
11919 |
|
11920 |
|
11921 |
|
11922 |
|
11923 | function sampleSize(collection, n) {
|
11924 | var index = -1,
|
11925 | result = toArray(collection),
|
11926 | length = result.length,
|
11927 | lastIndex = length - 1;
|
11928 |
|
11929 | n = baseClamp(toInteger(n), 0, length);
|
11930 | while (++index < n) {
|
11931 | var rand = baseRandom(index, lastIndex),
|
11932 | value = result[rand];
|
11933 |
|
11934 | result[rand] = result[index];
|
11935 | result[index] = value;
|
11936 | }
|
11937 | result.length = n;
|
11938 | return result;
|
11939 | }
|
11940 |
|
11941 | |
11942 |
|
11943 |
|
11944 |
|
11945 |
|
11946 |
|
11947 |
|
11948 |
|
11949 |
|
11950 |
|
11951 |
|
11952 |
|
11953 |
|
11954 |
|
11955 | function shuffle(collection) {
|
11956 | return sampleSize(collection, MAX_ARRAY_LENGTH);
|
11957 | }
|
11958 |
|
11959 | |
11960 |
|
11961 |
|
11962 |
|
11963 |
|
11964 |
|
11965 |
|
11966 |
|
11967 |
|
11968 |
|
11969 |
|
11970 |
|
11971 |
|
11972 |
|
11973 |
|
11974 |
|
11975 |
|
11976 |
|
11977 |
|
11978 |
|
11979 | function size(collection) {
|
11980 | if (collection == null) {
|
11981 | return 0;
|
11982 | }
|
11983 | if (isArrayLike(collection)) {
|
11984 | var result = collection.length;
|
11985 | return (result && isString(collection)) ? stringSize(collection) : result;
|
11986 | }
|
11987 | return keys(collection).length;
|
11988 | }
|
11989 |
|
11990 | |
11991 |
|
11992 |
|
11993 |
|
11994 |
|
11995 |
|
11996 |
|
11997 |
|
11998 |
|
11999 |
|
12000 |
|
12001 |
|
12002 |
|
12003 |
|
12004 |
|
12005 |
|
12006 |
|
12007 |
|
12008 |
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 |
|
12014 |
|
12015 |
|
12016 |
|
12017 |
|
12018 |
|
12019 |
|
12020 |
|
12021 |
|
12022 |
|
12023 |
|
12024 | function some(collection, predicate, guard) {
|
12025 | var func = isArray(collection) ? arraySome : baseSome;
|
12026 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
12027 | predicate = undefined;
|
12028 | }
|
12029 | return func(collection, getIteratee(predicate, 3));
|
12030 | }
|
12031 |
|
12032 | |
12033 |
|
12034 |
|
12035 |
|
12036 |
|
12037 |
|
12038 |
|
12039 |
|
12040 |
|
12041 |
|
12042 |
|
12043 |
|
12044 |
|
12045 |
|
12046 |
|
12047 |
|
12048 |
|
12049 |
|
12050 |
|
12051 |
|
12052 |
|
12053 |
|
12054 |
|
12055 |
|
12056 |
|
12057 |
|
12058 |
|
12059 |
|
12060 |
|
12061 |
|
12062 |
|
12063 |
|
12064 |
|
12065 | var sortBy = rest(function(collection, iteratees) {
|
12066 | if (collection == null) {
|
12067 | return [];
|
12068 | }
|
12069 | var length = iteratees.length;
|
12070 | if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
|
12071 | iteratees = [];
|
12072 | } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
|
12073 | iteratees.length = 1;
|
12074 | }
|
12075 | return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
|
12076 | });
|
12077 |
|
12078 |
|
12079 |
|
12080 | |
12081 |
|
12082 |
|
12083 |
|
12084 |
|
12085 |
|
12086 |
|
12087 |
|
12088 |
|
12089 |
|
12090 |
|
12091 |
|
12092 |
|
12093 |
|
12094 |
|
12095 |
|
12096 | var now = Date.now;
|
12097 |
|
12098 |
|
12099 |
|
12100 | |
12101 |
|
12102 |
|
12103 |
|
12104 |
|
12105 |
|
12106 |
|
12107 |
|
12108 |
|
12109 |
|
12110 |
|
12111 |
|
12112 |
|
12113 |
|
12114 |
|
12115 |
|
12116 |
|
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 |
|
12123 | function after(n, func) {
|
12124 | if (typeof func != 'function') {
|
12125 | throw new TypeError(FUNC_ERROR_TEXT);
|
12126 | }
|
12127 | n = toInteger(n);
|
12128 | return function() {
|
12129 | if (--n < 1) {
|
12130 | return func.apply(this, arguments);
|
12131 | }
|
12132 | };
|
12133 | }
|
12134 |
|
12135 | |
12136 |
|
12137 |
|
12138 |
|
12139 |
|
12140 |
|
12141 |
|
12142 |
|
12143 |
|
12144 |
|
12145 |
|
12146 |
|
12147 |
|
12148 |
|
12149 |
|
12150 |
|
12151 | function ary(func, n, guard) {
|
12152 | n = guard ? undefined : n;
|
12153 | n = (func && n == null) ? func.length : n;
|
12154 | return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
12155 | }
|
12156 |
|
12157 | |
12158 |
|
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 |
|
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 | function before(n, func) {
|
12174 | var result;
|
12175 | if (typeof func != 'function') {
|
12176 | throw new TypeError(FUNC_ERROR_TEXT);
|
12177 | }
|
12178 | n = toInteger(n);
|
12179 | return function() {
|
12180 | if (--n > 0) {
|
12181 | result = func.apply(this, arguments);
|
12182 | }
|
12183 | if (n <= 1) {
|
12184 | func = undefined;
|
12185 | }
|
12186 | return result;
|
12187 | };
|
12188 | }
|
12189 |
|
12190 | |
12191 |
|
12192 |
|
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 |
|
12198 |
|
12199 |
|
12200 |
|
12201 |
|
12202 |
|
12203 |
|
12204 |
|
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 |
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 |
|
12219 |
|
12220 |
|
12221 |
|
12222 |
|
12223 |
|
12224 |
|
12225 | var bind = rest(function(func, thisArg, partials) {
|
12226 | var bitmask = BIND_FLAG;
|
12227 | if (partials.length) {
|
12228 | var holders = replaceHolders(partials, getPlaceholder(bind));
|
12229 | bitmask |= PARTIAL_FLAG;
|
12230 | }
|
12231 | return createWrapper(func, bitmask, thisArg, partials, holders);
|
12232 | });
|
12233 |
|
12234 | |
12235 |
|
12236 |
|
12237 |
|
12238 |
|
12239 |
|
12240 |
|
12241 |
|
12242 |
|
12243 |
|
12244 |
|
12245 |
|
12246 |
|
12247 |
|
12248 |
|
12249 |
|
12250 |
|
12251 |
|
12252 |
|
12253 |
|
12254 |
|
12255 |
|
12256 |
|
12257 |
|
12258 |
|
12259 |
|
12260 |
|
12261 |
|
12262 |
|
12263 |
|
12264 |
|
12265 |
|
12266 |
|
12267 |
|
12268 |
|
12269 |
|
12270 |
|
12271 |
|
12272 |
|
12273 |
|
12274 |
|
12275 |
|
12276 |
|
12277 |
|
12278 | var bindKey = rest(function(object, key, partials) {
|
12279 | var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
12280 | if (partials.length) {
|
12281 | var holders = replaceHolders(partials, getPlaceholder(bindKey));
|
12282 | bitmask |= PARTIAL_FLAG;
|
12283 | }
|
12284 | return createWrapper(key, bitmask, object, partials, holders);
|
12285 | });
|
12286 |
|
12287 | |
12288 |
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 |
|
12294 |
|
12295 |
|
12296 |
|
12297 |
|
12298 |
|
12299 |
|
12300 |
|
12301 |
|
12302 |
|
12303 |
|
12304 |
|
12305 |
|
12306 |
|
12307 |
|
12308 |
|
12309 |
|
12310 |
|
12311 |
|
12312 |
|
12313 |
|
12314 |
|
12315 |
|
12316 |
|
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 |
|
12326 |
|
12327 | function curry(func, arity, guard) {
|
12328 | arity = guard ? undefined : arity;
|
12329 | var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
12330 | result.placeholder = curry.placeholder;
|
12331 | return result;
|
12332 | }
|
12333 |
|
12334 | |
12335 |
|
12336 |
|
12337 |
|
12338 |
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 |
|
12347 |
|
12348 |
|
12349 |
|
12350 |
|
12351 |
|
12352 |
|
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 |
|
12363 |
|
12364 |
|
12365 |
|
12366 |
|
12367 |
|
12368 |
|
12369 |
|
12370 |
|
12371 | function curryRight(func, arity, guard) {
|
12372 | arity = guard ? undefined : arity;
|
12373 | var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
12374 | result.placeholder = curryRight.placeholder;
|
12375 | return result;
|
12376 | }
|
12377 |
|
12378 | |
12379 |
|
12380 |
|
12381 |
|
12382 |
|
12383 |
|
12384 |
|
12385 |
|
12386 |
|
12387 |
|
12388 |
|
12389 |
|
12390 |
|
12391 |
|
12392 |
|
12393 |
|
12394 |
|
12395 |
|
12396 |
|
12397 |
|
12398 |
|
12399 |
|
12400 |
|
12401 |
|
12402 |
|
12403 |
|
12404 |
|
12405 |
|
12406 |
|
12407 |
|
12408 |
|
12409 |
|
12410 |
|
12411 |
|
12412 |
|
12413 |
|
12414 |
|
12415 |
|
12416 |
|
12417 |
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 |
|
12425 |
|
12426 |
|
12427 | function debounce(func, wait, options) {
|
12428 | var args,
|
12429 | maxTimeoutId,
|
12430 | result,
|
12431 | stamp,
|
12432 | thisArg,
|
12433 | timeoutId,
|
12434 | trailingCall,
|
12435 | lastCalled = 0,
|
12436 | leading = false,
|
12437 | maxWait = false,
|
12438 | trailing = true;
|
12439 |
|
12440 | if (typeof func != 'function') {
|
12441 | throw new TypeError(FUNC_ERROR_TEXT);
|
12442 | }
|
12443 | wait = toNumber(wait) || 0;
|
12444 | if (isObject(options)) {
|
12445 | leading = !!options.leading;
|
12446 | maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait);
|
12447 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
12448 | }
|
12449 |
|
12450 | function cancel() {
|
12451 | if (timeoutId) {
|
12452 | clearTimeout(timeoutId);
|
12453 | }
|
12454 | if (maxTimeoutId) {
|
12455 | clearTimeout(maxTimeoutId);
|
12456 | }
|
12457 | lastCalled = 0;
|
12458 | args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined;
|
12459 | }
|
12460 |
|
12461 | function complete(isCalled, id) {
|
12462 | if (id) {
|
12463 | clearTimeout(id);
|
12464 | }
|
12465 | maxTimeoutId = timeoutId = trailingCall = undefined;
|
12466 | if (isCalled) {
|
12467 | lastCalled = now();
|
12468 | result = func.apply(thisArg, args);
|
12469 | if (!timeoutId && !maxTimeoutId) {
|
12470 | args = thisArg = undefined;
|
12471 | }
|
12472 | }
|
12473 | }
|
12474 |
|
12475 | function delayed() {
|
12476 | var remaining = wait - (now() - stamp);
|
12477 | if (remaining <= 0 || remaining > wait) {
|
12478 | complete(trailingCall, maxTimeoutId);
|
12479 | } else {
|
12480 | timeoutId = setTimeout(delayed, remaining);
|
12481 | }
|
12482 | }
|
12483 |
|
12484 | function flush() {
|
12485 | if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) {
|
12486 | result = func.apply(thisArg, args);
|
12487 | }
|
12488 | cancel();
|
12489 | return result;
|
12490 | }
|
12491 |
|
12492 | function maxDelayed() {
|
12493 | complete(trailing, timeoutId);
|
12494 | }
|
12495 |
|
12496 | function debounced() {
|
12497 | args = arguments;
|
12498 | stamp = now();
|
12499 | thisArg = this;
|
12500 | trailingCall = trailing && (timeoutId || !leading);
|
12501 |
|
12502 | if (maxWait === false) {
|
12503 | var leadingCall = leading && !timeoutId;
|
12504 | } else {
|
12505 | if (!lastCalled && !maxTimeoutId && !leading) {
|
12506 | lastCalled = stamp;
|
12507 | }
|
12508 | var remaining = maxWait - (stamp - lastCalled);
|
12509 |
|
12510 | var isCalled = (remaining <= 0 || remaining > maxWait) &&
|
12511 | (leading || maxTimeoutId);
|
12512 |
|
12513 | if (isCalled) {
|
12514 | if (maxTimeoutId) {
|
12515 | maxTimeoutId = clearTimeout(maxTimeoutId);
|
12516 | }
|
12517 | lastCalled = stamp;
|
12518 | result = func.apply(thisArg, args);
|
12519 | }
|
12520 | else if (!maxTimeoutId) {
|
12521 | maxTimeoutId = setTimeout(maxDelayed, remaining);
|
12522 | }
|
12523 | }
|
12524 | if (isCalled && timeoutId) {
|
12525 | timeoutId = clearTimeout(timeoutId);
|
12526 | }
|
12527 | else if (!timeoutId && wait !== maxWait) {
|
12528 | timeoutId = setTimeout(delayed, wait);
|
12529 | }
|
12530 | if (leadingCall) {
|
12531 | isCalled = true;
|
12532 | result = func.apply(thisArg, args);
|
12533 | }
|
12534 | if (isCalled && !timeoutId && !maxTimeoutId) {
|
12535 | args = thisArg = undefined;
|
12536 | }
|
12537 | return result;
|
12538 | }
|
12539 | debounced.cancel = cancel;
|
12540 | debounced.flush = flush;
|
12541 | return debounced;
|
12542 | }
|
12543 |
|
12544 | |
12545 |
|
12546 |
|
12547 |
|
12548 |
|
12549 |
|
12550 |
|
12551 |
|
12552 |
|
12553 |
|
12554 |
|
12555 |
|
12556 |
|
12557 |
|
12558 |
|
12559 |
|
12560 |
|
12561 | var defer = rest(function(func, args) {
|
12562 | return baseDelay(func, 1, args);
|
12563 | });
|
12564 |
|
12565 | |
12566 |
|
12567 |
|
12568 |
|
12569 |
|
12570 |
|
12571 |
|
12572 |
|
12573 |
|
12574 |
|
12575 |
|
12576 |
|
12577 |
|
12578 |
|
12579 |
|
12580 |
|
12581 |
|
12582 |
|
12583 | var delay = rest(function(func, wait, args) {
|
12584 | return baseDelay(func, toNumber(wait) || 0, args);
|
12585 | });
|
12586 |
|
12587 | |
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 |
|
12595 |
|
12596 |
|
12597 |
|
12598 |
|
12599 |
|
12600 |
|
12601 |
|
12602 |
|
12603 |
|
12604 | function flip(func) {
|
12605 | return createWrapper(func, FLIP_FLAG);
|
12606 | }
|
12607 |
|
12608 | |
12609 |
|
12610 |
|
12611 |
|
12612 |
|
12613 |
|
12614 |
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 |
|
12620 |
|
12621 |
|
12622 |
|
12623 |
|
12624 |
|
12625 |
|
12626 |
|
12627 |
|
12628 |
|
12629 |
|
12630 |
|
12631 |
|
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 |
|
12640 |
|
12641 |
|
12642 |
|
12643 |
|
12644 |
|
12645 |
|
12646 |
|
12647 |
|
12648 |
|
12649 |
|
12650 | function memoize(func, resolver) {
|
12651 | if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
|
12652 | throw new TypeError(FUNC_ERROR_TEXT);
|
12653 | }
|
12654 | var memoized = function() {
|
12655 | var args = arguments,
|
12656 | key = resolver ? resolver.apply(this, args) : args[0],
|
12657 | cache = memoized.cache;
|
12658 |
|
12659 | if (cache.has(key)) {
|
12660 | return cache.get(key);
|
12661 | }
|
12662 | var result = func.apply(this, args);
|
12663 | memoized.cache = cache.set(key, result);
|
12664 | return result;
|
12665 | };
|
12666 | memoized.cache = new memoize.Cache;
|
12667 | return memoized;
|
12668 | }
|
12669 |
|
12670 | |
12671 |
|
12672 |
|
12673 |
|
12674 |
|
12675 |
|
12676 |
|
12677 |
|
12678 |
|
12679 |
|
12680 |
|
12681 |
|
12682 |
|
12683 |
|
12684 |
|
12685 |
|
12686 |
|
12687 |
|
12688 |
|
12689 | function negate(predicate) {
|
12690 | if (typeof predicate != 'function') {
|
12691 | throw new TypeError(FUNC_ERROR_TEXT);
|
12692 | }
|
12693 | return function() {
|
12694 | return !predicate.apply(this, arguments);
|
12695 | };
|
12696 | }
|
12697 |
|
12698 | |
12699 |
|
12700 |
|
12701 |
|
12702 |
|
12703 |
|
12704 |
|
12705 |
|
12706 |
|
12707 |
|
12708 |
|
12709 |
|
12710 |
|
12711 |
|
12712 |
|
12713 |
|
12714 |
|
12715 | function once(func) {
|
12716 | return before(2, func);
|
12717 | }
|
12718 |
|
12719 | |
12720 |
|
12721 |
|
12722 |
|
12723 |
|
12724 |
|
12725 |
|
12726 |
|
12727 |
|
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 |
|
12734 |
|
12735 |
|
12736 |
|
12737 |
|
12738 |
|
12739 |
|
12740 |
|
12741 |
|
12742 |
|
12743 |
|
12744 |
|
12745 |
|
12746 |
|
12747 |
|
12748 |
|
12749 |
|
12750 | var overArgs = rest(function(func, transforms) {
|
12751 | transforms = arrayMap(baseFlatten(transforms, 1), getIteratee());
|
12752 |
|
12753 | var funcsLength = transforms.length;
|
12754 | return rest(function(args) {
|
12755 | var index = -1,
|
12756 | length = nativeMin(args.length, funcsLength);
|
12757 |
|
12758 | while (++index < length) {
|
12759 | args[index] = transforms[index].call(this, args[index]);
|
12760 | }
|
12761 | return apply(func, this, args);
|
12762 | });
|
12763 | });
|
12764 |
|
12765 | |
12766 |
|
12767 |
|
12768 |
|
12769 |
|
12770 |
|
12771 |
|
12772 |
|
12773 |
|
12774 |
|
12775 |
|
12776 |
|
12777 |
|
12778 |
|
12779 |
|
12780 |
|
12781 |
|
12782 |
|
12783 |
|
12784 |
|
12785 |
|
12786 |
|
12787 |
|
12788 |
|
12789 |
|
12790 |
|
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 |
|
12796 |
|
12797 | var partial = rest(function(func, partials) {
|
12798 | var holders = replaceHolders(partials, getPlaceholder(partial));
|
12799 | return createWrapper(func, PARTIAL_FLAG, undefined, partials, holders);
|
12800 | });
|
12801 |
|
12802 | |
12803 |
|
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 |
|
12824 |
|
12825 |
|
12826 |
|
12827 |
|
12828 |
|
12829 |
|
12830 |
|
12831 |
|
12832 |
|
12833 | var partialRight = rest(function(func, partials) {
|
12834 | var holders = replaceHolders(partials, getPlaceholder(partialRight));
|
12835 | return createWrapper(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
|
12836 | });
|
12837 |
|
12838 | |
12839 |
|
12840 |
|
12841 |
|
12842 |
|
12843 |
|
12844 |
|
12845 |
|
12846 |
|
12847 |
|
12848 |
|
12849 |
|
12850 |
|
12851 |
|
12852 |
|
12853 |
|
12854 |
|
12855 |
|
12856 |
|
12857 |
|
12858 |
|
12859 |
|
12860 | var rearg = rest(function(func, indexes) {
|
12861 | return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
|
12862 | });
|
12863 |
|
12864 | |
12865 |
|
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 |
|
12871 |
|
12872 |
|
12873 |
|
12874 |
|
12875 |
|
12876 |
|
12877 |
|
12878 |
|
12879 |
|
12880 |
|
12881 |
|
12882 |
|
12883 |
|
12884 |
|
12885 |
|
12886 | function rest(func, start) {
|
12887 | if (typeof func != 'function') {
|
12888 | throw new TypeError(FUNC_ERROR_TEXT);
|
12889 | }
|
12890 | start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
|
12891 | return function() {
|
12892 | var args = arguments,
|
12893 | index = -1,
|
12894 | length = nativeMax(args.length - start, 0),
|
12895 | array = Array(length);
|
12896 |
|
12897 | while (++index < length) {
|
12898 | array[index] = args[start + index];
|
12899 | }
|
12900 | switch (start) {
|
12901 | case 0: return func.call(this, array);
|
12902 | case 1: return func.call(this, args[0], array);
|
12903 | case 2: return func.call(this, args[0], args[1], array);
|
12904 | }
|
12905 | var otherArgs = Array(start + 1);
|
12906 | index = -1;
|
12907 | while (++index < start) {
|
12908 | otherArgs[index] = args[index];
|
12909 | }
|
12910 | otherArgs[start] = array;
|
12911 | return apply(func, this, otherArgs);
|
12912 | };
|
12913 | }
|
12914 |
|
12915 | |
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 |
|
12921 |
|
12922 |
|
12923 |
|
12924 |
|
12925 |
|
12926 |
|
12927 |
|
12928 |
|
12929 |
|
12930 |
|
12931 |
|
12932 |
|
12933 |
|
12934 |
|
12935 |
|
12936 |
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 |
|
12946 | function spread(func, start) {
|
12947 | if (typeof func != 'function') {
|
12948 | throw new TypeError(FUNC_ERROR_TEXT);
|
12949 | }
|
12950 | start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
|
12951 | return rest(function(args) {
|
12952 | var array = args[start],
|
12953 | otherArgs = args.slice(0, start);
|
12954 |
|
12955 | if (array) {
|
12956 | arrayPush(otherArgs, array);
|
12957 | }
|
12958 | return apply(func, this, otherArgs);
|
12959 | });
|
12960 | }
|
12961 |
|
12962 | |
12963 |
|
12964 |
|
12965 |
|
12966 |
|
12967 |
|
12968 |
|
12969 |
|
12970 |
|
12971 |
|
12972 |
|
12973 |
|
12974 |
|
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 |
|
12983 |
|
12984 |
|
12985 |
|
12986 |
|
12987 |
|
12988 |
|
12989 |
|
12990 |
|
12991 |
|
12992 |
|
12993 |
|
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 |
|
12999 |
|
13000 |
|
13001 |
|
13002 | function throttle(func, wait, options) {
|
13003 | var leading = true,
|
13004 | trailing = true;
|
13005 |
|
13006 | if (typeof func != 'function') {
|
13007 | throw new TypeError(FUNC_ERROR_TEXT);
|
13008 | }
|
13009 | if (isObject(options)) {
|
13010 | leading = 'leading' in options ? !!options.leading : leading;
|
13011 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
13012 | }
|
13013 | return debounce(func, wait, {
|
13014 | 'leading': leading,
|
13015 | 'maxWait': wait,
|
13016 | 'trailing': trailing
|
13017 | });
|
13018 | }
|
13019 |
|
13020 | |
13021 |
|
13022 |
|
13023 |
|
13024 |
|
13025 |
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 |
|
13032 |
|
13033 |
|
13034 | function unary(func) {
|
13035 | return ary(func, 1);
|
13036 | }
|
13037 |
|
13038 | |
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 |
|
13048 |
|
13049 |
|
13050 |
|
13051 |
|
13052 |
|
13053 |
|
13054 |
|
13055 |
|
13056 |
|
13057 |
|
13058 |
|
13059 | function wrap(value, wrapper) {
|
13060 | wrapper = wrapper == null ? identity : wrapper;
|
13061 | return partial(wrapper, value);
|
13062 | }
|
13063 |
|
13064 |
|
13065 |
|
13066 | |
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 |
|
13078 |
|
13079 |
|
13080 |
|
13081 |
|
13082 |
|
13083 |
|
13084 |
|
13085 |
|
13086 |
|
13087 |
|
13088 |
|
13089 |
|
13090 |
|
13091 |
|
13092 |
|
13093 |
|
13094 |
|
13095 |
|
13096 |
|
13097 |
|
13098 | function castArray() {
|
13099 | if (!arguments.length) {
|
13100 | return [];
|
13101 | }
|
13102 | var value = arguments[0];
|
13103 | return isArray(value) ? value : [value];
|
13104 | }
|
13105 |
|
13106 | |
13107 |
|
13108 |
|
13109 |
|
13110 |
|
13111 |
|
13112 |
|
13113 |
|
13114 |
|
13115 |
|
13116 |
|
13117 |
|
13118 |
|
13119 |
|
13120 |
|
13121 |
|
13122 |
|
13123 |
|
13124 |
|
13125 |
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 | function clone(value) {
|
13131 | return baseClone(value, false, true);
|
13132 | }
|
13133 |
|
13134 | |
13135 |
|
13136 |
|
13137 |
|
13138 |
|
13139 |
|
13140 |
|
13141 |
|
13142 |
|
13143 |
|
13144 |
|
13145 |
|
13146 |
|
13147 |
|
13148 |
|
13149 |
|
13150 |
|
13151 |
|
13152 |
|
13153 |
|
13154 |
|
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 |
|
13160 |
|
13161 |
|
13162 |
|
13163 | function cloneWith(value, customizer) {
|
13164 | return baseClone(value, false, true, customizer);
|
13165 | }
|
13166 |
|
13167 | |
13168 |
|
13169 |
|
13170 |
|
13171 |
|
13172 |
|
13173 |
|
13174 |
|
13175 |
|
13176 |
|
13177 |
|
13178 |
|
13179 |
|
13180 |
|
13181 |
|
13182 |
|
13183 | function cloneDeep(value) {
|
13184 | return baseClone(value, true, true);
|
13185 | }
|
13186 |
|
13187 | |
13188 |
|
13189 |
|
13190 |
|
13191 |
|
13192 |
|
13193 |
|
13194 |
|
13195 |
|
13196 |
|
13197 |
|
13198 |
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 |
|
13205 |
|
13206 |
|
13207 |
|
13208 |
|
13209 |
|
13210 |
|
13211 |
|
13212 |
|
13213 | function cloneDeepWith(value, customizer) {
|
13214 | return baseClone(value, true, true, customizer);
|
13215 | }
|
13216 |
|
13217 | |
13218 |
|
13219 |
|
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 |
|
13227 |
|
13228 |
|
13229 |
|
13230 |
|
13231 |
|
13232 |
|
13233 |
|
13234 |
|
13235 |
|
13236 |
|
13237 |
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 |
|
13243 |
|
13244 |
|
13245 |
|
13246 |
|
13247 | function eq(value, other) {
|
13248 | return value === other || (value !== value && other !== other);
|
13249 | }
|
13250 |
|
13251 | |
13252 |
|
13253 |
|
13254 |
|
13255 |
|
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 |
|
13264 |
|
13265 |
|
13266 |
|
13267 |
|
13268 |
|
13269 |
|
13270 |
|
13271 | function gt(value, other) {
|
13272 | return value > other;
|
13273 | }
|
13274 |
|
13275 | |
13276 |
|
13277 |
|
13278 |
|
13279 |
|
13280 |
|
13281 |
|
13282 |
|
13283 |
|
13284 |
|
13285 |
|
13286 |
|
13287 |
|
13288 |
|
13289 |
|
13290 |
|
13291 |
|
13292 |
|
13293 |
|
13294 |
|
13295 | function gte(value, other) {
|
13296 | return value >= other;
|
13297 | }
|
13298 |
|
13299 | |
13300 |
|
13301 |
|
13302 |
|
13303 |
|
13304 |
|
13305 |
|
13306 |
|
13307 |
|
13308 |
|
13309 |
|
13310 |
|
13311 |
|
13312 |
|
13313 |
|
13314 |
|
13315 | function isArguments(value) {
|
13316 |
|
13317 | return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
13318 | (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
13319 | }
|
13320 |
|
13321 | |
13322 |
|
13323 |
|
13324 |
|
13325 |
|
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 |
|
13331 |
|
13332 |
|
13333 |
|
13334 |
|
13335 |
|
13336 |
|
13337 |
|
13338 |
|
13339 |
|
13340 |
|
13341 |
|
13342 |
|
13343 |
|
13344 | var isArray = Array.isArray;
|
13345 |
|
13346 | |
13347 |
|
13348 |
|
13349 |
|
13350 |
|
13351 |
|
13352 |
|
13353 |
|
13354 |
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 |
|
13360 |
|
13361 |
|
13362 | function isArrayBuffer(value) {
|
13363 | return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
|
13364 | }
|
13365 |
|
13366 | |
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 |
|
13383 |
|
13384 |
|
13385 |
|
13386 |
|
13387 |
|
13388 |
|
13389 |
|
13390 | function isArrayLike(value) {
|
13391 | return value != null && isLength(getLength(value)) && !isFunction(value);
|
13392 | }
|
13393 |
|
13394 | |
13395 |
|
13396 |
|
13397 |
|
13398 |
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 |
|
13412 |
|
13413 |
|
13414 |
|
13415 |
|
13416 |
|
13417 | function isArrayLikeObject(value) {
|
13418 | return isObjectLike(value) && isArrayLike(value);
|
13419 | }
|
13420 |
|
13421 | |
13422 |
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 |
|
13428 |
|
13429 |
|
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 |
|
13435 |
|
13436 |
|
13437 | function isBoolean(value) {
|
13438 | return value === true || value === false ||
|
13439 | (isObjectLike(value) && objectToString.call(value) == boolTag);
|
13440 | }
|
13441 |
|
13442 | |
13443 |
|
13444 |
|
13445 |
|
13446 |
|
13447 |
|
13448 |
|
13449 |
|
13450 |
|
13451 |
|
13452 |
|
13453 |
|
13454 |
|
13455 |
|
13456 |
|
13457 |
|
13458 | var isBuffer = !Buffer ? constant(false) : function(value) {
|
13459 | return value instanceof Buffer;
|
13460 | };
|
13461 |
|
13462 | |
13463 |
|
13464 |
|
13465 |
|
13466 |
|
13467 |
|
13468 |
|
13469 |
|
13470 |
|
13471 |
|
13472 |
|
13473 |
|
13474 |
|
13475 |
|
13476 |
|
13477 |
|
13478 | function isDate(value) {
|
13479 | return isObjectLike(value) && objectToString.call(value) == dateTag;
|
13480 | }
|
13481 |
|
13482 | |
13483 |
|
13484 |
|
13485 |
|
13486 |
|
13487 |
|
13488 |
|
13489 |
|
13490 |
|
13491 |
|
13492 |
|
13493 |
|
13494 |
|
13495 |
|
13496 |
|
13497 |
|
13498 | function isElement(value) {
|
13499 | return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
|
13500 | }
|
13501 |
|
13502 | |
13503 |
|
13504 |
|
13505 |
|
13506 |
|
13507 |
|
13508 |
|
13509 |
|
13510 |
|
13511 |
|
13512 |
|
13513 |
|
13514 |
|
13515 |
|
13516 |
|
13517 |
|
13518 |
|
13519 |
|
13520 |
|
13521 |
|
13522 |
|
13523 |
|
13524 |
|
13525 |
|
13526 |
|
13527 |
|
13528 |
|
13529 | function isEmpty(value) {
|
13530 | if (isArrayLike(value) &&
|
13531 | (isArray(value) || isString(value) ||
|
13532 | isFunction(value.splice) || isArguments(value))) {
|
13533 | return !value.length;
|
13534 | }
|
13535 | for (var key in value) {
|
13536 | if (hasOwnProperty.call(value, key)) {
|
13537 | return false;
|
13538 | }
|
13539 | }
|
13540 | return true;
|
13541 | }
|
13542 |
|
13543 | |
13544 |
|
13545 |
|
13546 |
|
13547 |
|
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 |
|
13553 |
|
13554 |
|
13555 |
|
13556 |
|
13557 |
|
13558 |
|
13559 |
|
13560 |
|
13561 |
|
13562 |
|
13563 |
|
13564 |
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 | function isEqual(value, other) {
|
13571 | return baseIsEqual(value, other);
|
13572 | }
|
13573 |
|
13574 | |
13575 |
|
13576 |
|
13577 |
|
13578 |
|
13579 |
|
13580 |
|
13581 |
|
13582 |
|
13583 |
|
13584 |
|
13585 |
|
13586 |
|
13587 |
|
13588 |
|
13589 |
|
13590 |
|
13591 |
|
13592 |
|
13593 |
|
13594 |
|
13595 |
|
13596 |
|
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 | function isEqualWith(value, other, customizer) {
|
13606 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
13607 | var result = customizer ? customizer(value, other) : undefined;
|
13608 | return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
|
13609 | }
|
13610 |
|
13611 | |
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 |
|
13622 |
|
13623 |
|
13624 |
|
13625 |
|
13626 |
|
13627 |
|
13628 | function isError(value) {
|
13629 | if (!isObjectLike(value)) {
|
13630 | return false;
|
13631 | }
|
13632 | return (objectToString.call(value) == errorTag) ||
|
13633 | (typeof value.message == 'string' && typeof value.name == 'string');
|
13634 | }
|
13635 |
|
13636 | |
13637 |
|
13638 |
|
13639 |
|
13640 |
|
13641 |
|
13642 |
|
13643 |
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 |
|
13655 |
|
13656 |
|
13657 |
|
13658 |
|
13659 |
|
13660 | function isFinite(value) {
|
13661 | return typeof value == 'number' && nativeIsFinite(value);
|
13662 | }
|
13663 |
|
13664 | |
13665 |
|
13666 |
|
13667 |
|
13668 |
|
13669 |
|
13670 |
|
13671 |
|
13672 |
|
13673 |
|
13674 |
|
13675 |
|
13676 |
|
13677 |
|
13678 |
|
13679 |
|
13680 | function isFunction(value) {
|
13681 |
|
13682 |
|
13683 |
|
13684 | var tag = isObject(value) ? objectToString.call(value) : '';
|
13685 | return tag == funcTag || tag == genTag;
|
13686 | }
|
13687 |
|
13688 | |
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 |
|
13703 |
|
13704 |
|
13705 |
|
13706 |
|
13707 |
|
13708 |
|
13709 |
|
13710 |
|
13711 |
|
13712 | function isInteger(value) {
|
13713 | return typeof value == 'number' && value == toInteger(value);
|
13714 | }
|
13715 |
|
13716 | |
13717 |
|
13718 |
|
13719 |
|
13720 |
|
13721 |
|
13722 |
|
13723 |
|
13724 |
|
13725 |
|
13726 |
|
13727 |
|
13728 |
|
13729 |
|
13730 |
|
13731 |
|
13732 |
|
13733 |
|
13734 |
|
13735 |
|
13736 |
|
13737 |
|
13738 |
|
13739 |
|
13740 | function isLength(value) {
|
13741 | return typeof value == 'number' &&
|
13742 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
13743 | }
|
13744 |
|
13745 | |
13746 |
|
13747 |
|
13748 |
|
13749 |
|
13750 |
|
13751 |
|
13752 |
|
13753 |
|
13754 |
|
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 |
|
13766 |
|
13767 |
|
13768 | function isObject(value) {
|
13769 | var type = typeof value;
|
13770 | return !!value && (type == 'object' || type == 'function');
|
13771 | }
|
13772 |
|
13773 | |
13774 |
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 |
|
13780 |
|
13781 |
|
13782 |
|
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 |
|
13790 |
|
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 |
|
13796 | function isObjectLike(value) {
|
13797 | return !!value && typeof value == 'object';
|
13798 | }
|
13799 |
|
13800 | |
13801 |
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 | function isMap(value) {
|
13817 | return isObjectLike(value) && getTag(value) == mapTag;
|
13818 | }
|
13819 |
|
13820 | |
13821 |
|
13822 |
|
13823 |
|
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 |
|
13832 |
|
13833 |
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 |
|
13839 |
|
13840 |
|
13841 |
|
13842 |
|
13843 | function isMatch(object, source) {
|
13844 | return object === source || baseIsMatch(object, source, getMatchData(source));
|
13845 | }
|
13846 |
|
13847 | |
13848 |
|
13849 |
|
13850 |
|
13851 |
|
13852 |
|
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 |
|
13875 |
|
13876 |
|
13877 |
|
13878 | function isMatchWith(object, source, customizer) {
|
13879 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
13880 | return baseIsMatch(object, source, getMatchData(source), customizer);
|
13881 | }
|
13882 |
|
13883 | |
13884 |
|
13885 |
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 |
|
13894 |
|
13895 |
|
13896 |
|
13897 |
|
13898 |
|
13899 |
|
13900 |
|
13901 |
|
13902 |
|
13903 |
|
13904 |
|
13905 |
|
13906 |
|
13907 |
|
13908 | function isNaN(value) {
|
13909 |
|
13910 |
|
13911 | return isNumber(value) && value != +value;
|
13912 | }
|
13913 |
|
13914 | |
13915 |
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 |
|
13921 |
|
13922 |
|
13923 |
|
13924 |
|
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 | function isNative(value) {
|
13931 | if (value == null) {
|
13932 | return false;
|
13933 | }
|
13934 | if (isFunction(value)) {
|
13935 | return reIsNative.test(funcToString.call(value));
|
13936 | }
|
13937 | return isObjectLike(value) &&
|
13938 | (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
|
13939 | }
|
13940 |
|
13941 | |
13942 |
|
13943 |
|
13944 |
|
13945 |
|
13946 |
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 |
|
13953 |
|
13954 |
|
13955 |
|
13956 |
|
13957 | function isNull(value) {
|
13958 | return value === null;
|
13959 | }
|
13960 |
|
13961 | |
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 |
|
13974 |
|
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 |
|
13980 | function isNil(value) {
|
13981 | return value == null;
|
13982 | }
|
13983 |
|
13984 | |
13985 |
|
13986 |
|
13987 |
|
13988 |
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 |
|
13998 |
|
13999 |
|
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 | function isNumber(value) {
|
14010 | return typeof value == 'number' ||
|
14011 | (isObjectLike(value) && objectToString.call(value) == numberTag);
|
14012 | }
|
14013 |
|
14014 | |
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 |
|
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 |
|
14030 |
|
14031 |
|
14032 |
|
14033 |
|
14034 |
|
14035 |
|
14036 |
|
14037 |
|
14038 |
|
14039 |
|
14040 |
|
14041 | function isPlainObject(value) {
|
14042 | if (!isObjectLike(value) ||
|
14043 | objectToString.call(value) != objectTag || isHostObject(value)) {
|
14044 | return false;
|
14045 | }
|
14046 | var proto = getPrototypeOf(value);
|
14047 | if (proto === null) {
|
14048 | return true;
|
14049 | }
|
14050 | var Ctor = proto.constructor;
|
14051 | return (typeof Ctor == 'function' &&
|
14052 | Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
|
14053 | }
|
14054 |
|
14055 | |
14056 |
|
14057 |
|
14058 |
|
14059 |
|
14060 |
|
14061 |
|
14062 |
|
14063 |
|
14064 |
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 | function isRegExp(value) {
|
14072 | return isObject(value) && objectToString.call(value) == regexpTag;
|
14073 | }
|
14074 |
|
14075 | |
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 |
|
14087 |
|
14088 |
|
14089 |
|
14090 |
|
14091 |
|
14092 |
|
14093 |
|
14094 |
|
14095 |
|
14096 |
|
14097 |
|
14098 |
|
14099 |
|
14100 | function isSafeInteger(value) {
|
14101 | return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
14102 | }
|
14103 |
|
14104 | |
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 | function isSet(value) {
|
14121 | return isObjectLike(value) && getTag(value) == setTag;
|
14122 | }
|
14123 |
|
14124 | |
14125 |
|
14126 |
|
14127 |
|
14128 |
|
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 |
|
14138 |
|
14139 |
|
14140 | function isString(value) {
|
14141 | return typeof value == 'string' ||
|
14142 | (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
|
14143 | }
|
14144 |
|
14145 | |
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 |
|
14152 |
|
14153 |
|
14154 |
|
14155 |
|
14156 |
|
14157 |
|
14158 |
|
14159 |
|
14160 |
|
14161 | function isSymbol(value) {
|
14162 | return typeof value == 'symbol' ||
|
14163 | (isObjectLike(value) && objectToString.call(value) == symbolTag);
|
14164 | }
|
14165 |
|
14166 | |
14167 |
|
14168 |
|
14169 |
|
14170 |
|
14171 |
|
14172 |
|
14173 |
|
14174 |
|
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 |
|
14180 |
|
14181 |
|
14182 | function isTypedArray(value) {
|
14183 | return isObjectLike(value) &&
|
14184 | isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
|
14185 | }
|
14186 |
|
14187 | |
14188 |
|
14189 |
|
14190 |
|
14191 |
|
14192 |
|
14193 |
|
14194 |
|
14195 |
|
14196 |
|
14197 |
|
14198 |
|
14199 |
|
14200 |
|
14201 |
|
14202 |
|
14203 | function isUndefined(value) {
|
14204 | return value === undefined;
|
14205 | }
|
14206 |
|
14207 | |
14208 |
|
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 |
|
14214 |
|
14215 |
|
14216 |
|
14217 |
|
14218 |
|
14219 |
|
14220 |
|
14221 |
|
14222 |
|
14223 | function isWeakMap(value) {
|
14224 | return isObjectLike(value) && getTag(value) == weakMapTag;
|
14225 | }
|
14226 |
|
14227 | |
14228 |
|
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 |
|
14234 |
|
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 |
|
14240 |
|
14241 |
|
14242 |
|
14243 | function isWeakSet(value) {
|
14244 | return isObjectLike(value) && objectToString.call(value) == weakSetTag;
|
14245 | }
|
14246 |
|
14247 | |
14248 |
|
14249 |
|
14250 |
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 |
|
14257 |
|
14258 |
|
14259 |
|
14260 |
|
14261 |
|
14262 |
|
14263 |
|
14264 |
|
14265 |
|
14266 |
|
14267 | function lt(value, other) {
|
14268 | return value < other;
|
14269 | }
|
14270 |
|
14271 | |
14272 |
|
14273 |
|
14274 |
|
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 |
|
14280 |
|
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 |
|
14291 | function lte(value, other) {
|
14292 | return value <= other;
|
14293 | }
|
14294 |
|
14295 | |
14296 |
|
14297 |
|
14298 |
|
14299 |
|
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 |
|
14316 |
|
14317 | function toArray(value) {
|
14318 | if (!value) {
|
14319 | return [];
|
14320 | }
|
14321 | if (isArrayLike(value)) {
|
14322 | return isString(value) ? stringToArray(value) : copyArray(value);
|
14323 | }
|
14324 | if (iteratorSymbol && value[iteratorSymbol]) {
|
14325 | return iteratorToArray(value[iteratorSymbol]());
|
14326 | }
|
14327 | var tag = getTag(value),
|
14328 | func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
|
14329 |
|
14330 | return func(value);
|
14331 | }
|
14332 |
|
14333 | |
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 |
|
14349 |
|
14350 |
|
14351 |
|
14352 |
|
14353 |
|
14354 |
|
14355 |
|
14356 |
|
14357 | function toInteger(value) {
|
14358 | if (!value) {
|
14359 | return value === 0 ? value : 0;
|
14360 | }
|
14361 | value = toNumber(value);
|
14362 | if (value === INFINITY || value === -INFINITY) {
|
14363 | var sign = (value < 0 ? -1 : 1);
|
14364 | return sign * MAX_INTEGER;
|
14365 | }
|
14366 | var remainder = value % 1;
|
14367 | return value === value ? (remainder ? value - remainder : value) : 0;
|
14368 | }
|
14369 |
|
14370 | |
14371 |
|
14372 |
|
14373 |
|
14374 |
|
14375 |
|
14376 |
|
14377 |
|
14378 |
|
14379 |
|
14380 |
|
14381 |
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 | function toLength(value) {
|
14396 | return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
|
14397 | }
|
14398 |
|
14399 | |
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 |
|
14407 |
|
14408 |
|
14409 |
|
14410 |
|
14411 |
|
14412 |
|
14413 |
|
14414 |
|
14415 |
|
14416 |
|
14417 |
|
14418 |
|
14419 |
|
14420 |
|
14421 | function toNumber(value) {
|
14422 | if (isObject(value)) {
|
14423 | var other = isFunction(value.valueOf) ? value.valueOf() : value;
|
14424 | value = isObject(other) ? (other + '') : other;
|
14425 | }
|
14426 | if (typeof value != 'string') {
|
14427 | return value === 0 ? value : +value;
|
14428 | }
|
14429 | value = value.replace(reTrim, '');
|
14430 | var isBinary = reIsBinary.test(value);
|
14431 | return (isBinary || reIsOctal.test(value))
|
14432 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
14433 | : (reIsBadHex.test(value) ? NAN : +value);
|
14434 | }
|
14435 |
|
14436 | |
14437 |
|
14438 |
|
14439 |
|
14440 |
|
14441 |
|
14442 |
|
14443 |
|
14444 |
|
14445 |
|
14446 |
|
14447 |
|
14448 |
|
14449 |
|
14450 |
|
14451 |
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 |
|
14459 | function toPlainObject(value) {
|
14460 | return copyObject(value, keysIn(value));
|
14461 | }
|
14462 |
|
14463 | |
14464 |
|
14465 |
|
14466 |
|
14467 |
|
14468 |
|
14469 |
|
14470 |
|
14471 |
|
14472 |
|
14473 |
|
14474 |
|
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 |
|
14480 |
|
14481 |
|
14482 |
|
14483 |
|
14484 |
|
14485 |
|
14486 | function toSafeInteger(value) {
|
14487 | return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
14488 | }
|
14489 |
|
14490 | |
14491 |
|
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 |
|
14506 |
|
14507 |
|
14508 |
|
14509 |
|
14510 | function toString(value) {
|
14511 |
|
14512 | if (typeof value == 'string') {
|
14513 | return value;
|
14514 | }
|
14515 | if (value == null) {
|
14516 | return '';
|
14517 | }
|
14518 | if (isSymbol(value)) {
|
14519 | return symbolToString ? symbolToString.call(value) : '';
|
14520 | }
|
14521 | var result = (value + '');
|
14522 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
14523 | }
|
14524 |
|
14525 |
|
14526 |
|
14527 | |
14528 |
|
14529 |
|
14530 |
|
14531 |
|
14532 |
|
14533 |
|
14534 |
|
14535 |
|
14536 |
|
14537 |
|
14538 |
|
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 |
|
14544 |
|
14545 |
|
14546 |
|
14547 |
|
14548 |
|
14549 |
|
14550 |
|
14551 |
|
14552 |
|
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 | var assign = createAssigner(function(object, source) {
|
14558 | if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
|
14559 | copyObject(source, keys(source), object);
|
14560 | return;
|
14561 | }
|
14562 | for (var key in source) {
|
14563 | if (hasOwnProperty.call(source, key)) {
|
14564 | assignValue(object, key, source[key]);
|
14565 | }
|
14566 | }
|
14567 | });
|
14568 |
|
14569 | |
14570 |
|
14571 |
|
14572 |
|
14573 |
|
14574 |
|
14575 |
|
14576 |
|
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 |
|
14585 |
|
14586 |
|
14587 |
|
14588 |
|
14589 |
|
14590 |
|
14591 |
|
14592 |
|
14593 |
|
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 | var assignIn = createAssigner(function(object, source) {
|
14599 | if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
|
14600 | copyObject(source, keysIn(source), object);
|
14601 | return;
|
14602 | }
|
14603 | for (var key in source) {
|
14604 | assignValue(object, key, source[key]);
|
14605 | }
|
14606 | });
|
14607 |
|
14608 | |
14609 |
|
14610 |
|
14611 |
|
14612 |
|
14613 |
|
14614 |
|
14615 |
|
14616 |
|
14617 |
|
14618 |
|
14619 |
|
14620 |
|
14621 |
|
14622 |
|
14623 |
|
14624 |
|
14625 |
|
14626 |
|
14627 |
|
14628 |
|
14629 |
|
14630 |
|
14631 |
|
14632 |
|
14633 |
|
14634 |
|
14635 | var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
|
14636 | copyObjectWith(source, keysIn(source), object, customizer);
|
14637 | });
|
14638 |
|
14639 | |
14640 |
|
14641 |
|
14642 |
|
14643 |
|
14644 |
|
14645 |
|
14646 |
|
14647 |
|
14648 |
|
14649 |
|
14650 |
|
14651 |
|
14652 |
|
14653 |
|
14654 |
|
14655 |
|
14656 |
|
14657 |
|
14658 |
|
14659 |
|
14660 |
|
14661 |
|
14662 |
|
14663 |
|
14664 |
|
14665 | var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
|
14666 | copyObjectWith(source, keys(source), object, customizer);
|
14667 | });
|
14668 |
|
14669 | |
14670 |
|
14671 |
|
14672 |
|
14673 |
|
14674 |
|
14675 |
|
14676 |
|
14677 |
|
14678 |
|
14679 |
|
14680 |
|
14681 |
|
14682 |
|
14683 |
|
14684 |
|
14685 |
|
14686 |
|
14687 |
|
14688 |
|
14689 | var at = rest(function(object, paths) {
|
14690 | return baseAt(object, baseFlatten(paths, 1));
|
14691 | });
|
14692 |
|
14693 | |
14694 |
|
14695 |
|
14696 |
|
14697 |
|
14698 |
|
14699 |
|
14700 |
|
14701 |
|
14702 |
|
14703 |
|
14704 |
|
14705 |
|
14706 |
|
14707 |
|
14708 |
|
14709 |
|
14710 |
|
14711 |
|
14712 |
|
14713 |
|
14714 |
|
14715 |
|
14716 |
|
14717 |
|
14718 |
|
14719 |
|
14720 |
|
14721 |
|
14722 |
|
14723 |
|
14724 |
|
14725 | function create(prototype, properties) {
|
14726 | var result = baseCreate(prototype);
|
14727 | return properties ? baseAssign(result, properties) : result;
|
14728 | }
|
14729 |
|
14730 | |
14731 |
|
14732 |
|
14733 |
|
14734 |
|
14735 |
|
14736 |
|
14737 |
|
14738 |
|
14739 |
|
14740 |
|
14741 |
|
14742 |
|
14743 |
|
14744 |
|
14745 |
|
14746 |
|
14747 |
|
14748 |
|
14749 | var defaults = rest(function(args) {
|
14750 | args.push(undefined, assignInDefaults);
|
14751 | return apply(assignInWith, undefined, args);
|
14752 | });
|
14753 |
|
14754 | |
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 |
|
14760 |
|
14761 |
|
14762 |
|
14763 |
|
14764 |
|
14765 |
|
14766 |
|
14767 |
|
14768 |
|
14769 |
|
14770 |
|
14771 |
|
14772 | var defaultsDeep = rest(function(args) {
|
14773 | args.push(undefined, mergeDefaults);
|
14774 | return apply(mergeWith, undefined, args);
|
14775 | });
|
14776 |
|
14777 | |
14778 |
|
14779 |
|
14780 |
|
14781 |
|
14782 |
|
14783 |
|
14784 |
|
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 |
|
14792 |
|
14793 |
|
14794 |
|
14795 |
|
14796 |
|
14797 |
|
14798 |
|
14799 |
|
14800 |
|
14801 |
|
14802 |
|
14803 |
|
14804 |
|
14805 |
|
14806 |
|
14807 |
|
14808 |
|
14809 |
|
14810 | function findKey(object, predicate) {
|
14811 | return baseFind(object, getIteratee(predicate, 3), baseForOwn, true);
|
14812 | }
|
14813 |
|
14814 | |
14815 |
|
14816 |
|
14817 |
|
14818 |
|
14819 |
|
14820 |
|
14821 |
|
14822 |
|
14823 |
|
14824 |
|
14825 |
|
14826 |
|
14827 |
|
14828 |
|
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 |
|
14834 |
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 |
|
14846 |
|
14847 | function findLastKey(object, predicate) {
|
14848 | return baseFind(object, getIteratee(predicate, 3), baseForOwnRight, true);
|
14849 | }
|
14850 |
|
14851 | |
14852 |
|
14853 |
|
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 |
|
14860 |
|
14861 |
|
14862 |
|
14863 |
|
14864 |
|
14865 |
|
14866 |
|
14867 |
|
14868 |
|
14869 |
|
14870 |
|
14871 |
|
14872 |
|
14873 |
|
14874 |
|
14875 |
|
14876 |
|
14877 | function forIn(object, iteratee) {
|
14878 | return object == null
|
14879 | ? object
|
14880 | : baseFor(object, baseCastFunction(iteratee), keysIn);
|
14881 | }
|
14882 |
|
14883 | |
14884 |
|
14885 |
|
14886 |
|
14887 |
|
14888 |
|
14889 |
|
14890 |
|
14891 |
|
14892 |
|
14893 |
|
14894 |
|
14895 |
|
14896 |
|
14897 |
|
14898 |
|
14899 |
|
14900 |
|
14901 |
|
14902 |
|
14903 |
|
14904 |
|
14905 |
|
14906 |
|
14907 | function forInRight(object, iteratee) {
|
14908 | return object == null
|
14909 | ? object
|
14910 | : baseForRight(object, baseCastFunction(iteratee), keysIn);
|
14911 | }
|
14912 |
|
14913 | |
14914 |
|
14915 |
|
14916 |
|
14917 |
|
14918 |
|
14919 |
|
14920 |
|
14921 |
|
14922 |
|
14923 |
|
14924 |
|
14925 |
|
14926 |
|
14927 |
|
14928 |
|
14929 |
|
14930 |
|
14931 |
|
14932 |
|
14933 |
|
14934 |
|
14935 |
|
14936 |
|
14937 |
|
14938 |
|
14939 | function forOwn(object, iteratee) {
|
14940 | return object && baseForOwn(object, baseCastFunction(iteratee));
|
14941 | }
|
14942 |
|
14943 | |
14944 |
|
14945 |
|
14946 |
|
14947 |
|
14948 |
|
14949 |
|
14950 |
|
14951 |
|
14952 |
|
14953 |
|
14954 |
|
14955 |
|
14956 |
|
14957 |
|
14958 |
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 |
|
14964 |
|
14965 |
|
14966 |
|
14967 | function forOwnRight(object, iteratee) {
|
14968 | return object && baseForOwnRight(object, baseCastFunction(iteratee));
|
14969 | }
|
14970 |
|
14971 | |
14972 |
|
14973 |
|
14974 |
|
14975 |
|
14976 |
|
14977 |
|
14978 |
|
14979 |
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 |
|
14986 |
|
14987 |
|
14988 |
|
14989 |
|
14990 |
|
14991 |
|
14992 | function functions(object) {
|
14993 | return object == null ? [] : baseFunctions(object, keys(object));
|
14994 | }
|
14995 |
|
14996 | |
14997 |
|
14998 |
|
14999 |
|
15000 |
|
15001 |
|
15002 |
|
15003 |
|
15004 |
|
15005 |
|
15006 |
|
15007 |
|
15008 |
|
15009 |
|
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 | function functionsIn(object) {
|
15018 | return object == null ? [] : baseFunctions(object, keysIn(object));
|
15019 | }
|
15020 |
|
15021 | |
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 |
|
15027 |
|
15028 |
|
15029 |
|
15030 |
|
15031 |
|
15032 |
|
15033 |
|
15034 |
|
15035 |
|
15036 |
|
15037 |
|
15038 |
|
15039 |
|
15040 |
|
15041 |
|
15042 |
|
15043 |
|
15044 |
|
15045 | function get(object, path, defaultValue) {
|
15046 | var result = object == null ? undefined : baseGet(object, path);
|
15047 | return result === undefined ? defaultValue : result;
|
15048 | }
|
15049 |
|
15050 | |
15051 |
|
15052 |
|
15053 |
|
15054 |
|
15055 |
|
15056 |
|
15057 |
|
15058 |
|
15059 |
|
15060 |
|
15061 |
|
15062 |
|
15063 |
|
15064 |
|
15065 |
|
15066 |
|
15067 |
|
15068 |
|
15069 |
|
15070 |
|
15071 |
|
15072 |
|
15073 |
|
15074 |
|
15075 |
|
15076 | function has(object, path) {
|
15077 | return hasPath(object, path, baseHas);
|
15078 | }
|
15079 |
|
15080 | |
15081 |
|
15082 |
|
15083 |
|
15084 |
|
15085 |
|
15086 |
|
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 |
|
15092 |
|
15093 |
|
15094 |
|
15095 |
|
15096 |
|
15097 |
|
15098 |
|
15099 |
|
15100 |
|
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 | function hasIn(object, path) {
|
15106 | return hasPath(object, path, baseHasIn);
|
15107 | }
|
15108 |
|
15109 | |
15110 |
|
15111 |
|
15112 |
|
15113 |
|
15114 |
|
15115 |
|
15116 |
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 |
|
15122 |
|
15123 |
|
15124 |
|
15125 |
|
15126 | var invert = createInverter(function(result, value, key) {
|
15127 | result[value] = key;
|
15128 | }, constant(identity));
|
15129 |
|
15130 | |
15131 |
|
15132 |
|
15133 |
|
15134 |
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 |
|
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 |
|
15152 |
|
15153 |
|
15154 |
|
15155 | var invertBy = createInverter(function(result, value, key) {
|
15156 | if (hasOwnProperty.call(result, value)) {
|
15157 | result[value].push(key);
|
15158 | } else {
|
15159 | result[value] = [key];
|
15160 | }
|
15161 | }, getIteratee);
|
15162 |
|
15163 | |
15164 |
|
15165 |
|
15166 |
|
15167 |
|
15168 |
|
15169 |
|
15170 |
|
15171 |
|
15172 |
|
15173 |
|
15174 |
|
15175 |
|
15176 |
|
15177 |
|
15178 |
|
15179 |
|
15180 | var invoke = rest(baseInvoke);
|
15181 |
|
15182 | |
15183 |
|
15184 |
|
15185 |
|
15186 |
|
15187 |
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 |
|
15193 |
|
15194 |
|
15195 |
|
15196 |
|
15197 |
|
15198 |
|
15199 |
|
15200 |
|
15201 |
|
15202 |
|
15203 |
|
15204 |
|
15205 |
|
15206 |
|
15207 |
|
15208 |
|
15209 | function keys(object) {
|
15210 | var isProto = isPrototype(object);
|
15211 | if (!(isProto || isArrayLike(object))) {
|
15212 | return baseKeys(object);
|
15213 | }
|
15214 | var indexes = indexKeys(object),
|
15215 | skipIndexes = !!indexes,
|
15216 | result = indexes || [],
|
15217 | length = result.length;
|
15218 |
|
15219 | for (var key in object) {
|
15220 | if (baseHas(object, key) &&
|
15221 | !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
|
15222 | !(isProto && key == 'constructor')) {
|
15223 | result.push(key);
|
15224 | }
|
15225 | }
|
15226 | return result;
|
15227 | }
|
15228 |
|
15229 | |
15230 |
|
15231 |
|
15232 |
|
15233 |
|
15234 |
|
15235 |
|
15236 |
|
15237 |
|
15238 |
|
15239 |
|
15240 |
|
15241 |
|
15242 |
|
15243 |
|
15244 |
|
15245 |
|
15246 |
|
15247 |
|
15248 |
|
15249 |
|
15250 |
|
15251 | function keysIn(object) {
|
15252 | var index = -1,
|
15253 | isProto = isPrototype(object),
|
15254 | props = baseKeysIn(object),
|
15255 | propsLength = props.length,
|
15256 | indexes = indexKeys(object),
|
15257 | skipIndexes = !!indexes,
|
15258 | result = indexes || [],
|
15259 | length = result.length;
|
15260 |
|
15261 | while (++index < propsLength) {
|
15262 | var key = props[index];
|
15263 | if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
|
15264 | !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
15265 | result.push(key);
|
15266 | }
|
15267 | }
|
15268 | return result;
|
15269 | }
|
15270 |
|
15271 | |
15272 |
|
15273 |
|
15274 |
|
15275 |
|
15276 |
|
15277 |
|
15278 |
|
15279 |
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 |
|
15285 |
|
15286 |
|
15287 |
|
15288 |
|
15289 |
|
15290 | function mapKeys(object, iteratee) {
|
15291 | var result = {};
|
15292 | iteratee = getIteratee(iteratee, 3);
|
15293 |
|
15294 | baseForOwn(object, function(value, key, object) {
|
15295 | result[iteratee(value, key, object)] = value;
|
15296 | });
|
15297 | return result;
|
15298 | }
|
15299 |
|
15300 | |
15301 |
|
15302 |
|
15303 |
|
15304 |
|
15305 |
|
15306 |
|
15307 |
|
15308 |
|
15309 |
|
15310 |
|
15311 |
|
15312 |
|
15313 |
|
15314 |
|
15315 |
|
15316 |
|
15317 |
|
15318 |
|
15319 |
|
15320 |
|
15321 |
|
15322 |
|
15323 |
|
15324 |
|
15325 | function mapValues(object, iteratee) {
|
15326 | var result = {};
|
15327 | iteratee = getIteratee(iteratee, 3);
|
15328 |
|
15329 | baseForOwn(object, function(value, key, object) {
|
15330 | result[key] = iteratee(value, key, object);
|
15331 | });
|
15332 | return result;
|
15333 | }
|
15334 |
|
15335 | |
15336 |
|
15337 |
|
15338 |
|
15339 |
|
15340 |
|
15341 |
|
15342 |
|
15343 |
|
15344 |
|
15345 |
|
15346 |
|
15347 |
|
15348 |
|
15349 |
|
15350 |
|
15351 |
|
15352 |
|
15353 |
|
15354 |
|
15355 |
|
15356 |
|
15357 |
|
15358 |
|
15359 |
|
15360 |
|
15361 |
|
15362 |
|
15363 |
|
15364 |
|
15365 | var merge = createAssigner(function(object, source, srcIndex) {
|
15366 | baseMerge(object, source, srcIndex);
|
15367 | });
|
15368 |
|
15369 | |
15370 |
|
15371 |
|
15372 |
|
15373 |
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 |
|
15379 |
|
15380 |
|
15381 |
|
15382 |
|
15383 |
|
15384 |
|
15385 |
|
15386 |
|
15387 |
|
15388 |
|
15389 |
|
15390 |
|
15391 |
|
15392 |
|
15393 |
|
15394 |
|
15395 |
|
15396 |
|
15397 |
|
15398 |
|
15399 |
|
15400 |
|
15401 |
|
15402 |
|
15403 |
|
15404 |
|
15405 |
|
15406 | var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
|
15407 | baseMerge(object, source, srcIndex, customizer);
|
15408 | });
|
15409 |
|
15410 | |
15411 |
|
15412 |
|
15413 |
|
15414 |
|
15415 |
|
15416 |
|
15417 |
|
15418 |
|
15419 |
|
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 |
|
15425 |
|
15426 |
|
15427 |
|
15428 | var omit = rest(function(object, props) {
|
15429 | if (object == null) {
|
15430 | return {};
|
15431 | }
|
15432 | props = arrayMap(baseFlatten(props, 1), String);
|
15433 | return basePick(object, baseDifference(keysIn(object), props));
|
15434 | });
|
15435 |
|
15436 | |
15437 |
|
15438 |
|
15439 |
|
15440 |
|
15441 |
|
15442 |
|
15443 |
|
15444 |
|
15445 |
|
15446 |
|
15447 |
|
15448 |
|
15449 |
|
15450 |
|
15451 |
|
15452 |
|
15453 |
|
15454 |
|
15455 | function omitBy(object, predicate) {
|
15456 | predicate = getIteratee(predicate);
|
15457 | return basePickBy(object, function(value, key) {
|
15458 | return !predicate(value, key);
|
15459 | });
|
15460 | }
|
15461 |
|
15462 | |
15463 |
|
15464 |
|
15465 |
|
15466 |
|
15467 |
|
15468 |
|
15469 |
|
15470 |
|
15471 |
|
15472 |
|
15473 |
|
15474 |
|
15475 |
|
15476 |
|
15477 |
|
15478 |
|
15479 | var pick = rest(function(object, props) {
|
15480 | return object == null ? {} : basePick(object, baseFlatten(props, 1));
|
15481 | });
|
15482 |
|
15483 | |
15484 |
|
15485 |
|
15486 |
|
15487 |
|
15488 |
|
15489 |
|
15490 |
|
15491 |
|
15492 |
|
15493 |
|
15494 |
|
15495 |
|
15496 |
|
15497 |
|
15498 |
|
15499 |
|
15500 | function pickBy(object, predicate) {
|
15501 | return object == null ? {} : basePickBy(object, getIteratee(predicate));
|
15502 | }
|
15503 |
|
15504 | |
15505 |
|
15506 |
|
15507 |
|
15508 |
|
15509 |
|
15510 |
|
15511 |
|
15512 |
|
15513 |
|
15514 |
|
15515 |
|
15516 |
|
15517 |
|
15518 |
|
15519 |
|
15520 |
|
15521 |
|
15522 |
|
15523 |
|
15524 |
|
15525 |
|
15526 |
|
15527 |
|
15528 |
|
15529 |
|
15530 |
|
15531 |
|
15532 | function result(object, path, defaultValue) {
|
15533 | if (!isKey(path, object)) {
|
15534 | path = baseCastPath(path);
|
15535 | var result = get(object, path);
|
15536 | object = parent(object, path);
|
15537 | } else {
|
15538 | result = object == null ? undefined : object[path];
|
15539 | }
|
15540 | if (result === undefined) {
|
15541 | result = defaultValue;
|
15542 | }
|
15543 | return isFunction(result) ? result.call(object) : result;
|
15544 | }
|
15545 |
|
15546 | |
15547 |
|
15548 |
|
15549 |
|
15550 |
|
15551 |
|
15552 |
|
15553 |
|
15554 |
|
15555 |
|
15556 |
|
15557 |
|
15558 |
|
15559 |
|
15560 |
|
15561 |
|
15562 |
|
15563 |
|
15564 |
|
15565 |
|
15566 |
|
15567 |
|
15568 |
|
15569 |
|
15570 |
|
15571 |
|
15572 |
|
15573 | function set(object, path, value) {
|
15574 | return object == null ? object : baseSet(object, path, value);
|
15575 | }
|
15576 |
|
15577 | |
15578 |
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 |
|
15594 |
|
15595 |
|
15596 |
|
15597 |
|
15598 |
|
15599 |
|
15600 | function setWith(object, path, value, customizer) {
|
15601 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
15602 | return object == null ? object : baseSet(object, path, value, customizer);
|
15603 | }
|
15604 |
|
15605 | |
15606 |
|
15607 |
|
15608 |
|
15609 |
|
15610 |
|
15611 |
|
15612 |
|
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 |
|
15622 |
|
15623 |
|
15624 |
|
15625 |
|
15626 | function toPairs(object) {
|
15627 | return baseToPairs(object, keys(object));
|
15628 | }
|
15629 |
|
15630 | |
15631 |
|
15632 |
|
15633 |
|
15634 |
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 |
|
15640 |
|
15641 |
|
15642 |
|
15643 |
|
15644 |
|
15645 |
|
15646 |
|
15647 |
|
15648 |
|
15649 |
|
15650 |
|
15651 | function toPairsIn(object) {
|
15652 | return baseToPairs(object, keysIn(object));
|
15653 | }
|
15654 |
|
15655 | |
15656 |
|
15657 |
|
15658 |
|
15659 |
|
15660 |
|
15661 |
|
15662 |
|
15663 |
|
15664 |
|
15665 |
|
15666 |
|
15667 |
|
15668 |
|
15669 |
|
15670 |
|
15671 |
|
15672 |
|
15673 |
|
15674 |
|
15675 |
|
15676 |
|
15677 |
|
15678 |
|
15679 |
|
15680 |
|
15681 |
|
15682 |
|
15683 | function transform(object, iteratee, accumulator) {
|
15684 | var isArr = isArray(object) || isTypedArray(object);
|
15685 | iteratee = getIteratee(iteratee, 4);
|
15686 |
|
15687 | if (accumulator == null) {
|
15688 | if (isArr || isObject(object)) {
|
15689 | var Ctor = object.constructor;
|
15690 | if (isArr) {
|
15691 | accumulator = isArray(object) ? new Ctor : [];
|
15692 | } else {
|
15693 | accumulator = isFunction(Ctor) ? baseCreate(getPrototypeOf(object)) : {};
|
15694 | }
|
15695 | } else {
|
15696 | accumulator = {};
|
15697 | }
|
15698 | }
|
15699 | (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
15700 | return iteratee(accumulator, value, index, object);
|
15701 | });
|
15702 | return accumulator;
|
15703 | }
|
15704 |
|
15705 | |
15706 |
|
15707 |
|
15708 |
|
15709 |
|
15710 |
|
15711 |
|
15712 |
|
15713 |
|
15714 |
|
15715 |
|
15716 |
|
15717 |
|
15718 |
|
15719 |
|
15720 |
|
15721 |
|
15722 |
|
15723 |
|
15724 |
|
15725 |
|
15726 |
|
15727 |
|
15728 |
|
15729 |
|
15730 |
|
15731 | function unset(object, path) {
|
15732 | return object == null ? true : baseUnset(object, path);
|
15733 | }
|
15734 |
|
15735 | |
15736 |
|
15737 |
|
15738 |
|
15739 |
|
15740 |
|
15741 |
|
15742 |
|
15743 |
|
15744 |
|
15745 |
|
15746 |
|
15747 |
|
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 |
|
15753 |
|
15754 |
|
15755 |
|
15756 |
|
15757 |
|
15758 |
|
15759 |
|
15760 |
|
15761 | function update(object, path, updater) {
|
15762 | return object == null ? object : baseUpdate(object, path, baseCastFunction(updater));
|
15763 | }
|
15764 |
|
15765 | |
15766 |
|
15767 |
|
15768 |
|
15769 |
|
15770 |
|
15771 |
|
15772 |
|
15773 |
|
15774 |
|
15775 |
|
15776 |
|
15777 |
|
15778 |
|
15779 |
|
15780 |
|
15781 |
|
15782 |
|
15783 |
|
15784 |
|
15785 |
|
15786 |
|
15787 |
|
15788 | function updateWith(object, path, updater, customizer) {
|
15789 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
15790 | return object == null ? object : baseUpdate(object, path, baseCastFunction(updater), customizer);
|
15791 | }
|
15792 |
|
15793 | |
15794 |
|
15795 |
|
15796 |
|
15797 |
|
15798 |
|
15799 |
|
15800 |
|
15801 |
|
15802 |
|
15803 |
|
15804 |
|
15805 |
|
15806 |
|
15807 |
|
15808 |
|
15809 |
|
15810 |
|
15811 |
|
15812 |
|
15813 |
|
15814 |
|
15815 |
|
15816 |
|
15817 |
|
15818 | function values(object) {
|
15819 | return object ? baseValues(object, keys(object)) : [];
|
15820 | }
|
15821 |
|
15822 | |
15823 |
|
15824 |
|
15825 |
|
15826 |
|
15827 |
|
15828 |
|
15829 |
|
15830 |
|
15831 |
|
15832 |
|
15833 |
|
15834 |
|
15835 |
|
15836 |
|
15837 |
|
15838 |
|
15839 |
|
15840 |
|
15841 |
|
15842 |
|
15843 |
|
15844 | function valuesIn(object) {
|
15845 | return object == null ? [] : baseValues(object, keysIn(object));
|
15846 | }
|
15847 |
|
15848 |
|
15849 |
|
15850 | |
15851 |
|
15852 |
|
15853 |
|
15854 |
|
15855 |
|
15856 |
|
15857 |
|
15858 |
|
15859 |
|
15860 |
|
15861 |
|
15862 |
|
15863 |
|
15864 |
|
15865 |
|
15866 |
|
15867 |
|
15868 | function clamp(number, lower, upper) {
|
15869 | if (upper === undefined) {
|
15870 | upper = lower;
|
15871 | lower = undefined;
|
15872 | }
|
15873 | if (upper !== undefined) {
|
15874 | upper = toNumber(upper);
|
15875 | upper = upper === upper ? upper : 0;
|
15876 | }
|
15877 | if (lower !== undefined) {
|
15878 | lower = toNumber(lower);
|
15879 | lower = lower === lower ? lower : 0;
|
15880 | }
|
15881 | return baseClamp(toNumber(number), lower, upper);
|
15882 | }
|
15883 |
|
15884 | |
15885 |
|
15886 |
|
15887 |
|
15888 |
|
15889 |
|
15890 |
|
15891 |
|
15892 |
|
15893 |
|
15894 |
|
15895 |
|
15896 |
|
15897 |
|
15898 |
|
15899 |
|
15900 |
|
15901 |
|
15902 |
|
15903 |
|
15904 |
|
15905 |
|
15906 |
|
15907 |
|
15908 |
|
15909 |
|
15910 |
|
15911 |
|
15912 |
|
15913 |
|
15914 |
|
15915 |
|
15916 |
|
15917 |
|
15918 |
|
15919 |
|
15920 | function inRange(number, start, end) {
|
15921 | start = toNumber(start) || 0;
|
15922 | if (end === undefined) {
|
15923 | end = start;
|
15924 | start = 0;
|
15925 | } else {
|
15926 | end = toNumber(end) || 0;
|
15927 | }
|
15928 | number = toNumber(number);
|
15929 | return baseInRange(number, start, end);
|
15930 | }
|
15931 |
|
15932 | |
15933 |
|
15934 |
|
15935 |
|
15936 |
|
15937 |
|
15938 |
|
15939 |
|
15940 |
|
15941 |
|
15942 |
|
15943 |
|
15944 |
|
15945 |
|
15946 |
|
15947 |
|
15948 |
|
15949 |
|
15950 |
|
15951 |
|
15952 |
|
15953 |
|
15954 |
|
15955 |
|
15956 |
|
15957 |
|
15958 |
|
15959 |
|
15960 |
|
15961 |
|
15962 | function random(lower, upper, floating) {
|
15963 | if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
|
15964 | upper = floating = undefined;
|
15965 | }
|
15966 | if (floating === undefined) {
|
15967 | if (typeof upper == 'boolean') {
|
15968 | floating = upper;
|
15969 | upper = undefined;
|
15970 | }
|
15971 | else if (typeof lower == 'boolean') {
|
15972 | floating = lower;
|
15973 | lower = undefined;
|
15974 | }
|
15975 | }
|
15976 | if (lower === undefined && upper === undefined) {
|
15977 | lower = 0;
|
15978 | upper = 1;
|
15979 | }
|
15980 | else {
|
15981 | lower = toNumber(lower) || 0;
|
15982 | if (upper === undefined) {
|
15983 | upper = lower;
|
15984 | lower = 0;
|
15985 | } else {
|
15986 | upper = toNumber(upper) || 0;
|
15987 | }
|
15988 | }
|
15989 | if (lower > upper) {
|
15990 | var temp = lower;
|
15991 | lower = upper;
|
15992 | upper = temp;
|
15993 | }
|
15994 | if (floating || lower % 1 || upper % 1) {
|
15995 | var rand = nativeRandom();
|
15996 | return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
|
15997 | }
|
15998 | return baseRandom(lower, upper);
|
15999 | }
|
16000 |
|
16001 |
|
16002 |
|
16003 | |
16004 |
|
16005 |
|
16006 |
|
16007 |
|
16008 |
|
16009 |
|
16010 |
|
16011 |
|
16012 |
|
16013 |
|
16014 |
|
16015 |
|
16016 |
|
16017 |
|
16018 |
|
16019 |
|
16020 |
|
16021 |
|
16022 | var camelCase = createCompounder(function(result, word, index) {
|
16023 | word = word.toLowerCase();
|
16024 | return result + (index ? capitalize(word) : word);
|
16025 | });
|
16026 |
|
16027 | |
16028 |
|
16029 |
|
16030 |
|
16031 |
|
16032 |
|
16033 |
|
16034 |
|
16035 |
|
16036 |
|
16037 |
|
16038 |
|
16039 |
|
16040 |
|
16041 | function capitalize(string) {
|
16042 | return upperFirst(toString(string).toLowerCase());
|
16043 | }
|
16044 |
|
16045 | |
16046 |
|
16047 |
|
16048 |
|
16049 |
|
16050 |
|
16051 |
|
16052 |
|
16053 |
|
16054 |
|
16055 |
|
16056 |
|
16057 |
|
16058 |
|
16059 | function deburr(string) {
|
16060 | string = toString(string);
|
16061 | return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
|
16062 | }
|
16063 |
|
16064 | |
16065 |
|
16066 |
|
16067 |
|
16068 |
|
16069 |
|
16070 |
|
16071 |
|
16072 |
|
16073 |
|
16074 |
|
16075 |
|
16076 |
|
16077 |
|
16078 |
|
16079 |
|
16080 |
|
16081 |
|
16082 |
|
16083 |
|
16084 |
|
16085 | function endsWith(string, target, position) {
|
16086 | string = toString(string);
|
16087 | target = typeof target == 'string' ? target : (target + '');
|
16088 |
|
16089 | var length = string.length;
|
16090 | position = position === undefined
|
16091 | ? length
|
16092 | : baseClamp(toInteger(position), 0, length);
|
16093 |
|
16094 | position -= target.length;
|
16095 | return position >= 0 && string.indexOf(target, position) == position;
|
16096 | }
|
16097 |
|
16098 | |
16099 |
|
16100 |
|
16101 |
|
16102 |
|
16103 |
|
16104 |
|
16105 |
|
16106 |
|
16107 |
|
16108 |
|
16109 |
|
16110 |
|
16111 |
|
16112 |
|
16113 |
|
16114 |
|
16115 |
|
16116 |
|
16117 |
|
16118 |
|
16119 |
|
16120 |
|
16121 |
|
16122 |
|
16123 |
|
16124 |
|
16125 |
|
16126 |
|
16127 |
|
16128 |
|
16129 |
|
16130 | function escape(string) {
|
16131 | string = toString(string);
|
16132 | return (string && reHasUnescapedHtml.test(string))
|
16133 | ? string.replace(reUnescapedHtml, escapeHtmlChar)
|
16134 | : string;
|
16135 | }
|
16136 |
|
16137 | |
16138 |
|
16139 |
|
16140 |
|
16141 |
|
16142 |
|
16143 |
|
16144 |
|
16145 |
|
16146 |
|
16147 |
|
16148 |
|
16149 |
|
16150 |
|
16151 | function escapeRegExp(string) {
|
16152 | string = toString(string);
|
16153 | return (string && reHasRegExpChar.test(string))
|
16154 | ? string.replace(reRegExpChar, '\\$&')
|
16155 | : string;
|
16156 | }
|
16157 |
|
16158 | |
16159 |
|
16160 |
|
16161 |
|
16162 |
|
16163 |
|
16164 |
|
16165 |
|
16166 |
|
16167 |
|
16168 |
|
16169 |
|
16170 |
|
16171 |
|
16172 |
|
16173 |
|
16174 |
|
16175 |
|
16176 |
|
16177 | var kebabCase = createCompounder(function(result, word, index) {
|
16178 | return result + (index ? '-' : '') + word.toLowerCase();
|
16179 | });
|
16180 |
|
16181 | |
16182 |
|
16183 |
|
16184 |
|
16185 |
|
16186 |
|
16187 |
|
16188 |
|
16189 |
|
16190 |
|
16191 |
|
16192 |
|
16193 |
|
16194 |
|
16195 |
|
16196 |
|
16197 |
|
16198 |
|
16199 |
|
16200 | var lowerCase = createCompounder(function(result, word, index) {
|
16201 | return result + (index ? ' ' : '') + word.toLowerCase();
|
16202 | });
|
16203 |
|
16204 | |
16205 |
|
16206 |
|
16207 |
|
16208 |
|
16209 |
|
16210 |
|
16211 |
|
16212 |
|
16213 |
|
16214 |
|
16215 |
|
16216 |
|
16217 |
|
16218 |
|
16219 |
|
16220 | var lowerFirst = createCaseFirst('toLowerCase');
|
16221 |
|
16222 | |
16223 |
|
16224 |
|
16225 |
|
16226 |
|
16227 |
|
16228 |
|
16229 |
|
16230 |
|
16231 |
|
16232 |
|
16233 |
|
16234 |
|
16235 |
|
16236 |
|
16237 |
|
16238 | var upperFirst = createCaseFirst('toUpperCase');
|
16239 |
|
16240 | |
16241 |
|
16242 |
|
16243 |
|
16244 |
|
16245 |
|
16246 |
|
16247 |
|
16248 |
|
16249 |
|
16250 |
|
16251 |
|
16252 |
|
16253 |
|
16254 |
|
16255 |
|
16256 |
|
16257 |
|
16258 |
|
16259 |
|
16260 |
|
16261 |
|
16262 | function pad(string, length, chars) {
|
16263 | string = toString(string);
|
16264 | length = toInteger(length);
|
16265 |
|
16266 | var strLength = stringSize(string);
|
16267 | if (!length || strLength >= length) {
|
16268 | return string;
|
16269 | }
|
16270 | var mid = (length - strLength) / 2,
|
16271 | leftLength = nativeFloor(mid),
|
16272 | rightLength = nativeCeil(mid);
|
16273 |
|
16274 | return createPadding('', leftLength, chars) + string + createPadding('', rightLength, chars);
|
16275 | }
|
16276 |
|
16277 | |
16278 |
|
16279 |
|
16280 |
|
16281 |
|
16282 |
|
16283 |
|
16284 |
|
16285 |
|
16286 |
|
16287 |
|
16288 |
|
16289 |
|
16290 |
|
16291 |
|
16292 |
|
16293 |
|
16294 |
|
16295 |
|
16296 |
|
16297 |
|
16298 |
|
16299 | function padEnd(string, length, chars) {
|
16300 | string = toString(string);
|
16301 | return string + createPadding(string, length, chars);
|
16302 | }
|
16303 |
|
16304 | |
16305 |
|
16306 |
|
16307 |
|
16308 |
|
16309 |
|
16310 |
|
16311 |
|
16312 |
|
16313 |
|
16314 |
|
16315 |
|
16316 |
|
16317 |
|
16318 |
|
16319 |
|
16320 |
|
16321 |
|
16322 |
|
16323 |
|
16324 |
|
16325 |
|
16326 | function padStart(string, length, chars) {
|
16327 | string = toString(string);
|
16328 | return createPadding(string, length, chars) + string;
|
16329 | }
|
16330 |
|
16331 | |
16332 |
|
16333 |
|
16334 |
|
16335 |
|
16336 |
|
16337 |
|
16338 |
|
16339 |
|
16340 |
|
16341 |
|
16342 |
|
16343 |
|
16344 |
|
16345 |
|
16346 |
|
16347 |
|
16348 |
|
16349 |
|
16350 |
|
16351 |
|
16352 |
|
16353 |
|
16354 | function parseInt(string, radix, guard) {
|
16355 |
|
16356 |
|
16357 | if (guard || radix == null) {
|
16358 | radix = 0;
|
16359 | } else if (radix) {
|
16360 | radix = +radix;
|
16361 | }
|
16362 | string = toString(string).replace(reTrim, '');
|
16363 | return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
|
16364 | }
|
16365 |
|
16366 | |
16367 |
|
16368 |
|
16369 |
|
16370 |
|
16371 |
|
16372 |
|
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 |
|
16380 |
|
16381 |
|
16382 |
|
16383 |
|
16384 |
|
16385 |
|
16386 | function repeat(string, n) {
|
16387 | string = toString(string);
|
16388 | n = toInteger(n);
|
16389 |
|
16390 | var result = '';
|
16391 | if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
|
16392 | return result;
|
16393 | }
|
16394 |
|
16395 |
|
16396 | do {
|
16397 | if (n % 2) {
|
16398 | result += string;
|
16399 | }
|
16400 | n = nativeFloor(n / 2);
|
16401 | string += string;
|
16402 | } while (n);
|
16403 |
|
16404 | return result;
|
16405 | }
|
16406 |
|
16407 | |
16408 |
|
16409 |
|
16410 |
|
16411 |
|
16412 |
|
16413 |
|
16414 |
|
16415 |
|
16416 |
|
16417 |
|
16418 |
|
16419 |
|
16420 |
|
16421 |
|
16422 |
|
16423 |
|
16424 | function replace() {
|
16425 | var args = arguments,
|
16426 | string = toString(args[0]);
|
16427 |
|
16428 | return args.length < 3 ? string : string.replace(args[1], args[2]);
|
16429 | }
|
16430 |
|
16431 | |
16432 |
|
16433 |
|
16434 |
|
16435 |
|
16436 |
|
16437 |
|
16438 |
|
16439 |
|
16440 |
|
16441 |
|
16442 |
|
16443 |
|
16444 |
|
16445 |
|
16446 |
|
16447 |
|
16448 |
|
16449 |
|
16450 | var snakeCase = createCompounder(function(result, word, index) {
|
16451 | return result + (index ? '_' : '') + word.toLowerCase();
|
16452 | });
|
16453 |
|
16454 | |
16455 |
|
16456 |
|
16457 |
|
16458 |
|
16459 |
|
16460 |
|
16461 |
|
16462 |
|
16463 |
|
16464 |
|
16465 |
|
16466 |
|
16467 |
|
16468 |
|
16469 |
|
16470 |
|
16471 | function split(string, separator, limit) {
|
16472 | return toString(string).split(separator, limit);
|
16473 | }
|
16474 |
|
16475 | |
16476 |
|
16477 |
|
16478 |
|
16479 |
|
16480 |
|
16481 |
|
16482 |
|
16483 |
|
16484 |
|
16485 |
|
16486 |
|
16487 |
|
16488 |
|
16489 |
|
16490 |
|
16491 |
|
16492 |
|
16493 |
|
16494 | var startCase = createCompounder(function(result, word, index) {
|
16495 | return result + (index ? ' ' : '') + capitalize(word);
|
16496 | });
|
16497 |
|
16498 | |
16499 |
|
16500 |
|
16501 |
|
16502 |
|
16503 |
|
16504 |
|
16505 |
|
16506 |
|
16507 |
|
16508 |
|
16509 |
|
16510 |
|
16511 |
|
16512 |
|
16513 |
|
16514 |
|
16515 |
|
16516 |
|
16517 |
|
16518 |
|
16519 | function startsWith(string, target, position) {
|
16520 | string = toString(string);
|
16521 | position = baseClamp(toInteger(position), 0, string.length);
|
16522 | return string.lastIndexOf(target, position) == position;
|
16523 | }
|
16524 |
|
16525 | |
16526 |
|
16527 |
|
16528 |
|
16529 |
|
16530 |
|
16531 |
|
16532 |
|
16533 |
|
16534 |
|
16535 |
|
16536 |
|
16537 |
|
16538 |
|
16539 |
|
16540 |
|
16541 |
|
16542 |
|
16543 |
|
16544 |
|
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 |
|
16552 |
|
16553 |
|
16554 |
|
16555 |
|
16556 |
|
16557 |
|
16558 |
|
16559 |
|
16560 |
|
16561 |
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 |
|
16567 |
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 |
|
16574 |
|
16575 |
|
16576 |
|
16577 |
|
16578 |
|
16579 |
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 |
|
16585 |
|
16586 |
|
16587 |
|
16588 |
|
16589 |
|
16590 |
|
16591 |
|
16592 |
|
16593 |
|
16594 |
|
16595 |
|
16596 |
|
16597 |
|
16598 |
|
16599 |
|
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 |
|
16607 |
|
16608 |
|
16609 |
|
16610 |
|
16611 |
|
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 |
|
16618 |
|
16619 |
|
16620 |
|
16621 | function template(string, options, guard) {
|
16622 |
|
16623 |
|
16624 | var settings = lodash.templateSettings;
|
16625 |
|
16626 | if (guard && isIterateeCall(string, options, guard)) {
|
16627 | options = undefined;
|
16628 | }
|
16629 | string = toString(string);
|
16630 | options = assignInWith({}, options, settings, assignInDefaults);
|
16631 |
|
16632 | var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
|
16633 | importsKeys = keys(imports),
|
16634 | importsValues = baseValues(imports, importsKeys);
|
16635 |
|
16636 | var isEscaping,
|
16637 | isEvaluating,
|
16638 | index = 0,
|
16639 | interpolate = options.interpolate || reNoMatch,
|
16640 | source = "__p += '";
|
16641 |
|
16642 |
|
16643 | var reDelimiters = RegExp(
|
16644 | (options.escape || reNoMatch).source + '|' +
|
16645 | interpolate.source + '|' +
|
16646 | (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
16647 | (options.evaluate || reNoMatch).source + '|$'
|
16648 | , 'g');
|
16649 |
|
16650 |
|
16651 | var sourceURL = '//# sourceURL=' +
|
16652 | ('sourceURL' in options
|
16653 | ? options.sourceURL
|
16654 | : ('lodash.templateSources[' + (++templateCounter) + ']')
|
16655 | ) + '\n';
|
16656 |
|
16657 | string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
16658 | interpolateValue || (interpolateValue = esTemplateValue);
|
16659 |
|
16660 |
|
16661 | source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
|
16662 |
|
16663 |
|
16664 | if (escapeValue) {
|
16665 | isEscaping = true;
|
16666 | source += "' +\n__e(" + escapeValue + ") +\n'";
|
16667 | }
|
16668 | if (evaluateValue) {
|
16669 | isEvaluating = true;
|
16670 | source += "';\n" + evaluateValue + ";\n__p += '";
|
16671 | }
|
16672 | if (interpolateValue) {
|
16673 | source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
|
16674 | }
|
16675 | index = offset + match.length;
|
16676 |
|
16677 |
|
16678 |
|
16679 | return match;
|
16680 | });
|
16681 |
|
16682 | source += "';\n";
|
16683 |
|
16684 |
|
16685 |
|
16686 | var variable = options.variable;
|
16687 | if (!variable) {
|
16688 | source = 'with (obj) {\n' + source + '\n}\n';
|
16689 | }
|
16690 |
|
16691 | source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
16692 | .replace(reEmptyStringMiddle, '$1')
|
16693 | .replace(reEmptyStringTrailing, '$1;');
|
16694 |
|
16695 |
|
16696 | source = 'function(' + (variable || 'obj') + ') {\n' +
|
16697 | (variable
|
16698 | ? ''
|
16699 | : 'obj || (obj = {});\n'
|
16700 | ) +
|
16701 | "var __t, __p = ''" +
|
16702 | (isEscaping
|
16703 | ? ', __e = _.escape'
|
16704 | : ''
|
16705 | ) +
|
16706 | (isEvaluating
|
16707 | ? ', __j = Array.prototype.join;\n' +
|
16708 | "function print() { __p += __j.call(arguments, '') }\n"
|
16709 | : ';\n'
|
16710 | ) +
|
16711 | source +
|
16712 | 'return __p\n}';
|
16713 |
|
16714 | var result = attempt(function() {
|
16715 | return Function(importsKeys, sourceURL + 'return ' + source)
|
16716 | .apply(undefined, importsValues);
|
16717 | });
|
16718 |
|
16719 |
|
16720 |
|
16721 | result.source = source;
|
16722 | if (isError(result)) {
|
16723 | throw result;
|
16724 | }
|
16725 | return result;
|
16726 | }
|
16727 |
|
16728 | |
16729 |
|
16730 |
|
16731 |
|
16732 |
|
16733 |
|
16734 |
|
16735 |
|
16736 |
|
16737 |
|
16738 |
|
16739 |
|
16740 |
|
16741 |
|
16742 |
|
16743 |
|
16744 |
|
16745 |
|
16746 |
|
16747 |
|
16748 | function toLower(value) {
|
16749 | return toString(value).toLowerCase();
|
16750 | }
|
16751 |
|
16752 | |
16753 |
|
16754 |
|
16755 |
|
16756 |
|
16757 |
|
16758 |
|
16759 |
|
16760 |
|
16761 |
|
16762 |
|
16763 |
|
16764 |
|
16765 |
|
16766 |
|
16767 |
|
16768 |
|
16769 |
|
16770 |
|
16771 |
|
16772 | function toUpper(value) {
|
16773 | return toString(value).toUpperCase();
|
16774 | }
|
16775 |
|
16776 | |
16777 |
|
16778 |
|
16779 |
|
16780 |
|
16781 |
|
16782 |
|
16783 |
|
16784 |
|
16785 |
|
16786 |
|
16787 |
|
16788 |
|
16789 |
|
16790 |
|
16791 |
|
16792 |
|
16793 |
|
16794 |
|
16795 |
|
16796 |
|
16797 | function trim(string, chars, guard) {
|
16798 | string = toString(string);
|
16799 | if (!string) {
|
16800 | return string;
|
16801 | }
|
16802 | if (guard || chars === undefined) {
|
16803 | return string.replace(reTrim, '');
|
16804 | }
|
16805 | chars = (chars + '');
|
16806 | if (!chars) {
|
16807 | return string;
|
16808 | }
|
16809 | var strSymbols = stringToArray(string),
|
16810 | chrSymbols = stringToArray(chars);
|
16811 |
|
16812 | return strSymbols
|
16813 | .slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1)
|
16814 | .join('');
|
16815 | }
|
16816 |
|
16817 | |
16818 |
|
16819 |
|
16820 |
|
16821 |
|
16822 |
|
16823 |
|
16824 |
|
16825 |
|
16826 |
|
16827 |
|
16828 |
|
16829 |
|
16830 |
|
16831 |
|
16832 |
|
16833 |
|
16834 |
|
16835 | function trimEnd(string, chars, guard) {
|
16836 | string = toString(string);
|
16837 | if (!string) {
|
16838 | return string;
|
16839 | }
|
16840 | if (guard || chars === undefined) {
|
16841 | return string.replace(reTrimEnd, '');
|
16842 | }
|
16843 | chars = (chars + '');
|
16844 | if (!chars) {
|
16845 | return string;
|
16846 | }
|
16847 | var strSymbols = stringToArray(string);
|
16848 | return strSymbols
|
16849 | .slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1)
|
16850 | .join('');
|
16851 | }
|
16852 |
|
16853 | |
16854 |
|
16855 |
|
16856 |
|
16857 |
|
16858 |
|
16859 |
|
16860 |
|
16861 |
|
16862 |
|
16863 |
|
16864 |
|
16865 |
|
16866 |
|
16867 |
|
16868 |
|
16869 |
|
16870 |
|
16871 | function trimStart(string, chars, guard) {
|
16872 | string = toString(string);
|
16873 | if (!string) {
|
16874 | return string;
|
16875 | }
|
16876 | if (guard || chars === undefined) {
|
16877 | return string.replace(reTrimStart, '');
|
16878 | }
|
16879 | chars = (chars + '');
|
16880 | if (!chars) {
|
16881 | return string;
|
16882 | }
|
16883 | var strSymbols = stringToArray(string);
|
16884 | return strSymbols
|
16885 | .slice(charsStartIndex(strSymbols, stringToArray(chars)))
|
16886 | .join('');
|
16887 | }
|
16888 |
|
16889 | |
16890 |
|
16891 |
|
16892 |
|
16893 |
|
16894 |
|
16895 |
|
16896 |
|
16897 |
|
16898 |
|
16899 |
|
16900 |
|
16901 |
|
16902 |
|
16903 |
|
16904 |
|
16905 |
|
16906 |
|
16907 |
|
16908 |
|
16909 |
|
16910 |
|
16911 |
|
16912 |
|
16913 |
|
16914 |
|
16915 |
|
16916 |
|
16917 |
|
16918 |
|
16919 |
|
16920 |
|
16921 |
|
16922 |
|
16923 |
|
16924 |
|
16925 | function truncate(string, options) {
|
16926 | var length = DEFAULT_TRUNC_LENGTH,
|
16927 | omission = DEFAULT_TRUNC_OMISSION;
|
16928 |
|
16929 | if (isObject(options)) {
|
16930 | var separator = 'separator' in options ? options.separator : separator;
|
16931 | length = 'length' in options ? toInteger(options.length) : length;
|
16932 | omission = 'omission' in options ? toString(options.omission) : omission;
|
16933 | }
|
16934 | string = toString(string);
|
16935 |
|
16936 | var strLength = string.length;
|
16937 | if (reHasComplexSymbol.test(string)) {
|
16938 | var strSymbols = stringToArray(string);
|
16939 | strLength = strSymbols.length;
|
16940 | }
|
16941 | if (length >= strLength) {
|
16942 | return string;
|
16943 | }
|
16944 | var end = length - stringSize(omission);
|
16945 | if (end < 1) {
|
16946 | return omission;
|
16947 | }
|
16948 | var result = strSymbols
|
16949 | ? strSymbols.slice(0, end).join('')
|
16950 | : string.slice(0, end);
|
16951 |
|
16952 | if (separator === undefined) {
|
16953 | return result + omission;
|
16954 | }
|
16955 | if (strSymbols) {
|
16956 | end += (result.length - end);
|
16957 | }
|
16958 | if (isRegExp(separator)) {
|
16959 | if (string.slice(end).search(separator)) {
|
16960 | var match,
|
16961 | substring = result;
|
16962 |
|
16963 | if (!separator.global) {
|
16964 | separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
|
16965 | }
|
16966 | separator.lastIndex = 0;
|
16967 | while ((match = separator.exec(substring))) {
|
16968 | var newEnd = match.index;
|
16969 | }
|
16970 | result = result.slice(0, newEnd === undefined ? end : newEnd);
|
16971 | }
|
16972 | } else if (string.indexOf(separator, end) != end) {
|
16973 | var index = result.lastIndexOf(separator);
|
16974 | if (index > -1) {
|
16975 | result = result.slice(0, index);
|
16976 | }
|
16977 | }
|
16978 | return result + omission;
|
16979 | }
|
16980 |
|
16981 | |
16982 |
|
16983 |
|
16984 |
|
16985 |
|
16986 |
|
16987 |
|
16988 |
|
16989 |
|
16990 |
|
16991 |
|
16992 |
|
16993 |
|
16994 |
|
16995 |
|
16996 |
|
16997 |
|
16998 |
|
16999 | function unescape(string) {
|
17000 | string = toString(string);
|
17001 | return (string && reHasEscapedHtml.test(string))
|
17002 | ? string.replace(reEscapedHtml, unescapeHtmlChar)
|
17003 | : string;
|
17004 | }
|
17005 |
|
17006 | |
17007 |
|
17008 |
|
17009 |
|
17010 |
|
17011 |
|
17012 |
|
17013 |
|
17014 |
|
17015 |
|
17016 |
|
17017 |
|
17018 |
|
17019 |
|
17020 |
|
17021 |
|
17022 |
|
17023 |
|
17024 |
|
17025 | var upperCase = createCompounder(function(result, word, index) {
|
17026 | return result + (index ? ' ' : '') + word.toUpperCase();
|
17027 | });
|
17028 |
|
17029 | |
17030 |
|
17031 |
|
17032 |
|
17033 |
|
17034 |
|
17035 |
|
17036 |
|
17037 |
|
17038 |
|
17039 |
|
17040 |
|
17041 |
|
17042 |
|
17043 |
|
17044 |
|
17045 |
|
17046 |
|
17047 | function words(string, pattern, guard) {
|
17048 | string = toString(string);
|
17049 | pattern = guard ? undefined : pattern;
|
17050 |
|
17051 | if (pattern === undefined) {
|
17052 | pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
|
17053 | }
|
17054 | return string.match(pattern) || [];
|
17055 | }
|
17056 |
|
17057 |
|
17058 |
|
17059 | |
17060 |
|
17061 |
|
17062 |
|
17063 |
|
17064 |
|
17065 |
|
17066 |
|
17067 |
|
17068 |
|
17069 |
|
17070 |
|
17071 |
|
17072 |
|
17073 |
|
17074 |
|
17075 |
|
17076 |
|
17077 |
|
17078 |
|
17079 | var attempt = rest(function(func, args) {
|
17080 | try {
|
17081 | return apply(func, undefined, args);
|
17082 | } catch (e) {
|
17083 | return isError(e) ? e : new Error(e);
|
17084 | }
|
17085 | });
|
17086 |
|
17087 | |
17088 |
|
17089 |
|
17090 |
|
17091 |
|
17092 |
|
17093 |
|
17094 |
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 |
|
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 | var bindAll = rest(function(object, methodNames) {
|
17114 | arrayEach(baseFlatten(methodNames, 1), function(key) {
|
17115 | object[key] = bind(object[key], object);
|
17116 | });
|
17117 | return object;
|
17118 | });
|
17119 |
|
17120 | |
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 |
|
17130 |
|
17131 |
|
17132 |
|
17133 |
|
17134 |
|
17135 |
|
17136 |
|
17137 |
|
17138 |
|
17139 |
|
17140 |
|
17141 |
|
17142 |
|
17143 |
|
17144 |
|
17145 |
|
17146 |
|
17147 |
|
17148 | function cond(pairs) {
|
17149 | var length = pairs ? pairs.length : 0,
|
17150 | toIteratee = getIteratee();
|
17151 |
|
17152 | pairs = !length ? [] : arrayMap(pairs, function(pair) {
|
17153 | if (typeof pair[1] != 'function') {
|
17154 | throw new TypeError(FUNC_ERROR_TEXT);
|
17155 | }
|
17156 | return [toIteratee(pair[0]), pair[1]];
|
17157 | });
|
17158 |
|
17159 | return rest(function(args) {
|
17160 | var index = -1;
|
17161 | while (++index < length) {
|
17162 | var pair = pairs[index];
|
17163 | if (apply(pair[0], this, args)) {
|
17164 | return apply(pair[1], this, args);
|
17165 | }
|
17166 | }
|
17167 | });
|
17168 | }
|
17169 |
|
17170 | |
17171 |
|
17172 |
|
17173 |
|
17174 |
|
17175 |
|
17176 |
|
17177 |
|
17178 |
|
17179 |
|
17180 |
|
17181 |
|
17182 |
|
17183 |
|
17184 |
|
17185 |
|
17186 |
|
17187 |
|
17188 |
|
17189 |
|
17190 | function conforms(source) {
|
17191 | return baseConforms(baseClone(source, true));
|
17192 | }
|
17193 |
|
17194 | |
17195 |
|
17196 |
|
17197 |
|
17198 |
|
17199 |
|
17200 |
|
17201 |
|
17202 |
|
17203 |
|
17204 |
|
17205 |
|
17206 |
|
17207 |
|
17208 |
|
17209 |
|
17210 | function constant(value) {
|
17211 | return function() {
|
17212 | return value;
|
17213 | };
|
17214 | }
|
17215 |
|
17216 | |
17217 |
|
17218 |
|
17219 |
|
17220 |
|
17221 |
|
17222 |
|
17223 |
|
17224 |
|
17225 |
|
17226 |
|
17227 |
|
17228 |
|
17229 |
|
17230 |
|
17231 |
|
17232 |
|
17233 |
|
17234 |
|
17235 |
|
17236 | var flow = createFlow();
|
17237 |
|
17238 | |
17239 |
|
17240 |
|
17241 |
|
17242 |
|
17243 |
|
17244 |
|
17245 |
|
17246 |
|
17247 |
|
17248 |
|
17249 |
|
17250 |
|
17251 |
|
17252 |
|
17253 |
|
17254 |
|
17255 |
|
17256 |
|
17257 | var flowRight = createFlow(true);
|
17258 |
|
17259 | |
17260 |
|
17261 |
|
17262 |
|
17263 |
|
17264 |
|
17265 |
|
17266 |
|
17267 |
|
17268 |
|
17269 |
|
17270 |
|
17271 |
|
17272 |
|
17273 |
|
17274 | function identity(value) {
|
17275 | return value;
|
17276 | }
|
17277 |
|
17278 | |
17279 |
|
17280 |
|
17281 |
|
17282 |
|
17283 |
|
17284 |
|
17285 |
|
17286 |
|
17287 |
|
17288 |
|
17289 |
|
17290 |
|
17291 |
|
17292 |
|
17293 |
|
17294 |
|
17295 |
|
17296 |
|
17297 |
|
17298 |
|
17299 |
|
17300 |
|
17301 |
|
17302 |
|
17303 |
|
17304 |
|
17305 |
|
17306 |
|
17307 |
|
17308 | function iteratee(func) {
|
17309 | return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
|
17310 | }
|
17311 |
|
17312 | |
17313 |
|
17314 |
|
17315 |
|
17316 |
|
17317 |
|
17318 |
|
17319 |
|
17320 |
|
17321 |
|
17322 |
|
17323 |
|
17324 |
|
17325 |
|
17326 |
|
17327 |
|
17328 |
|
17329 |
|
17330 |
|
17331 |
|
17332 |
|
17333 |
|
17334 |
|
17335 | function matches(source) {
|
17336 | return baseMatches(baseClone(source, true));
|
17337 | }
|
17338 |
|
17339 | |
17340 |
|
17341 |
|
17342 |
|
17343 |
|
17344 |
|
17345 |
|
17346 |
|
17347 |
|
17348 |
|
17349 |
|
17350 |
|
17351 |
|
17352 |
|
17353 |
|
17354 |
|
17355 |
|
17356 |
|
17357 |
|
17358 |
|
17359 |
|
17360 |
|
17361 |
|
17362 | function matchesProperty(path, srcValue) {
|
17363 | return baseMatchesProperty(path, baseClone(srcValue, true));
|
17364 | }
|
17365 |
|
17366 | |
17367 |
|
17368 |
|
17369 |
|
17370 |
|
17371 |
|
17372 |
|
17373 |
|
17374 |
|
17375 |
|
17376 |
|
17377 |
|
17378 |
|
17379 |
|
17380 |
|
17381 |
|
17382 |
|
17383 |
|
17384 |
|
17385 |
|
17386 |
|
17387 |
|
17388 |
|
17389 | var method = rest(function(path, args) {
|
17390 | return function(object) {
|
17391 | return baseInvoke(object, path, args);
|
17392 | };
|
17393 | });
|
17394 |
|
17395 | |
17396 |
|
17397 |
|
17398 |
|
17399 |
|
17400 |
|
17401 |
|
17402 |
|
17403 |
|
17404 |
|
17405 |
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 |
|
17413 |
|
17414 |
|
17415 |
|
17416 |
|
17417 | var methodOf = rest(function(object, args) {
|
17418 | return function(path) {
|
17419 | return baseInvoke(object, path, args);
|
17420 | };
|
17421 | });
|
17422 |
|
17423 | |
17424 |
|
17425 |
|
17426 |
|
17427 |
|
17428 |
|
17429 |
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 |
|
17435 |
|
17436 |
|
17437 |
|
17438 |
|
17439 |
|
17440 |
|
17441 |
|
17442 |
|
17443 |
|
17444 |
|
17445 |
|
17446 |
|
17447 |
|
17448 |
|
17449 |
|
17450 |
|
17451 |
|
17452 |
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 | function mixin(object, source, options) {
|
17460 | var props = keys(source),
|
17461 | methodNames = baseFunctions(source, props);
|
17462 |
|
17463 | if (options == null &&
|
17464 | !(isObject(source) && (methodNames.length || !props.length))) {
|
17465 | options = source;
|
17466 | source = object;
|
17467 | object = this;
|
17468 | methodNames = baseFunctions(source, keys(source));
|
17469 | }
|
17470 | var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
|
17471 | isFunc = isFunction(object);
|
17472 |
|
17473 | arrayEach(methodNames, function(methodName) {
|
17474 | var func = source[methodName];
|
17475 | object[methodName] = func;
|
17476 | if (isFunc) {
|
17477 | object.prototype[methodName] = function() {
|
17478 | var chainAll = this.__chain__;
|
17479 | if (chain || chainAll) {
|
17480 | var result = object(this.__wrapped__),
|
17481 | actions = result.__actions__ = copyArray(this.__actions__);
|
17482 |
|
17483 | actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
17484 | result.__chain__ = chainAll;
|
17485 | return result;
|
17486 | }
|
17487 | return func.apply(object, arrayPush([this.value()], arguments));
|
17488 | };
|
17489 | }
|
17490 | });
|
17491 |
|
17492 | return object;
|
17493 | }
|
17494 |
|
17495 | |
17496 |
|
17497 |
|
17498 |
|
17499 |
|
17500 |
|
17501 |
|
17502 |
|
17503 |
|
17504 |
|
17505 |
|
17506 |
|
17507 | function noConflict() {
|
17508 | if (root._ === this) {
|
17509 | root._ = oldDash;
|
17510 | }
|
17511 | return this;
|
17512 | }
|
17513 |
|
17514 | |
17515 |
|
17516 |
|
17517 |
|
17518 |
|
17519 |
|
17520 |
|
17521 |
|
17522 |
|
17523 |
|
17524 |
|
17525 |
|
17526 |
|
17527 |
|
17528 | function noop() {
|
17529 |
|
17530 | }
|
17531 |
|
17532 | |
17533 |
|
17534 |
|
17535 |
|
17536 |
|
17537 |
|
17538 |
|
17539 |
|
17540 |
|
17541 |
|
17542 |
|
17543 |
|
17544 |
|
17545 |
|
17546 |
|
17547 | function nthArg(n) {
|
17548 | n = toInteger(n);
|
17549 | return function() {
|
17550 | return arguments[n];
|
17551 | };
|
17552 | }
|
17553 |
|
17554 | |
17555 |
|
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 |
|
17561 |
|
17562 |
|
17563 |
|
17564 |
|
17565 |
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 | var over = createOver(arrayMap);
|
17571 |
|
17572 | |
17573 |
|
17574 |
|
17575 |
|
17576 |
|
17577 |
|
17578 |
|
17579 |
|
17580 |
|
17581 |
|
17582 |
|
17583 |
|
17584 |
|
17585 |
|
17586 |
|
17587 |
|
17588 |
|
17589 |
|
17590 |
|
17591 |
|
17592 |
|
17593 |
|
17594 | var overEvery = createOver(arrayEvery);
|
17595 |
|
17596 | |
17597 |
|
17598 |
|
17599 |
|
17600 |
|
17601 |
|
17602 |
|
17603 |
|
17604 |
|
17605 |
|
17606 |
|
17607 |
|
17608 |
|
17609 |
|
17610 |
|
17611 |
|
17612 |
|
17613 |
|
17614 |
|
17615 |
|
17616 |
|
17617 |
|
17618 | var overSome = createOver(arraySome);
|
17619 |
|
17620 | |
17621 |
|
17622 |
|
17623 |
|
17624 |
|
17625 |
|
17626 |
|
17627 |
|
17628 |
|
17629 |
|
17630 |
|
17631 |
|
17632 |
|
17633 |
|
17634 |
|
17635 |
|
17636 |
|
17637 |
|
17638 |
|
17639 |
|
17640 |
|
17641 | function property(path) {
|
17642 | return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
17643 | }
|
17644 |
|
17645 | |
17646 |
|
17647 |
|
17648 |
|
17649 |
|
17650 |
|
17651 |
|
17652 |
|
17653 |
|
17654 |
|
17655 |
|
17656 |
|
17657 |
|
17658 |
|
17659 |
|
17660 |
|
17661 |
|
17662 |
|
17663 |
|
17664 |
|
17665 | function propertyOf(object) {
|
17666 | return function(path) {
|
17667 | return object == null ? undefined : baseGet(object, path);
|
17668 | };
|
17669 | }
|
17670 |
|
17671 | |
17672 |
|
17673 |
|
17674 |
|
17675 |
|
17676 |
|
17677 |
|
17678 |
|
17679 |
|
17680 |
|
17681 |
|
17682 |
|
17683 |
|
17684 |
|
17685 |
|
17686 |
|
17687 |
|
17688 |
|
17689 |
|
17690 |
|
17691 |
|
17692 |
|
17693 |
|
17694 |
|
17695 |
|
17696 |
|
17697 |
|
17698 |
|
17699 |
|
17700 |
|
17701 |
|
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 |
|
17709 |
|
17710 | var range = createRange();
|
17711 |
|
17712 | |
17713 |
|
17714 |
|
17715 |
|
17716 |
|
17717 |
|
17718 |
|
17719 |
|
17720 |
|
17721 |
|
17722 |
|
17723 |
|
17724 |
|
17725 |
|
17726 |
|
17727 |
|
17728 |
|
17729 |
|
17730 |
|
17731 |
|
17732 |
|
17733 |
|
17734 |
|
17735 |
|
17736 |
|
17737 |
|
17738 |
|
17739 |
|
17740 |
|
17741 |
|
17742 |
|
17743 |
|
17744 |
|
17745 |
|
17746 | var rangeRight = createRange(true);
|
17747 |
|
17748 | |
17749 |
|
17750 |
|
17751 |
|
17752 |
|
17753 |
|
17754 |
|
17755 |
|
17756 |
|
17757 |
|
17758 |
|
17759 |
|
17760 |
|
17761 |
|
17762 |
|
17763 |
|
17764 |
|
17765 |
|
17766 | function times(n, iteratee) {
|
17767 | n = toInteger(n);
|
17768 | if (n < 1 || n > MAX_SAFE_INTEGER) {
|
17769 | return [];
|
17770 | }
|
17771 | var index = MAX_ARRAY_LENGTH,
|
17772 | length = nativeMin(n, MAX_ARRAY_LENGTH);
|
17773 |
|
17774 | iteratee = baseCastFunction(iteratee);
|
17775 | n -= MAX_ARRAY_LENGTH;
|
17776 |
|
17777 | var result = baseTimes(length, iteratee);
|
17778 | while (++index < n) {
|
17779 | iteratee(index);
|
17780 | }
|
17781 | return result;
|
17782 | }
|
17783 |
|
17784 | |
17785 |
|
17786 |
|
17787 |
|
17788 |
|
17789 |
|
17790 |
|
17791 |
|
17792 |
|
17793 |
|
17794 |
|
17795 |
|
17796 |
|
17797 |
|
17798 |
|
17799 |
|
17800 |
|
17801 |
|
17802 |
|
17803 |
|
17804 |
|
17805 |
|
17806 |
|
17807 |
|
17808 |
|
17809 | function toPath(value) {
|
17810 | return isArray(value) ? arrayMap(value, String) : stringToPath(value);
|
17811 | }
|
17812 |
|
17813 | |
17814 |
|
17815 |
|
17816 |
|
17817 |
|
17818 |
|
17819 |
|
17820 |
|
17821 |
|
17822 |
|
17823 |
|
17824 |
|
17825 |
|
17826 |
|
17827 |
|
17828 |
|
17829 | function uniqueId(prefix) {
|
17830 | var id = ++idCounter;
|
17831 | return toString(prefix) + id;
|
17832 | }
|
17833 |
|
17834 |
|
17835 |
|
17836 | |
17837 |
|
17838 |
|
17839 |
|
17840 |
|
17841 |
|
17842 |
|
17843 |
|
17844 |
|
17845 |
|
17846 |
|
17847 |
|
17848 |
|
17849 |
|
17850 | function add(augend, addend) {
|
17851 | var result;
|
17852 | if (augend === undefined && addend === undefined) {
|
17853 | return 0;
|
17854 | }
|
17855 | if (augend !== undefined) {
|
17856 | result = augend;
|
17857 | }
|
17858 | if (addend !== undefined) {
|
17859 | result = result === undefined ? addend : (result + addend);
|
17860 | }
|
17861 | return result;
|
17862 | }
|
17863 |
|
17864 | |
17865 |
|
17866 |
|
17867 |
|
17868 |
|
17869 |
|
17870 |
|
17871 |
|
17872 |
|
17873 |
|
17874 |
|
17875 |
|
17876 |
|
17877 |
|
17878 |
|
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 |
|
17884 | var ceil = createRound('ceil');
|
17885 |
|
17886 | |
17887 |
|
17888 |
|
17889 |
|
17890 |
|
17891 |
|
17892 |
|
17893 |
|
17894 |
|
17895 |
|
17896 |
|
17897 |
|
17898 |
|
17899 |
|
17900 |
|
17901 |
|
17902 |
|
17903 |
|
17904 |
|
17905 |
|
17906 | var floor = createRound('floor');
|
17907 |
|
17908 | |
17909 |
|
17910 |
|
17911 |
|
17912 |
|
17913 |
|
17914 |
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 | function max(array) {
|
17926 | return (array && array.length)
|
17927 | ? baseExtremum(array, identity, gt)
|
17928 | : undefined;
|
17929 | }
|
17930 |
|
17931 | |
17932 |
|
17933 |
|
17934 |
|
17935 |
|
17936 |
|
17937 |
|
17938 |
|
17939 |
|
17940 |
|
17941 |
|
17942 |
|
17943 |
|
17944 |
|
17945 |
|
17946 |
|
17947 |
|
17948 |
|
17949 |
|
17950 |
|
17951 |
|
17952 |
|
17953 | function maxBy(array, iteratee) {
|
17954 | return (array && array.length)
|
17955 | ? baseExtremum(array, getIteratee(iteratee), gt)
|
17956 | : undefined;
|
17957 | }
|
17958 |
|
17959 | |
17960 |
|
17961 |
|
17962 |
|
17963 |
|
17964 |
|
17965 |
|
17966 |
|
17967 |
|
17968 |
|
17969 |
|
17970 |
|
17971 |
|
17972 | function mean(array) {
|
17973 | return sum(array) / (array ? array.length : 0);
|
17974 | }
|
17975 |
|
17976 | |
17977 |
|
17978 |
|
17979 |
|
17980 |
|
17981 |
|
17982 |
|
17983 |
|
17984 |
|
17985 |
|
17986 |
|
17987 |
|
17988 |
|
17989 |
|
17990 |
|
17991 |
|
17992 |
|
17993 | function min(array) {
|
17994 | return (array && array.length)
|
17995 | ? baseExtremum(array, identity, lt)
|
17996 | : undefined;
|
17997 | }
|
17998 |
|
17999 | |
18000 |
|
18001 |
|
18002 |
|
18003 |
|
18004 |
|
18005 |
|
18006 |
|
18007 |
|
18008 |
|
18009 |
|
18010 |
|
18011 |
|
18012 |
|
18013 |
|
18014 |
|
18015 |
|
18016 |
|
18017 |
|
18018 |
|
18019 |
|
18020 |
|
18021 | function minBy(array, iteratee) {
|
18022 | return (array && array.length)
|
18023 | ? baseExtremum(array, getIteratee(iteratee), lt)
|
18024 | : undefined;
|
18025 | }
|
18026 |
|
18027 | |
18028 |
|
18029 |
|
18030 |
|
18031 |
|
18032 |
|
18033 |
|
18034 |
|
18035 |
|
18036 |
|
18037 |
|
18038 |
|
18039 |
|
18040 |
|
18041 |
|
18042 |
|
18043 |
|
18044 |
|
18045 |
|
18046 |
|
18047 | var round = createRound('round');
|
18048 |
|
18049 | |
18050 |
|
18051 |
|
18052 |
|
18053 |
|
18054 |
|
18055 |
|
18056 |
|
18057 |
|
18058 |
|
18059 |
|
18060 |
|
18061 |
|
18062 |
|
18063 | function subtract(minuend, subtrahend) {
|
18064 | var result;
|
18065 | if (minuend === undefined && subtrahend === undefined) {
|
18066 | return 0;
|
18067 | }
|
18068 | if (minuend !== undefined) {
|
18069 | result = minuend;
|
18070 | }
|
18071 | if (subtrahend !== undefined) {
|
18072 | result = result === undefined ? subtrahend : (result - subtrahend);
|
18073 | }
|
18074 | return result;
|
18075 | }
|
18076 |
|
18077 | |
18078 |
|
18079 |
|
18080 |
|
18081 |
|
18082 |
|
18083 |
|
18084 |
|
18085 |
|
18086 |
|
18087 |
|
18088 |
|
18089 |
|
18090 | function sum(array) {
|
18091 | return (array && array.length)
|
18092 | ? baseSum(array, identity)
|
18093 | : 0;
|
18094 | }
|
18095 |
|
18096 | |
18097 |
|
18098 |
|
18099 |
|
18100 |
|
18101 |
|
18102 |
|
18103 |
|
18104 |
|
18105 |
|
18106 |
|
18107 |
|
18108 |
|
18109 |
|
18110 |
|
18111 |
|
18112 |
|
18113 |
|
18114 |
|
18115 |
|
18116 |
|
18117 |
|
18118 | function sumBy(array, iteratee) {
|
18119 | return (array && array.length)
|
18120 | ? baseSum(array, getIteratee(iteratee))
|
18121 | : 0;
|
18122 | }
|
18123 |
|
18124 |
|
18125 |
|
18126 |
|
18127 | lodash.prototype = baseLodash.prototype;
|
18128 | lodash.prototype.constructor = lodash;
|
18129 |
|
18130 | LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
18131 | LodashWrapper.prototype.constructor = LodashWrapper;
|
18132 |
|
18133 | LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
18134 | LazyWrapper.prototype.constructor = LazyWrapper;
|
18135 |
|
18136 |
|
18137 | Hash.prototype = nativeCreate ? nativeCreate(null) : objectProto;
|
18138 |
|
18139 |
|
18140 | MapCache.prototype.clear = mapClear;
|
18141 | MapCache.prototype['delete'] = mapDelete;
|
18142 | MapCache.prototype.get = mapGet;
|
18143 | MapCache.prototype.has = mapHas;
|
18144 | MapCache.prototype.set = mapSet;
|
18145 |
|
18146 |
|
18147 | SetCache.prototype.push = cachePush;
|
18148 |
|
18149 |
|
18150 | Stack.prototype.clear = stackClear;
|
18151 | Stack.prototype['delete'] = stackDelete;
|
18152 | Stack.prototype.get = stackGet;
|
18153 | Stack.prototype.has = stackHas;
|
18154 | Stack.prototype.set = stackSet;
|
18155 |
|
18156 |
|
18157 | memoize.Cache = MapCache;
|
18158 |
|
18159 |
|
18160 | lodash.after = after;
|
18161 | lodash.ary = ary;
|
18162 | lodash.assign = assign;
|
18163 | lodash.assignIn = assignIn;
|
18164 | lodash.assignInWith = assignInWith;
|
18165 | lodash.assignWith = assignWith;
|
18166 | lodash.at = at;
|
18167 | lodash.before = before;
|
18168 | lodash.bind = bind;
|
18169 | lodash.bindAll = bindAll;
|
18170 | lodash.bindKey = bindKey;
|
18171 | lodash.castArray = castArray;
|
18172 | lodash.chain = chain;
|
18173 | lodash.chunk = chunk;
|
18174 | lodash.compact = compact;
|
18175 | lodash.concat = concat;
|
18176 | lodash.cond = cond;
|
18177 | lodash.conforms = conforms;
|
18178 | lodash.constant = constant;
|
18179 | lodash.countBy = countBy;
|
18180 | lodash.create = create;
|
18181 | lodash.curry = curry;
|
18182 | lodash.curryRight = curryRight;
|
18183 | lodash.debounce = debounce;
|
18184 | lodash.defaults = defaults;
|
18185 | lodash.defaultsDeep = defaultsDeep;
|
18186 | lodash.defer = defer;
|
18187 | lodash.delay = delay;
|
18188 | lodash.difference = difference;
|
18189 | lodash.differenceBy = differenceBy;
|
18190 | lodash.differenceWith = differenceWith;
|
18191 | lodash.drop = drop;
|
18192 | lodash.dropRight = dropRight;
|
18193 | lodash.dropRightWhile = dropRightWhile;
|
18194 | lodash.dropWhile = dropWhile;
|
18195 | lodash.fill = fill;
|
18196 | lodash.filter = filter;
|
18197 | lodash.flatMap = flatMap;
|
18198 | lodash.flatten = flatten;
|
18199 | lodash.flattenDeep = flattenDeep;
|
18200 | lodash.flattenDepth = flattenDepth;
|
18201 | lodash.flip = flip;
|
18202 | lodash.flow = flow;
|
18203 | lodash.flowRight = flowRight;
|
18204 | lodash.fromPairs = fromPairs;
|
18205 | lodash.functions = functions;
|
18206 | lodash.functionsIn = functionsIn;
|
18207 | lodash.groupBy = groupBy;
|
18208 | lodash.initial = initial;
|
18209 | lodash.intersection = intersection;
|
18210 | lodash.intersectionBy = intersectionBy;
|
18211 | lodash.intersectionWith = intersectionWith;
|
18212 | lodash.invert = invert;
|
18213 | lodash.invertBy = invertBy;
|
18214 | lodash.invokeMap = invokeMap;
|
18215 | lodash.iteratee = iteratee;
|
18216 | lodash.keyBy = keyBy;
|
18217 | lodash.keys = keys;
|
18218 | lodash.keysIn = keysIn;
|
18219 | lodash.map = map;
|
18220 | lodash.mapKeys = mapKeys;
|
18221 | lodash.mapValues = mapValues;
|
18222 | lodash.matches = matches;
|
18223 | lodash.matchesProperty = matchesProperty;
|
18224 | lodash.memoize = memoize;
|
18225 | lodash.merge = merge;
|
18226 | lodash.mergeWith = mergeWith;
|
18227 | lodash.method = method;
|
18228 | lodash.methodOf = methodOf;
|
18229 | lodash.mixin = mixin;
|
18230 | lodash.negate = negate;
|
18231 | lodash.nthArg = nthArg;
|
18232 | lodash.omit = omit;
|
18233 | lodash.omitBy = omitBy;
|
18234 | lodash.once = once;
|
18235 | lodash.orderBy = orderBy;
|
18236 | lodash.over = over;
|
18237 | lodash.overArgs = overArgs;
|
18238 | lodash.overEvery = overEvery;
|
18239 | lodash.overSome = overSome;
|
18240 | lodash.partial = partial;
|
18241 | lodash.partialRight = partialRight;
|
18242 | lodash.partition = partition;
|
18243 | lodash.pick = pick;
|
18244 | lodash.pickBy = pickBy;
|
18245 | lodash.property = property;
|
18246 | lodash.propertyOf = propertyOf;
|
18247 | lodash.pull = pull;
|
18248 | lodash.pullAll = pullAll;
|
18249 | lodash.pullAllBy = pullAllBy;
|
18250 | lodash.pullAllWith = pullAllWith;
|
18251 | lodash.pullAt = pullAt;
|
18252 | lodash.range = range;
|
18253 | lodash.rangeRight = rangeRight;
|
18254 | lodash.rearg = rearg;
|
18255 | lodash.reject = reject;
|
18256 | lodash.remove = remove;
|
18257 | lodash.rest = rest;
|
18258 | lodash.reverse = reverse;
|
18259 | lodash.sampleSize = sampleSize;
|
18260 | lodash.set = set;
|
18261 | lodash.setWith = setWith;
|
18262 | lodash.shuffle = shuffle;
|
18263 | lodash.slice = slice;
|
18264 | lodash.sortBy = sortBy;
|
18265 | lodash.sortedUniq = sortedUniq;
|
18266 | lodash.sortedUniqBy = sortedUniqBy;
|
18267 | lodash.split = split;
|
18268 | lodash.spread = spread;
|
18269 | lodash.tail = tail;
|
18270 | lodash.take = take;
|
18271 | lodash.takeRight = takeRight;
|
18272 | lodash.takeRightWhile = takeRightWhile;
|
18273 | lodash.takeWhile = takeWhile;
|
18274 | lodash.tap = tap;
|
18275 | lodash.throttle = throttle;
|
18276 | lodash.thru = thru;
|
18277 | lodash.toArray = toArray;
|
18278 | lodash.toPairs = toPairs;
|
18279 | lodash.toPairsIn = toPairsIn;
|
18280 | lodash.toPath = toPath;
|
18281 | lodash.toPlainObject = toPlainObject;
|
18282 | lodash.transform = transform;
|
18283 | lodash.unary = unary;
|
18284 | lodash.union = union;
|
18285 | lodash.unionBy = unionBy;
|
18286 | lodash.unionWith = unionWith;
|
18287 | lodash.uniq = uniq;
|
18288 | lodash.uniqBy = uniqBy;
|
18289 | lodash.uniqWith = uniqWith;
|
18290 | lodash.unset = unset;
|
18291 | lodash.unzip = unzip;
|
18292 | lodash.unzipWith = unzipWith;
|
18293 | lodash.update = update;
|
18294 | lodash.updateWith = updateWith;
|
18295 | lodash.values = values;
|
18296 | lodash.valuesIn = valuesIn;
|
18297 | lodash.without = without;
|
18298 | lodash.words = words;
|
18299 | lodash.wrap = wrap;
|
18300 | lodash.xor = xor;
|
18301 | lodash.xorBy = xorBy;
|
18302 | lodash.xorWith = xorWith;
|
18303 | lodash.zip = zip;
|
18304 | lodash.zipObject = zipObject;
|
18305 | lodash.zipObjectDeep = zipObjectDeep;
|
18306 | lodash.zipWith = zipWith;
|
18307 |
|
18308 | // Add aliases.
|
18309 | lodash.extend = assignIn;
|
18310 | lodash.extendWith = assignInWith;
|
18311 |
|
18312 | // Add functions to `lodash.prototype`.
|
18313 | mixin(lodash, lodash);
|
18314 |
|
18315 | /*------------------------------------------------------------------------*/
|
18316 |
|
18317 | // Add functions that return unwrapped values when chaining.
|
18318 | lodash.add = add;
|
18319 | lodash.attempt = attempt;
|
18320 | lodash.camelCase = camelCase;
|
18321 | lodash.capitalize = capitalize;
|
18322 | lodash.ceil = ceil;
|
18323 | lodash.clamp = clamp;
|
18324 | lodash.clone = clone;
|
18325 | lodash.cloneDeep = cloneDeep;
|
18326 | lodash.cloneDeepWith = cloneDeepWith;
|
18327 | lodash.cloneWith = cloneWith;
|
18328 | lodash.deburr = deburr;
|
18329 | lodash.endsWith = endsWith;
|
18330 | lodash.eq = eq;
|
18331 | lodash.escape = escape;
|
18332 | lodash.escapeRegExp = escapeRegExp;
|
18333 | lodash.every = every;
|
18334 | lodash.find = find;
|
18335 | lodash.findIndex = findIndex;
|
18336 | lodash.findKey = findKey;
|
18337 | lodash.findLast = findLast;
|
18338 | lodash.findLastIndex = findLastIndex;
|
18339 | lodash.findLastKey = findLastKey;
|
18340 | lodash.floor = floor;
|
18341 | lodash.forEach = forEach;
|
18342 | lodash.forEachRight = forEachRight;
|
18343 | lodash.forIn = forIn;
|
18344 | lodash.forInRight = forInRight;
|
18345 | lodash.forOwn = forOwn;
|
18346 | lodash.forOwnRight = forOwnRight;
|
18347 | lodash.get = get;
|
18348 | lodash.gt = gt;
|
18349 | lodash.gte = gte;
|
18350 | lodash.has = has;
|
18351 | lodash.hasIn = hasIn;
|
18352 | lodash.head = head;
|
18353 | lodash.identity = identity;
|
18354 | lodash.includes = includes;
|
18355 | lodash.indexOf = indexOf;
|
18356 | lodash.inRange = inRange;
|
18357 | lodash.invoke = invoke;
|
18358 | lodash.isArguments = isArguments;
|
18359 | lodash.isArray = isArray;
|
18360 | lodash.isArrayBuffer = isArrayBuffer;
|
18361 | lodash.isArrayLike = isArrayLike;
|
18362 | lodash.isArrayLikeObject = isArrayLikeObject;
|
18363 | lodash.isBoolean = isBoolean;
|
18364 | lodash.isBuffer = isBuffer;
|
18365 | lodash.isDate = isDate;
|
18366 | lodash.isElement = isElement;
|
18367 | lodash.isEmpty = isEmpty;
|
18368 | lodash.isEqual = isEqual;
|
18369 | lodash.isEqualWith = isEqualWith;
|
18370 | lodash.isError = isError;
|
18371 | lodash.isFinite = isFinite;
|
18372 | lodash.isFunction = isFunction;
|
18373 | lodash.isInteger = isInteger;
|
18374 | lodash.isLength = isLength;
|
18375 | lodash.isMap = isMap;
|
18376 | lodash.isMatch = isMatch;
|
18377 | lodash.isMatchWith = isMatchWith;
|
18378 | lodash.isNaN = isNaN;
|
18379 | lodash.isNative = isNative;
|
18380 | lodash.isNil = isNil;
|
18381 | lodash.isNull = isNull;
|
18382 | lodash.isNumber = isNumber;
|
18383 | lodash.isObject = isObject;
|
18384 | lodash.isObjectLike = isObjectLike;
|
18385 | lodash.isPlainObject = isPlainObject;
|
18386 | lodash.isRegExp = isRegExp;
|
18387 | lodash.isSafeInteger = isSafeInteger;
|
18388 | lodash.isSet = isSet;
|
18389 | lodash.isString = isString;
|
18390 | lodash.isSymbol = isSymbol;
|
18391 | lodash.isTypedArray = isTypedArray;
|
18392 | lodash.isUndefined = isUndefined;
|
18393 | lodash.isWeakMap = isWeakMap;
|
18394 | lodash.isWeakSet = isWeakSet;
|
18395 | lodash.join = join;
|
18396 | lodash.kebabCase = kebabCase;
|
18397 | lodash.last = last;
|
18398 | lodash.lastIndexOf = lastIndexOf;
|
18399 | lodash.lowerCase = lowerCase;
|
18400 | lodash.lowerFirst = lowerFirst;
|
18401 | lodash.lt = lt;
|
18402 | lodash.lte = lte;
|
18403 | lodash.max = max;
|
18404 | lodash.maxBy = maxBy;
|
18405 | lodash.mean = mean;
|
18406 | lodash.min = min;
|
18407 | lodash.minBy = minBy;
|
18408 | lodash.noConflict = noConflict;
|
18409 | lodash.noop = noop;
|
18410 | lodash.now = now;
|
18411 | lodash.pad = pad;
|
18412 | lodash.padEnd = padEnd;
|
18413 | lodash.padStart = padStart;
|
18414 | lodash.parseInt = parseInt;
|
18415 | lodash.random = random;
|
18416 | lodash.reduce = reduce;
|
18417 | lodash.reduceRight = reduceRight;
|
18418 | lodash.repeat = repeat;
|
18419 | lodash.replace = replace;
|
18420 | lodash.result = result;
|
18421 | lodash.round = round;
|
18422 | lodash.runInContext = runInContext;
|
18423 | lodash.sample = sample;
|
18424 | lodash.size = size;
|
18425 | lodash.snakeCase = snakeCase;
|
18426 | lodash.some = some;
|
18427 | lodash.sortedIndex = sortedIndex;
|
18428 | lodash.sortedIndexBy = sortedIndexBy;
|
18429 | lodash.sortedIndexOf = sortedIndexOf;
|
18430 | lodash.sortedLastIndex = sortedLastIndex;
|
18431 | lodash.sortedLastIndexBy = sortedLastIndexBy;
|
18432 | lodash.sortedLastIndexOf = sortedLastIndexOf;
|
18433 | lodash.startCase = startCase;
|
18434 | lodash.startsWith = startsWith;
|
18435 | lodash.subtract = subtract;
|
18436 | lodash.sum = sum;
|
18437 | lodash.sumBy = sumBy;
|
18438 | lodash.template = template;
|
18439 | lodash.times = times;
|
18440 | lodash.toInteger = toInteger;
|
18441 | lodash.toLength = toLength;
|
18442 | lodash.toLower = toLower;
|
18443 | lodash.toNumber = toNumber;
|
18444 | lodash.toSafeInteger = toSafeInteger;
|
18445 | lodash.toString = toString;
|
18446 | lodash.toUpper = toUpper;
|
18447 | lodash.trim = trim;
|
18448 | lodash.trimEnd = trimEnd;
|
18449 | lodash.trimStart = trimStart;
|
18450 | lodash.truncate = truncate;
|
18451 | lodash.unescape = unescape;
|
18452 | lodash.uniqueId = uniqueId;
|
18453 | lodash.upperCase = upperCase;
|
18454 | lodash.upperFirst = upperFirst;
|
18455 |
|
18456 | // Add aliases.
|
18457 | lodash.each = forEach;
|
18458 | lodash.eachRight = forEachRight;
|
18459 | lodash.first = head;
|
18460 |
|
18461 | mixin(lodash, (function() {
|
18462 | var source = {};
|
18463 | baseForOwn(lodash, function(func, methodName) {
|
18464 | if (!hasOwnProperty.call(lodash.prototype, methodName)) {
|
18465 | source[methodName] = func;
|
18466 | }
|
18467 | });
|
18468 | return source;
|
18469 | }()), { 'chain': false });
|
18470 |
|
18471 |
|
18472 |
|
18473 | |
18474 |
|
18475 |
|
18476 |
|
18477 |
|
18478 |
|
18479 |
|
18480 | lodash.VERSION = VERSION;
|
18481 |
|
18482 |
|
18483 | arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
|
18484 | lodash[methodName].placeholder = lodash;
|
18485 | });
|
18486 |
|
18487 |
|
18488 | arrayEach(['drop', 'take'], function(methodName, index) {
|
18489 | LazyWrapper.prototype[methodName] = function(n) {
|
18490 | var filtered = this.__filtered__;
|
18491 | if (filtered && !index) {
|
18492 | return new LazyWrapper(this);
|
18493 | }
|
18494 | n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
|
18495 |
|
18496 | var result = this.clone();
|
18497 | if (filtered) {
|
18498 | result.__takeCount__ = nativeMin(n, result.__takeCount__);
|
18499 | } else {
|
18500 | result.__views__.push({
|
18501 | 'size': nativeMin(n, MAX_ARRAY_LENGTH),
|
18502 | 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
|
18503 | });
|
18504 | }
|
18505 | return result;
|
18506 | };
|
18507 |
|
18508 | LazyWrapper.prototype[methodName + 'Right'] = function(n) {
|
18509 | return this.reverse()[methodName](n).reverse();
|
18510 | };
|
18511 | });
|
18512 |
|
18513 |
|
18514 | arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
|
18515 | var type = index + 1,
|
18516 | isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
|
18517 |
|
18518 | LazyWrapper.prototype[methodName] = function(iteratee) {
|
18519 | var result = this.clone();
|
18520 | result.__iteratees__.push({
|
18521 | 'iteratee': getIteratee(iteratee, 3),
|
18522 | 'type': type
|
18523 | });
|
18524 | result.__filtered__ = result.__filtered__ || isFilter;
|
18525 | return result;
|
18526 | };
|
18527 | });
|
18528 |
|
18529 |
|
18530 | arrayEach(['head', 'last'], function(methodName, index) {
|
18531 | var takeName = 'take' + (index ? 'Right' : '');
|
18532 |
|
18533 | LazyWrapper.prototype[methodName] = function() {
|
18534 | return this[takeName](1).value()[0];
|
18535 | };
|
18536 | });
|
18537 |
|
18538 |
|
18539 | arrayEach(['initial', 'tail'], function(methodName, index) {
|
18540 | var dropName = 'drop' + (index ? '' : 'Right');
|
18541 |
|
18542 | LazyWrapper.prototype[methodName] = function() {
|
18543 | return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
|
18544 | };
|
18545 | });
|
18546 |
|
18547 | LazyWrapper.prototype.compact = function() {
|
18548 | return this.filter(identity);
|
18549 | };
|
18550 |
|
18551 | LazyWrapper.prototype.find = function(predicate) {
|
18552 | return this.filter(predicate).head();
|
18553 | };
|
18554 |
|
18555 | LazyWrapper.prototype.findLast = function(predicate) {
|
18556 | return this.reverse().find(predicate);
|
18557 | };
|
18558 |
|
18559 | LazyWrapper.prototype.invokeMap = rest(function(path, args) {
|
18560 | if (typeof path == 'function') {
|
18561 | return new LazyWrapper(this);
|
18562 | }
|
18563 | return this.map(function(value) {
|
18564 | return baseInvoke(value, path, args);
|
18565 | });
|
18566 | });
|
18567 |
|
18568 | LazyWrapper.prototype.reject = function(predicate) {
|
18569 | predicate = getIteratee(predicate, 3);
|
18570 | return this.filter(function(value) {
|
18571 | return !predicate(value);
|
18572 | });
|
18573 | };
|
18574 |
|
18575 | LazyWrapper.prototype.slice = function(start, end) {
|
18576 | start = toInteger(start);
|
18577 |
|
18578 | var result = this;
|
18579 | if (result.__filtered__ && (start > 0 || end < 0)) {
|
18580 | return new LazyWrapper(result);
|
18581 | }
|
18582 | if (start < 0) {
|
18583 | result = result.takeRight(-start);
|
18584 | } else if (start) {
|
18585 | result = result.drop(start);
|
18586 | }
|
18587 | if (end !== undefined) {
|
18588 | end = toInteger(end);
|
18589 | result = end < 0 ? result.dropRight(-end) : result.take(end - start);
|
18590 | }
|
18591 | return result;
|
18592 | };
|
18593 |
|
18594 | LazyWrapper.prototype.takeRightWhile = function(predicate) {
|
18595 | return this.reverse().takeWhile(predicate).reverse();
|
18596 | };
|
18597 |
|
18598 | LazyWrapper.prototype.toArray = function() {
|
18599 | return this.take(MAX_ARRAY_LENGTH);
|
18600 | };
|
18601 |
|
18602 |
|
18603 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
18604 | var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
|
18605 | isTaker = /^(?:head|last)$/.test(methodName),
|
18606 | lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
|
18607 | retUnwrapped = isTaker || /^find/.test(methodName);
|
18608 |
|
18609 | if (!lodashFunc) {
|
18610 | return;
|
18611 | }
|
18612 | lodash.prototype[methodName] = function() {
|
18613 | var value = this.__wrapped__,
|
18614 | args = isTaker ? [1] : arguments,
|
18615 | isLazy = value instanceof LazyWrapper,
|
18616 | iteratee = args[0],
|
18617 | useLazy = isLazy || isArray(value);
|
18618 |
|
18619 | var interceptor = function(value) {
|
18620 | var result = lodashFunc.apply(lodash, arrayPush([value], args));
|
18621 | return (isTaker && chainAll) ? result[0] : result;
|
18622 | };
|
18623 |
|
18624 | if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
18625 |
|
18626 | isLazy = useLazy = false;
|
18627 | }
|
18628 | var chainAll = this.__chain__,
|
18629 | isHybrid = !!this.__actions__.length,
|
18630 | isUnwrapped = retUnwrapped && !chainAll,
|
18631 | onlyLazy = isLazy && !isHybrid;
|
18632 |
|
18633 | if (!retUnwrapped && useLazy) {
|
18634 | value = onlyLazy ? value : new LazyWrapper(this);
|
18635 | var result = func.apply(value, args);
|
18636 | result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
18637 | return new LodashWrapper(result, chainAll);
|
18638 | }
|
18639 | if (isUnwrapped && onlyLazy) {
|
18640 | return func.apply(this, args);
|
18641 | }
|
18642 | result = this.thru(interceptor);
|
18643 | return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
|
18644 | };
|
18645 | });
|
18646 |
|
18647 |
|
18648 | arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
18649 | var func = arrayProto[methodName],
|
18650 | chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
18651 | retUnwrapped = /^(?:pop|shift)$/.test(methodName);
|
18652 |
|
18653 | lodash.prototype[methodName] = function() {
|
18654 | var args = arguments;
|
18655 | if (retUnwrapped && !this.__chain__) {
|
18656 | return func.apply(this.value(), args);
|
18657 | }
|
18658 | return this[chainName](function(value) {
|
18659 | return func.apply(value, args);
|
18660 | });
|
18661 | };
|
18662 | });
|
18663 |
|
18664 |
|
18665 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
18666 | var lodashFunc = lodash[methodName];
|
18667 | if (lodashFunc) {
|
18668 | var key = (lodashFunc.name + ''),
|
18669 | names = realNames[key] || (realNames[key] = []);
|
18670 |
|
18671 | names.push({ 'name': methodName, 'func': lodashFunc });
|
18672 | }
|
18673 | });
|
18674 |
|
18675 | realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{
|
18676 | 'name': 'wrapper',
|
18677 | 'func': undefined
|
18678 | }];
|
18679 |
|
18680 |
|
18681 | LazyWrapper.prototype.clone = lazyClone;
|
18682 | LazyWrapper.prototype.reverse = lazyReverse;
|
18683 | LazyWrapper.prototype.value = lazyValue;
|
18684 |
|
18685 |
|
18686 | lodash.prototype.at = wrapperAt;
|
18687 | lodash.prototype.chain = wrapperChain;
|
18688 | lodash.prototype.commit = wrapperCommit;
|
18689 | lodash.prototype.flatMap = wrapperFlatMap;
|
18690 | lodash.prototype.next = wrapperNext;
|
18691 | lodash.prototype.plant = wrapperPlant;
|
18692 | lodash.prototype.reverse = wrapperReverse;
|
18693 | lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
18694 |
|
18695 | if (iteratorSymbol) {
|
18696 | lodash.prototype[iteratorSymbol] = wrapperToIterator;
|
18697 | }
|
18698 | return lodash;
|
18699 | }
|
18700 |
|
18701 |
|
18702 |
|
18703 |
|
18704 | var _ = runInContext();
|
18705 |
|
18706 |
|
18707 |
|
18708 |
|
18709 | (freeWindow || freeSelf || {})._ = _;
|
18710 |
|
18711 |
|
18712 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
18713 |
|
18714 |
|
18715 | define(function() {
|
18716 | return _;
|
18717 | });
|
18718 | }
|
18719 |
|
18720 | else if (freeExports && freeModule) {
|
18721 |
|
18722 | if (moduleExports) {
|
18723 | (freeModule.exports = _)._ = _;
|
18724 | }
|
18725 |
|
18726 | freeExports._ = _;
|
18727 | }
|
18728 | else {
|
18729 |
|
18730 | root._ = _;
|
18731 | }
|
18732 | }.call(this));
|
18733 |
|
18734 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
18735 | },{}],3:[function(require,module,exports){
|
18736 | (function (global){
|
18737 | "use strict";
|
18738 |
|
18739 | var numeric = (typeof exports === "undefined")?(function numeric() {}):(exports);
|
18740 | if(typeof global !== "undefined") { global.numeric = numeric; }
|
18741 |
|
18742 | numeric.version = "1.2.6";
|
18743 |
|
18744 |
|
18745 | numeric.bench = function bench (f,interval) {
|
18746 | var t1,t2,n,i;
|
18747 | if(typeof interval === "undefined") { interval = 15; }
|
18748 | n = 0.5;
|
18749 | t1 = new Date();
|
18750 | while(1) {
|
18751 | n*=2;
|
18752 | for(i=n;i>3;i-=4) { f(); f(); f(); f(); }
|
18753 | while(i>0) { f(); i--; }
|
18754 | t2 = new Date();
|
18755 | if(t2-t1 > interval) break;
|
18756 | }
|
18757 | for(i=n;i>3;i-=4) { f(); f(); f(); f(); }
|
18758 | while(i>0) { f(); i--; }
|
18759 | t2 = new Date();
|
18760 | return 1000*(3*n-1)/(t2-t1);
|
18761 | }
|
18762 |
|
18763 | numeric._myIndexOf = (function _myIndexOf(w) {
|
18764 | var n = this.length,k;
|
18765 | for(k=0;k<n;++k) if(this[k]===w) return k;
|
18766 | return -1;
|
18767 | });
|
18768 | numeric.myIndexOf = (Array.prototype.indexOf)?Array.prototype.indexOf:numeric._myIndexOf;
|
18769 |
|
18770 | numeric.Function = Function;
|
18771 | numeric.precision = 4;
|
18772 | numeric.largeArray = 50;
|
18773 |
|
18774 | numeric.prettyPrint = function prettyPrint(x) {
|
18775 | function fmtnum(x) {
|
18776 | if(x === 0) { return '0'; }
|
18777 | if(isNaN(x)) { return 'NaN'; }
|
18778 | if(x<0) { return '-'+fmtnum(-x); }
|
18779 | if(isFinite(x)) {
|
18780 | var scale = Math.floor(Math.log(x) / Math.log(10));
|
18781 | var normalized = x / Math.pow(10,scale);
|
18782 | var basic = normalized.toPrecision(numeric.precision);
|
18783 | if(parseFloat(basic) === 10) { scale++; normalized = 1; basic = normalized.toPrecision(numeric.precision); }
|
18784 | return parseFloat(basic).toString()+'e'+scale.toString();
|
18785 | }
|
18786 | return 'Infinity';
|
18787 | }
|
18788 | var ret = [];
|
18789 | function foo(x) {
|
18790 | var k;
|
18791 | if(typeof x === "undefined") { ret.push(Array(numeric.precision+8).join(' ')); return false; }
|
18792 | if(typeof x === "string") { ret.push('"'+x+'"'); return false; }
|
18793 | if(typeof x === "boolean") { ret.push(x.toString()); return false; }
|
18794 | if(typeof x === "number") {
|
18795 | var a = fmtnum(x);
|
18796 | var b = x.toPrecision(numeric.precision);
|
18797 | var c = parseFloat(x.toString()).toString();
|
18798 | var d = [a,b,c,parseFloat(b).toString(),parseFloat(c).toString()];
|
18799 | for(k=1;k<d.length;k++) { if(d[k].length < a.length) a = d[k]; }
|
18800 | ret.push(Array(numeric.precision+8-a.length).join(' ')+a);
|
18801 | return false;
|
18802 | }
|
18803 | if(x === null) { ret.push("null"); return false; }
|
18804 | if(typeof x === "function") {
|
18805 | ret.push(x.toString());
|
18806 | var flag = false;
|
18807 | for(k in x) { if(x.hasOwnProperty(k)) {
|
18808 | if(flag) ret.push(',\n');
|
18809 | else ret.push('\n{');
|
18810 | flag = true;
|
18811 | ret.push(k);
|
18812 | ret.push(': \n');
|
18813 | foo(x[k]);
|
18814 | } }
|
18815 | if(flag) ret.push('}\n');
|
18816 | return true;
|
18817 | }
|
18818 | if(x instanceof Array) {
|
18819 | if(x.length > numeric.largeArray) { ret.push('...Large Array...'); return true; }
|
18820 | var flag = false;
|
18821 | ret.push('[');
|
18822 | for(k=0;k<x.length;k++) { if(k>0) { ret.push(','); if(flag) ret.push('\n '); } flag = foo(x[k]); }
|
18823 | ret.push(']');
|
18824 | return true;
|
18825 | }
|
18826 | ret.push('{');
|
18827 | var flag = false;
|
18828 | for(k in x) { if(x.hasOwnProperty(k)) { if(flag) ret.push(',\n'); flag = true; ret.push(k); ret.push(': \n'); foo(x[k]); } }
|
18829 | ret.push('}');
|
18830 | return true;
|
18831 | }
|
18832 | foo(x);
|
18833 | return ret.join('');
|
18834 | }
|
18835 |
|
18836 | numeric.parseDate = function parseDate(d) {
|
18837 | function foo(d) {
|
18838 | if(typeof d === 'string') { return Date.parse(d.replace(/-/g,'/')); }
|
18839 | if(!(d instanceof Array)) { throw new Error("parseDate: parameter must be arrays of strings"); }
|
18840 | var ret = [],k;
|
18841 | for(k=0;k<d.length;k++) { ret[k] = foo(d[k]); }
|
18842 | return ret;
|
18843 | }
|
18844 | return foo(d);
|
18845 | }
|
18846 |
|
18847 | numeric.parseFloat = function parseFloat_(d) {
|
18848 | function foo(d) {
|
18849 | if(typeof d === 'string') { return parseFloat(d); }
|
18850 | if(!(d instanceof Array)) { throw new Error("parseFloat: parameter must be arrays of strings"); }
|
18851 | var ret = [],k;
|
18852 | for(k=0;k<d.length;k++) { ret[k] = foo(d[k]); }
|
18853 | return ret;
|
18854 | }
|
18855 | return foo(d);
|
18856 | }
|
18857 |
|
18858 | numeric.parseCSV = function parseCSV(t) {
|
18859 | var foo = t.split('\n');
|
18860 | var j,k;
|
18861 | var ret = [];
|
18862 | var pat = /(([^'",]*)|('[^']*')|("[^"]*")),/g;
|
18863 | var patnum = /^\s*(([+-]?[0-9]+(\.[0-9]*)?(e[+-]?[0-9]+)?)|([+-]?[0-9]*(\.[0-9]+)?(e[+-]?[0-9]+)?))\s*$/;
|
18864 | var stripper = function(n) { return n.substr(0,n.length-1); }
|
18865 | var count = 0;
|
18866 | for(k=0;k<foo.length;k++) {
|
18867 | var bar = (foo[k]+",").match(pat),baz;
|
18868 | if(bar.length>0) {
|
18869 | ret[count] = [];
|
18870 | for(j=0;j<bar.length;j++) {
|
18871 | baz = stripper(bar[j]);
|
18872 | if(patnum.test(baz)) { ret[count][j] = parseFloat(baz); }
|
18873 | else ret[count][j] = baz;
|
18874 | }
|
18875 | count++;
|
18876 | }
|
18877 | }
|
18878 | return ret;
|
18879 | }
|
18880 |
|
18881 | numeric.toCSV = function toCSV(A) {
|
18882 | var s = numeric.dim(A);
|
18883 | var i,j,m,n,row,ret;
|
18884 | m = s[0];
|
18885 | n = s[1];
|
18886 | ret = [];
|
18887 | for(i=0;i<m;i++) {
|
18888 | row = [];
|
18889 | for(j=0;j<m;j++) { row[j] = A[i][j].toString(); }
|
18890 | ret[i] = row.join(', ');
|
18891 | }
|
18892 | return ret.join('\n')+'\n';
|
18893 | }
|
18894 |
|
18895 | numeric.getURL = function getURL(url) {
|
18896 | var client = new XMLHttpRequest();
|
18897 | client.open("GET",url,false);
|
18898 | client.send();
|
18899 | return client;
|
18900 | }
|
18901 |
|
18902 | numeric.imageURL = function imageURL(img) {
|
18903 | function base64(A) {
|
18904 | var n = A.length, i,x,y,z,p,q,r,s;
|
18905 | var key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
18906 | var ret = "";
|
18907 | for(i=0;i<n;i+=3) {
|
18908 | x = A[i];
|
18909 | y = A[i+1];
|
18910 | z = A[i+2];
|
18911 | p = x >> 2;
|
18912 | q = ((x & 3) << 4) + (y >> 4);
|
18913 | r = ((y & 15) << 2) + (z >> 6);
|
18914 | s = z & 63;
|
18915 | if(i+1>=n) { r = s = 64; }
|
18916 | else if(i+2>=n) { s = 64; }
|
18917 | ret += key.charAt(p) + key.charAt(q) + key.charAt(r) + key.charAt(s);
|
18918 | }
|
18919 | return ret;
|
18920 | }
|
18921 | function crc32Array (a,from,to) {
|
18922 | if(typeof from === "undefined") { from = 0; }
|
18923 | if(typeof to === "undefined") { to = a.length; }
|
18924 | var table = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
18925 | 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
18926 | 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
18927 | 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
18928 | 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
18929 | 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
18930 | 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
18931 | 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
|
18932 | 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
18933 | 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
18934 | 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
18935 | 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
18936 | 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
18937 | 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
18938 | 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
18939 | 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
18940 | 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
18941 | 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
18942 | 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
18943 | 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
18944 | 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
18945 | 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
18946 | 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
18947 | 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
18948 | 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
18949 | 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
18950 | 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
18951 | 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
18952 | 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
18953 | 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
18954 | 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
18955 | 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D];
|
18956 |
|
18957 | var crc = -1, y = 0, n = a.length,i;
|
18958 |
|
18959 | for (i = from; i < to; i++) {
|
18960 | y = (crc ^ a[i]) & 0xFF;
|
18961 | crc = (crc >>> 8) ^ table[y];
|
18962 | }
|
18963 |
|
18964 | return crc ^ (-1);
|
18965 | }
|
18966 |
|
18967 | var h = img[0].length, w = img[0][0].length, s1, s2, next,k,length,a,b,i,j,adler32,crc32;
|
18968 | var stream = [
|
18969 | 137, 80, 78, 71, 13, 10, 26, 10,
|
18970 | 0,0,0,13,
|
18971 | 73, 72, 68, 82,
|
18972 | (w >> 24) & 255, (w >> 16) & 255, (w >> 8) & 255, w&255,
|
18973 | (h >> 24) & 255, (h >> 16) & 255, (h >> 8) & 255, h&255,
|
18974 | 8,
|
18975 | 2,
|
18976 | 0,
|
18977 | 0,
|
18978 | 0,
|
18979 | -1,-2,-3,-4,
|
18980 | -5,-6,-7,-8,
|
18981 | 73, 68, 65, 84,
|
18982 |
|
18983 | 8,
|
18984 | 29
|
18985 | ];
|
18986 | crc32 = crc32Array(stream,12,29);
|
18987 | stream[29] = (crc32>>24)&255;
|
18988 | stream[30] = (crc32>>16)&255;
|
18989 | stream[31] = (crc32>>8)&255;
|
18990 | stream[32] = (crc32)&255;
|
18991 | s1 = 1;
|
18992 | s2 = 0;
|
18993 | for(i=0;i<h;i++) {
|
18994 | if(i<h-1) { stream.push(0); }
|
18995 | else { stream.push(1); }
|
18996 | a = (3*w+1+(i===0))&255; b = ((3*w+1+(i===0))>>8)&255;
|
18997 | stream.push(a); stream.push(b);
|
18998 | stream.push((~a)&255); stream.push((~b)&255);
|
18999 | if(i===0) stream.push(0);
|
19000 | for(j=0;j<w;j++) {
|
19001 | for(k=0;k<3;k++) {
|
19002 | a = img[k][i][j];
|
19003 | if(a>255) a = 255;
|
19004 | else if(a<0) a=0;
|
19005 | else a = Math.round(a);
|
19006 | s1 = (s1 + a )%65521;
|
19007 | s2 = (s2 + s1)%65521;
|
19008 | stream.push(a);
|
19009 | }
|
19010 | }
|
19011 | stream.push(0);
|
19012 | }
|
19013 | adler32 = (s2<<16)+s1;
|
19014 | stream.push((adler32>>24)&255);
|
19015 | stream.push((adler32>>16)&255);
|
19016 | stream.push((adler32>>8)&255);
|
19017 | stream.push((adler32)&255);
|
19018 | length = stream.length - 41;
|
19019 | stream[33] = (length>>24)&255;
|
19020 | stream[34] = (length>>16)&255;
|
19021 | stream[35] = (length>>8)&255;
|
19022 | stream[36] = (length)&255;
|
19023 | crc32 = crc32Array(stream,37);
|
19024 | stream.push((crc32>>24)&255);
|
19025 | stream.push((crc32>>16)&255);
|
19026 | stream.push((crc32>>8)&255);
|
19027 | stream.push((crc32)&255);
|
19028 | stream.push(0);
|
19029 | stream.push(0);
|
19030 | stream.push(0);
|
19031 | stream.push(0);
|
19032 |
|
19033 | stream.push(73);
|
19034 | stream.push(69);
|
19035 | stream.push(78);
|
19036 | stream.push(68);
|
19037 | stream.push(174);
|
19038 | stream.push(66);
|
19039 | stream.push(96);
|
19040 | stream.push(130);
|
19041 | return 'data:image/png;base64,'+base64(stream);
|
19042 | }
|
19043 |
|
19044 |
|
19045 | numeric._dim = function _dim(x) {
|
19046 | var ret = [];
|
19047 | while(typeof x === "object") { ret.push(x.length); x = x[0]; }
|
19048 | return ret;
|
19049 | }
|
19050 |
|
19051 | numeric.dim = function dim(x) {
|
19052 | var y,z;
|
19053 | if(typeof x === "object") {
|
19054 | y = x[0];
|
19055 | if(typeof y === "object") {
|
19056 | z = y[0];
|
19057 | if(typeof z === "object") {
|
19058 | return numeric._dim(x);
|
19059 | }
|
19060 | return [x.length,y.length];
|
19061 | }
|
19062 | return [x.length];
|
19063 | }
|
19064 | return [];
|
19065 | }
|
19066 |
|
19067 | numeric.mapreduce = function mapreduce(body,init) {
|
19068 | return Function('x','accum','_s','_k',
|
19069 | 'if(typeof accum === "undefined") accum = '+init+';\n'+
|
19070 | 'if(typeof x === "number") { var xi = x; '+body+'; return accum; }\n'+
|
19071 | 'if(typeof _s === "undefined") _s = numeric.dim(x);\n'+
|
19072 | 'if(typeof _k === "undefined") _k = 0;\n'+
|
19073 | 'var _n = _s[_k];\n'+
|
19074 | 'var i,xi;\n'+
|
19075 | 'if(_k < _s.length-1) {\n'+
|
19076 | ' for(i=_n-1;i>=0;i--) {\n'+
|
19077 | ' accum = arguments.callee(x[i],accum,_s,_k+1);\n'+
|
19078 | ' }'+
|
19079 | ' return accum;\n'+
|
19080 | '}\n'+
|
19081 | 'for(i=_n-1;i>=1;i-=2) { \n'+
|
19082 | ' xi = x[i];\n'+
|
19083 | ' '+body+';\n'+
|
19084 | ' xi = x[i-1];\n'+
|
19085 | ' '+body+';\n'+
|
19086 | '}\n'+
|
19087 | 'if(i === 0) {\n'+
|
19088 | ' xi = x[i];\n'+
|
19089 | ' '+body+'\n'+
|
19090 | '}\n'+
|
19091 | 'return accum;'
|
19092 | );
|
19093 | }
|
19094 | numeric.mapreduce2 = function mapreduce2(body,setup) {
|
19095 | return Function('x',
|
19096 | 'var n = x.length;\n'+
|
19097 | 'var i,xi;\n'+setup+';\n'+
|
19098 | 'for(i=n-1;i!==-1;--i) { \n'+
|
19099 | ' xi = x[i];\n'+
|
19100 | ' '+body+';\n'+
|
19101 | '}\n'+
|
19102 | 'return accum;'
|
19103 | );
|
19104 | }
|
19105 |
|
19106 |
|
19107 | numeric.same = function same(x,y) {
|
19108 | var i,n;
|
19109 | if(!(x instanceof Array) || !(y instanceof Array)) { return false; }
|
19110 | n = x.length;
|
19111 | if(n !== y.length) { return false; }
|
19112 | for(i=0;i<n;i++) {
|
19113 | if(x[i] === y[i]) { continue; }
|
19114 | if(typeof x[i] === "object") { if(!same(x[i],y[i])) return false; }
|
19115 | else { return false; }
|
19116 | }
|
19117 | return true;
|
19118 | }
|
19119 |
|
19120 | numeric.rep = function rep(s,v,k) {
|
19121 | if(typeof k === "undefined") { k=0; }
|
19122 | var n = s[k], ret = Array(n), i;
|
19123 | if(k === s.length-1) {
|
19124 | for(i=n-2;i>=0;i-=2) { ret[i+1] = v; ret[i] = v; }
|
19125 | if(i===-1) { ret[0] = v; }
|
19126 | return ret;
|
19127 | }
|
19128 | for(i=n-1;i>=0;i--) { ret[i] = numeric.rep(s,v,k+1); }
|
19129 | return ret;
|
19130 | }
|
19131 |
|
19132 |
|
19133 | numeric.dotMMsmall = function dotMMsmall(x,y) {
|
19134 | var i,j,k,p,q,r,ret,foo,bar,woo,i0,k0,p0,r0;
|
19135 | p = x.length; q = y.length; r = y[0].length;
|
19136 | ret = Array(p);
|
19137 | for(i=p-1;i>=0;i--) {
|
19138 | foo = Array(r);
|
19139 | bar = x[i];
|
19140 | for(k=r-1;k>=0;k--) {
|
19141 | woo = bar[q-1]*y[q-1][k];
|
19142 | for(j=q-2;j>=1;j-=2) {
|
19143 | i0 = j-1;
|
19144 | woo += bar[j]*y[j][k] + bar[i0]*y[i0][k];
|
19145 | }
|
19146 | if(j===0) { woo += bar[0]*y[0][k]; }
|
19147 | foo[k] = woo;
|
19148 | }
|
19149 | ret[i] = foo;
|
19150 | }
|
19151 | return ret;
|
19152 | }
|
19153 | numeric._getCol = function _getCol(A,j,x) {
|
19154 | var n = A.length, i;
|
19155 | for(i=n-1;i>0;--i) {
|
19156 | x[i] = A[i][j];
|
19157 | --i;
|
19158 | x[i] = A[i][j];
|
19159 | }
|
19160 | if(i===0) x[0] = A[0][j];
|
19161 | }
|
19162 | numeric.dotMMbig = function dotMMbig(x,y){
|
19163 | var gc = numeric._getCol, p = y.length, v = Array(p);
|
19164 | var m = x.length, n = y[0].length, A = new Array(m), xj;
|
19165 | var VV = numeric.dotVV;
|
19166 | var i,j,k,z;
|
19167 | --p;
|
19168 | --m;
|
19169 | for(i=m;i!==-1;--i) A[i] = Array(n);
|
19170 | --n;
|
19171 | for(i=n;i!==-1;--i) {
|
19172 | gc(y,i,v);
|
19173 | for(j=m;j!==-1;--j) {
|
19174 | z=0;
|
19175 | xj = x[j];
|
19176 | A[j][i] = VV(xj,v);
|
19177 | }
|
19178 | }
|
19179 | return A;
|
19180 | }
|
19181 |
|
19182 | numeric.dotMV = function dotMV(x,y) {
|
19183 | var p = x.length, q = y.length,i;
|
19184 | var ret = Array(p), dotVV = numeric.dotVV;
|
19185 | for(i=p-1;i>=0;i--) { ret[i] = dotVV(x[i],y); }
|
19186 | return ret;
|
19187 | }
|
19188 |
|
19189 | numeric.dotVM = function dotVM(x,y) {
|
19190 | var i,j,k,p,q,r,ret,foo,bar,woo,i0,k0,p0,r0,s1,s2,s3,baz,accum;
|
19191 | p = x.length; q = y[0].length;
|
19192 | ret = Array(q);
|
19193 | for(k=q-1;k>=0;k--) {
|
19194 | woo = x[p-1]*y[p-1][k];
|
19195 | for(j=p-2;j>=1;j-=2) {
|
19196 | i0 = j-1;
|
19197 | woo += x[j]*y[j][k] + x[i0]*y[i0][k];
|
19198 | }
|
19199 | if(j===0) { woo += x[0]*y[0][k]; }
|
19200 | ret[k] = woo;
|
19201 | }
|
19202 | return ret;
|
19203 | }
|
19204 |
|
19205 | numeric.dotVV = function dotVV(x,y) {
|
19206 | var i,n=x.length,i1,ret = x[n-1]*y[n-1];
|
19207 | for(i=n-2;i>=1;i-=2) {
|
19208 | i1 = i-1;
|
19209 | ret += x[i]*y[i] + x[i1]*y[i1];
|
19210 | }
|
19211 | if(i===0) { ret += x[0]*y[0]; }
|
19212 | return ret;
|
19213 | }
|
19214 |
|
19215 | numeric.dot = function dot(x,y) {
|
19216 | var d = numeric.dim;
|
19217 | switch(d(x).length*1000+d(y).length) {
|
19218 | case 2002:
|
19219 | if(y.length < 10) return numeric.dotMMsmall(x,y);
|
19220 | else return numeric.dotMMbig(x,y);
|
19221 | case 2001: return numeric.dotMV(x,y);
|
19222 | case 1002: return numeric.dotVM(x,y);
|
19223 | case 1001: return numeric.dotVV(x,y);
|
19224 | case 1000: return numeric.mulVS(x,y);
|
19225 | case 1: return numeric.mulSV(x,y);
|
19226 | case 0: return x*y;
|
19227 | default: throw new Error('numeric.dot only works on vectors and matrices');
|
19228 | }
|
19229 | }
|
19230 |
|
19231 | numeric.diag = function diag(d) {
|
19232 | var i,i1,j,n = d.length, A = Array(n), Ai;
|
19233 | for(i=n-1;i>=0;i--) {
|
19234 | Ai = Array(n);
|
19235 | i1 = i+2;
|
19236 | for(j=n-1;j>=i1;j-=2) {
|
19237 | Ai[j] = 0;
|
19238 | Ai[j-1] = 0;
|
19239 | }
|
19240 | if(j>i) { Ai[j] = 0; }
|
19241 | Ai[i] = d[i];
|
19242 | for(j=i-1;j>=1;j-=2) {
|
19243 | Ai[j] = 0;
|
19244 | Ai[j-1] = 0;
|
19245 | }
|
19246 | if(j===0) { Ai[0] = 0; }
|
19247 | A[i] = Ai;
|
19248 | }
|
19249 | return A;
|
19250 | }
|
19251 | numeric.getDiag = function(A) {
|
19252 | var n = Math.min(A.length,A[0].length),i,ret = Array(n);
|
19253 | for(i=n-1;i>=1;--i) {
|
19254 | ret[i] = A[i][i];
|
19255 | --i;
|
19256 | ret[i] = A[i][i];
|
19257 | }
|
19258 | if(i===0) {
|
19259 | ret[0] = A[0][0];
|
19260 | }
|
19261 | return ret;
|
19262 | }
|
19263 |
|
19264 | numeric.identity = function identity(n) { return numeric.diag(numeric.rep([n],1)); }
|
19265 | numeric.pointwise = function pointwise(params,body,setup) {
|
19266 | if(typeof setup === "undefined") { setup = ""; }
|
19267 | var fun = [];
|
19268 | var k;
|
19269 | var avec = /\[i\]$/,p,thevec = '';
|
19270 | var haveret = false;
|
19271 | for(k=0;k<params.length;k++) {
|
19272 | if(avec.test(params[k])) {
|
19273 | p = params[k].substring(0,params[k].length-3);
|
19274 | thevec = p;
|
19275 | } else { p = params[k]; }
|
19276 | if(p==='ret') haveret = true;
|
19277 | fun.push(p);
|
19278 | }
|
19279 | fun[params.length] = '_s';
|
19280 | fun[params.length+1] = '_k';
|
19281 | fun[params.length+2] = (
|
19282 | 'if(typeof _s === "undefined") _s = numeric.dim('+thevec+');\n'+
|
19283 | 'if(typeof _k === "undefined") _k = 0;\n'+
|
19284 | 'var _n = _s[_k];\n'+
|
19285 | 'var i'+(haveret?'':', ret = Array(_n)')+';\n'+
|
19286 | 'if(_k < _s.length-1) {\n'+
|
19287 | ' for(i=_n-1;i>=0;i--) ret[i] = arguments.callee('+params.join(',')+',_s,_k+1);\n'+
|
19288 | ' return ret;\n'+
|
19289 | '}\n'+
|
19290 | setup+'\n'+
|
19291 | 'for(i=_n-1;i!==-1;--i) {\n'+
|
19292 | ' '+body+'\n'+
|
19293 | '}\n'+
|
19294 | 'return ret;'
|
19295 | );
|
19296 | return Function.apply(null,fun);
|
19297 | }
|
19298 | numeric.pointwise2 = function pointwise2(params,body,setup) {
|
19299 | if(typeof setup === "undefined") { setup = ""; }
|
19300 | var fun = [];
|
19301 | var k;
|
19302 | var avec = /\[i\]$/,p,thevec = '';
|
19303 | var haveret = false;
|
19304 | for(k=0;k<params.length;k++) {
|
19305 | if(avec.test(params[k])) {
|
19306 | p = params[k].substring(0,params[k].length-3);
|
19307 | thevec = p;
|
19308 | } else { p = params[k]; }
|
19309 | if(p==='ret') haveret = true;
|
19310 | fun.push(p);
|
19311 | }
|
19312 | fun[params.length] = (
|
19313 | 'var _n = '+thevec+'.length;\n'+
|
19314 | 'var i'+(haveret?'':', ret = Array(_n)')+';\n'+
|
19315 | setup+'\n'+
|
19316 | 'for(i=_n-1;i!==-1;--i) {\n'+
|
19317 | body+'\n'+
|
19318 | '}\n'+
|
19319 | 'return ret;'
|
19320 | );
|
19321 | return Function.apply(null,fun);
|
19322 | }
|
19323 | numeric._biforeach = (function _biforeach(x,y,s,k,f) {
|
19324 | if(k === s.length-1) { f(x,y); return; }
|
19325 | var i,n=s[k];
|
19326 | for(i=n-1;i>=0;i--) { _biforeach(typeof x==="object"?x[i]:x,typeof y==="object"?y[i]:y,s,k+1,f); }
|
19327 | });
|
19328 | numeric._biforeach2 = (function _biforeach2(x,y,s,k,f) {
|
19329 | if(k === s.length-1) { return f(x,y); }
|
19330 | var i,n=s[k],ret = Array(n);
|
19331 | for(i=n-1;i>=0;--i) { ret[i] = _biforeach2(typeof x==="object"?x[i]:x,typeof y==="object"?y[i]:y,s,k+1,f); }
|
19332 | return ret;
|
19333 | });
|
19334 | numeric._foreach = (function _foreach(x,s,k,f) {
|
19335 | if(k === s.length-1) { f(x); return; }
|
19336 | var i,n=s[k];
|
19337 | for(i=n-1;i>=0;i--) { _foreach(x[i],s,k+1,f); }
|
19338 | });
|
19339 | numeric._foreach2 = (function _foreach2(x,s,k,f) {
|
19340 | if(k === s.length-1) { return f(x); }
|
19341 | var i,n=s[k], ret = Array(n);
|
19342 | for(i=n-1;i>=0;i--) { ret[i] = _foreach2(x[i],s,k+1,f); }
|
19343 | return ret;
|
19344 | });
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 |
|
19351 | numeric.ops2 = {
|
19352 | add: '+',
|
19353 | sub: '-',
|
19354 | mul: '*',
|
19355 | div: '/',
|
19356 | mod: '%',
|
19357 | and: '&&',
|
19358 | or: '||',
|
19359 | eq: '===',
|
19360 | neq: '!==',
|
19361 | lt: '<',
|
19362 | gt: '>',
|
19363 | leq: '<=',
|
19364 | geq: '>=',
|
19365 | band: '&',
|
19366 | bor: '|',
|
19367 | bxor: '^',
|
19368 | lshift: '<<',
|
19369 | rshift: '>>',
|
19370 | rrshift: '>>>'
|
19371 | };
|
19372 | numeric.opseq = {
|
19373 | addeq: '+=',
|
19374 | subeq: '-=',
|
19375 | muleq: '*=',
|
19376 | diveq: '/=',
|
19377 | modeq: '%=',
|
19378 | lshifteq: '<<=',
|
19379 | rshifteq: '>>=',
|
19380 | rrshifteq: '>>>=',
|
19381 | bandeq: '&=',
|
19382 | boreq: '|=',
|
19383 | bxoreq: '^='
|
19384 | };
|
19385 | numeric.mathfuns = ['abs','acos','asin','atan','ceil','cos',
|
19386 | 'exp','floor','log','round','sin','sqrt','tan',
|
19387 | 'isNaN','isFinite'];
|
19388 | numeric.mathfuns2 = ['atan2','pow','max','min'];
|
19389 | numeric.ops1 = {
|
19390 | neg: '-',
|
19391 | not: '!',
|
19392 | bnot: '~',
|
19393 | clone: ''
|
19394 | };
|
19395 | numeric.mapreducers = {
|
19396 | any: ['if(xi) return true;','var accum = false;'],
|
19397 | all: ['if(!xi) return false;','var accum = true;'],
|
19398 | sum: ['accum += xi;','var accum = 0;'],
|
19399 | prod: ['accum *= xi;','var accum = 1;'],
|
19400 | norm2Squared: ['accum += xi*xi;','var accum = 0;'],
|
19401 | norminf: ['accum = max(accum,abs(xi));','var accum = 0, max = Math.max, abs = Math.abs;'],
|
19402 | norm1: ['accum += abs(xi)','var accum = 0, abs = Math.abs;'],
|
19403 | sup: ['accum = max(accum,xi);','var accum = -Infinity, max = Math.max;'],
|
19404 | inf: ['accum = min(accum,xi);','var accum = Infinity, min = Math.min;']
|
19405 | };
|
19406 |
|
19407 | (function () {
|
19408 | var i,o;
|
19409 | for(i=0;i<numeric.mathfuns2.length;++i) {
|
19410 | o = numeric.mathfuns2[i];
|
19411 | numeric.ops2[o] = o;
|
19412 | }
|
19413 | for(i in numeric.ops2) {
|
19414 | if(numeric.ops2.hasOwnProperty(i)) {
|
19415 | o = numeric.ops2[i];
|
19416 | var code, codeeq, setup = '';
|
19417 | if(numeric.myIndexOf.call(numeric.mathfuns2,i)!==-1) {
|
19418 | setup = 'var '+o+' = Math.'+o+';\n';
|
19419 | code = function(r,x,y) { return r+' = '+o+'('+x+','+y+')'; };
|
19420 | codeeq = function(x,y) { return x+' = '+o+'('+x+','+y+')'; };
|
19421 | } else {
|
19422 | code = function(r,x,y) { return r+' = '+x+' '+o+' '+y; };
|
19423 | if(numeric.opseq.hasOwnProperty(i+'eq')) {
|
19424 | codeeq = function(x,y) { return x+' '+o+'= '+y; };
|
19425 | } else {
|
19426 | codeeq = function(x,y) { return x+' = '+x+' '+o+' '+y; };
|
19427 | }
|
19428 | }
|
19429 | numeric[i+'VV'] = numeric.pointwise2(['x[i]','y[i]'],code('ret[i]','x[i]','y[i]'),setup);
|
19430 | numeric[i+'SV'] = numeric.pointwise2(['x','y[i]'],code('ret[i]','x','y[i]'),setup);
|
19431 | numeric[i+'VS'] = numeric.pointwise2(['x[i]','y'],code('ret[i]','x[i]','y'),setup);
|
19432 | numeric[i] = Function(
|
19433 | 'var n = arguments.length, i, x = arguments[0], y;\n'+
|
19434 | 'var VV = numeric.'+i+'VV, VS = numeric.'+i+'VS, SV = numeric.'+i+'SV;\n'+
|
19435 | 'var dim = numeric.dim;\n'+
|
19436 | 'for(i=1;i!==n;++i) { \n'+
|
19437 | ' y = arguments[i];\n'+
|
19438 | ' if(typeof x === "object") {\n'+
|
19439 | ' if(typeof y === "object") x = numeric._biforeach2(x,y,dim(x),0,VV);\n'+
|
19440 | ' else x = numeric._biforeach2(x,y,dim(x),0,VS);\n'+
|
19441 | ' } else if(typeof y === "object") x = numeric._biforeach2(x,y,dim(y),0,SV);\n'+
|
19442 | ' else '+codeeq('x','y')+'\n'+
|
19443 | '}\nreturn x;\n');
|
19444 | numeric[o] = numeric[i];
|
19445 | numeric[i+'eqV'] = numeric.pointwise2(['ret[i]','x[i]'], codeeq('ret[i]','x[i]'),setup);
|
19446 | numeric[i+'eqS'] = numeric.pointwise2(['ret[i]','x'], codeeq('ret[i]','x'),setup);
|
19447 | numeric[i+'eq'] = Function(
|
19448 | 'var n = arguments.length, i, x = arguments[0], y;\n'+
|
19449 | 'var V = numeric.'+i+'eqV, S = numeric.'+i+'eqS\n'+
|
19450 | 'var s = numeric.dim(x);\n'+
|
19451 | 'for(i=1;i!==n;++i) { \n'+
|
19452 | ' y = arguments[i];\n'+
|
19453 | ' if(typeof y === "object") numeric._biforeach(x,y,s,0,V);\n'+
|
19454 | ' else numeric._biforeach(x,y,s,0,S);\n'+
|
19455 | '}\nreturn x;\n');
|
19456 | }
|
19457 | }
|
19458 | for(i=0;i<numeric.mathfuns2.length;++i) {
|
19459 | o = numeric.mathfuns2[i];
|
19460 | delete numeric.ops2[o];
|
19461 | }
|
19462 | for(i=0;i<numeric.mathfuns.length;++i) {
|
19463 | o = numeric.mathfuns[i];
|
19464 | numeric.ops1[o] = o;
|
19465 | }
|
19466 | for(i in numeric.ops1) {
|
19467 | if(numeric.ops1.hasOwnProperty(i)) {
|
19468 | setup = '';
|
19469 | o = numeric.ops1[i];
|
19470 | if(numeric.myIndexOf.call(numeric.mathfuns,i)!==-1) {
|
19471 | if(Math.hasOwnProperty(o)) setup = 'var '+o+' = Math.'+o+';\n';
|
19472 | }
|
19473 | numeric[i+'eqV'] = numeric.pointwise2(['ret[i]'],'ret[i] = '+o+'(ret[i]);',setup);
|
19474 | numeric[i+'eq'] = Function('x',
|
19475 | 'if(typeof x !== "object") return '+o+'x\n'+
|
19476 | 'var i;\n'+
|
19477 | 'var V = numeric.'+i+'eqV;\n'+
|
19478 | 'var s = numeric.dim(x);\n'+
|
19479 | 'numeric._foreach(x,s,0,V);\n'+
|
19480 | 'return x;\n');
|
19481 | numeric[i+'V'] = numeric.pointwise2(['x[i]'],'ret[i] = '+o+'(x[i]);',setup);
|
19482 | numeric[i] = Function('x',
|
19483 | 'if(typeof x !== "object") return '+o+'(x)\n'+
|
19484 | 'var i;\n'+
|
19485 | 'var V = numeric.'+i+'V;\n'+
|
19486 | 'var s = numeric.dim(x);\n'+
|
19487 | 'return numeric._foreach2(x,s,0,V);\n');
|
19488 | }
|
19489 | }
|
19490 | for(i=0;i<numeric.mathfuns.length;++i) {
|
19491 | o = numeric.mathfuns[i];
|
19492 | delete numeric.ops1[o];
|
19493 | }
|
19494 | for(i in numeric.mapreducers) {
|
19495 | if(numeric.mapreducers.hasOwnProperty(i)) {
|
19496 | o = numeric.mapreducers[i];
|
19497 | numeric[i+'V'] = numeric.mapreduce2(o[0],o[1]);
|
19498 | numeric[i] = Function('x','s','k',
|
19499 | o[1]+
|
19500 | 'if(typeof x !== "object") {'+
|
19501 | ' xi = x;\n'+
|
19502 | o[0]+';\n'+
|
19503 | ' return accum;\n'+
|
19504 | '}'+
|
19505 | 'if(typeof s === "undefined") s = numeric.dim(x);\n'+
|
19506 | 'if(typeof k === "undefined") k = 0;\n'+
|
19507 | 'if(k === s.length-1) return numeric.'+i+'V(x);\n'+
|
19508 | 'var xi;\n'+
|
19509 | 'var n = x.length, i;\n'+
|
19510 | 'for(i=n-1;i!==-1;--i) {\n'+
|
19511 | ' xi = arguments.callee(x[i]);\n'+
|
19512 | o[0]+';\n'+
|
19513 | '}\n'+
|
19514 | 'return accum;\n');
|
19515 | }
|
19516 | }
|
19517 | }());
|
19518 |
|
19519 | numeric.truncVV = numeric.pointwise(['x[i]','y[i]'],'ret[i] = round(x[i]/y[i])*y[i];','var round = Math.round;');
|
19520 | numeric.truncVS = numeric.pointwise(['x[i]','y'],'ret[i] = round(x[i]/y)*y;','var round = Math.round;');
|
19521 | numeric.truncSV = numeric.pointwise(['x','y[i]'],'ret[i] = round(x/y[i])*y[i];','var round = Math.round;');
|
19522 | numeric.trunc = function trunc(x,y) {
|
19523 | if(typeof x === "object") {
|
19524 | if(typeof y === "object") return numeric.truncVV(x,y);
|
19525 | return numeric.truncVS(x,y);
|
19526 | }
|
19527 | if (typeof y === "object") return numeric.truncSV(x,y);
|
19528 | return Math.round(x/y)*y;
|
19529 | }
|
19530 |
|
19531 | numeric.inv = function inv(x) {
|
19532 | var s = numeric.dim(x), abs = Math.abs, m = s[0], n = s[1];
|
19533 | var A = numeric.clone(x), Ai, Aj;
|
19534 | var I = numeric.identity(m), Ii, Ij;
|
19535 | var i,j,k,x;
|
19536 | for(j=0;j<n;++j) {
|
19537 | var i0 = -1;
|
19538 | var v0 = -1;
|
19539 | for(i=j;i!==m;++i) { k = abs(A[i][j]); if(k>v0) { i0 = i; v0 = k; } }
|
19540 | Aj = A[i0]; A[i0] = A[j]; A[j] = Aj;
|
19541 | Ij = I[i0]; I[i0] = I[j]; I[j] = Ij;
|
19542 | x = Aj[j];
|
19543 | for(k=j;k!==n;++k) Aj[k] /= x;
|
19544 | for(k=n-1;k!==-1;--k) Ij[k] /= x;
|
19545 | for(i=m-1;i!==-1;--i) {
|
19546 | if(i!==j) {
|
19547 | Ai = A[i];
|
19548 | Ii = I[i];
|
19549 | x = Ai[j];
|
19550 | for(k=j+1;k!==n;++k) Ai[k] -= Aj[k]*x;
|
19551 | for(k=n-1;k>0;--k) { Ii[k] -= Ij[k]*x; --k; Ii[k] -= Ij[k]*x; }
|
19552 | if(k===0) Ii[0] -= Ij[0]*x;
|
19553 | }
|
19554 | }
|
19555 | }
|
19556 | return I;
|
19557 | }
|
19558 |
|
19559 | numeric.det = function det(x) {
|
19560 | var s = numeric.dim(x);
|
19561 | if(s.length !== 2 || s[0] !== s[1]) { throw new Error('numeric: det() only works on square matrices'); }
|
19562 | var n = s[0], ret = 1,i,j,k,A = numeric.clone(x),Aj,Ai,alpha,temp,k1,k2,k3;
|
19563 | for(j=0;j<n-1;j++) {
|
19564 | k=j;
|
19565 | for(i=j+1;i<n;i++) { if(Math.abs(A[i][j]) > Math.abs(A[k][j])) { k = i; } }
|
19566 | if(k !== j) {
|
19567 | temp = A[k]; A[k] = A[j]; A[j] = temp;
|
19568 | ret *= -1;
|
19569 | }
|
19570 | Aj = A[j];
|
19571 | for(i=j+1;i<n;i++) {
|
19572 | Ai = A[i];
|
19573 | alpha = Ai[j]/Aj[j];
|
19574 | for(k=j+1;k<n-1;k+=2) {
|
19575 | k1 = k+1;
|
19576 | Ai[k] -= Aj[k]*alpha;
|
19577 | Ai[k1] -= Aj[k1]*alpha;
|
19578 | }
|
19579 | if(k!==n) { Ai[k] -= Aj[k]*alpha; }
|
19580 | }
|
19581 | if(Aj[j] === 0) { return 0; }
|
19582 | ret *= Aj[j];
|
19583 | }
|
19584 | return ret*A[j][j];
|
19585 | }
|
19586 |
|
19587 | numeric.transpose = function transpose(x) {
|
19588 | var i,j,m = x.length,n = x[0].length, ret=Array(n),A0,A1,Bj;
|
19589 | for(j=0;j<n;j++) ret[j] = Array(m);
|
19590 | for(i=m-1;i>=1;i-=2) {
|
19591 | A1 = x[i];
|
19592 | A0 = x[i-1];
|
19593 | for(j=n-1;j>=1;--j) {
|
19594 | Bj = ret[j]; Bj[i] = A1[j]; Bj[i-1] = A0[j];
|
19595 | --j;
|
19596 | Bj = ret[j]; Bj[i] = A1[j]; Bj[i-1] = A0[j];
|
19597 | }
|
19598 | if(j===0) {
|
19599 | Bj = ret[0]; Bj[i] = A1[0]; Bj[i-1] = A0[0];
|
19600 | }
|
19601 | }
|
19602 | if(i===0) {
|
19603 | A0 = x[0];
|
19604 | for(j=n-1;j>=1;--j) {
|
19605 | ret[j][0] = A0[j];
|
19606 | --j;
|
19607 | ret[j][0] = A0[j];
|
19608 | }
|
19609 | if(j===0) { ret[0][0] = A0[0]; }
|
19610 | }
|
19611 | return ret;
|
19612 | }
|
19613 | numeric.negtranspose = function negtranspose(x) {
|
19614 | var i,j,m = x.length,n = x[0].length, ret=Array(n),A0,A1,Bj;
|
19615 | for(j=0;j<n;j++) ret[j] = Array(m);
|
19616 | for(i=m-1;i>=1;i-=2) {
|
19617 | A1 = x[i];
|
19618 | A0 = x[i-1];
|
19619 | for(j=n-1;j>=1;--j) {
|
19620 | Bj = ret[j]; Bj[i] = -A1[j]; Bj[i-1] = -A0[j];
|
19621 | --j;
|
19622 | Bj = ret[j]; Bj[i] = -A1[j]; Bj[i-1] = -A0[j];
|
19623 | }
|
19624 | if(j===0) {
|
19625 | Bj = ret[0]; Bj[i] = -A1[0]; Bj[i-1] = -A0[0];
|
19626 | }
|
19627 | }
|
19628 | if(i===0) {
|
19629 | A0 = x[0];
|
19630 | for(j=n-1;j>=1;--j) {
|
19631 | ret[j][0] = -A0[j];
|
19632 | --j;
|
19633 | ret[j][0] = -A0[j];
|
19634 | }
|
19635 | if(j===0) { ret[0][0] = -A0[0]; }
|
19636 | }
|
19637 | return ret;
|
19638 | }
|
19639 |
|
19640 | numeric._random = function _random(s,k) {
|
19641 | var i,n=s[k],ret=Array(n), rnd;
|
19642 | if(k === s.length-1) {
|
19643 | rnd = Math.random;
|
19644 | for(i=n-1;i>=1;i-=2) {
|
19645 | ret[i] = rnd();
|
19646 | ret[i-1] = rnd();
|
19647 | }
|
19648 | if(i===0) { ret[0] = rnd(); }
|
19649 | return ret;
|
19650 | }
|
19651 | for(i=n-1;i>=0;i--) ret[i] = _random(s,k+1);
|
19652 | return ret;
|
19653 | }
|
19654 | numeric.random = function random(s) { return numeric._random(s,0); }
|
19655 |
|
19656 | numeric.norm2 = function norm2(x) { return Math.sqrt(numeric.norm2Squared(x)); }
|
19657 |
|
19658 | numeric.linspace = function linspace(a,b,n) {
|
19659 | if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1);
|
19660 | if(n<2) { return n===1?[a]:[]; }
|
19661 | var i,ret = Array(n);
|
19662 | n--;
|
19663 | for(i=n;i>=0;i--) { ret[i] = (i*b+(n-i)*a)/n; }
|
19664 | return ret;
|
19665 | }
|
19666 |
|
19667 | numeric.getBlock = function getBlock(x,from,to) {
|
19668 | var s = numeric.dim(x);
|
19669 | function foo(x,k) {
|
19670 | var i,a = from[k], n = to[k]-a, ret = Array(n);
|
19671 | if(k === s.length-1) {
|
19672 | for(i=n;i>=0;i--) { ret[i] = x[i+a]; }
|
19673 | return ret;
|
19674 | }
|
19675 | for(i=n;i>=0;i--) { ret[i] = foo(x[i+a],k+1); }
|
19676 | return ret;
|
19677 | }
|
19678 | return foo(x,0);
|
19679 | }
|
19680 |
|
19681 | numeric.setBlock = function setBlock(x,from,to,B) {
|
19682 | var s = numeric.dim(x);
|
19683 | function foo(x,y,k) {
|
19684 | var i,a = from[k], n = to[k]-a;
|
19685 | if(k === s.length-1) { for(i=n;i>=0;i--) { x[i+a] = y[i]; } }
|
19686 | for(i=n;i>=0;i--) { foo(x[i+a],y[i],k+1); }
|
19687 | }
|
19688 | foo(x,B,0);
|
19689 | return x;
|
19690 | }
|
19691 |
|
19692 | numeric.getRange = function getRange(A,I,J) {
|
19693 | var m = I.length, n = J.length;
|
19694 | var i,j;
|
19695 | var B = Array(m), Bi, AI;
|
19696 | for(i=m-1;i!==-1;--i) {
|
19697 | B[i] = Array(n);
|
19698 | Bi = B[i];
|
19699 | AI = A[I[i]];
|
19700 | for(j=n-1;j!==-1;--j) Bi[j] = AI[J[j]];
|
19701 | }
|
19702 | return B;
|
19703 | }
|
19704 |
|
19705 | numeric.blockMatrix = function blockMatrix(X) {
|
19706 | var s = numeric.dim(X);
|
19707 | if(s.length<4) return numeric.blockMatrix([X]);
|
19708 | var m=s[0],n=s[1],M,N,i,j,Xij;
|
19709 | M = 0; N = 0;
|
19710 | for(i=0;i<m;++i) M+=X[i][0].length;
|
19711 | for(j=0;j<n;++j) N+=X[0][j][0].length;
|
19712 | var Z = Array(M);
|
19713 | for(i=0;i<M;++i) Z[i] = Array(N);
|
19714 | var I=0,J,ZI,k,l,Xijk;
|
19715 | for(i=0;i<m;++i) {
|
19716 | J=N;
|
19717 | for(j=n-1;j!==-1;--j) {
|
19718 | Xij = X[i][j];
|
19719 | J -= Xij[0].length;
|
19720 | for(k=Xij.length-1;k!==-1;--k) {
|
19721 | Xijk = Xij[k];
|
19722 | ZI = Z[I+k];
|
19723 | for(l = Xijk.length-1;l!==-1;--l) ZI[J+l] = Xijk[l];
|
19724 | }
|
19725 | }
|
19726 | I += X[i][0].length;
|
19727 | }
|
19728 | return Z;
|
19729 | }
|
19730 |
|
19731 | numeric.tensor = function tensor(x,y) {
|
19732 | if(typeof x === "number" || typeof y === "number") return numeric.mul(x,y);
|
19733 | var s1 = numeric.dim(x), s2 = numeric.dim(y);
|
19734 | if(s1.length !== 1 || s2.length !== 1) {
|
19735 | throw new Error('numeric: tensor product is only defined for vectors');
|
19736 | }
|
19737 | var m = s1[0], n = s2[0], A = Array(m), Ai, i,j,xi;
|
19738 | for(i=m-1;i>=0;i--) {
|
19739 | Ai = Array(n);
|
19740 | xi = x[i];
|
19741 | for(j=n-1;j>=3;--j) {
|
19742 | Ai[j] = xi * y[j];
|
19743 | --j;
|
19744 | Ai[j] = xi * y[j];
|
19745 | --j;
|
19746 | Ai[j] = xi * y[j];
|
19747 | --j;
|
19748 | Ai[j] = xi * y[j];
|
19749 | }
|
19750 | while(j>=0) { Ai[j] = xi * y[j]; --j; }
|
19751 | A[i] = Ai;
|
19752 | }
|
19753 | return A;
|
19754 | }
|
19755 |
|
19756 |
|
19757 | numeric.T = function T(x,y) { this.x = x; this.y = y; }
|
19758 | numeric.t = function t(x,y) { return new numeric.T(x,y); }
|
19759 |
|
19760 | numeric.Tbinop = function Tbinop(rr,rc,cr,cc,setup) {
|
19761 | var io = numeric.indexOf;
|
19762 | if(typeof setup !== "string") {
|
19763 | var k;
|
19764 | setup = '';
|
19765 | for(k in numeric) {
|
19766 | if(numeric.hasOwnProperty(k) && (rr.indexOf(k)>=0 || rc.indexOf(k)>=0 || cr.indexOf(k)>=0 || cc.indexOf(k)>=0) && k.length>1) {
|
19767 | setup += 'var '+k+' = numeric.'+k+';\n';
|
19768 | }
|
19769 | }
|
19770 | }
|
19771 | return Function(['y'],
|
19772 | 'var x = this;\n'+
|
19773 | 'if(!(y instanceof numeric.T)) { y = new numeric.T(y); }\n'+
|
19774 | setup+'\n'+
|
19775 | 'if(x.y) {'+
|
19776 | ' if(y.y) {'+
|
19777 | ' return new numeric.T('+cc+');\n'+
|
19778 | ' }\n'+
|
19779 | ' return new numeric.T('+cr+');\n'+
|
19780 | '}\n'+
|
19781 | 'if(y.y) {\n'+
|
19782 | ' return new numeric.T('+rc+');\n'+
|
19783 | '}\n'+
|
19784 | 'return new numeric.T('+rr+');\n'
|
19785 | );
|
19786 | }
|
19787 |
|
19788 | numeric.T.prototype.add = numeric.Tbinop(
|
19789 | 'add(x.x,y.x)',
|
19790 | 'add(x.x,y.x),y.y',
|
19791 | 'add(x.x,y.x),x.y',
|
19792 | 'add(x.x,y.x),add(x.y,y.y)');
|
19793 | numeric.T.prototype.sub = numeric.Tbinop(
|
19794 | 'sub(x.x,y.x)',
|
19795 | 'sub(x.x,y.x),neg(y.y)',
|
19796 | 'sub(x.x,y.x),x.y',
|
19797 | 'sub(x.x,y.x),sub(x.y,y.y)');
|
19798 | numeric.T.prototype.mul = numeric.Tbinop(
|
19799 | 'mul(x.x,y.x)',
|
19800 | 'mul(x.x,y.x),mul(x.x,y.y)',
|
19801 | 'mul(x.x,y.x),mul(x.y,y.x)',
|
19802 | 'sub(mul(x.x,y.x),mul(x.y,y.y)),add(mul(x.x,y.y),mul(x.y,y.x))');
|
19803 |
|
19804 | numeric.T.prototype.reciprocal = function reciprocal() {
|
19805 | var mul = numeric.mul, div = numeric.div;
|
19806 | if(this.y) {
|
19807 | var d = numeric.add(mul(this.x,this.x),mul(this.y,this.y));
|
19808 | return new numeric.T(div(this.x,d),div(numeric.neg(this.y),d));
|
19809 | }
|
19810 | return new T(div(1,this.x));
|
19811 | }
|
19812 | numeric.T.prototype.div = function div(y) {
|
19813 | if(!(y instanceof numeric.T)) y = new numeric.T(y);
|
19814 | if(y.y) { return this.mul(y.reciprocal()); }
|
19815 | var div = numeric.div;
|
19816 | if(this.y) { return new numeric.T(div(this.x,y.x),div(this.y,y.x)); }
|
19817 | return new numeric.T(div(this.x,y.x));
|
19818 | }
|
19819 | numeric.T.prototype.dot = numeric.Tbinop(
|
19820 | 'dot(x.x,y.x)',
|
19821 | 'dot(x.x,y.x),dot(x.x,y.y)',
|
19822 | 'dot(x.x,y.x),dot(x.y,y.x)',
|
19823 | 'sub(dot(x.x,y.x),dot(x.y,y.y)),add(dot(x.x,y.y),dot(x.y,y.x))'
|
19824 | );
|
19825 | numeric.T.prototype.transpose = function transpose() {
|
19826 | var t = numeric.transpose, x = this.x, y = this.y;
|
19827 | if(y) { return new numeric.T(t(x),t(y)); }
|
19828 | return new numeric.T(t(x));
|
19829 | }
|
19830 | numeric.T.prototype.transjugate = function transjugate() {
|
19831 | var t = numeric.transpose, x = this.x, y = this.y;
|
19832 | if(y) { return new numeric.T(t(x),numeric.negtranspose(y)); }
|
19833 | return new numeric.T(t(x));
|
19834 | }
|
19835 | numeric.Tunop = function Tunop(r,c,s) {
|
19836 | if(typeof s !== "string") { s = ''; }
|
19837 | return Function(
|
19838 | 'var x = this;\n'+
|
19839 | s+'\n'+
|
19840 | 'if(x.y) {'+
|
19841 | ' '+c+';\n'+
|
19842 | '}\n'+
|
19843 | r+';\n'
|
19844 | );
|
19845 | }
|
19846 |
|
19847 | numeric.T.prototype.exp = numeric.Tunop(
|
19848 | 'return new numeric.T(ex)',
|
19849 | 'return new numeric.T(mul(cos(x.y),ex),mul(sin(x.y),ex))',
|
19850 | 'var ex = numeric.exp(x.x), cos = numeric.cos, sin = numeric.sin, mul = numeric.mul;');
|
19851 | numeric.T.prototype.conj = numeric.Tunop(
|
19852 | 'return new numeric.T(x.x);',
|
19853 | 'return new numeric.T(x.x,numeric.neg(x.y));');
|
19854 | numeric.T.prototype.neg = numeric.Tunop(
|
19855 | 'return new numeric.T(neg(x.x));',
|
19856 | 'return new numeric.T(neg(x.x),neg(x.y));',
|
19857 | 'var neg = numeric.neg;');
|
19858 | numeric.T.prototype.sin = numeric.Tunop(
|
19859 | 'return new numeric.T(numeric.sin(x.x))',
|
19860 | 'return x.exp().sub(x.neg().exp()).div(new numeric.T(0,2));');
|
19861 | numeric.T.prototype.cos = numeric.Tunop(
|
19862 | 'return new numeric.T(numeric.cos(x.x))',
|
19863 | 'return x.exp().add(x.neg().exp()).div(2);');
|
19864 | numeric.T.prototype.abs = numeric.Tunop(
|
19865 | 'return new numeric.T(numeric.abs(x.x));',
|
19866 | 'return new numeric.T(numeric.sqrt(numeric.add(mul(x.x,x.x),mul(x.y,x.y))));',
|
19867 | 'var mul = numeric.mul;');
|
19868 | numeric.T.prototype.log = numeric.Tunop(
|
19869 | 'return new numeric.T(numeric.log(x.x));',
|
19870 | 'var theta = new numeric.T(numeric.atan2(x.y,x.x)), r = x.abs();\n'+
|
19871 | 'return new numeric.T(numeric.log(r.x),theta.x);');
|
19872 | numeric.T.prototype.norm2 = numeric.Tunop(
|
19873 | 'return numeric.norm2(x.x);',
|
19874 | 'var f = numeric.norm2Squared;\n'+
|
19875 | 'return Math.sqrt(f(x.x)+f(x.y));');
|
19876 | numeric.T.prototype.inv = function inv() {
|
19877 | var A = this;
|
19878 | if(typeof A.y === "undefined") { return new numeric.T(numeric.inv(A.x)); }
|
19879 | var n = A.x.length, i, j, k;
|
19880 | var Rx = numeric.identity(n),Ry = numeric.rep([n,n],0);
|
19881 | var Ax = numeric.clone(A.x), Ay = numeric.clone(A.y);
|
19882 | var Aix, Aiy, Ajx, Ajy, Rix, Riy, Rjx, Rjy;
|
19883 | var i,j,k,d,d1,ax,ay,bx,by,temp;
|
19884 | for(i=0;i<n;i++) {
|
19885 | ax = Ax[i][i]; ay = Ay[i][i];
|
19886 | d = ax*ax+ay*ay;
|
19887 | k = i;
|
19888 | for(j=i+1;j<n;j++) {
|
19889 | ax = Ax[j][i]; ay = Ay[j][i];
|
19890 | d1 = ax*ax+ay*ay;
|
19891 | if(d1 > d) { k=j; d = d1; }
|
19892 | }
|
19893 | if(k!==i) {
|
19894 | temp = Ax[i]; Ax[i] = Ax[k]; Ax[k] = temp;
|
19895 | temp = Ay[i]; Ay[i] = Ay[k]; Ay[k] = temp;
|
19896 | temp = Rx[i]; Rx[i] = Rx[k]; Rx[k] = temp;
|
19897 | temp = Ry[i]; Ry[i] = Ry[k]; Ry[k] = temp;
|
19898 | }
|
19899 | Aix = Ax[i]; Aiy = Ay[i];
|
19900 | Rix = Rx[i]; Riy = Ry[i];
|
19901 | ax = Aix[i]; ay = Aiy[i];
|
19902 | for(j=i+1;j<n;j++) {
|
19903 | bx = Aix[j]; by = Aiy[j];
|
19904 | Aix[j] = (bx*ax+by*ay)/d;
|
19905 | Aiy[j] = (by*ax-bx*ay)/d;
|
19906 | }
|
19907 | for(j=0;j<n;j++) {
|
19908 | bx = Rix[j]; by = Riy[j];
|
19909 | Rix[j] = (bx*ax+by*ay)/d;
|
19910 | Riy[j] = (by*ax-bx*ay)/d;
|
19911 | }
|
19912 | for(j=i+1;j<n;j++) {
|
19913 | Ajx = Ax[j]; Ajy = Ay[j];
|
19914 | Rjx = Rx[j]; Rjy = Ry[j];
|
19915 | ax = Ajx[i]; ay = Ajy[i];
|
19916 | for(k=i+1;k<n;k++) {
|
19917 | bx = Aix[k]; by = Aiy[k];
|
19918 | Ajx[k] -= bx*ax-by*ay;
|
19919 | Ajy[k] -= by*ax+bx*ay;
|
19920 | }
|
19921 | for(k=0;k<n;k++) {
|
19922 | bx = Rix[k]; by = Riy[k];
|
19923 | Rjx[k] -= bx*ax-by*ay;
|
19924 | Rjy[k] -= by*ax+bx*ay;
|
19925 | }
|
19926 | }
|
19927 | }
|
19928 | for(i=n-1;i>0;i--) {
|
19929 | Rix = Rx[i]; Riy = Ry[i];
|
19930 | for(j=i-1;j>=0;j--) {
|
19931 | Rjx = Rx[j]; Rjy = Ry[j];
|
19932 | ax = Ax[j][i]; ay = Ay[j][i];
|
19933 | for(k=n-1;k>=0;k--) {
|
19934 | bx = Rix[k]; by = Riy[k];
|
19935 | Rjx[k] -= ax*bx - ay*by;
|
19936 | Rjy[k] -= ax*by + ay*bx;
|
19937 | }
|
19938 | }
|
19939 | }
|
19940 | return new numeric.T(Rx,Ry);
|
19941 | }
|
19942 | numeric.T.prototype.get = function get(i) {
|
19943 | var x = this.x, y = this.y, k = 0, ik, n = i.length;
|
19944 | if(y) {
|
19945 | while(k<n) {
|
19946 | ik = i[k];
|
19947 | x = x[ik];
|
19948 | y = y[ik];
|
19949 | k++;
|
19950 | }
|
19951 | return new numeric.T(x,y);
|
19952 | }
|
19953 | while(k<n) {
|
19954 | ik = i[k];
|
19955 | x = x[ik];
|
19956 | k++;
|
19957 | }
|
19958 | return new numeric.T(x);
|
19959 | }
|
19960 | numeric.T.prototype.set = function set(i,v) {
|
19961 | var x = this.x, y = this.y, k = 0, ik, n = i.length, vx = v.x, vy = v.y;
|
19962 | if(n===0) {
|
19963 | if(vy) { this.y = vy; }
|
19964 | else if(y) { this.y = undefined; }
|
19965 | this.x = x;
|
19966 | return this;
|
19967 | }
|
19968 | if(vy) {
|
19969 | if(y) { }
|
19970 | else {
|
19971 | y = numeric.rep(numeric.dim(x),0);
|
19972 | this.y = y;
|
19973 | }
|
19974 | while(k<n-1) {
|
19975 | ik = i[k];
|
19976 | x = x[ik];
|
19977 | y = y[ik];
|
19978 | k++;
|
19979 | }
|
19980 | ik = i[k];
|
19981 | x[ik] = vx;
|
19982 | y[ik] = vy;
|
19983 | return this;
|
19984 | }
|
19985 | if(y) {
|
19986 | while(k<n-1) {
|
19987 | ik = i[k];
|
19988 | x = x[ik];
|
19989 | y = y[ik];
|
19990 | k++;
|
19991 | }
|
19992 | ik = i[k];
|
19993 | x[ik] = vx;
|
19994 | if(vx instanceof Array) y[ik] = numeric.rep(numeric.dim(vx),0);
|
19995 | else y[ik] = 0;
|
19996 | return this;
|
19997 | }
|
19998 | while(k<n-1) {
|
19999 | ik = i[k];
|
20000 | x = x[ik];
|
20001 | k++;
|
20002 | }
|
20003 | ik = i[k];
|
20004 | x[ik] = vx;
|
20005 | return this;
|
20006 | }
|
20007 | numeric.T.prototype.getRows = function getRows(i0,i1) {
|
20008 | var n = i1-i0+1, j;
|
20009 | var rx = Array(n), ry, x = this.x, y = this.y;
|
20010 | for(j=i0;j<=i1;j++) { rx[j-i0] = x[j]; }
|
20011 | if(y) {
|
20012 | ry = Array(n);
|
20013 | for(j=i0;j<=i1;j++) { ry[j-i0] = y[j]; }
|
20014 | return new numeric.T(rx,ry);
|
20015 | }
|
20016 | return new numeric.T(rx);
|
20017 | }
|
20018 | numeric.T.prototype.setRows = function setRows(i0,i1,A) {
|
20019 | var j;
|
20020 | var rx = this.x, ry = this.y, x = A.x, y = A.y;
|
20021 | for(j=i0;j<=i1;j++) { rx[j] = x[j-i0]; }
|
20022 | if(y) {
|
20023 | if(!ry) { ry = numeric.rep(numeric.dim(rx),0); this.y = ry; }
|
20024 | for(j=i0;j<=i1;j++) { ry[j] = y[j-i0]; }
|
20025 | } else if(ry) {
|
20026 | for(j=i0;j<=i1;j++) { ry[j] = numeric.rep([x[j-i0].length],0); }
|
20027 | }
|
20028 | return this;
|
20029 | }
|
20030 | numeric.T.prototype.getRow = function getRow(k) {
|
20031 | var x = this.x, y = this.y;
|
20032 | if(y) { return new numeric.T(x[k],y[k]); }
|
20033 | return new numeric.T(x[k]);
|
20034 | }
|
20035 | numeric.T.prototype.setRow = function setRow(i,v) {
|
20036 | var rx = this.x, ry = this.y, x = v.x, y = v.y;
|
20037 | rx[i] = x;
|
20038 | if(y) {
|
20039 | if(!ry) { ry = numeric.rep(numeric.dim(rx),0); this.y = ry; }
|
20040 | ry[i] = y;
|
20041 | } else if(ry) {
|
20042 | ry = numeric.rep([x.length],0);
|
20043 | }
|
20044 | return this;
|
20045 | }
|
20046 |
|
20047 | numeric.T.prototype.getBlock = function getBlock(from,to) {
|
20048 | var x = this.x, y = this.y, b = numeric.getBlock;
|
20049 | if(y) { return new numeric.T(b(x,from,to),b(y,from,to)); }
|
20050 | return new numeric.T(b(x,from,to));
|
20051 | }
|
20052 | numeric.T.prototype.setBlock = function setBlock(from,to,A) {
|
20053 | if(!(A instanceof numeric.T)) A = new numeric.T(A);
|
20054 | var x = this.x, y = this.y, b = numeric.setBlock, Ax = A.x, Ay = A.y;
|
20055 | if(Ay) {
|
20056 | if(!y) { this.y = numeric.rep(numeric.dim(this),0); y = this.y; }
|
20057 | b(x,from,to,Ax);
|
20058 | b(y,from,to,Ay);
|
20059 | return this;
|
20060 | }
|
20061 | b(x,from,to,Ax);
|
20062 | if(y) b(y,from,to,numeric.rep(numeric.dim(Ax),0));
|
20063 | }
|
20064 | numeric.T.rep = function rep(s,v) {
|
20065 | var T = numeric.T;
|
20066 | if(!(v instanceof T)) v = new T(v);
|
20067 | var x = v.x, y = v.y, r = numeric.rep;
|
20068 | if(y) return new T(r(s,x),r(s,y));
|
20069 | return new T(r(s,x));
|
20070 | }
|
20071 | numeric.T.diag = function diag(d) {
|
20072 | if(!(d instanceof numeric.T)) d = new numeric.T(d);
|
20073 | var x = d.x, y = d.y, diag = numeric.diag;
|
20074 | if(y) return new numeric.T(diag(x),diag(y));
|
20075 | return new numeric.T(diag(x));
|
20076 | }
|
20077 | numeric.T.eig = function eig() {
|
20078 | if(this.y) { throw new Error('eig: not implemented for complex matrices.'); }
|
20079 | return numeric.eig(this.x);
|
20080 | }
|
20081 | numeric.T.identity = function identity(n) { return new numeric.T(numeric.identity(n)); }
|
20082 | numeric.T.prototype.getDiag = function getDiag() {
|
20083 | var n = numeric;
|
20084 | var x = this.x, y = this.y;
|
20085 | if(y) { return new n.T(n.getDiag(x),n.getDiag(y)); }
|
20086 | return new n.T(n.getDiag(x));
|
20087 | }
|
20088 |
|
20089 |
|
20090 |
|
20091 | numeric.house = function house(x) {
|
20092 | var v = numeric.clone(x);
|
20093 | var s = x[0] >= 0 ? 1 : -1;
|
20094 | var alpha = s*numeric.norm2(x);
|
20095 | v[0] += alpha;
|
20096 | var foo = numeric.norm2(v);
|
20097 | if(foo === 0) { throw new Error('eig: internal error'); }
|
20098 | return numeric.div(v,foo);
|
20099 | }
|
20100 |
|
20101 | numeric.toUpperHessenberg = function toUpperHessenberg(me) {
|
20102 | var s = numeric.dim(me);
|
20103 | if(s.length !== 2 || s[0] !== s[1]) { throw new Error('numeric: toUpperHessenberg() only works on square matrices'); }
|
20104 | var m = s[0], i,j,k,x,v,A = numeric.clone(me),B,C,Ai,Ci,Q = numeric.identity(m),Qi;
|
20105 | for(j=0;j<m-2;j++) {
|
20106 | x = Array(m-j-1);
|
20107 | for(i=j+1;i<m;i++) { x[i-j-1] = A[i][j]; }
|
20108 | if(numeric.norm2(x)>0) {
|
20109 | v = numeric.house(x);
|
20110 | B = numeric.getBlock(A,[j+1,j],[m-1,m-1]);
|
20111 | C = numeric.tensor(v,numeric.dot(v,B));
|
20112 | for(i=j+1;i<m;i++) { Ai = A[i]; Ci = C[i-j-1]; for(k=j;k<m;k++) Ai[k] -= 2*Ci[k-j]; }
|
20113 | B = numeric.getBlock(A,[0,j+1],[m-1,m-1]);
|
20114 | C = numeric.tensor(numeric.dot(B,v),v);
|
20115 | for(i=0;i<m;i++) { Ai = A[i]; Ci = C[i]; for(k=j+1;k<m;k++) Ai[k] -= 2*Ci[k-j-1]; }
|
20116 | B = Array(m-j-1);
|
20117 | for(i=j+1;i<m;i++) B[i-j-1] = Q[i];
|
20118 | C = numeric.tensor(v,numeric.dot(v,B));
|
20119 | for(i=j+1;i<m;i++) { Qi = Q[i]; Ci = C[i-j-1]; for(k=0;k<m;k++) Qi[k] -= 2*Ci[k]; }
|
20120 | }
|
20121 | }
|
20122 | return {H:A, Q:Q};
|
20123 | }
|
20124 |
|
20125 | numeric.epsilon = 2.220446049250313e-16;
|
20126 |
|
20127 | numeric.QRFrancis = function(H,maxiter) {
|
20128 | if(typeof maxiter === "undefined") { maxiter = 10000; }
|
20129 | H = numeric.clone(H);
|
20130 | var H0 = numeric.clone(H);
|
20131 | var s = numeric.dim(H),m=s[0],x,v,a,b,c,d,det,tr, Hloc, Q = numeric.identity(m), Qi, Hi, B, C, Ci,i,j,k,iter;
|
20132 | if(m<3) { return {Q:Q, B:[ [0,m-1] ]}; }
|
20133 | var epsilon = numeric.epsilon;
|
20134 | for(iter=0;iter<maxiter;iter++) {
|
20135 | for(j=0;j<m-1;j++) {
|
20136 | if(Math.abs(H[j+1][j]) < epsilon*(Math.abs(H[j][j])+Math.abs(H[j+1][j+1]))) {
|
20137 | var QH1 = numeric.QRFrancis(numeric.getBlock(H,[0,0],[j,j]),maxiter);
|
20138 | var QH2 = numeric.QRFrancis(numeric.getBlock(H,[j+1,j+1],[m-1,m-1]),maxiter);
|
20139 | B = Array(j+1);
|
20140 | for(i=0;i<=j;i++) { B[i] = Q[i]; }
|
20141 | C = numeric.dot(QH1.Q,B);
|
20142 | for(i=0;i<=j;i++) { Q[i] = C[i]; }
|
20143 | B = Array(m-j-1);
|
20144 | for(i=j+1;i<m;i++) { B[i-j-1] = Q[i]; }
|
20145 | C = numeric.dot(QH2.Q,B);
|
20146 | for(i=j+1;i<m;i++) { Q[i] = C[i-j-1]; }
|
20147 | return {Q:Q,B:QH1.B.concat(numeric.add(QH2.B,j+1))};
|
20148 | }
|
20149 | }
|
20150 | a = H[m-2][m-2]; b = H[m-2][m-1];
|
20151 | c = H[m-1][m-2]; d = H[m-1][m-1];
|
20152 | tr = a+d;
|
20153 | det = (a*d-b*c);
|
20154 | Hloc = numeric.getBlock(H, [0,0], [2,2]);
|
20155 | if(tr*tr>=4*det) {
|
20156 | var s1,s2;
|
20157 | s1 = 0.5*(tr+Math.sqrt(tr*tr-4*det));
|
20158 | s2 = 0.5*(tr-Math.sqrt(tr*tr-4*det));
|
20159 | Hloc = numeric.add(numeric.sub(numeric.dot(Hloc,Hloc),
|
20160 | numeric.mul(Hloc,s1+s2)),
|
20161 | numeric.diag(numeric.rep([3],s1*s2)));
|
20162 | } else {
|
20163 | Hloc = numeric.add(numeric.sub(numeric.dot(Hloc,Hloc),
|
20164 | numeric.mul(Hloc,tr)),
|
20165 | numeric.diag(numeric.rep([3],det)));
|
20166 | }
|
20167 | x = [Hloc[0][0],Hloc[1][0],Hloc[2][0]];
|
20168 | v = numeric.house(x);
|
20169 | B = [H[0],H[1],H[2]];
|
20170 | C = numeric.tensor(v,numeric.dot(v,B));
|
20171 | for(i=0;i<3;i++) { Hi = H[i]; Ci = C[i]; for(k=0;k<m;k++) Hi[k] -= 2*Ci[k]; }
|
20172 | B = numeric.getBlock(H, [0,0],[m-1,2]);
|
20173 | C = numeric.tensor(numeric.dot(B,v),v);
|
20174 | for(i=0;i<m;i++) { Hi = H[i]; Ci = C[i]; for(k=0;k<3;k++) Hi[k] -= 2*Ci[k]; }
|
20175 | B = [Q[0],Q[1],Q[2]];
|
20176 | C = numeric.tensor(v,numeric.dot(v,B));
|
20177 | for(i=0;i<3;i++) { Qi = Q[i]; Ci = C[i]; for(k=0;k<m;k++) Qi[k] -= 2*Ci[k]; }
|
20178 | var J;
|
20179 | for(j=0;j<m-2;j++) {
|
20180 | for(k=j;k<=j+1;k++) {
|
20181 | if(Math.abs(H[k+1][k]) < epsilon*(Math.abs(H[k][k])+Math.abs(H[k+1][k+1]))) {
|
20182 | var QH1 = numeric.QRFrancis(numeric.getBlock(H,[0,0],[k,k]),maxiter);
|
20183 | var QH2 = numeric.QRFrancis(numeric.getBlock(H,[k+1,k+1],[m-1,m-1]),maxiter);
|
20184 | B = Array(k+1);
|
20185 | for(i=0;i<=k;i++) { B[i] = Q[i]; }
|
20186 | C = numeric.dot(QH1.Q,B);
|
20187 | for(i=0;i<=k;i++) { Q[i] = C[i]; }
|
20188 | B = Array(m-k-1);
|
20189 | for(i=k+1;i<m;i++) { B[i-k-1] = Q[i]; }
|
20190 | C = numeric.dot(QH2.Q,B);
|
20191 | for(i=k+1;i<m;i++) { Q[i] = C[i-k-1]; }
|
20192 | return {Q:Q,B:QH1.B.concat(numeric.add(QH2.B,k+1))};
|
20193 | }
|
20194 | }
|
20195 | J = Math.min(m-1,j+3);
|
20196 | x = Array(J-j);
|
20197 | for(i=j+1;i<=J;i++) { x[i-j-1] = H[i][j]; }
|
20198 | v = numeric.house(x);
|
20199 | B = numeric.getBlock(H, [j+1,j],[J,m-1]);
|
20200 | C = numeric.tensor(v,numeric.dot(v,B));
|
20201 | for(i=j+1;i<=J;i++) { Hi = H[i]; Ci = C[i-j-1]; for(k=j;k<m;k++) Hi[k] -= 2*Ci[k-j]; }
|
20202 | B = numeric.getBlock(H, [0,j+1],[m-1,J]);
|
20203 | C = numeric.tensor(numeric.dot(B,v),v);
|
20204 | for(i=0;i<m;i++) { Hi = H[i]; Ci = C[i]; for(k=j+1;k<=J;k++) Hi[k] -= 2*Ci[k-j-1]; }
|
20205 | B = Array(J-j);
|
20206 | for(i=j+1;i<=J;i++) B[i-j-1] = Q[i];
|
20207 | C = numeric.tensor(v,numeric.dot(v,B));
|
20208 | for(i=j+1;i<=J;i++) { Qi = Q[i]; Ci = C[i-j-1]; for(k=0;k<m;k++) Qi[k] -= 2*Ci[k]; }
|
20209 | }
|
20210 | }
|
20211 | throw new Error('numeric: eigenvalue iteration does not converge -- increase maxiter?');
|
20212 | }
|
20213 |
|
20214 | numeric.eig = function eig(A,maxiter) {
|
20215 | var QH = numeric.toUpperHessenberg(A);
|
20216 | var QB = numeric.QRFrancis(QH.H,maxiter);
|
20217 | var T = numeric.T;
|
20218 | var n = A.length,i,k,flag = false,B = QB.B,H = numeric.dot(QB.Q,numeric.dot(QH.H,numeric.transpose(QB.Q)));
|
20219 | var Q = new T(numeric.dot(QB.Q,QH.Q)),Q0;
|
20220 | var m = B.length,j;
|
20221 | var a,b,c,d,p1,p2,disc,x,y,p,q,n1,n2;
|
20222 | var sqrt = Math.sqrt;
|
20223 | for(k=0;k<m;k++) {
|
20224 | i = B[k][0];
|
20225 | if(i === B[k][1]) {
|
20226 |
|
20227 | } else {
|
20228 | j = i+1;
|
20229 | a = H[i][i];
|
20230 | b = H[i][j];
|
20231 | c = H[j][i];
|
20232 | d = H[j][j];
|
20233 | if(b === 0 && c === 0) continue;
|
20234 | p1 = -a-d;
|
20235 | p2 = a*d-b*c;
|
20236 | disc = p1*p1-4*p2;
|
20237 | if(disc>=0) {
|
20238 | if(p1<0) x = -0.5*(p1-sqrt(disc));
|
20239 | else x = -0.5*(p1+sqrt(disc));
|
20240 | n1 = (a-x)*(a-x)+b*b;
|
20241 | n2 = c*c+(d-x)*(d-x);
|
20242 | if(n1>n2) {
|
20243 | n1 = sqrt(n1);
|
20244 | p = (a-x)/n1;
|
20245 | q = b/n1;
|
20246 | } else {
|
20247 | n2 = sqrt(n2);
|
20248 | p = c/n2;
|
20249 | q = (d-x)/n2;
|
20250 | }
|
20251 | Q0 = new T([[q,-p],[p,q]]);
|
20252 | Q.setRows(i,j,Q0.dot(Q.getRows(i,j)));
|
20253 | } else {
|
20254 | x = -0.5*p1;
|
20255 | y = 0.5*sqrt(-disc);
|
20256 | n1 = (a-x)*(a-x)+b*b;
|
20257 | n2 = c*c+(d-x)*(d-x);
|
20258 | if(n1>n2) {
|
20259 | n1 = sqrt(n1+y*y);
|
20260 | p = (a-x)/n1;
|
20261 | q = b/n1;
|
20262 | x = 0;
|
20263 | y /= n1;
|
20264 | } else {
|
20265 | n2 = sqrt(n2+y*y);
|
20266 | p = c/n2;
|
20267 | q = (d-x)/n2;
|
20268 | x = y/n2;
|
20269 | y = 0;
|
20270 | }
|
20271 | Q0 = new T([[q,-p],[p,q]],[[x,y],[y,-x]]);
|
20272 | Q.setRows(i,j,Q0.dot(Q.getRows(i,j)));
|
20273 | }
|
20274 | }
|
20275 | }
|
20276 | var R = Q.dot(A).dot(Q.transjugate()), n = A.length, E = numeric.T.identity(n);
|
20277 | for(j=0;j<n;j++) {
|
20278 | if(j>0) {
|
20279 | for(k=j-1;k>=0;k--) {
|
20280 | var Rk = R.get([k,k]), Rj = R.get([j,j]);
|
20281 | if(numeric.neq(Rk.x,Rj.x) || numeric.neq(Rk.y,Rj.y)) {
|
20282 | x = R.getRow(k).getBlock([k],[j-1]);
|
20283 | y = E.getRow(j).getBlock([k],[j-1]);
|
20284 | E.set([j,k],(R.get([k,j]).neg().sub(x.dot(y))).div(Rk.sub(Rj)));
|
20285 | } else {
|
20286 | E.setRow(j,E.getRow(k));
|
20287 | continue;
|
20288 | }
|
20289 | }
|
20290 | }
|
20291 | }
|
20292 | for(j=0;j<n;j++) {
|
20293 | x = E.getRow(j);
|
20294 | E.setRow(j,x.div(x.norm2()));
|
20295 | }
|
20296 | E = E.transpose();
|
20297 | E = Q.transjugate().dot(E);
|
20298 | return { lambda:R.getDiag(), E:E };
|
20299 | };
|
20300 |
|
20301 |
|
20302 | numeric.ccsSparse = function ccsSparse(A) {
|
20303 | var m = A.length,n,foo, i,j, counts = [];
|
20304 | for(i=m-1;i!==-1;--i) {
|
20305 | foo = A[i];
|
20306 | for(j in foo) {
|
20307 | j = parseInt(j);
|
20308 | while(j>=counts.length) counts[counts.length] = 0;
|
20309 | if(foo[j]!==0) counts[j]++;
|
20310 | }
|
20311 | }
|
20312 | var n = counts.length;
|
20313 | var Ai = Array(n+1);
|
20314 | Ai[0] = 0;
|
20315 | for(i=0;i<n;++i) Ai[i+1] = Ai[i] + counts[i];
|
20316 | var Aj = Array(Ai[n]), Av = Array(Ai[n]);
|
20317 | for(i=m-1;i!==-1;--i) {
|
20318 | foo = A[i];
|
20319 | for(j in foo) {
|
20320 | if(foo[j]!==0) {
|
20321 | counts[j]--;
|
20322 | Aj[Ai[j]+counts[j]] = i;
|
20323 | Av[Ai[j]+counts[j]] = foo[j];
|
20324 | }
|
20325 | }
|
20326 | }
|
20327 | return [Ai,Aj,Av];
|
20328 | }
|
20329 | numeric.ccsFull = function ccsFull(A) {
|
20330 | var Ai = A[0], Aj = A[1], Av = A[2], s = numeric.ccsDim(A), m = s[0], n = s[1], i,j,j0,j1,k;
|
20331 | var B = numeric.rep([m,n],0);
|
20332 | for(i=0;i<n;i++) {
|
20333 | j0 = Ai[i];
|
20334 | j1 = Ai[i+1];
|
20335 | for(j=j0;j<j1;++j) { B[Aj[j]][i] = Av[j]; }
|
20336 | }
|
20337 | return B;
|
20338 | }
|
20339 | numeric.ccsTSolve = function ccsTSolve(A,b,x,bj,xj) {
|
20340 | var Ai = A[0], Aj = A[1], Av = A[2],m = Ai.length-1, max = Math.max,n=0;
|
20341 | if(typeof bj === "undefined") x = numeric.rep([m],0);
|
20342 | if(typeof bj === "undefined") bj = numeric.linspace(0,x.length-1);
|
20343 | if(typeof xj === "undefined") xj = [];
|
20344 | function dfs(j) {
|
20345 | var k;
|
20346 | if(x[j] !== 0) return;
|
20347 | x[j] = 1;
|
20348 | for(k=Ai[j];k<Ai[j+1];++k) dfs(Aj[k]);
|
20349 | xj[n] = j;
|
20350 | ++n;
|
20351 | }
|
20352 | var i,j,j0,j1,k,l,l0,l1,a;
|
20353 | for(i=bj.length-1;i!==-1;--i) { dfs(bj[i]); }
|
20354 | xj.length = n;
|
20355 | for(i=xj.length-1;i!==-1;--i) { x[xj[i]] = 0; }
|
20356 | for(i=bj.length-1;i!==-1;--i) { j = bj[i]; x[j] = b[j]; }
|
20357 | for(i=xj.length-1;i!==-1;--i) {
|
20358 | j = xj[i];
|
20359 | j0 = Ai[j];
|
20360 | j1 = max(Ai[j+1],j0);
|
20361 | for(k=j0;k!==j1;++k) { if(Aj[k] === j) { x[j] /= Av[k]; break; } }
|
20362 | a = x[j];
|
20363 | for(k=j0;k!==j1;++k) {
|
20364 | l = Aj[k];
|
20365 | if(l !== j) x[l] -= a*Av[k];
|
20366 | }
|
20367 | }
|
20368 | return x;
|
20369 | }
|
20370 | numeric.ccsDFS = function ccsDFS(n) {
|
20371 | this.k = Array(n);
|
20372 | this.k1 = Array(n);
|
20373 | this.j = Array(n);
|
20374 | }
|
20375 | numeric.ccsDFS.prototype.dfs = function dfs(J,Ai,Aj,x,xj,Pinv) {
|
20376 | var m = 0,foo,n=xj.length;
|
20377 | var k = this.k, k1 = this.k1, j = this.j,km,k11;
|
20378 | if(x[J]!==0) return;
|
20379 | x[J] = 1;
|
20380 | j[0] = J;
|
20381 | k[0] = km = Ai[J];
|
20382 | k1[0] = k11 = Ai[J+1];
|
20383 | while(1) {
|
20384 | if(km >= k11) {
|
20385 | xj[n] = j[m];
|
20386 | if(m===0) return;
|
20387 | ++n;
|
20388 | --m;
|
20389 | km = k[m];
|
20390 | k11 = k1[m];
|
20391 | } else {
|
20392 | foo = Pinv[Aj[km]];
|
20393 | if(x[foo] === 0) {
|
20394 | x[foo] = 1;
|
20395 | k[m] = km;
|
20396 | ++m;
|
20397 | j[m] = foo;
|
20398 | km = Ai[foo];
|
20399 | k1[m] = k11 = Ai[foo+1];
|
20400 | } else ++km;
|
20401 | }
|
20402 | }
|
20403 | }
|
20404 | numeric.ccsLPSolve = function ccsLPSolve(A,B,x,xj,I,Pinv,dfs) {
|
20405 | var Ai = A[0], Aj = A[1], Av = A[2],m = Ai.length-1, n=0;
|
20406 | var Bi = B[0], Bj = B[1], Bv = B[2];
|
20407 |
|
20408 | var i,i0,i1,j,J,j0,j1,k,l,l0,l1,a;
|
20409 | i0 = Bi[I];
|
20410 | i1 = Bi[I+1];
|
20411 | xj.length = 0;
|
20412 | for(i=i0;i<i1;++i) { dfs.dfs(Pinv[Bj[i]],Ai,Aj,x,xj,Pinv); }
|
20413 | for(i=xj.length-1;i!==-1;--i) { x[xj[i]] = 0; }
|
20414 | for(i=i0;i!==i1;++i) { j = Pinv[Bj[i]]; x[j] = Bv[i]; }
|
20415 | for(i=xj.length-1;i!==-1;--i) {
|
20416 | j = xj[i];
|
20417 | j0 = Ai[j];
|
20418 | j1 = Ai[j+1];
|
20419 | for(k=j0;k<j1;++k) { if(Pinv[Aj[k]] === j) { x[j] /= Av[k]; break; } }
|
20420 | a = x[j];
|
20421 | for(k=j0;k<j1;++k) {
|
20422 | l = Pinv[Aj[k]];
|
20423 | if(l !== j) x[l] -= a*Av[k];
|
20424 | }
|
20425 | }
|
20426 | return x;
|
20427 | }
|
20428 | numeric.ccsLUP1 = function ccsLUP1(A,threshold) {
|
20429 | var m = A[0].length-1;
|
20430 | var L = [numeric.rep([m+1],0),[],[]], U = [numeric.rep([m+1], 0),[],[]];
|
20431 | var Li = L[0], Lj = L[1], Lv = L[2], Ui = U[0], Uj = U[1], Uv = U[2];
|
20432 | var x = numeric.rep([m],0), xj = numeric.rep([m],0);
|
20433 | var i,j,k,j0,j1,a,e,c,d,K;
|
20434 | var sol = numeric.ccsLPSolve, max = Math.max, abs = Math.abs;
|
20435 | var P = numeric.linspace(0,m-1),Pinv = numeric.linspace(0,m-1);
|
20436 | var dfs = new numeric.ccsDFS(m);
|
20437 | if(typeof threshold === "undefined") { threshold = 1; }
|
20438 | for(i=0;i<m;++i) {
|
20439 | sol(L,A,x,xj,i,Pinv,dfs);
|
20440 | a = -1;
|
20441 | e = -1;
|
20442 | for(j=xj.length-1;j!==-1;--j) {
|
20443 | k = xj[j];
|
20444 | if(k <= i) continue;
|
20445 | c = abs(x[k]);
|
20446 | if(c > a) { e = k; a = c; }
|
20447 | }
|
20448 | if(abs(x[i])<threshold*a) {
|
20449 | j = P[i];
|
20450 | a = P[e];
|
20451 | P[i] = a; Pinv[a] = i;
|
20452 | P[e] = j; Pinv[j] = e;
|
20453 | a = x[i]; x[i] = x[e]; x[e] = a;
|
20454 | }
|
20455 | a = Li[i];
|
20456 | e = Ui[i];
|
20457 | d = x[i];
|
20458 | Lj[a] = P[i];
|
20459 | Lv[a] = 1;
|
20460 | ++a;
|
20461 | for(j=xj.length-1;j!==-1;--j) {
|
20462 | k = xj[j];
|
20463 | c = x[k];
|
20464 | xj[j] = 0;
|
20465 | x[k] = 0;
|
20466 | if(k<=i) { Uj[e] = k; Uv[e] = c; ++e; }
|
20467 | else { Lj[a] = P[k]; Lv[a] = c/d; ++a; }
|
20468 | }
|
20469 | Li[i+1] = a;
|
20470 | Ui[i+1] = e;
|
20471 | }
|
20472 | for(j=Lj.length-1;j!==-1;--j) { Lj[j] = Pinv[Lj[j]]; }
|
20473 | return {L:L, U:U, P:P, Pinv:Pinv};
|
20474 | }
|
20475 | numeric.ccsDFS0 = function ccsDFS0(n) {
|
20476 | this.k = Array(n);
|
20477 | this.k1 = Array(n);
|
20478 | this.j = Array(n);
|
20479 | }
|
20480 | numeric.ccsDFS0.prototype.dfs = function dfs(J,Ai,Aj,x,xj,Pinv,P) {
|
20481 | var m = 0,foo,n=xj.length;
|
20482 | var k = this.k, k1 = this.k1, j = this.j,km,k11;
|
20483 | if(x[J]!==0) return;
|
20484 | x[J] = 1;
|
20485 | j[0] = J;
|
20486 | k[0] = km = Ai[Pinv[J]];
|
20487 | k1[0] = k11 = Ai[Pinv[J]+1];
|
20488 | while(1) {
|
20489 | if(isNaN(km)) throw new Error("Ow!");
|
20490 | if(km >= k11) {
|
20491 | xj[n] = Pinv[j[m]];
|
20492 | if(m===0) return;
|
20493 | ++n;
|
20494 | --m;
|
20495 | km = k[m];
|
20496 | k11 = k1[m];
|
20497 | } else {
|
20498 | foo = Aj[km];
|
20499 | if(x[foo] === 0) {
|
20500 | x[foo] = 1;
|
20501 | k[m] = km;
|
20502 | ++m;
|
20503 | j[m] = foo;
|
20504 | foo = Pinv[foo];
|
20505 | km = Ai[foo];
|
20506 | k1[m] = k11 = Ai[foo+1];
|
20507 | } else ++km;
|
20508 | }
|
20509 | }
|
20510 | }
|
20511 | numeric.ccsLPSolve0 = function ccsLPSolve0(A,B,y,xj,I,Pinv,P,dfs) {
|
20512 | var Ai = A[0], Aj = A[1], Av = A[2],m = Ai.length-1, n=0;
|
20513 | var Bi = B[0], Bj = B[1], Bv = B[2];
|
20514 |
|
20515 | var i,i0,i1,j,J,j0,j1,k,l,l0,l1,a;
|
20516 | i0 = Bi[I];
|
20517 | i1 = Bi[I+1];
|
20518 | xj.length = 0;
|
20519 | for(i=i0;i<i1;++i) { dfs.dfs(Bj[i],Ai,Aj,y,xj,Pinv,P); }
|
20520 | for(i=xj.length-1;i!==-1;--i) { j = xj[i]; y[P[j]] = 0; }
|
20521 | for(i=i0;i!==i1;++i) { j = Bj[i]; y[j] = Bv[i]; }
|
20522 | for(i=xj.length-1;i!==-1;--i) {
|
20523 | j = xj[i];
|
20524 | l = P[j];
|
20525 | j0 = Ai[j];
|
20526 | j1 = Ai[j+1];
|
20527 | for(k=j0;k<j1;++k) { if(Aj[k] === l) { y[l] /= Av[k]; break; } }
|
20528 | a = y[l];
|
20529 | for(k=j0;k<j1;++k) y[Aj[k]] -= a*Av[k];
|
20530 | y[l] = a;
|
20531 | }
|
20532 | }
|
20533 | numeric.ccsLUP0 = function ccsLUP0(A,threshold) {
|
20534 | var m = A[0].length-1;
|
20535 | var L = [numeric.rep([m+1],0),[],[]], U = [numeric.rep([m+1], 0),[],[]];
|
20536 | var Li = L[0], Lj = L[1], Lv = L[2], Ui = U[0], Uj = U[1], Uv = U[2];
|
20537 | var y = numeric.rep([m],0), xj = numeric.rep([m],0);
|
20538 | var i,j,k,j0,j1,a,e,c,d,K;
|
20539 | var sol = numeric.ccsLPSolve0, max = Math.max, abs = Math.abs;
|
20540 | var P = numeric.linspace(0,m-1),Pinv = numeric.linspace(0,m-1);
|
20541 | var dfs = new numeric.ccsDFS0(m);
|
20542 | if(typeof threshold === "undefined") { threshold = 1; }
|
20543 | for(i=0;i<m;++i) {
|
20544 | sol(L,A,y,xj,i,Pinv,P,dfs);
|
20545 | a = -1;
|
20546 | e = -1;
|
20547 | for(j=xj.length-1;j!==-1;--j) {
|
20548 | k = xj[j];
|
20549 | if(k <= i) continue;
|
20550 | c = abs(y[P[k]]);
|
20551 | if(c > a) { e = k; a = c; }
|
20552 | }
|
20553 | if(abs(y[P[i]])<threshold*a) {
|
20554 | j = P[i];
|
20555 | a = P[e];
|
20556 | P[i] = a; Pinv[a] = i;
|
20557 | P[e] = j; Pinv[j] = e;
|
20558 | }
|
20559 | a = Li[i];
|
20560 | e = Ui[i];
|
20561 | d = y[P[i]];
|
20562 | Lj[a] = P[i];
|
20563 | Lv[a] = 1;
|
20564 | ++a;
|
20565 | for(j=xj.length-1;j!==-1;--j) {
|
20566 | k = xj[j];
|
20567 | c = y[P[k]];
|
20568 | xj[j] = 0;
|
20569 | y[P[k]] = 0;
|
20570 | if(k<=i) { Uj[e] = k; Uv[e] = c; ++e; }
|
20571 | else { Lj[a] = P[k]; Lv[a] = c/d; ++a; }
|
20572 | }
|
20573 | Li[i+1] = a;
|
20574 | Ui[i+1] = e;
|
20575 | }
|
20576 | for(j=Lj.length-1;j!==-1;--j) { Lj[j] = Pinv[Lj[j]]; }
|
20577 | return {L:L, U:U, P:P, Pinv:Pinv};
|
20578 | }
|
20579 | numeric.ccsLUP = numeric.ccsLUP0;
|
20580 |
|
20581 | numeric.ccsDim = function ccsDim(A) { return [numeric.sup(A[1])+1,A[0].length-1]; }
|
20582 | numeric.ccsGetBlock = function ccsGetBlock(A,i,j) {
|
20583 | var s = numeric.ccsDim(A),m=s[0],n=s[1];
|
20584 | if(typeof i === "undefined") { i = numeric.linspace(0,m-1); }
|
20585 | else if(typeof i === "number") { i = [i]; }
|
20586 | if(typeof j === "undefined") { j = numeric.linspace(0,n-1); }
|
20587 | else if(typeof j === "number") { j = [j]; }
|
20588 | var p,p0,p1,P = i.length,q,Q = j.length,r,jq,ip;
|
20589 | var Bi = numeric.rep([n],0), Bj=[], Bv=[], B = [Bi,Bj,Bv];
|
20590 | var Ai = A[0], Aj = A[1], Av = A[2];
|
20591 | var x = numeric.rep([m],0),count=0,flags = numeric.rep([m],0);
|
20592 | for(q=0;q<Q;++q) {
|
20593 | jq = j[q];
|
20594 | var q0 = Ai[jq];
|
20595 | var q1 = Ai[jq+1];
|
20596 | for(p=q0;p<q1;++p) {
|
20597 | r = Aj[p];
|
20598 | flags[r] = 1;
|
20599 | x[r] = Av[p];
|
20600 | }
|
20601 | for(p=0;p<P;++p) {
|
20602 | ip = i[p];
|
20603 | if(flags[ip]) {
|
20604 | Bj[count] = p;
|
20605 | Bv[count] = x[i[p]];
|
20606 | ++count;
|
20607 | }
|
20608 | }
|
20609 | for(p=q0;p<q1;++p) {
|
20610 | r = Aj[p];
|
20611 | flags[r] = 0;
|
20612 | }
|
20613 | Bi[q+1] = count;
|
20614 | }
|
20615 | return B;
|
20616 | }
|
20617 |
|
20618 | numeric.ccsDot = function ccsDot(A,B) {
|
20619 | var Ai = A[0], Aj = A[1], Av = A[2];
|
20620 | var Bi = B[0], Bj = B[1], Bv = B[2];
|
20621 | var sA = numeric.ccsDim(A), sB = numeric.ccsDim(B);
|
20622 | var m = sA[0], n = sA[1], o = sB[1];
|
20623 | var x = numeric.rep([m],0), flags = numeric.rep([m],0), xj = Array(m);
|
20624 | var Ci = numeric.rep([o],0), Cj = [], Cv = [], C = [Ci,Cj,Cv];
|
20625 | var i,j,k,j0,j1,i0,i1,l,p,a,b;
|
20626 | for(k=0;k!==o;++k) {
|
20627 | j0 = Bi[k];
|
20628 | j1 = Bi[k+1];
|
20629 | p = 0;
|
20630 | for(j=j0;j<j1;++j) {
|
20631 | a = Bj[j];
|
20632 | b = Bv[j];
|
20633 | i0 = Ai[a];
|
20634 | i1 = Ai[a+1];
|
20635 | for(i=i0;i<i1;++i) {
|
20636 | l = Aj[i];
|
20637 | if(flags[l]===0) {
|
20638 | xj[p] = l;
|
20639 | flags[l] = 1;
|
20640 | p = p+1;
|
20641 | }
|
20642 | x[l] = x[l] + Av[i]*b;
|
20643 | }
|
20644 | }
|
20645 | j0 = Ci[k];
|
20646 | j1 = j0+p;
|
20647 | Ci[k+1] = j1;
|
20648 | for(j=p-1;j!==-1;--j) {
|
20649 | b = j0+j;
|
20650 | i = xj[j];
|
20651 | Cj[b] = i;
|
20652 | Cv[b] = x[i];
|
20653 | flags[i] = 0;
|
20654 | x[i] = 0;
|
20655 | }
|
20656 | Ci[k+1] = Ci[k]+p;
|
20657 | }
|
20658 | return C;
|
20659 | }
|
20660 |
|
20661 | numeric.ccsLUPSolve = function ccsLUPSolve(LUP,B) {
|
20662 | var L = LUP.L, U = LUP.U, P = LUP.P;
|
20663 | var Bi = B[0];
|
20664 | var flag = false;
|
20665 | if(typeof Bi !== "object") { B = [[0,B.length],numeric.linspace(0,B.length-1),B]; Bi = B[0]; flag = true; }
|
20666 | var Bj = B[1], Bv = B[2];
|
20667 | var n = L[0].length-1, m = Bi.length-1;
|
20668 | var x = numeric.rep([n],0), xj = Array(n);
|
20669 | var b = numeric.rep([n],0), bj = Array(n);
|
20670 | var Xi = numeric.rep([m+1],0), Xj = [], Xv = [];
|
20671 | var sol = numeric.ccsTSolve;
|
20672 | var i,j,j0,j1,k,J,N=0;
|
20673 | for(i=0;i<m;++i) {
|
20674 | k = 0;
|
20675 | j0 = Bi[i];
|
20676 | j1 = Bi[i+1];
|
20677 | for(j=j0;j<j1;++j) {
|
20678 | J = LUP.Pinv[Bj[j]];
|
20679 | bj[k] = J;
|
20680 | b[J] = Bv[j];
|
20681 | ++k;
|
20682 | }
|
20683 | bj.length = k;
|
20684 | sol(L,b,x,bj,xj);
|
20685 | for(j=bj.length-1;j!==-1;--j) b[bj[j]] = 0;
|
20686 | sol(U,x,b,xj,bj);
|
20687 | if(flag) return b;
|
20688 | for(j=xj.length-1;j!==-1;--j) x[xj[j]] = 0;
|
20689 | for(j=bj.length-1;j!==-1;--j) {
|
20690 | J = bj[j];
|
20691 | Xj[N] = J;
|
20692 | Xv[N] = b[J];
|
20693 | b[J] = 0;
|
20694 | ++N;
|
20695 | }
|
20696 | Xi[i+1] = N;
|
20697 | }
|
20698 | return [Xi,Xj,Xv];
|
20699 | }
|
20700 |
|
20701 | numeric.ccsbinop = function ccsbinop(body,setup) {
|
20702 | if(typeof setup === "undefined") setup='';
|
20703 | return Function('X','Y',
|
20704 | 'var Xi = X[0], Xj = X[1], Xv = X[2];\n'+
|
20705 | 'var Yi = Y[0], Yj = Y[1], Yv = Y[2];\n'+
|
20706 | 'var n = Xi.length-1,m = Math.max(numeric.sup(Xj),numeric.sup(Yj))+1;\n'+
|
20707 | 'var Zi = numeric.rep([n+1],0), Zj = [], Zv = [];\n'+
|
20708 | 'var x = numeric.rep([m],0),y = numeric.rep([m],0);\n'+
|
20709 | 'var xk,yk,zk;\n'+
|
20710 | 'var i,j,j0,j1,k,p=0;\n'+
|
20711 | setup+
|
20712 | 'for(i=0;i<n;++i) {\n'+
|
20713 | ' j0 = Xi[i]; j1 = Xi[i+1];\n'+
|
20714 | ' for(j=j0;j!==j1;++j) {\n'+
|
20715 | ' k = Xj[j];\n'+
|
20716 | ' x[k] = 1;\n'+
|
20717 | ' Zj[p] = k;\n'+
|
20718 | ' ++p;\n'+
|
20719 | ' }\n'+
|
20720 | ' j0 = Yi[i]; j1 = Yi[i+1];\n'+
|
20721 | ' for(j=j0;j!==j1;++j) {\n'+
|
20722 | ' k = Yj[j];\n'+
|
20723 | ' y[k] = Yv[j];\n'+
|
20724 | ' if(x[k] === 0) {\n'+
|
20725 | ' Zj[p] = k;\n'+
|
20726 | ' ++p;\n'+
|
20727 | ' }\n'+
|
20728 | ' }\n'+
|
20729 | ' Zi[i+1] = p;\n'+
|
20730 | ' j0 = Xi[i]; j1 = Xi[i+1];\n'+
|
20731 | ' for(j=j0;j!==j1;++j) x[Xj[j]] = Xv[j];\n'+
|
20732 | ' j0 = Zi[i]; j1 = Zi[i+1];\n'+
|
20733 | ' for(j=j0;j!==j1;++j) {\n'+
|
20734 | ' k = Zj[j];\n'+
|
20735 | ' xk = x[k];\n'+
|
20736 | ' yk = y[k];\n'+
|
20737 | body+'\n'+
|
20738 | ' Zv[j] = zk;\n'+
|
20739 | ' }\n'+
|
20740 | ' j0 = Xi[i]; j1 = Xi[i+1];\n'+
|
20741 | ' for(j=j0;j!==j1;++j) x[Xj[j]] = 0;\n'+
|
20742 | ' j0 = Yi[i]; j1 = Yi[i+1];\n'+
|
20743 | ' for(j=j0;j!==j1;++j) y[Yj[j]] = 0;\n'+
|
20744 | '}\n'+
|
20745 | 'return [Zi,Zj,Zv];'
|
20746 | );
|
20747 | };
|
20748 |
|
20749 | (function() {
|
20750 | var k,A,B,C;
|
20751 | for(k in numeric.ops2) {
|
20752 | if(isFinite(eval('1'+numeric.ops2[k]+'0'))) A = '[Y[0],Y[1],numeric.'+k+'(X,Y[2])]';
|
20753 | else A = 'NaN';
|
20754 | if(isFinite(eval('0'+numeric.ops2[k]+'1'))) B = '[X[0],X[1],numeric.'+k+'(X[2],Y)]';
|
20755 | else B = 'NaN';
|
20756 | if(isFinite(eval('1'+numeric.ops2[k]+'0')) && isFinite(eval('0'+numeric.ops2[k]+'1'))) C = 'numeric.ccs'+k+'MM(X,Y)';
|
20757 | else C = 'NaN';
|
20758 | numeric['ccs'+k+'MM'] = numeric.ccsbinop('zk = xk '+numeric.ops2[k]+'yk;');
|
20759 | numeric['ccs'+k] = Function('X','Y',
|
20760 | 'if(typeof X === "number") return '+A+';\n'+
|
20761 | 'if(typeof Y === "number") return '+B+';\n'+
|
20762 | 'return '+C+';\n'
|
20763 | );
|
20764 | }
|
20765 | }());
|
20766 |
|
20767 | numeric.ccsScatter = function ccsScatter(A) {
|
20768 | var Ai = A[0], Aj = A[1], Av = A[2];
|
20769 | var n = numeric.sup(Aj)+1,m=Ai.length;
|
20770 | var Ri = numeric.rep([n],0),Rj=Array(m), Rv = Array(m);
|
20771 | var counts = numeric.rep([n],0),i;
|
20772 | for(i=0;i<m;++i) counts[Aj[i]]++;
|
20773 | for(i=0;i<n;++i) Ri[i+1] = Ri[i] + counts[i];
|
20774 | var ptr = Ri.slice(0),k,Aii;
|
20775 | for(i=0;i<m;++i) {
|
20776 | Aii = Aj[i];
|
20777 | k = ptr[Aii];
|
20778 | Rj[k] = Ai[i];
|
20779 | Rv[k] = Av[i];
|
20780 | ptr[Aii]=ptr[Aii]+1;
|
20781 | }
|
20782 | return [Ri,Rj,Rv];
|
20783 | }
|
20784 |
|
20785 | numeric.ccsGather = function ccsGather(A) {
|
20786 | var Ai = A[0], Aj = A[1], Av = A[2];
|
20787 | var n = Ai.length-1,m = Aj.length;
|
20788 | var Ri = Array(m), Rj = Array(m), Rv = Array(m);
|
20789 | var i,j,j0,j1,p;
|
20790 | p=0;
|
20791 | for(i=0;i<n;++i) {
|
20792 | j0 = Ai[i];
|
20793 | j1 = Ai[i+1];
|
20794 | for(j=j0;j!==j1;++j) {
|
20795 | Rj[p] = i;
|
20796 | Ri[p] = Aj[j];
|
20797 | Rv[p] = Av[j];
|
20798 | ++p;
|
20799 | }
|
20800 | }
|
20801 | return [Ri,Rj,Rv];
|
20802 | }
|
20803 |
|
20804 |
|
20805 |
|
20806 | numeric.sdim = function dim(A,ret,k) {
|
20807 | if(typeof ret === "undefined") { ret = []; }
|
20808 | if(typeof A !== "object") return ret;
|
20809 | if(typeof k === "undefined") { k=0; }
|
20810 | if(!(k in ret)) { ret[k] = 0; }
|
20811 | if(A.length > ret[k]) ret[k] = A.length;
|
20812 | var i;
|
20813 | for(i in A) {
|
20814 | if(A.hasOwnProperty(i)) dim(A[i],ret,k+1);
|
20815 | }
|
20816 | return ret;
|
20817 | };
|
20818 |
|
20819 | numeric.sclone = function clone(A,k,n) {
|
20820 | if(typeof k === "undefined") { k=0; }
|
20821 | if(typeof n === "undefined") { n = numeric.sdim(A).length; }
|
20822 | var i,ret = Array(A.length);
|
20823 | if(k === n-1) {
|
20824 | for(i in A) { if(A.hasOwnProperty(i)) ret[i] = A[i]; }
|
20825 | return ret;
|
20826 | }
|
20827 | for(i in A) {
|
20828 | if(A.hasOwnProperty(i)) ret[i] = clone(A[i],k+1,n);
|
20829 | }
|
20830 | return ret;
|
20831 | }
|
20832 |
|
20833 | numeric.sdiag = function diag(d) {
|
20834 | var n = d.length,i,ret = Array(n),i1,i2,i3;
|
20835 | for(i=n-1;i>=1;i-=2) {
|
20836 | i1 = i-1;
|
20837 | ret[i] = []; ret[i][i] = d[i];
|
20838 | ret[i1] = []; ret[i1][i1] = d[i1];
|
20839 | }
|
20840 | if(i===0) { ret[0] = []; ret[0][0] = d[i]; }
|
20841 | return ret;
|
20842 | }
|
20843 |
|
20844 | numeric.sidentity = function identity(n) { return numeric.sdiag(numeric.rep([n],1)); }
|
20845 |
|
20846 | numeric.stranspose = function transpose(A) {
|
20847 | var ret = [], n = A.length, i,j,Ai;
|
20848 | for(i in A) {
|
20849 | if(!(A.hasOwnProperty(i))) continue;
|
20850 | Ai = A[i];
|
20851 | for(j in Ai) {
|
20852 | if(!(Ai.hasOwnProperty(j))) continue;
|
20853 | if(typeof ret[j] !== "object") { ret[j] = []; }
|
20854 | ret[j][i] = Ai[j];
|
20855 | }
|
20856 | }
|
20857 | return ret;
|
20858 | }
|
20859 |
|
20860 | numeric.sLUP = function LUP(A,tol) {
|
20861 | throw new Error("The function numeric.sLUP had a bug in it and has been removed. Please use the new numeric.ccsLUP function instead.");
|
20862 | };
|
20863 |
|
20864 | numeric.sdotMM = function dotMM(A,B) {
|
20865 | var p = A.length, q = B.length, BT = numeric.stranspose(B), r = BT.length, Ai, BTk;
|
20866 | var i,j,k,accum;
|
20867 | var ret = Array(p),reti;
|
20868 | for(i=p-1;i>=0;i--) {
|
20869 | reti = [];
|
20870 | Ai = A[i];
|
20871 | for(k=r-1;k>=0;k--) {
|
20872 | accum = 0;
|
20873 | BTk = BT[k];
|
20874 | for(j in Ai) {
|
20875 | if(!(Ai.hasOwnProperty(j))) continue;
|
20876 | if(j in BTk) { accum += Ai[j]*BTk[j]; }
|
20877 | }
|
20878 | if(accum) reti[k] = accum;
|
20879 | }
|
20880 | ret[i] = reti;
|
20881 | }
|
20882 | return ret;
|
20883 | }
|
20884 |
|
20885 | numeric.sdotMV = function dotMV(A,x) {
|
20886 | var p = A.length, Ai, i,j;
|
20887 | var ret = Array(p), accum;
|
20888 | for(i=p-1;i>=0;i--) {
|
20889 | Ai = A[i];
|
20890 | accum = 0;
|
20891 | for(j in Ai) {
|
20892 | if(!(Ai.hasOwnProperty(j))) continue;
|
20893 | if(x[j]) accum += Ai[j]*x[j];
|
20894 | }
|
20895 | if(accum) ret[i] = accum;
|
20896 | }
|
20897 | return ret;
|
20898 | }
|
20899 |
|
20900 | numeric.sdotVM = function dotMV(x,A) {
|
20901 | var i,j,Ai,alpha;
|
20902 | var ret = [], accum;
|
20903 | for(i in x) {
|
20904 | if(!x.hasOwnProperty(i)) continue;
|
20905 | Ai = A[i];
|
20906 | alpha = x[i];
|
20907 | for(j in Ai) {
|
20908 | if(!Ai.hasOwnProperty(j)) continue;
|
20909 | if(!ret[j]) { ret[j] = 0; }
|
20910 | ret[j] += alpha*Ai[j];
|
20911 | }
|
20912 | }
|
20913 | return ret;
|
20914 | }
|
20915 |
|
20916 | numeric.sdotVV = function dotVV(x,y) {
|
20917 | var i,ret=0;
|
20918 | for(i in x) { if(x[i] && y[i]) ret+= x[i]*y[i]; }
|
20919 | return ret;
|
20920 | }
|
20921 |
|
20922 | numeric.sdot = function dot(A,B) {
|
20923 | var m = numeric.sdim(A).length, n = numeric.sdim(B).length;
|
20924 | var k = m*1000+n;
|
20925 | switch(k) {
|
20926 | case 0: return A*B;
|
20927 | case 1001: return numeric.sdotVV(A,B);
|
20928 | case 2001: return numeric.sdotMV(A,B);
|
20929 | case 1002: return numeric.sdotVM(A,B);
|
20930 | case 2002: return numeric.sdotMM(A,B);
|
20931 | default: throw new Error('numeric.sdot not implemented for tensors of order '+m+' and '+n);
|
20932 | }
|
20933 | }
|
20934 |
|
20935 | numeric.sscatter = function scatter(V) {
|
20936 | var n = V[0].length, Vij, i, j, m = V.length, A = [], Aj;
|
20937 | for(i=n-1;i>=0;--i) {
|
20938 | if(!V[m-1][i]) continue;
|
20939 | Aj = A;
|
20940 | for(j=0;j<m-2;j++) {
|
20941 | Vij = V[j][i];
|
20942 | if(!Aj[Vij]) Aj[Vij] = [];
|
20943 | Aj = Aj[Vij];
|
20944 | }
|
20945 | Aj[V[j][i]] = V[j+1][i];
|
20946 | }
|
20947 | return A;
|
20948 | }
|
20949 |
|
20950 | numeric.sgather = function gather(A,ret,k) {
|
20951 | if(typeof ret === "undefined") ret = [];
|
20952 | if(typeof k === "undefined") k = [];
|
20953 | var n,i,Ai;
|
20954 | n = k.length;
|
20955 | for(i in A) {
|
20956 | if(A.hasOwnProperty(i)) {
|
20957 | k[n] = parseInt(i);
|
20958 | Ai = A[i];
|
20959 | if(typeof Ai === "number") {
|
20960 | if(Ai) {
|
20961 | if(ret.length === 0) {
|
20962 | for(i=n+1;i>=0;--i) ret[i] = [];
|
20963 | }
|
20964 | for(i=n;i>=0;--i) ret[i].push(k[i]);
|
20965 | ret[n+1].push(Ai);
|
20966 | }
|
20967 | } else gather(Ai,ret,k);
|
20968 | }
|
20969 | }
|
20970 | if(k.length>n) k.pop();
|
20971 | return ret;
|
20972 | }
|
20973 |
|
20974 |
|
20975 | numeric.cLU = function LU(A) {
|
20976 | var I = A[0], J = A[1], V = A[2];
|
20977 | var p = I.length, m=0, i,j,k,a,b,c;
|
20978 | for(i=0;i<p;i++) if(I[i]>m) m=I[i];
|
20979 | m++;
|
20980 | var L = Array(m), U = Array(m), left = numeric.rep([m],Infinity), right = numeric.rep([m],-Infinity);
|
20981 | var Ui, Uj,alpha;
|
20982 | for(k=0;k<p;k++) {
|
20983 | i = I[k];
|
20984 | j = J[k];
|
20985 | if(j<left[i]) left[i] = j;
|
20986 | if(j>right[i]) right[i] = j;
|
20987 | }
|
20988 | for(i=0;i<m-1;i++) { if(right[i] > right[i+1]) right[i+1] = right[i]; }
|
20989 | for(i=m-1;i>=1;i--) { if(left[i]<left[i-1]) left[i-1] = left[i]; }
|
20990 | var countL = 0, countU = 0;
|
20991 | for(i=0;i<m;i++) {
|
20992 | U[i] = numeric.rep([right[i]-left[i]+1],0);
|
20993 | L[i] = numeric.rep([i-left[i]],0);
|
20994 | countL += i-left[i]+1;
|
20995 | countU += right[i]-i+1;
|
20996 | }
|
20997 | for(k=0;k<p;k++) { i = I[k]; U[i][J[k]-left[i]] = V[k]; }
|
20998 | for(i=0;i<m-1;i++) {
|
20999 | a = i-left[i];
|
21000 | Ui = U[i];
|
21001 | for(j=i+1;left[j]<=i && j<m;j++) {
|
21002 | b = i-left[j];
|
21003 | c = right[i]-i;
|
21004 | Uj = U[j];
|
21005 | alpha = Uj[b]/Ui[a];
|
21006 | if(alpha) {
|
21007 | for(k=1;k<=c;k++) { Uj[k+b] -= alpha*Ui[k+a]; }
|
21008 | L[j][i-left[j]] = alpha;
|
21009 | }
|
21010 | }
|
21011 | }
|
21012 | var Ui = [], Uj = [], Uv = [], Li = [], Lj = [], Lv = [];
|
21013 | var p,q,foo;
|
21014 | p=0; q=0;
|
21015 | for(i=0;i<m;i++) {
|
21016 | a = left[i];
|
21017 | b = right[i];
|
21018 | foo = U[i];
|
21019 | for(j=i;j<=b;j++) {
|
21020 | if(foo[j-a]) {
|
21021 | Ui[p] = i;
|
21022 | Uj[p] = j;
|
21023 | Uv[p] = foo[j-a];
|
21024 | p++;
|
21025 | }
|
21026 | }
|
21027 | foo = L[i];
|
21028 | for(j=a;j<i;j++) {
|
21029 | if(foo[j-a]) {
|
21030 | Li[q] = i;
|
21031 | Lj[q] = j;
|
21032 | Lv[q] = foo[j-a];
|
21033 | q++;
|
21034 | }
|
21035 | }
|
21036 | Li[q] = i;
|
21037 | Lj[q] = i;
|
21038 | Lv[q] = 1;
|
21039 | q++;
|
21040 | }
|
21041 | return {U:[Ui,Uj,Uv], L:[Li,Lj,Lv]};
|
21042 | };
|
21043 |
|
21044 | numeric.cLUsolve = function LUsolve(lu,b) {
|
21045 | var L = lu.L, U = lu.U, ret = numeric.clone(b);
|
21046 | var Li = L[0], Lj = L[1], Lv = L[2];
|
21047 | var Ui = U[0], Uj = U[1], Uv = U[2];
|
21048 | var p = Ui.length, q = Li.length;
|
21049 | var m = ret.length,i,j,k;
|
21050 | k = 0;
|
21051 | for(i=0;i<m;i++) {
|
21052 | while(Lj[k] < i) {
|
21053 | ret[i] -= Lv[k]*ret[Lj[k]];
|
21054 | k++;
|
21055 | }
|
21056 | k++;
|
21057 | }
|
21058 | k = p-1;
|
21059 | for(i=m-1;i>=0;i--) {
|
21060 | while(Uj[k] > i) {
|
21061 | ret[i] -= Uv[k]*ret[Uj[k]];
|
21062 | k--;
|
21063 | }
|
21064 | ret[i] /= Uv[k];
|
21065 | k--;
|
21066 | }
|
21067 | return ret;
|
21068 | };
|
21069 |
|
21070 | numeric.cgrid = function grid(n,shape) {
|
21071 | if(typeof n === "number") n = [n,n];
|
21072 | var ret = numeric.rep(n,-1);
|
21073 | var i,j,count;
|
21074 | if(typeof shape !== "function") {
|
21075 | switch(shape) {
|
21076 | case 'L':
|
21077 | shape = function(i,j) { return (i>=n[0]/2 || j<n[1]/2); }
|
21078 | break;
|
21079 | default:
|
21080 | shape = function(i,j) { return true; };
|
21081 | break;
|
21082 | }
|
21083 | }
|
21084 | count=0;
|
21085 | for(i=1;i<n[0]-1;i++) for(j=1;j<n[1]-1;j++)
|
21086 | if(shape(i,j)) {
|
21087 | ret[i][j] = count;
|
21088 | count++;
|
21089 | }
|
21090 | return ret;
|
21091 | }
|
21092 |
|
21093 | numeric.cdelsq = function delsq(g) {
|
21094 | var dir = [[-1,0],[0,-1],[0,1],[1,0]];
|
21095 | var s = numeric.dim(g), m = s[0], n = s[1], i,j,k,p,q;
|
21096 | var Li = [], Lj = [], Lv = [];
|
21097 | for(i=1;i<m-1;i++) for(j=1;j<n-1;j++) {
|
21098 | if(g[i][j]<0) continue;
|
21099 | for(k=0;k<4;k++) {
|
21100 | p = i+dir[k][0];
|
21101 | q = j+dir[k][1];
|
21102 | if(g[p][q]<0) continue;
|
21103 | Li.push(g[i][j]);
|
21104 | Lj.push(g[p][q]);
|
21105 | Lv.push(-1);
|
21106 | }
|
21107 | Li.push(g[i][j]);
|
21108 | Lj.push(g[i][j]);
|
21109 | Lv.push(4);
|
21110 | }
|
21111 | return [Li,Lj,Lv];
|
21112 | }
|
21113 |
|
21114 | numeric.cdotMV = function dotMV(A,x) {
|
21115 | var ret, Ai = A[0], Aj = A[1], Av = A[2],k,p=Ai.length,N;
|
21116 | N=0;
|
21117 | for(k=0;k<p;k++) { if(Ai[k]>N) N = Ai[k]; }
|
21118 | N++;
|
21119 | ret = numeric.rep([N],0);
|
21120 | for(k=0;k<p;k++) { ret[Ai[k]]+=Av[k]*x[Aj[k]]; }
|
21121 | return ret;
|
21122 | }
|
21123 |
|
21124 |
|
21125 |
|
21126 | numeric.Spline = function Spline(x,yl,yr,kl,kr) { this.x = x; this.yl = yl; this.yr = yr; this.kl = kl; this.kr = kr; }
|
21127 | numeric.Spline.prototype._at = function _at(x1,p) {
|
21128 | var x = this.x;
|
21129 | var yl = this.yl;
|
21130 | var yr = this.yr;
|
21131 | var kl = this.kl;
|
21132 | var kr = this.kr;
|
21133 | var x1,a,b,t;
|
21134 | var add = numeric.add, sub = numeric.sub, mul = numeric.mul;
|
21135 | a = sub(mul(kl[p],x[p+1]-x[p]),sub(yr[p+1],yl[p]));
|
21136 | b = add(mul(kr[p+1],x[p]-x[p+1]),sub(yr[p+1],yl[p]));
|
21137 | t = (x1-x[p])/(x[p+1]-x[p]);
|
21138 | var s = t*(1-t);
|
21139 | return add(add(add(mul(1-t,yl[p]),mul(t,yr[p+1])),mul(a,s*(1-t))),mul(b,s*t));
|
21140 | }
|
21141 | numeric.Spline.prototype.at = function at(x0) {
|
21142 | if(typeof x0 === "number") {
|
21143 | var x = this.x;
|
21144 | var n = x.length;
|
21145 | var p,q,mid,floor = Math.floor,a,b,t;
|
21146 | p = 0;
|
21147 | q = n-1;
|
21148 | while(q-p>1) {
|
21149 | mid = floor((p+q)/2);
|
21150 | if(x[mid] <= x0) p = mid;
|
21151 | else q = mid;
|
21152 | }
|
21153 | return this._at(x0,p);
|
21154 | }
|
21155 | var n = x0.length, i, ret = Array(n);
|
21156 | for(i=n-1;i!==-1;--i) ret[i] = this.at(x0[i]);
|
21157 | return ret;
|
21158 | }
|
21159 | numeric.Spline.prototype.diff = function diff() {
|
21160 | var x = this.x;
|
21161 | var yl = this.yl;
|
21162 | var yr = this.yr;
|
21163 | var kl = this.kl;
|
21164 | var kr = this.kr;
|
21165 | var n = yl.length;
|
21166 | var i,dx,dy;
|
21167 | var zl = kl, zr = kr, pl = Array(n), pr = Array(n);
|
21168 | var add = numeric.add, mul = numeric.mul, div = numeric.div, sub = numeric.sub;
|
21169 | for(i=n-1;i!==-1;--i) {
|
21170 | dx = x[i+1]-x[i];
|
21171 | dy = sub(yr[i+1],yl[i]);
|
21172 | pl[i] = div(add(mul(dy, 6),mul(kl[i],-4*dx),mul(kr[i+1],-2*dx)),dx*dx);
|
21173 | pr[i+1] = div(add(mul(dy,-6),mul(kl[i], 2*dx),mul(kr[i+1], 4*dx)),dx*dx);
|
21174 | }
|
21175 | return new numeric.Spline(x,zl,zr,pl,pr);
|
21176 | }
|
21177 | numeric.Spline.prototype.roots = function roots() {
|
21178 | function sqr(x) { return x*x; }
|
21179 | function heval(y0,y1,k0,k1,x) {
|
21180 | var A = k0*2-(y1-y0);
|
21181 | var B = -k1*2+(y1-y0);
|
21182 | var t = (x+1)*0.5;
|
21183 | var s = t*(1-t);
|
21184 | return (1-t)*y0+t*y1+A*s*(1-t)+B*s*t;
|
21185 | }
|
21186 | var ret = [];
|
21187 | var x = this.x, yl = this.yl, yr = this.yr, kl = this.kl, kr = this.kr;
|
21188 | if(typeof yl[0] === "number") {
|
21189 | yl = [yl];
|
21190 | yr = [yr];
|
21191 | kl = [kl];
|
21192 | kr = [kr];
|
21193 | }
|
21194 | var m = yl.length,n=x.length-1,i,j,k,y,s,t;
|
21195 | var ai,bi,ci,di, ret = Array(m),ri,k0,k1,y0,y1,A,B,D,dx,cx,stops,z0,z1,zm,t0,t1,tm;
|
21196 | var sqrt = Math.sqrt;
|
21197 | for(i=0;i!==m;++i) {
|
21198 | ai = yl[i];
|
21199 | bi = yr[i];
|
21200 | ci = kl[i];
|
21201 | di = kr[i];
|
21202 | ri = [];
|
21203 | for(j=0;j!==n;j++) {
|
21204 | if(j>0 && bi[j]*ai[j]<0) ri.push(x[j]);
|
21205 | dx = (x[j+1]-x[j]);
|
21206 | cx = x[j];
|
21207 | y0 = ai[j];
|
21208 | y1 = bi[j+1];
|
21209 | k0 = ci[j]/dx;
|
21210 | k1 = di[j+1]/dx;
|
21211 | D = sqr(k0-k1+3*(y0-y1)) + 12*k1*y0;
|
21212 | A = k1+3*y0+2*k0-3*y1;
|
21213 | B = 3*(k1+k0+2*(y0-y1));
|
21214 | if(D<=0) {
|
21215 | z0 = A/B;
|
21216 | if(z0>x[j] && z0<x[j+1]) stops = [x[j],z0,x[j+1]];
|
21217 | else stops = [x[j],x[j+1]];
|
21218 | } else {
|
21219 | z0 = (A-sqrt(D))/B;
|
21220 | z1 = (A+sqrt(D))/B;
|
21221 | stops = [x[j]];
|
21222 | if(z0>x[j] && z0<x[j+1]) stops.push(z0);
|
21223 | if(z1>x[j] && z1<x[j+1]) stops.push(z1);
|
21224 | stops.push(x[j+1]);
|
21225 | }
|
21226 | t0 = stops[0];
|
21227 | z0 = this._at(t0,j);
|
21228 | for(k=0;k<stops.length-1;k++) {
|
21229 | t1 = stops[k+1];
|
21230 | z1 = this._at(t1,j);
|
21231 | if(z0 === 0) {
|
21232 | ri.push(t0);
|
21233 | t0 = t1;
|
21234 | z0 = z1;
|
21235 | continue;
|
21236 | }
|
21237 | if(z1 === 0 || z0*z1>0) {
|
21238 | t0 = t1;
|
21239 | z0 = z1;
|
21240 | continue;
|
21241 | }
|
21242 | var side = 0;
|
21243 | while(1) {
|
21244 | tm = (z0*t1-z1*t0)/(z0-z1);
|
21245 | if(tm <= t0 || tm >= t1) { break; }
|
21246 | zm = this._at(tm,j);
|
21247 | if(zm*z1>0) {
|
21248 | t1 = tm;
|
21249 | z1 = zm;
|
21250 | if(side === -1) z0*=0.5;
|
21251 | side = -1;
|
21252 | } else if(zm*z0>0) {
|
21253 | t0 = tm;
|
21254 | z0 = zm;
|
21255 | if(side === 1) z1*=0.5;
|
21256 | side = 1;
|
21257 | } else break;
|
21258 | }
|
21259 | ri.push(tm);
|
21260 | t0 = stops[k+1];
|
21261 | z0 = this._at(t0, j);
|
21262 | }
|
21263 | if(z1 === 0) ri.push(t1);
|
21264 | }
|
21265 | ret[i] = ri;
|
21266 | }
|
21267 | if(typeof this.yl[0] === "number") return ret[0];
|
21268 | return ret;
|
21269 | }
|
21270 | numeric.spline = function spline(x,y,k1,kn) {
|
21271 | var n = x.length, b = [], dx = [], dy = [];
|
21272 | var i;
|
21273 | var sub = numeric.sub,mul = numeric.mul,add = numeric.add;
|
21274 | for(i=n-2;i>=0;i--) { dx[i] = x[i+1]-x[i]; dy[i] = sub(y[i+1],y[i]); }
|
21275 | if(typeof k1 === "string" || typeof kn === "string") {
|
21276 | k1 = kn = "periodic";
|
21277 | }
|
21278 |
|
21279 | var T = [[],[],[]];
|
21280 | switch(typeof k1) {
|
21281 | case "undefined":
|
21282 | b[0] = mul(3/(dx[0]*dx[0]),dy[0]);
|
21283 | T[0].push(0,0);
|
21284 | T[1].push(0,1);
|
21285 | T[2].push(2/dx[0],1/dx[0]);
|
21286 | break;
|
21287 | case "string":
|
21288 | b[0] = add(mul(3/(dx[n-2]*dx[n-2]),dy[n-2]),mul(3/(dx[0]*dx[0]),dy[0]));
|
21289 | T[0].push(0,0,0);
|
21290 | T[1].push(n-2,0,1);
|
21291 | T[2].push(1/dx[n-2],2/dx[n-2]+2/dx[0],1/dx[0]);
|
21292 | break;
|
21293 | default:
|
21294 | b[0] = k1;
|
21295 | T[0].push(0);
|
21296 | T[1].push(0);
|
21297 | T[2].push(1);
|
21298 | break;
|
21299 | }
|
21300 | for(i=1;i<n-1;i++) {
|
21301 | b[i] = add(mul(3/(dx[i-1]*dx[i-1]),dy[i-1]),mul(3/(dx[i]*dx[i]),dy[i]));
|
21302 | T[0].push(i,i,i);
|
21303 | T[1].push(i-1,i,i+1);
|
21304 | T[2].push(1/dx[i-1],2/dx[i-1]+2/dx[i],1/dx[i]);
|
21305 | }
|
21306 | switch(typeof kn) {
|
21307 | case "undefined":
|
21308 | b[n-1] = mul(3/(dx[n-2]*dx[n-2]),dy[n-2]);
|
21309 | T[0].push(n-1,n-1);
|
21310 | T[1].push(n-2,n-1);
|
21311 | T[2].push(1/dx[n-2],2/dx[n-2]);
|
21312 | break;
|
21313 | case "string":
|
21314 | T[1][T[1].length-1] = 0;
|
21315 | break;
|
21316 | default:
|
21317 | b[n-1] = kn;
|
21318 | T[0].push(n-1);
|
21319 | T[1].push(n-1);
|
21320 | T[2].push(1);
|
21321 | break;
|
21322 | }
|
21323 | if(typeof b[0] !== "number") b = numeric.transpose(b);
|
21324 | else b = [b];
|
21325 | var k = Array(b.length);
|
21326 | if(typeof k1 === "string") {
|
21327 | for(i=k.length-1;i!==-1;--i) {
|
21328 | k[i] = numeric.ccsLUPSolve(numeric.ccsLUP(numeric.ccsScatter(T)),b[i]);
|
21329 | k[i][n-1] = k[i][0];
|
21330 | }
|
21331 | } else {
|
21332 | for(i=k.length-1;i!==-1;--i) {
|
21333 | k[i] = numeric.cLUsolve(numeric.cLU(T),b[i]);
|
21334 | }
|
21335 | }
|
21336 | if(typeof y[0] === "number") k = k[0];
|
21337 | else k = numeric.transpose(k);
|
21338 | return new numeric.Spline(x,y,y,k,k);
|
21339 | }
|
21340 |
|
21341 |
|
21342 | numeric.fftpow2 = function fftpow2(x,y) {
|
21343 | var n = x.length;
|
21344 | if(n === 1) return;
|
21345 | var cos = Math.cos, sin = Math.sin, i,j;
|
21346 | var xe = Array(n/2), ye = Array(n/2), xo = Array(n/2), yo = Array(n/2);
|
21347 | j = n/2;
|
21348 | for(i=n-1;i!==-1;--i) {
|
21349 | --j;
|
21350 | xo[j] = x[i];
|
21351 | yo[j] = y[i];
|
21352 | --i;
|
21353 | xe[j] = x[i];
|
21354 | ye[j] = y[i];
|
21355 | }
|
21356 | fftpow2(xe,ye);
|
21357 | fftpow2(xo,yo);
|
21358 | j = n/2;
|
21359 | var t,k = (-6.2831853071795864769252867665590057683943387987502116419/n),ci,si;
|
21360 | for(i=n-1;i!==-1;--i) {
|
21361 | --j;
|
21362 | if(j === -1) j = n/2-1;
|
21363 | t = k*i;
|
21364 | ci = cos(t);
|
21365 | si = sin(t);
|
21366 | x[i] = xe[j] + ci*xo[j] - si*yo[j];
|
21367 | y[i] = ye[j] + ci*yo[j] + si*xo[j];
|
21368 | }
|
21369 | }
|
21370 | numeric._ifftpow2 = function _ifftpow2(x,y) {
|
21371 | var n = x.length;
|
21372 | if(n === 1) return;
|
21373 | var cos = Math.cos, sin = Math.sin, i,j;
|
21374 | var xe = Array(n/2), ye = Array(n/2), xo = Array(n/2), yo = Array(n/2);
|
21375 | j = n/2;
|
21376 | for(i=n-1;i!==-1;--i) {
|
21377 | --j;
|
21378 | xo[j] = x[i];
|
21379 | yo[j] = y[i];
|
21380 | --i;
|
21381 | xe[j] = x[i];
|
21382 | ye[j] = y[i];
|
21383 | }
|
21384 | _ifftpow2(xe,ye);
|
21385 | _ifftpow2(xo,yo);
|
21386 | j = n/2;
|
21387 | var t,k = (6.2831853071795864769252867665590057683943387987502116419/n),ci,si;
|
21388 | for(i=n-1;i!==-1;--i) {
|
21389 | --j;
|
21390 | if(j === -1) j = n/2-1;
|
21391 | t = k*i;
|
21392 | ci = cos(t);
|
21393 | si = sin(t);
|
21394 | x[i] = xe[j] + ci*xo[j] - si*yo[j];
|
21395 | y[i] = ye[j] + ci*yo[j] + si*xo[j];
|
21396 | }
|
21397 | }
|
21398 | numeric.ifftpow2 = function ifftpow2(x,y) {
|
21399 | numeric._ifftpow2(x,y);
|
21400 | numeric.diveq(x,x.length);
|
21401 | numeric.diveq(y,y.length);
|
21402 | }
|
21403 | numeric.convpow2 = function convpow2(ax,ay,bx,by) {
|
21404 | numeric.fftpow2(ax,ay);
|
21405 | numeric.fftpow2(bx,by);
|
21406 | var i,n = ax.length,axi,bxi,ayi,byi;
|
21407 | for(i=n-1;i!==-1;--i) {
|
21408 | axi = ax[i]; ayi = ay[i]; bxi = bx[i]; byi = by[i];
|
21409 | ax[i] = axi*bxi-ayi*byi;
|
21410 | ay[i] = axi*byi+ayi*bxi;
|
21411 | }
|
21412 | numeric.ifftpow2(ax,ay);
|
21413 | }
|
21414 | numeric.T.prototype.fft = function fft() {
|
21415 | var x = this.x, y = this.y;
|
21416 | var n = x.length, log = Math.log, log2 = log(2),
|
21417 | p = Math.ceil(log(2*n-1)/log2), m = Math.pow(2,p);
|
21418 | var cx = numeric.rep([m],0), cy = numeric.rep([m],0), cos = Math.cos, sin = Math.sin;
|
21419 | var k, c = (-3.141592653589793238462643383279502884197169399375105820/n),t;
|
21420 | var a = numeric.rep([m],0), b = numeric.rep([m],0),nhalf = Math.floor(n/2);
|
21421 | for(k=0;k<n;k++) a[k] = x[k];
|
21422 | if(typeof y !== "undefined") for(k=0;k<n;k++) b[k] = y[k];
|
21423 | cx[0] = 1;
|
21424 | for(k=1;k<=m/2;k++) {
|
21425 | t = c*k*k;
|
21426 | cx[k] = cos(t);
|
21427 | cy[k] = sin(t);
|
21428 | cx[m-k] = cos(t);
|
21429 | cy[m-k] = sin(t)
|
21430 | }
|
21431 | var X = new numeric.T(a,b), Y = new numeric.T(cx,cy);
|
21432 | X = X.mul(Y);
|
21433 | numeric.convpow2(X.x,X.y,numeric.clone(Y.x),numeric.neg(Y.y));
|
21434 | X = X.mul(Y);
|
21435 | X.x.length = n;
|
21436 | X.y.length = n;
|
21437 | return X;
|
21438 | }
|
21439 | numeric.T.prototype.ifft = function ifft() {
|
21440 | var x = this.x, y = this.y;
|
21441 | var n = x.length, log = Math.log, log2 = log(2),
|
21442 | p = Math.ceil(log(2*n-1)/log2), m = Math.pow(2,p);
|
21443 | var cx = numeric.rep([m],0), cy = numeric.rep([m],0), cos = Math.cos, sin = Math.sin;
|
21444 | var k, c = (3.141592653589793238462643383279502884197169399375105820/n),t;
|
21445 | var a = numeric.rep([m],0), b = numeric.rep([m],0),nhalf = Math.floor(n/2);
|
21446 | for(k=0;k<n;k++) a[k] = x[k];
|
21447 | if(typeof y !== "undefined") for(k=0;k<n;k++) b[k] = y[k];
|
21448 | cx[0] = 1;
|
21449 | for(k=1;k<=m/2;k++) {
|
21450 | t = c*k*k;
|
21451 | cx[k] = cos(t);
|
21452 | cy[k] = sin(t);
|
21453 | cx[m-k] = cos(t);
|
21454 | cy[m-k] = sin(t)
|
21455 | }
|
21456 | var X = new numeric.T(a,b), Y = new numeric.T(cx,cy);
|
21457 | X = X.mul(Y);
|
21458 | numeric.convpow2(X.x,X.y,numeric.clone(Y.x),numeric.neg(Y.y));
|
21459 | X = X.mul(Y);
|
21460 | X.x.length = n;
|
21461 | X.y.length = n;
|
21462 | return X.div(n);
|
21463 | }
|
21464 |
|
21465 |
|
21466 | numeric.gradient = function gradient(f,x) {
|
21467 | var n = x.length;
|
21468 | var f0 = f(x);
|
21469 | if(isNaN(f0)) throw new Error('gradient: f(x) is a NaN!');
|
21470 | var max = Math.max;
|
21471 | var i,x0 = numeric.clone(x),f1,f2, J = Array(n);
|
21472 | var div = numeric.div, sub = numeric.sub,errest,roundoff,max = Math.max,eps = 1e-3,abs = Math.abs, min = Math.min;
|
21473 | var t0,t1,t2,it=0,d1,d2,N;
|
21474 | for(i=0;i<n;i++) {
|
21475 | var h = max(1e-6*f0,1e-8);
|
21476 | while(1) {
|
21477 | ++it;
|
21478 | if(it>20) { throw new Error("Numerical gradient fails"); }
|
21479 | x0[i] = x[i]+h;
|
21480 | f1 = f(x0);
|
21481 | x0[i] = x[i]-h;
|
21482 | f2 = f(x0);
|
21483 | x0[i] = x[i];
|
21484 | if(isNaN(f1) || isNaN(f2)) { h/=16; continue; }
|
21485 | J[i] = (f1-f2)/(2*h);
|
21486 | t0 = x[i]-h;
|
21487 | t1 = x[i];
|
21488 | t2 = x[i]+h;
|
21489 | d1 = (f1-f0)/h;
|
21490 | d2 = (f0-f2)/h;
|
21491 | N = max(abs(J[i]),abs(f0),abs(f1),abs(f2),abs(t0),abs(t1),abs(t2),1e-8);
|
21492 | errest = min(max(abs(d1-J[i]),abs(d2-J[i]),abs(d1-d2))/N,h/N);
|
21493 | if(errest>eps) { h/=16; }
|
21494 | else break;
|
21495 | }
|
21496 | }
|
21497 | return J;
|
21498 | }
|
21499 |
|
21500 | numeric.uncmin = function uncmin(f,x0,tol,gradient,maxit,callback,options) {
|
21501 | var grad = numeric.gradient;
|
21502 | if(typeof options === "undefined") { options = {}; }
|
21503 | if(typeof tol === "undefined") { tol = 1e-8; }
|
21504 | if(typeof gradient === "undefined") { gradient = function(x) { return grad(f,x); }; }
|
21505 | if(typeof maxit === "undefined") maxit = 1000;
|
21506 | x0 = numeric.clone(x0);
|
21507 | var n = x0.length;
|
21508 | var f0 = f(x0),f1,df0;
|
21509 | if(isNaN(f0)) throw new Error('uncmin: f(x0) is a NaN!');
|
21510 | var max = Math.max, norm2 = numeric.norm2;
|
21511 | tol = max(tol,numeric.epsilon);
|
21512 | var step,g0,g1,H1 = options.Hinv || numeric.identity(n);
|
21513 | var dot = numeric.dot, inv = numeric.inv, sub = numeric.sub, add = numeric.add, ten = numeric.tensor, div = numeric.div, mul = numeric.mul;
|
21514 | var all = numeric.all, isfinite = numeric.isFinite, neg = numeric.neg;
|
21515 | var it=0,i,s,x1,y,Hy,Hs,ys,i0,t,nstep,t1,t2;
|
21516 | var msg = "";
|
21517 | g0 = gradient(x0);
|
21518 | while(it<maxit) {
|
21519 | if(typeof callback === "function") { if(callback(it,x0,f0,g0,H1)) { msg = "Callback returned true"; break; } }
|
21520 | if(!all(isfinite(g0))) { msg = "Gradient has Infinity or NaN"; break; }
|
21521 | step = neg(dot(H1,g0));
|
21522 | if(!all(isfinite(step))) { msg = "Search direction has Infinity or NaN"; break; }
|
21523 | nstep = norm2(step);
|
21524 | if(nstep < tol) { msg="Newton step smaller than tol"; break; }
|
21525 | t = 1;
|
21526 | df0 = dot(g0,step);
|
21527 |
|
21528 | x1 = x0;
|
21529 | while(it < maxit) {
|
21530 | if(t*nstep < tol) { break; }
|
21531 | s = mul(step,t);
|
21532 | x1 = add(x0,s);
|
21533 | f1 = f(x1);
|
21534 | if(f1-f0 >= 0.1*t*df0 || isNaN(f1)) {
|
21535 | t *= 0.5;
|
21536 | ++it;
|
21537 | continue;
|
21538 | }
|
21539 | break;
|
21540 | }
|
21541 | if(t*nstep < tol) { msg = "Line search step size smaller than tol"; break; }
|
21542 | if(it === maxit) { msg = "maxit reached during line search"; break; }
|
21543 | g1 = gradient(x1);
|
21544 | y = sub(g1,g0);
|
21545 | ys = dot(y,s);
|
21546 | Hy = dot(H1,y);
|
21547 | H1 = sub(add(H1,
|
21548 | mul(
|
21549 | (ys+dot(y,Hy))/(ys*ys),
|
21550 | ten(s,s) )),
|
21551 | div(add(ten(Hy,s),ten(s,Hy)),ys));
|
21552 | x0 = x1;
|
21553 | f0 = f1;
|
21554 | g0 = g1;
|
21555 | ++it;
|
21556 | }
|
21557 | return {solution: x0, f: f0, gradient: g0, invHessian: H1, iterations:it, message: msg};
|
21558 | }
|
21559 |
|
21560 |
|
21561 | numeric.Dopri = function Dopri(x,y,f,ymid,iterations,msg,events) {
|
21562 | this.x = x;
|
21563 | this.y = y;
|
21564 | this.f = f;
|
21565 | this.ymid = ymid;
|
21566 | this.iterations = iterations;
|
21567 | this.events = events;
|
21568 | this.message = msg;
|
21569 | }
|
21570 | numeric.Dopri.prototype._at = function _at(xi,j) {
|
21571 | function sqr(x) { return x*x; }
|
21572 | var sol = this;
|
21573 | var xs = sol.x;
|
21574 | var ys = sol.y;
|
21575 | var k1 = sol.f;
|
21576 | var ymid = sol.ymid;
|
21577 | var n = xs.length;
|
21578 | var x0,x1,xh,y0,y1,yh,xi;
|
21579 | var floor = Math.floor,h;
|
21580 | var c = 0.5;
|
21581 | var add = numeric.add, mul = numeric.mul,sub = numeric.sub, p,q,w;
|
21582 | x0 = xs[j];
|
21583 | x1 = xs[j+1];
|
21584 | y0 = ys[j];
|
21585 | y1 = ys[j+1];
|
21586 | h = x1-x0;
|
21587 | xh = x0+c*h;
|
21588 | yh = ymid[j];
|
21589 | p = sub(k1[j ],mul(y0,1/(x0-xh)+2/(x0-x1)));
|
21590 | q = sub(k1[j+1],mul(y1,1/(x1-xh)+2/(x1-x0)));
|
21591 | w = [sqr(xi - x1) * (xi - xh) / sqr(x0 - x1) / (x0 - xh),
|
21592 | sqr(xi - x0) * sqr(xi - x1) / sqr(x0 - xh) / sqr(x1 - xh),
|
21593 | sqr(xi - x0) * (xi - xh) / sqr(x1 - x0) / (x1 - xh),
|
21594 | (xi - x0) * sqr(xi - x1) * (xi - xh) / sqr(x0-x1) / (x0 - xh),
|
21595 | (xi - x1) * sqr(xi - x0) * (xi - xh) / sqr(x0-x1) / (x1 - xh)];
|
21596 | return add(add(add(add(mul(y0,w[0]),
|
21597 | mul(yh,w[1])),
|
21598 | mul(y1,w[2])),
|
21599 | mul( p,w[3])),
|
21600 | mul( q,w[4]));
|
21601 | }
|
21602 | numeric.Dopri.prototype.at = function at(x) {
|
21603 | var i,j,k,floor = Math.floor;
|
21604 | if(typeof x !== "number") {
|
21605 | var n = x.length, ret = Array(n);
|
21606 | for(i=n-1;i!==-1;--i) {
|
21607 | ret[i] = this.at(x[i]);
|
21608 | }
|
21609 | return ret;
|
21610 | }
|
21611 | var x0 = this.x;
|
21612 | i = 0; j = x0.length-1;
|
21613 | while(j-i>1) {
|
21614 | k = floor(0.5*(i+j));
|
21615 | if(x0[k] <= x) i = k;
|
21616 | else j = k;
|
21617 | }
|
21618 | return this._at(x,i);
|
21619 | }
|
21620 |
|
21621 | numeric.dopri = function dopri(x0,x1,y0,f,tol,maxit,event) {
|
21622 | if(typeof tol === "undefined") { tol = 1e-6; }
|
21623 | if(typeof maxit === "undefined") { maxit = 1000; }
|
21624 | var xs = [x0], ys = [y0], k1 = [f(x0,y0)], k2,k3,k4,k5,k6,k7, ymid = [];
|
21625 | var A2 = 1/5;
|
21626 | var A3 = [3/40,9/40];
|
21627 | var A4 = [44/45,-56/15,32/9];
|
21628 | var A5 = [19372/6561,-25360/2187,64448/6561,-212/729];
|
21629 | var A6 = [9017/3168,-355/33,46732/5247,49/176,-5103/18656];
|
21630 | var b = [35/384,0,500/1113,125/192,-2187/6784,11/84];
|
21631 | var bm = [0.5*6025192743/30085553152,
|
21632 | 0,
|
21633 | 0.5*51252292925/65400821598,
|
21634 | 0.5*-2691868925/45128329728,
|
21635 | 0.5*187940372067/1594534317056,
|
21636 | 0.5*-1776094331/19743644256,
|
21637 | 0.5*11237099/235043384];
|
21638 | var c = [1/5,3/10,4/5,8/9,1,1];
|
21639 | var e = [-71/57600,0,71/16695,-71/1920,17253/339200,-22/525,1/40];
|
21640 | var i = 0,er,j;
|
21641 | var h = (x1-x0)/10;
|
21642 | var it = 0;
|
21643 | var add = numeric.add, mul = numeric.mul, y1,erinf;
|
21644 | var max = Math.max, min = Math.min, abs = Math.abs, norminf = numeric.norminf,pow = Math.pow;
|
21645 | var any = numeric.any, lt = numeric.lt, and = numeric.and, sub = numeric.sub;
|
21646 | var e0, e1, ev;
|
21647 | var ret = new numeric.Dopri(xs,ys,k1,ymid,-1,"");
|
21648 | if(typeof event === "function") e0 = event(x0,y0);
|
21649 | while(x0<x1 && it<maxit) {
|
21650 | ++it;
|
21651 | if(x0+h>x1) h = x1-x0;
|
21652 | k2 = f(x0+c[0]*h, add(y0,mul( A2*h,k1[i])));
|
21653 | k3 = f(x0+c[1]*h, add(add(y0,mul(A3[0]*h,k1[i])),mul(A3[1]*h,k2)));
|
21654 | k4 = f(x0+c[2]*h, add(add(add(y0,mul(A4[0]*h,k1[i])),mul(A4[1]*h,k2)),mul(A4[2]*h,k3)));
|
21655 | k5 = f(x0+c[3]*h, add(add(add(add(y0,mul(A5[0]*h,k1[i])),mul(A5[1]*h,k2)),mul(A5[2]*h,k3)),mul(A5[3]*h,k4)));
|
21656 | k6 = f(x0+c[4]*h,add(add(add(add(add(y0,mul(A6[0]*h,k1[i])),mul(A6[1]*h,k2)),mul(A6[2]*h,k3)),mul(A6[3]*h,k4)),mul(A6[4]*h,k5)));
|
21657 | y1 = add(add(add(add(add(y0,mul(k1[i],h*b[0])),mul(k3,h*b[2])),mul(k4,h*b[3])),mul(k5,h*b[4])),mul(k6,h*b[5]));
|
21658 | k7 = f(x0+h,y1);
|
21659 | er = add(add(add(add(add(mul(k1[i],h*e[0]),mul(k3,h*e[2])),mul(k4,h*e[3])),mul(k5,h*e[4])),mul(k6,h*e[5])),mul(k7,h*e[6]));
|
21660 | if(typeof er === "number") erinf = abs(er);
|
21661 | else erinf = norminf(er);
|
21662 | if(erinf > tol) {
|
21663 | h = 0.2*h*pow(tol/erinf,0.25);
|
21664 | if(x0+h === x0) {
|
21665 | ret.msg = "Step size became too small";
|
21666 | break;
|
21667 | }
|
21668 | continue;
|
21669 | }
|
21670 | ymid[i] = add(add(add(add(add(add(y0,
|
21671 | mul(k1[i],h*bm[0])),
|
21672 | mul(k3 ,h*bm[2])),
|
21673 | mul(k4 ,h*bm[3])),
|
21674 | mul(k5 ,h*bm[4])),
|
21675 | mul(k6 ,h*bm[5])),
|
21676 | mul(k7 ,h*bm[6]));
|
21677 | ++i;
|
21678 | xs[i] = x0+h;
|
21679 | ys[i] = y1;
|
21680 | k1[i] = k7;
|
21681 | if(typeof event === "function") {
|
21682 | var yi,xl = x0,xr = x0+0.5*h,xi;
|
21683 | e1 = event(xr,ymid[i-1]);
|
21684 | ev = and(lt(e0,0),lt(0,e1));
|
21685 | if(!any(ev)) { xl = xr; xr = x0+h; e0 = e1; e1 = event(xr,y1); ev = and(lt(e0,0),lt(0,e1)); }
|
21686 | if(any(ev)) {
|
21687 | var xc, yc, en,ei;
|
21688 | var side=0, sl = 1.0, sr = 1.0;
|
21689 | while(1) {
|
21690 | if(typeof e0 === "number") xi = (sr*e1*xl-sl*e0*xr)/(sr*e1-sl*e0);
|
21691 | else {
|
21692 | xi = xr;
|
21693 | for(j=e0.length-1;j!==-1;--j) {
|
21694 | if(e0[j]<0 && e1[j]>0) xi = min(xi,(sr*e1[j]*xl-sl*e0[j]*xr)/(sr*e1[j]-sl*e0[j]));
|
21695 | }
|
21696 | }
|
21697 | if(xi <= xl || xi >= xr) break;
|
21698 | yi = ret._at(xi, i-1);
|
21699 | ei = event(xi,yi);
|
21700 | en = and(lt(e0,0),lt(0,ei));
|
21701 | if(any(en)) {
|
21702 | xr = xi;
|
21703 | e1 = ei;
|
21704 | ev = en;
|
21705 | sr = 1.0;
|
21706 | if(side === -1) sl *= 0.5;
|
21707 | else sl = 1.0;
|
21708 | side = -1;
|
21709 | } else {
|
21710 | xl = xi;
|
21711 | e0 = ei;
|
21712 | sl = 1.0;
|
21713 | if(side === 1) sr *= 0.5;
|
21714 | else sr = 1.0;
|
21715 | side = 1;
|
21716 | }
|
21717 | }
|
21718 | y1 = ret._at(0.5*(x0+xi),i-1);
|
21719 | ret.f[i] = f(xi,yi);
|
21720 | ret.x[i] = xi;
|
21721 | ret.y[i] = yi;
|
21722 | ret.ymid[i-1] = y1;
|
21723 | ret.events = ev;
|
21724 | ret.iterations = it;
|
21725 | return ret;
|
21726 | }
|
21727 | }
|
21728 | x0 += h;
|
21729 | y0 = y1;
|
21730 | e0 = e1;
|
21731 | h = min(0.8*h*pow(tol/erinf,0.25),4*h);
|
21732 | }
|
21733 | ret.iterations = it;
|
21734 | return ret;
|
21735 | }
|
21736 |
|
21737 |
|
21738 | numeric.LU = function(A, fast) {
|
21739 | fast = fast || false;
|
21740 |
|
21741 | var abs = Math.abs;
|
21742 | var i, j, k, absAjk, Akk, Ak, Pk, Ai;
|
21743 | var max;
|
21744 | var n = A.length, n1 = n-1;
|
21745 | var P = new Array(n);
|
21746 | if(!fast) A = numeric.clone(A);
|
21747 |
|
21748 | for (k = 0; k < n; ++k) {
|
21749 | Pk = k;
|
21750 | Ak = A[k];
|
21751 | max = abs(Ak[k]);
|
21752 | for (j = k + 1; j < n; ++j) {
|
21753 | absAjk = abs(A[j][k]);
|
21754 | if (max < absAjk) {
|
21755 | max = absAjk;
|
21756 | Pk = j;
|
21757 | }
|
21758 | }
|
21759 | P[k] = Pk;
|
21760 |
|
21761 | if (Pk != k) {
|
21762 | A[k] = A[Pk];
|
21763 | A[Pk] = Ak;
|
21764 | Ak = A[k];
|
21765 | }
|
21766 |
|
21767 | Akk = Ak[k];
|
21768 |
|
21769 | for (i = k + 1; i < n; ++i) {
|
21770 | A[i][k] /= Akk;
|
21771 | }
|
21772 |
|
21773 | for (i = k + 1; i < n; ++i) {
|
21774 | Ai = A[i];
|
21775 | for (j = k + 1; j < n1; ++j) {
|
21776 | Ai[j] -= Ai[k] * Ak[j];
|
21777 | ++j;
|
21778 | Ai[j] -= Ai[k] * Ak[j];
|
21779 | }
|
21780 | if(j===n1) Ai[j] -= Ai[k] * Ak[j];
|
21781 | }
|
21782 | }
|
21783 |
|
21784 | return {
|
21785 | LU: A,
|
21786 | P: P
|
21787 | };
|
21788 | }
|
21789 |
|
21790 | numeric.LUsolve = function LUsolve(LUP, b) {
|
21791 | var i, j;
|
21792 | var LU = LUP.LU;
|
21793 | var n = LU.length;
|
21794 | var x = numeric.clone(b);
|
21795 | var P = LUP.P;
|
21796 | var Pi, LUi, LUii, tmp;
|
21797 |
|
21798 | for (i=n-1;i!==-1;--i) x[i] = b[i];
|
21799 | for (i = 0; i < n; ++i) {
|
21800 | Pi = P[i];
|
21801 | if (P[i] !== i) {
|
21802 | tmp = x[i];
|
21803 | x[i] = x[Pi];
|
21804 | x[Pi] = tmp;
|
21805 | }
|
21806 |
|
21807 | LUi = LU[i];
|
21808 | for (j = 0; j < i; ++j) {
|
21809 | x[i] -= x[j] * LUi[j];
|
21810 | }
|
21811 | }
|
21812 |
|
21813 | for (i = n - 1; i >= 0; --i) {
|
21814 | LUi = LU[i];
|
21815 | for (j = i + 1; j < n; ++j) {
|
21816 | x[i] -= x[j] * LUi[j];
|
21817 | }
|
21818 |
|
21819 | x[i] /= LUi[i];
|
21820 | }
|
21821 |
|
21822 | return x;
|
21823 | }
|
21824 |
|
21825 | numeric.solve = function solve(A,b,fast) { return numeric.LUsolve(numeric.LU(A,fast), b); }
|
21826 |
|
21827 |
|
21828 | numeric.echelonize = function echelonize(A) {
|
21829 | var s = numeric.dim(A), m = s[0], n = s[1];
|
21830 | var I = numeric.identity(m);
|
21831 | var P = Array(m);
|
21832 | var i,j,k,l,Ai,Ii,Z,a;
|
21833 | var abs = Math.abs;
|
21834 | var diveq = numeric.diveq;
|
21835 | A = numeric.clone(A);
|
21836 | for(i=0;i<m;++i) {
|
21837 | k = 0;
|
21838 | Ai = A[i];
|
21839 | Ii = I[i];
|
21840 | for(j=1;j<n;++j) if(abs(Ai[k])<abs(Ai[j])) k=j;
|
21841 | P[i] = k;
|
21842 | diveq(Ii,Ai[k]);
|
21843 | diveq(Ai,Ai[k]);
|
21844 | for(j=0;j<m;++j) if(j!==i) {
|
21845 | Z = A[j]; a = Z[k];
|
21846 | for(l=n-1;l!==-1;--l) Z[l] -= Ai[l]*a;
|
21847 | Z = I[j];
|
21848 | for(l=m-1;l!==-1;--l) Z[l] -= Ii[l]*a;
|
21849 | }
|
21850 | }
|
21851 | return {I:I, A:A, P:P};
|
21852 | }
|
21853 |
|
21854 | numeric.__solveLP = function __solveLP(c,A,b,tol,maxit,x,flag) {
|
21855 | var sum = numeric.sum, log = numeric.log, mul = numeric.mul, sub = numeric.sub, dot = numeric.dot, div = numeric.div, add = numeric.add;
|
21856 | var m = c.length, n = b.length,y;
|
21857 | var unbounded = false, cb,i0=0;
|
21858 | var alpha = 1.0;
|
21859 | var f0,df0,AT = numeric.transpose(A), svd = numeric.svd,transpose = numeric.transpose,leq = numeric.leq, sqrt = Math.sqrt, abs = Math.abs;
|
21860 | var muleq = numeric.muleq;
|
21861 | var norm = numeric.norminf, any = numeric.any,min = Math.min;
|
21862 | var all = numeric.all, gt = numeric.gt;
|
21863 | var p = Array(m), A0 = Array(n),e=numeric.rep([n],1), H;
|
21864 | var solve = numeric.solve, z = sub(b,dot(A,x)),count;
|
21865 | var dotcc = dot(c,c);
|
21866 | var g;
|
21867 | for(count=i0;count<maxit;++count) {
|
21868 | var i,j,d;
|
21869 | for(i=n-1;i!==-1;--i) A0[i] = div(A[i],z[i]);
|
21870 | var A1 = transpose(A0);
|
21871 | for(i=m-1;i!==-1;--i) p[i] = (sum(A1[i]));
|
21872 | alpha = 0.25*abs(dotcc/dot(c,p));
|
21873 | var a1 = 100*sqrt(dotcc/dot(p,p));
|
21874 | if(!isFinite(alpha) || alpha>a1) alpha = a1;
|
21875 | g = add(c,mul(alpha,p));
|
21876 | H = dot(A1,A0);
|
21877 | for(i=m-1;i!==-1;--i) H[i][i] += 1;
|
21878 | d = solve(H,div(g,alpha),true);
|
21879 | var t0 = div(z,dot(A,d));
|
21880 | var t = 1.0;
|
21881 | for(i=n-1;i!==-1;--i) if(t0[i]<0) t = min(t,-0.999*t0[i]);
|
21882 | y = sub(x,mul(d,t));
|
21883 | z = sub(b,dot(A,y));
|
21884 | if(!all(gt(z,0))) return { solution: x, message: "", iterations: count };
|
21885 | x = y;
|
21886 | if(alpha<tol) return { solution: y, message: "", iterations: count };
|
21887 | if(flag) {
|
21888 | var s = dot(c,g), Ag = dot(A,g);
|
21889 | unbounded = true;
|
21890 | for(i=n-1;i!==-1;--i) if(s*Ag[i]<0) { unbounded = false; break; }
|
21891 | } else {
|
21892 | if(x[m-1]>=0) unbounded = false;
|
21893 | else unbounded = true;
|
21894 | }
|
21895 | if(unbounded) return { solution: y, message: "Unbounded", iterations: count };
|
21896 | }
|
21897 | return { solution: x, message: "maximum iteration count exceeded", iterations:count };
|
21898 | }
|
21899 |
|
21900 | numeric._solveLP = function _solveLP(c,A,b,tol,maxit) {
|
21901 | var m = c.length, n = b.length,y;
|
21902 | var sum = numeric.sum, log = numeric.log, mul = numeric.mul, sub = numeric.sub, dot = numeric.dot, div = numeric.div, add = numeric.add;
|
21903 | var c0 = numeric.rep([m],0).concat([1]);
|
21904 | var J = numeric.rep([n,1],-1);
|
21905 | var A0 = numeric.blockMatrix([[A , J ]]);
|
21906 | var b0 = b;
|
21907 | var y = numeric.rep([m],0).concat(Math.max(0,numeric.sup(numeric.neg(b)))+1);
|
21908 | var x0 = numeric.__solveLP(c0,A0,b0,tol,maxit,y,false);
|
21909 | var x = numeric.clone(x0.solution);
|
21910 | x.length = m;
|
21911 | var foo = numeric.inf(sub(b,dot(A,x)));
|
21912 | if(foo<0) { return { solution: NaN, message: "Infeasible", iterations: x0.iterations }; }
|
21913 | var ret = numeric.__solveLP(c, A, b, tol, maxit-x0.iterations, x, true);
|
21914 | ret.iterations += x0.iterations;
|
21915 | return ret;
|
21916 | };
|
21917 |
|
21918 | numeric.solveLP = function solveLP(c,A,b,Aeq,beq,tol,maxit) {
|
21919 | if(typeof maxit === "undefined") maxit = 1000;
|
21920 | if(typeof tol === "undefined") tol = numeric.epsilon;
|
21921 | if(typeof Aeq === "undefined") return numeric._solveLP(c,A,b,tol,maxit);
|
21922 | var m = Aeq.length, n = Aeq[0].length, o = A.length;
|
21923 | var B = numeric.echelonize(Aeq);
|
21924 | var flags = numeric.rep([n],0);
|
21925 | var P = B.P;
|
21926 | var Q = [];
|
21927 | var i;
|
21928 | for(i=P.length-1;i!==-1;--i) flags[P[i]] = 1;
|
21929 | for(i=n-1;i!==-1;--i) if(flags[i]===0) Q.push(i);
|
21930 | var g = numeric.getRange;
|
21931 | var I = numeric.linspace(0,m-1), J = numeric.linspace(0,o-1);
|
21932 | var Aeq2 = g(Aeq,I,Q), A1 = g(A,J,P), A2 = g(A,J,Q), dot = numeric.dot, sub = numeric.sub;
|
21933 | var A3 = dot(A1,B.I);
|
21934 | var A4 = sub(A2,dot(A3,Aeq2)), b4 = sub(b,dot(A3,beq));
|
21935 | var c1 = Array(P.length), c2 = Array(Q.length);
|
21936 | for(i=P.length-1;i!==-1;--i) c1[i] = c[P[i]];
|
21937 | for(i=Q.length-1;i!==-1;--i) c2[i] = c[Q[i]];
|
21938 | var c4 = sub(c2,dot(c1,dot(B.I,Aeq2)));
|
21939 | var S = numeric._solveLP(c4,A4,b4,tol,maxit);
|
21940 | var x2 = S.solution;
|
21941 | if(x2!==x2) return S;
|
21942 | var x1 = dot(B.I,sub(beq,dot(Aeq2,x2)));
|
21943 | var x = Array(c.length);
|
21944 | for(i=P.length-1;i!==-1;--i) x[P[i]] = x1[i];
|
21945 | for(i=Q.length-1;i!==-1;--i) x[Q[i]] = x2[i];
|
21946 | return { solution: x, message:S.message, iterations: S.iterations };
|
21947 | }
|
21948 |
|
21949 | numeric.MPStoLP = function MPStoLP(MPS) {
|
21950 | if(MPS instanceof String) { MPS.split('\n'); }
|
21951 | var state = 0;
|
21952 | var states = ['Initial state','NAME','ROWS','COLUMNS','RHS','BOUNDS','ENDATA'];
|
21953 | var n = MPS.length;
|
21954 | var i,j,z,N=0,rows = {}, sign = [], rl = 0, vars = {}, nv = 0;
|
21955 | var name;
|
21956 | var c = [], A = [], b = [];
|
21957 | function err(e) { throw new Error('MPStoLP: '+e+'\nLine '+i+': '+MPS[i]+'\nCurrent state: '+states[state]+'\n'); }
|
21958 | for(i=0;i<n;++i) {
|
21959 | z = MPS[i];
|
21960 | var w0 = z.match(/\S*/g);
|
21961 | var w = [];
|
21962 | for(j=0;j<w0.length;++j) if(w0[j]!=="") w.push(w0[j]);
|
21963 | if(w.length === 0) continue;
|
21964 | for(j=0;j<states.length;++j) if(z.substr(0,states[j].length) === states[j]) break;
|
21965 | if(j<states.length) {
|
21966 | state = j;
|
21967 | if(j===1) { name = w[1]; }
|
21968 | if(j===6) return { name:name, c:c, A:numeric.transpose(A), b:b, rows:rows, vars:vars };
|
21969 | continue;
|
21970 | }
|
21971 | switch(state) {
|
21972 | case 0: case 1: err('Unexpected line');
|
21973 | case 2:
|
21974 | switch(w[0]) {
|
21975 | case 'N': if(N===0) N = w[1]; else err('Two or more N rows'); break;
|
21976 | case 'L': rows[w[1]] = rl; sign[rl] = 1; b[rl] = 0; ++rl; break;
|
21977 | case 'G': rows[w[1]] = rl; sign[rl] = -1;b[rl] = 0; ++rl; break;
|
21978 | case 'E': rows[w[1]] = rl; sign[rl] = 0;b[rl] = 0; ++rl; break;
|
21979 | default: err('Parse error '+numeric.prettyPrint(w));
|
21980 | }
|
21981 | break;
|
21982 | case 3:
|
21983 | if(!vars.hasOwnProperty(w[0])) { vars[w[0]] = nv; c[nv] = 0; A[nv] = numeric.rep([rl],0); ++nv; }
|
21984 | var p = vars[w[0]];
|
21985 | for(j=1;j<w.length;j+=2) {
|
21986 | if(w[j] === N) { c[p] = parseFloat(w[j+1]); continue; }
|
21987 | var q = rows[w[j]];
|
21988 | A[p][q] = (sign[q]<0?-1:1)*parseFloat(w[j+1]);
|
21989 | }
|
21990 | break;
|
21991 | case 4:
|
21992 | for(j=1;j<w.length;j+=2) b[rows[w[j]]] = (sign[rows[w[j]]]<0?-1:1)*parseFloat(w[j+1]);
|
21993 | break;
|
21994 | case 5: break;
|
21995 | case 6: err('Internal error');
|
21996 | }
|
21997 | }
|
21998 | err('Reached end of file without ENDATA');
|
21999 | }
|
22000 |
|
22001 |
|
22002 |
|
22003 |
|
22004 |
|
22005 |
|
22006 |
|
22007 |
|
22008 |
|
22009 |
|
22010 |
|
22011 |
|
22012 |
|
22013 |
|
22014 |
|
22015 |
|
22016 |
|
22017 |
|
22018 |
|
22019 |
|
22020 |
|
22021 |
|
22022 |
|
22023 |
|
22024 |
|
22025 |
|
22026 |
|
22027 |
|
22028 |
|
22029 |
|
22030 |
|
22031 |
|
22032 |
|
22033 |
|
22034 |
|
22035 |
|
22036 |
|
22037 |
|
22038 |
|
22039 |
|
22040 |
|
22041 |
|
22042 |
|
22043 |
|
22044 |
|
22045 |
|
22046 |
|
22047 |
|
22048 |
|
22049 |
|
22050 |
|
22051 |
|
22052 |
|
22053 |
|
22054 |
|
22055 |
|
22056 |
|
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 |
|
22062 |
|
22063 |
|
22064 |
|
22065 |
|
22066 |
|
22067 |
|
22068 |
|
22069 |
|
22070 |
|
22071 |
|
22072 |
|
22073 |
|
22074 |
|
22075 |
|
22076 |
|
22077 |
|
22078 |
|
22079 |
|
22080 |
|
22081 |
|
22082 |
|
22083 |
|
22084 |
|
22085 |
|
22086 |
|
22087 |
|
22088 |
|
22089 |
|
22090 |
|
22091 |
|
22092 |
|
22093 |
|
22094 |
|
22095 |
|
22096 |
|
22097 |
|
22098 |
|
22099 |
|
22100 |
|
22101 |
|
22102 |
|
22103 |
|
22104 | numeric.seedrandom = { pow:Math.pow, random:Math.random };
|
22105 |
|
22106 | (function (pool, math, width, chunks, significance, overflow, startdenom) {
|
22107 |
|
22108 |
|
22109 |
|
22110 |
|
22111 |
|
22112 |
|
22113 | math['seedrandom'] = function seedrandom(seed, use_entropy) {
|
22114 | var key = [];
|
22115 | var arc4;
|
22116 |
|
22117 |
|
22118 | seed = mixkey(flatten(
|
22119 | use_entropy ? [seed, pool] :
|
22120 | arguments.length ? seed :
|
22121 | [new Date().getTime(), pool, window], 3), key);
|
22122 |
|
22123 |
|
22124 | arc4 = new ARC4(key);
|
22125 |
|
22126 |
|
22127 | mixkey(arc4.S, pool);
|
22128 |
|
22129 |
|
22130 |
|
22131 |
|
22132 |
|
22133 |
|
22134 | math['random'] = function random() {
|
22135 | var n = arc4.g(chunks);
|
22136 | var d = startdenom;
|
22137 | var x = 0;
|
22138 | while (n < significance) {
|
22139 | n = (n + x) * width;
|
22140 | d *= width;
|
22141 | x = arc4.g(1);
|
22142 | }
|
22143 | while (n >= overflow) {
|
22144 | n /= 2;
|
22145 | d /= 2;
|
22146 | x >>>= 1;
|
22147 | }
|
22148 | return (n + x) / d;
|
22149 | };
|
22150 |
|
22151 |
|
22152 | return seed;
|
22153 | };
|
22154 |
|
22155 |
|
22156 |
|
22157 |
|
22158 |
|
22159 |
|
22160 |
|
22161 |
|
22162 |
|
22163 |
|
22164 |
|
22165 |
|
22166 | function ARC4(key) {
|
22167 | var t, u, me = this, keylen = key.length;
|
22168 | var i = 0, j = me.i = me.j = me.m = 0;
|
22169 | me.S = [];
|
22170 | me.c = [];
|
22171 |
|
22172 |
|
22173 | if (!keylen) { key = [keylen++]; }
|
22174 |
|
22175 |
|
22176 | while (i < width) { me.S[i] = i++; }
|
22177 | for (i = 0; i < width; i++) {
|
22178 | t = me.S[i];
|
22179 | j = lowbits(j + t + key[i % keylen]);
|
22180 | u = me.S[j];
|
22181 | me.S[i] = u;
|
22182 | me.S[j] = t;
|
22183 | }
|
22184 |
|
22185 |
|
22186 | me.g = function getnext(count) {
|
22187 | var s = me.S;
|
22188 | var i = lowbits(me.i + 1); var t = s[i];
|
22189 | var j = lowbits(me.j + t); var u = s[j];
|
22190 | s[i] = u;
|
22191 | s[j] = t;
|
22192 | var r = s[lowbits(t + u)];
|
22193 | while (--count) {
|
22194 | i = lowbits(i + 1); t = s[i];
|
22195 | j = lowbits(j + t); u = s[j];
|
22196 | s[i] = u;
|
22197 | s[j] = t;
|
22198 | r = r * width + s[lowbits(t + u)];
|
22199 | }
|
22200 | me.i = i;
|
22201 | me.j = j;
|
22202 | return r;
|
22203 | };
|
22204 |
|
22205 |
|
22206 | me.g(width);
|
22207 | }
|
22208 |
|
22209 |
|
22210 |
|
22211 |
|
22212 |
|
22213 |
|
22214 |
|
22215 |
|
22216 | function flatten(obj, depth, result, prop, typ) {
|
22217 | result = [];
|
22218 | typ = typeof(obj);
|
22219 | if (depth && typ == 'object') {
|
22220 | for (prop in obj) {
|
22221 | if (prop.indexOf('S') < 5) {
|
22222 | try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
|
22223 | }
|
22224 | }
|
22225 | }
|
22226 | return (result.length ? result : obj + (typ != 'string' ? '\0' : ''));
|
22227 | }
|
22228 |
|
22229 |
|
22230 |
|
22231 |
|
22232 |
|
22233 |
|
22234 |
|
22235 |
|
22236 | function mixkey(seed, key, smear, j) {
|
22237 | seed += '';
|
22238 | smear = 0;
|
22239 | for (j = 0; j < seed.length; j++) {
|
22240 | key[lowbits(j)] =
|
22241 | lowbits((smear ^= key[lowbits(j)] * 19) + seed.charCodeAt(j));
|
22242 | }
|
22243 | seed = '';
|
22244 | for (j in key) { seed += String.fromCharCode(key[j]); }
|
22245 | return seed;
|
22246 | }
|
22247 |
|
22248 |
|
22249 |
|
22250 |
|
22251 |
|
22252 | function lowbits(n) { return n & (width - 1); }
|
22253 |
|
22254 |
|
22255 |
|
22256 |
|
22257 | startdenom = math.pow(width, chunks);
|
22258 | significance = math.pow(2, significance);
|
22259 | overflow = significance * 2;
|
22260 |
|
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 |
|
22266 |
|
22267 |
|
22268 | mixkey(math.random(), pool);
|
22269 |
|
22270 |
|
22271 | }(
|
22272 | [],
|
22273 | numeric.seedrandom,
|
22274 | 256,
|
22275 | 6,
|
22276 | 52
|
22277 | ));
|
22278 |
|
22279 |
|
22280 |
|
22281 |
|
22282 | (function(exports) {
|
22283 |
|
22284 | function base0to1(A) {
|
22285 | if(typeof A !== "object") { return A; }
|
22286 | var ret = [], i,n=A.length;
|
22287 | for(i=0;i<n;i++) ret[i+1] = base0to1(A[i]);
|
22288 | return ret;
|
22289 | }
|
22290 | function base1to0(A) {
|
22291 | if(typeof A !== "object") { return A; }
|
22292 | var ret = [], i,n=A.length;
|
22293 | for(i=1;i<n;i++) ret[i-1] = base1to0(A[i]);
|
22294 | return ret;
|
22295 | }
|
22296 |
|
22297 | function dpori(a, lda, n) {
|
22298 | var i, j, k, kp1, t;
|
22299 |
|
22300 | for (k = 1; k <= n; k = k + 1) {
|
22301 | a[k][k] = 1 / a[k][k];
|
22302 | t = -a[k][k];
|
22303 |
|
22304 | for (i = 1; i < k; i = i + 1) {
|
22305 | a[i][k] = t * a[i][k];
|
22306 | }
|
22307 |
|
22308 | kp1 = k + 1;
|
22309 | if (n < kp1) {
|
22310 | break;
|
22311 | }
|
22312 | for (j = kp1; j <= n; j = j + 1) {
|
22313 | t = a[k][j];
|
22314 | a[k][j] = 0;
|
22315 |
|
22316 | for (i = 1; i <= k; i = i + 1) {
|
22317 | a[i][j] = a[i][j] + (t * a[i][k]);
|
22318 | }
|
22319 | }
|
22320 | }
|
22321 |
|
22322 | }
|
22323 |
|
22324 | function dposl(a, lda, n, b) {
|
22325 | var i, k, kb, t;
|
22326 |
|
22327 | for (k = 1; k <= n; k = k + 1) {
|
22328 |
|
22329 | t = 0;
|
22330 | for (i = 1; i < k; i = i + 1) {
|
22331 | t = t + (a[i][k] * b[i]);
|
22332 | }
|
22333 |
|
22334 | b[k] = (b[k] - t) / a[k][k];
|
22335 | }
|
22336 |
|
22337 | for (kb = 1; kb <= n; kb = kb + 1) {
|
22338 | k = n + 1 - kb;
|
22339 | b[k] = b[k] / a[k][k];
|
22340 | t = -b[k];
|
22341 |
|
22342 | for (i = 1; i < k; i = i + 1) {
|
22343 | b[i] = b[i] + (t * a[i][k]);
|
22344 | }
|
22345 | }
|
22346 | }
|
22347 |
|
22348 | function dpofa(a, lda, n, info) {
|
22349 | var i, j, jm1, k, t, s;
|
22350 |
|
22351 | for (j = 1; j <= n; j = j + 1) {
|
22352 | info[1] = j;
|
22353 | s = 0;
|
22354 | jm1 = j - 1;
|
22355 | if (jm1 < 1) {
|
22356 | s = a[j][j] - s;
|
22357 | if (s <= 0) {
|
22358 | break;
|
22359 | }
|
22360 | a[j][j] = Math.sqrt(s);
|
22361 | } else {
|
22362 | for (k = 1; k <= jm1; k = k + 1) {
|
22363 |
|
22364 | t = a[k][j];
|
22365 | for (i = 1; i < k; i = i + 1) {
|
22366 | t = t - (a[i][j] * a[i][k]);
|
22367 | }
|
22368 | t = t / a[k][k];
|
22369 | a[k][j] = t;
|
22370 | s = s + t * t;
|
22371 | }
|
22372 | s = a[j][j] - s;
|
22373 | if (s <= 0) {
|
22374 | break;
|
22375 | }
|
22376 | a[j][j] = Math.sqrt(s);
|
22377 | }
|
22378 | info[1] = 0;
|
22379 | }
|
22380 | }
|
22381 |
|
22382 | function qpgen2(dmat, dvec, fddmat, n, sol, crval, amat,
|
22383 | bvec, fdamat, q, meq, iact, nact, iter, work, ierr) {
|
22384 |
|
22385 | var i, j, l, l1, info, it1, iwzv, iwrv, iwrm, iwsv, iwuv, nvl, r, iwnbv,
|
22386 | temp, sum, t1, tt, gc, gs, nu,
|
22387 | t1inf, t2min,
|
22388 | vsmall, tmpa, tmpb,
|
22389 | go;
|
22390 |
|
22391 | r = Math.min(n, q);
|
22392 | l = 2 * n + (r * (r + 5)) / 2 + 2 * q + 1;
|
22393 |
|
22394 | vsmall = 1.0e-60;
|
22395 | do {
|
22396 | vsmall = vsmall + vsmall;
|
22397 | tmpa = 1 + 0.1 * vsmall;
|
22398 | tmpb = 1 + 0.2 * vsmall;
|
22399 | } while (tmpa <= 1 || tmpb <= 1);
|
22400 |
|
22401 | for (i = 1; i <= n; i = i + 1) {
|
22402 | work[i] = dvec[i];
|
22403 | }
|
22404 | for (i = n + 1; i <= l; i = i + 1) {
|
22405 | work[i] = 0;
|
22406 | }
|
22407 | for (i = 1; i <= q; i = i + 1) {
|
22408 | iact[i] = 0;
|
22409 | }
|
22410 |
|
22411 | info = [];
|
22412 |
|
22413 | if (ierr[1] === 0) {
|
22414 | dpofa(dmat, fddmat, n, info);
|
22415 | if (info[1] !== 0) {
|
22416 | ierr[1] = 2;
|
22417 | return;
|
22418 | }
|
22419 | dposl(dmat, fddmat, n, dvec);
|
22420 | dpori(dmat, fddmat, n);
|
22421 | } else {
|
22422 | for (j = 1; j <= n; j = j + 1) {
|
22423 | sol[j] = 0;
|
22424 | for (i = 1; i <= j; i = i + 1) {
|
22425 | sol[j] = sol[j] + dmat[i][j] * dvec[i];
|
22426 | }
|
22427 | }
|
22428 | for (j = 1; j <= n; j = j + 1) {
|
22429 | dvec[j] = 0;
|
22430 | for (i = j; i <= n; i = i + 1) {
|
22431 | dvec[j] = dvec[j] + dmat[j][i] * sol[i];
|
22432 | }
|
22433 | }
|
22434 | }
|
22435 |
|
22436 | crval[1] = 0;
|
22437 | for (j = 1; j <= n; j = j + 1) {
|
22438 | sol[j] = dvec[j];
|
22439 | crval[1] = crval[1] + work[j] * sol[j];
|
22440 | work[j] = 0;
|
22441 | for (i = j + 1; i <= n; i = i + 1) {
|
22442 | dmat[i][j] = 0;
|
22443 | }
|
22444 | }
|
22445 | crval[1] = -crval[1] / 2;
|
22446 | ierr[1] = 0;
|
22447 |
|
22448 | iwzv = n;
|
22449 | iwrv = iwzv + n;
|
22450 | iwuv = iwrv + r;
|
22451 | iwrm = iwuv + r + 1;
|
22452 | iwsv = iwrm + (r * (r + 1)) / 2;
|
22453 | iwnbv = iwsv + q;
|
22454 |
|
22455 | for (i = 1; i <= q; i = i + 1) {
|
22456 | sum = 0;
|
22457 | for (j = 1; j <= n; j = j + 1) {
|
22458 | sum = sum + amat[j][i] * amat[j][i];
|
22459 | }
|
22460 | work[iwnbv + i] = Math.sqrt(sum);
|
22461 | }
|
22462 | nact = 0;
|
22463 | iter[1] = 0;
|
22464 | iter[2] = 0;
|
22465 |
|
22466 | function fn_goto_50() {
|
22467 | iter[1] = iter[1] + 1;
|
22468 |
|
22469 | l = iwsv;
|
22470 | for (i = 1; i <= q; i = i + 1) {
|
22471 | l = l + 1;
|
22472 | sum = -bvec[i];
|
22473 | for (j = 1; j <= n; j = j + 1) {
|
22474 | sum = sum + amat[j][i] * sol[j];
|
22475 | }
|
22476 | if (Math.abs(sum) < vsmall) {
|
22477 | sum = 0;
|
22478 | }
|
22479 | if (i > meq) {
|
22480 | work[l] = sum;
|
22481 | } else {
|
22482 | work[l] = -Math.abs(sum);
|
22483 | if (sum > 0) {
|
22484 | for (j = 1; j <= n; j = j + 1) {
|
22485 | amat[j][i] = -amat[j][i];
|
22486 | }
|
22487 | bvec[i] = -bvec[i];
|
22488 | }
|
22489 | }
|
22490 | }
|
22491 |
|
22492 | for (i = 1; i <= nact; i = i + 1) {
|
22493 | work[iwsv + iact[i]] = 0;
|
22494 | }
|
22495 |
|
22496 | nvl = 0;
|
22497 | temp = 0;
|
22498 | for (i = 1; i <= q; i = i + 1) {
|
22499 | if (work[iwsv + i] < temp * work[iwnbv + i]) {
|
22500 | nvl = i;
|
22501 | temp = work[iwsv + i] / work[iwnbv + i];
|
22502 | }
|
22503 | }
|
22504 | if (nvl === 0) {
|
22505 | return 999;
|
22506 | }
|
22507 |
|
22508 | return 0;
|
22509 | }
|
22510 |
|
22511 | function fn_goto_55() {
|
22512 | for (i = 1; i <= n; i = i + 1) {
|
22513 | sum = 0;
|
22514 | for (j = 1; j <= n; j = j + 1) {
|
22515 | sum = sum + dmat[j][i] * amat[j][nvl];
|
22516 | }
|
22517 | work[i] = sum;
|
22518 | }
|
22519 |
|
22520 | l1 = iwzv;
|
22521 | for (i = 1; i <= n; i = i + 1) {
|
22522 | work[l1 + i] = 0;
|
22523 | }
|
22524 | for (j = nact + 1; j <= n; j = j + 1) {
|
22525 | for (i = 1; i <= n; i = i + 1) {
|
22526 | work[l1 + i] = work[l1 + i] + dmat[i][j] * work[j];
|
22527 | }
|
22528 | }
|
22529 |
|
22530 | t1inf = true;
|
22531 | for (i = nact; i >= 1; i = i - 1) {
|
22532 | sum = work[i];
|
22533 | l = iwrm + (i * (i + 3)) / 2;
|
22534 | l1 = l - i;
|
22535 | for (j = i + 1; j <= nact; j = j + 1) {
|
22536 | sum = sum - work[l] * work[iwrv + j];
|
22537 | l = l + j;
|
22538 | }
|
22539 | sum = sum / work[l1];
|
22540 | work[iwrv + i] = sum;
|
22541 | if (iact[i] < meq) {
|
22542 |
|
22543 | break;
|
22544 | }
|
22545 | if (sum < 0) {
|
22546 |
|
22547 | break;
|
22548 | }
|
22549 | t1inf = false;
|
22550 | it1 = i;
|
22551 | }
|
22552 |
|
22553 | if (!t1inf) {
|
22554 | t1 = work[iwuv + it1] / work[iwrv + it1];
|
22555 | for (i = 1; i <= nact; i = i + 1) {
|
22556 | if (iact[i] < meq) {
|
22557 |
|
22558 | break;
|
22559 | }
|
22560 | if (work[iwrv + i] < 0) {
|
22561 |
|
22562 | break;
|
22563 | }
|
22564 | temp = work[iwuv + i] / work[iwrv + i];
|
22565 | if (temp < t1) {
|
22566 | t1 = temp;
|
22567 | it1 = i;
|
22568 | }
|
22569 | }
|
22570 | }
|
22571 |
|
22572 | sum = 0;
|
22573 | for (i = iwzv + 1; i <= iwzv + n; i = i + 1) {
|
22574 | sum = sum + work[i] * work[i];
|
22575 | }
|
22576 | if (Math.abs(sum) <= vsmall) {
|
22577 | if (t1inf) {
|
22578 | ierr[1] = 1;
|
22579 |
|
22580 | return 999;
|
22581 | } else {
|
22582 | for (i = 1; i <= nact; i = i + 1) {
|
22583 | work[iwuv + i] = work[iwuv + i] - t1 * work[iwrv + i];
|
22584 | }
|
22585 | work[iwuv + nact + 1] = work[iwuv + nact + 1] + t1;
|
22586 |
|
22587 | return 700;
|
22588 | }
|
22589 | } else {
|
22590 | sum = 0;
|
22591 | for (i = 1; i <= n; i = i + 1) {
|
22592 | sum = sum + work[iwzv + i] * amat[i][nvl];
|
22593 | }
|
22594 | tt = -work[iwsv + nvl] / sum;
|
22595 | t2min = true;
|
22596 | if (!t1inf) {
|
22597 | if (t1 < tt) {
|
22598 | tt = t1;
|
22599 | t2min = false;
|
22600 | }
|
22601 | }
|
22602 |
|
22603 | for (i = 1; i <= n; i = i + 1) {
|
22604 | sol[i] = sol[i] + tt * work[iwzv + i];
|
22605 | if (Math.abs(sol[i]) < vsmall) {
|
22606 | sol[i] = 0;
|
22607 | }
|
22608 | }
|
22609 |
|
22610 | crval[1] = crval[1] + tt * sum * (tt / 2 + work[iwuv + nact + 1]);
|
22611 | for (i = 1; i <= nact; i = i + 1) {
|
22612 | work[iwuv + i] = work[iwuv + i] - tt * work[iwrv + i];
|
22613 | }
|
22614 | work[iwuv + nact + 1] = work[iwuv + nact + 1] + tt;
|
22615 |
|
22616 | if (t2min) {
|
22617 | nact = nact + 1;
|
22618 | iact[nact] = nvl;
|
22619 |
|
22620 | l = iwrm + ((nact - 1) * nact) / 2 + 1;
|
22621 | for (i = 1; i <= nact - 1; i = i + 1) {
|
22622 | work[l] = work[i];
|
22623 | l = l + 1;
|
22624 | }
|
22625 |
|
22626 | if (nact === n) {
|
22627 | work[l] = work[n];
|
22628 | } else {
|
22629 | for (i = n; i >= nact + 1; i = i - 1) {
|
22630 | if (work[i] === 0) {
|
22631 |
|
22632 | break;
|
22633 | }
|
22634 | gc = Math.max(Math.abs(work[i - 1]), Math.abs(work[i]));
|
22635 | gs = Math.min(Math.abs(work[i - 1]), Math.abs(work[i]));
|
22636 | if (work[i - 1] >= 0) {
|
22637 | temp = Math.abs(gc * Math.sqrt(1 + gs * gs / (gc * gc)));
|
22638 | } else {
|
22639 | temp = -Math.abs(gc * Math.sqrt(1 + gs * gs / (gc * gc)));
|
22640 | }
|
22641 | gc = work[i - 1] / temp;
|
22642 | gs = work[i] / temp;
|
22643 |
|
22644 | if (gc === 1) {
|
22645 |
|
22646 | break;
|
22647 | }
|
22648 | if (gc === 0) {
|
22649 | work[i - 1] = gs * temp;
|
22650 | for (j = 1; j <= n; j = j + 1) {
|
22651 | temp = dmat[j][i - 1];
|
22652 | dmat[j][i - 1] = dmat[j][i];
|
22653 | dmat[j][i] = temp;
|
22654 | }
|
22655 | } else {
|
22656 | work[i - 1] = temp;
|
22657 | nu = gs / (1 + gc);
|
22658 | for (j = 1; j <= n; j = j + 1) {
|
22659 | temp = gc * dmat[j][i - 1] + gs * dmat[j][i];
|
22660 | dmat[j][i] = nu * (dmat[j][i - 1] + temp) - dmat[j][i];
|
22661 | dmat[j][i - 1] = temp;
|
22662 |
|
22663 | }
|
22664 | }
|
22665 | }
|
22666 | work[l] = work[nact];
|
22667 | }
|
22668 | } else {
|
22669 | sum = -bvec[nvl];
|
22670 | for (j = 1; j <= n; j = j + 1) {
|
22671 | sum = sum + sol[j] * amat[j][nvl];
|
22672 | }
|
22673 | if (nvl > meq) {
|
22674 | work[iwsv + nvl] = sum;
|
22675 | } else {
|
22676 | work[iwsv + nvl] = -Math.abs(sum);
|
22677 | if (sum > 0) {
|
22678 | for (j = 1; j <= n; j = j + 1) {
|
22679 | amat[j][nvl] = -amat[j][nvl];
|
22680 | }
|
22681 | bvec[nvl] = -bvec[nvl];
|
22682 | }
|
22683 | }
|
22684 |
|
22685 | return 700;
|
22686 | }
|
22687 | }
|
22688 |
|
22689 | return 0;
|
22690 | }
|
22691 |
|
22692 | function fn_goto_797() {
|
22693 | l = iwrm + (it1 * (it1 + 1)) / 2 + 1;
|
22694 | l1 = l + it1;
|
22695 | if (work[l1] === 0) {
|
22696 |
|
22697 | return 798;
|
22698 | }
|
22699 | gc = Math.max(Math.abs(work[l1 - 1]), Math.abs(work[l1]));
|
22700 | gs = Math.min(Math.abs(work[l1 - 1]), Math.abs(work[l1]));
|
22701 | if (work[l1 - 1] >= 0) {
|
22702 | temp = Math.abs(gc * Math.sqrt(1 + gs * gs / (gc * gc)));
|
22703 | } else {
|
22704 | temp = -Math.abs(gc * Math.sqrt(1 + gs * gs / (gc * gc)));
|
22705 | }
|
22706 | gc = work[l1 - 1] / temp;
|
22707 | gs = work[l1] / temp;
|
22708 |
|
22709 | if (gc === 1) {
|
22710 |
|
22711 | return 798;
|
22712 | }
|
22713 | if (gc === 0) {
|
22714 | for (i = it1 + 1; i <= nact; i = i + 1) {
|
22715 | temp = work[l1 - 1];
|
22716 | work[l1 - 1] = work[l1];
|
22717 | work[l1] = temp;
|
22718 | l1 = l1 + i;
|
22719 | }
|
22720 | for (i = 1; i <= n; i = i + 1) {
|
22721 | temp = dmat[i][it1];
|
22722 | dmat[i][it1] = dmat[i][it1 + 1];
|
22723 | dmat[i][it1 + 1] = temp;
|
22724 | }
|
22725 | } else {
|
22726 | nu = gs / (1 + gc);
|
22727 | for (i = it1 + 1; i <= nact; i = i + 1) {
|
22728 | temp = gc * work[l1 - 1] + gs * work[l1];
|
22729 | work[l1] = nu * (work[l1 - 1] + temp) - work[l1];
|
22730 | work[l1 - 1] = temp;
|
22731 | l1 = l1 + i;
|
22732 | }
|
22733 | for (i = 1; i <= n; i = i + 1) {
|
22734 | temp = gc * dmat[i][it1] + gs * dmat[i][it1 + 1];
|
22735 | dmat[i][it1 + 1] = nu * (dmat[i][it1] + temp) - dmat[i][it1 + 1];
|
22736 | dmat[i][it1] = temp;
|
22737 | }
|
22738 | }
|
22739 |
|
22740 | return 0;
|
22741 | }
|
22742 |
|
22743 | function fn_goto_798() {
|
22744 | l1 = l - it1;
|
22745 | for (i = 1; i <= it1; i = i + 1) {
|
22746 | work[l1] = work[l];
|
22747 | l = l + 1;
|
22748 | l1 = l1 + 1;
|
22749 | }
|
22750 |
|
22751 | work[iwuv + it1] = work[iwuv + it1 + 1];
|
22752 | iact[it1] = iact[it1 + 1];
|
22753 | it1 = it1 + 1;
|
22754 | if (it1 < nact) {
|
22755 |
|
22756 | return 797;
|
22757 | }
|
22758 |
|
22759 | return 0;
|
22760 | }
|
22761 |
|
22762 | function fn_goto_799() {
|
22763 | work[iwuv + nact] = work[iwuv + nact + 1];
|
22764 | work[iwuv + nact + 1] = 0;
|
22765 | iact[nact] = 0;
|
22766 | nact = nact - 1;
|
22767 | iter[2] = iter[2] + 1;
|
22768 |
|
22769 | return 0;
|
22770 | }
|
22771 |
|
22772 | go = 0;
|
22773 | while (true) {
|
22774 | go = fn_goto_50();
|
22775 | if (go === 999) {
|
22776 | return;
|
22777 | }
|
22778 | while (true) {
|
22779 | go = fn_goto_55();
|
22780 | if (go === 0) {
|
22781 | break;
|
22782 | }
|
22783 | if (go === 999) {
|
22784 | return;
|
22785 | }
|
22786 | if (go === 700) {
|
22787 | if (it1 === nact) {
|
22788 | fn_goto_799();
|
22789 | } else {
|
22790 | while (true) {
|
22791 | fn_goto_797();
|
22792 | go = fn_goto_798();
|
22793 | if (go !== 797) {
|
22794 | break;
|
22795 | }
|
22796 | }
|
22797 | fn_goto_799();
|
22798 | }
|
22799 | }
|
22800 | }
|
22801 | }
|
22802 |
|
22803 | }
|
22804 |
|
22805 | function solveQP(Dmat, dvec, Amat, bvec, meq, factorized) {
|
22806 | Dmat = base0to1(Dmat);
|
22807 | dvec = base0to1(dvec);
|
22808 | Amat = base0to1(Amat);
|
22809 | var i, n, q,
|
22810 | nact, r,
|
22811 | crval = [], iact = [], sol = [], work = [], iter = [],
|
22812 | message;
|
22813 |
|
22814 | meq = meq || 0;
|
22815 | factorized = factorized ? base0to1(factorized) : [undefined, 0];
|
22816 | bvec = bvec ? base0to1(bvec) : [];
|
22817 |
|
22818 |
|
22819 | n = Dmat.length - 1;
|
22820 | q = Amat[1].length - 1;
|
22821 |
|
22822 | if (!bvec) {
|
22823 | for (i = 1; i <= q; i = i + 1) {
|
22824 | bvec[i] = 0;
|
22825 | }
|
22826 | }
|
22827 | for (i = 1; i <= q; i = i + 1) {
|
22828 | iact[i] = 0;
|
22829 | }
|
22830 | nact = 0;
|
22831 | r = Math.min(n, q);
|
22832 | for (i = 1; i <= n; i = i + 1) {
|
22833 | sol[i] = 0;
|
22834 | }
|
22835 | crval[1] = 0;
|
22836 | for (i = 1; i <= (2 * n + (r * (r + 5)) / 2 + 2 * q + 1); i = i + 1) {
|
22837 | work[i] = 0;
|
22838 | }
|
22839 | for (i = 1; i <= 2; i = i + 1) {
|
22840 | iter[i] = 0;
|
22841 | }
|
22842 |
|
22843 | qpgen2(Dmat, dvec, n, n, sol, crval, Amat,
|
22844 | bvec, n, q, meq, iact, nact, iter, work, factorized);
|
22845 |
|
22846 | message = "";
|
22847 | if (factorized[1] === 1) {
|
22848 | message = "constraints are inconsistent, no solution!";
|
22849 | }
|
22850 | if (factorized[1] === 2) {
|
22851 | message = "matrix D in quadratic function is not positive definite!";
|
22852 | }
|
22853 |
|
22854 | return {
|
22855 | solution: base1to0(sol),
|
22856 | value: base1to0(crval),
|
22857 | unconstrained_solution: base1to0(dvec),
|
22858 | iterations: base1to0(iter),
|
22859 | iact: base1to0(iact),
|
22860 | message: message
|
22861 | };
|
22862 | }
|
22863 | exports.solveQP = solveQP;
|
22864 | }(numeric));
|
22865 |
|
22866 |
|
22867 |
|
22868 |
|
22869 |
|
22870 |
|
22871 | numeric.svd= function svd(A) {
|
22872 | var temp;
|
22873 |
|
22874 | var prec= numeric.epsilon;
|
22875 | var tolerance= 1.e-64/prec;
|
22876 | var itmax= 50;
|
22877 | var c=0;
|
22878 | var i=0;
|
22879 | var j=0;
|
22880 | var k=0;
|
22881 | var l=0;
|
22882 |
|
22883 | var u= numeric.clone(A);
|
22884 | var m= u.length;
|
22885 |
|
22886 | var n= u[0].length;
|
22887 |
|
22888 | if (m < n) throw "Need more rows than columns"
|
22889 |
|
22890 | var e = new Array(n);
|
22891 | var q = new Array(n);
|
22892 | for (i=0; i<n; i++) e[i] = q[i] = 0.0;
|
22893 | var v = numeric.rep([n,n],0);
|
22894 |
|
22895 |
|
22896 | function pythag(a,b)
|
22897 | {
|
22898 | a = Math.abs(a)
|
22899 | b = Math.abs(b)
|
22900 | if (a > b)
|
22901 | return a*Math.sqrt(1.0+(b*b/a/a))
|
22902 | else if (b == 0.0)
|
22903 | return a
|
22904 | return b*Math.sqrt(1.0+(a*a/b/b))
|
22905 | }
|
22906 |
|
22907 |
|
22908 |
|
22909 | var f= 0.0;
|
22910 | var g= 0.0;
|
22911 | var h= 0.0;
|
22912 | var x= 0.0;
|
22913 | var y= 0.0;
|
22914 | var z= 0.0;
|
22915 | var s= 0.0;
|
22916 |
|
22917 | for (i=0; i < n; i++)
|
22918 | {
|
22919 | e[i]= g;
|
22920 | s= 0.0;
|
22921 | l= i+1;
|
22922 | for (j=i; j < m; j++)
|
22923 | s += (u[j][i]*u[j][i]);
|
22924 | if (s <= tolerance)
|
22925 | g= 0.0;
|
22926 | else
|
22927 | {
|
22928 | f= u[i][i];
|
22929 | g= Math.sqrt(s);
|
22930 | if (f >= 0.0) g= -g;
|
22931 | h= f*g-s
|
22932 | u[i][i]=f-g;
|
22933 | for (j=l; j < n; j++)
|
22934 | {
|
22935 | s= 0.0
|
22936 | for (k=i; k < m; k++)
|
22937 | s += u[k][i]*u[k][j]
|
22938 | f= s/h
|
22939 | for (k=i; k < m; k++)
|
22940 | u[k][j]+=f*u[k][i]
|
22941 | }
|
22942 | }
|
22943 | q[i]= g
|
22944 | s= 0.0
|
22945 | for (j=l; j < n; j++)
|
22946 | s= s + u[i][j]*u[i][j]
|
22947 | if (s <= tolerance)
|
22948 | g= 0.0
|
22949 | else
|
22950 | {
|
22951 | f= u[i][i+1]
|
22952 | g= Math.sqrt(s)
|
22953 | if (f >= 0.0) g= -g
|
22954 | h= f*g - s
|
22955 | u[i][i+1] = f-g;
|
22956 | for (j=l; j < n; j++) e[j]= u[i][j]/h
|
22957 | for (j=l; j < m; j++)
|
22958 | {
|
22959 | s=0.0
|
22960 | for (k=l; k < n; k++)
|
22961 | s += (u[j][k]*u[i][k])
|
22962 | for (k=l; k < n; k++)
|
22963 | u[j][k]+=s*e[k]
|
22964 | }
|
22965 | }
|
22966 | y= Math.abs(q[i])+Math.abs(e[i])
|
22967 | if (y>x)
|
22968 | x=y
|
22969 | }
|
22970 |
|
22971 |
|
22972 | for (i=n-1; i != -1; i+= -1)
|
22973 | {
|
22974 | if (g != 0.0)
|
22975 | {
|
22976 | h= g*u[i][i+1]
|
22977 | for (j=l; j < n; j++)
|
22978 | v[j][i]=u[i][j]/h
|
22979 | for (j=l; j < n; j++)
|
22980 | {
|
22981 | s=0.0
|
22982 | for (k=l; k < n; k++)
|
22983 | s += u[i][k]*v[k][j]
|
22984 | for (k=l; k < n; k++)
|
22985 | v[k][j]+=(s*v[k][i])
|
22986 | }
|
22987 | }
|
22988 | for (j=l; j < n; j++)
|
22989 | {
|
22990 | v[i][j] = 0;
|
22991 | v[j][i] = 0;
|
22992 | }
|
22993 | v[i][i] = 1;
|
22994 | g= e[i]
|
22995 | l= i
|
22996 | }
|
22997 |
|
22998 |
|
22999 | for (i=n-1; i != -1; i+= -1)
|
23000 | {
|
23001 | l= i+1
|
23002 | g= q[i]
|
23003 | for (j=l; j < n; j++)
|
23004 | u[i][j] = 0;
|
23005 | if (g != 0.0)
|
23006 | {
|
23007 | h= u[i][i]*g
|
23008 | for (j=l; j < n; j++)
|
23009 | {
|
23010 | s=0.0
|
23011 | for (k=l; k < m; k++) s += u[k][i]*u[k][j];
|
23012 | f= s/h
|
23013 | for (k=i; k < m; k++) u[k][j]+=f*u[k][i];
|
23014 | }
|
23015 | for (j=i; j < m; j++) u[j][i] = u[j][i]/g;
|
23016 | }
|
23017 | else
|
23018 | for (j=i; j < m; j++) u[j][i] = 0;
|
23019 | u[i][i] += 1;
|
23020 | }
|
23021 |
|
23022 |
|
23023 | prec= prec*x
|
23024 | for (k=n-1; k != -1; k+= -1)
|
23025 | {
|
23026 | for (var iteration=0; iteration < itmax; iteration++)
|
23027 | {
|
23028 | var test_convergence = false
|
23029 | for (l=k; l != -1; l+= -1)
|
23030 | {
|
23031 | if (Math.abs(e[l]) <= prec)
|
23032 | { test_convergence= true
|
23033 | break
|
23034 | }
|
23035 | if (Math.abs(q[l-1]) <= prec)
|
23036 | break
|
23037 | }
|
23038 | if (!test_convergence)
|
23039 | {
|
23040 | c= 0.0
|
23041 | s= 1.0
|
23042 | var l1= l-1
|
23043 | for (i =l; i<k+1; i++)
|
23044 | {
|
23045 | f= s*e[i]
|
23046 | e[i]= c*e[i]
|
23047 | if (Math.abs(f) <= prec)
|
23048 | break
|
23049 | g= q[i]
|
23050 | h= pythag(f,g)
|
23051 | q[i]= h
|
23052 | c= g/h
|
23053 | s= -f/h
|
23054 | for (j=0; j < m; j++)
|
23055 | {
|
23056 | y= u[j][l1]
|
23057 | z= u[j][i]
|
23058 | u[j][l1] = y*c+(z*s)
|
23059 | u[j][i] = -y*s+(z*c)
|
23060 | }
|
23061 | }
|
23062 | }
|
23063 |
|
23064 | z= q[k]
|
23065 | if (l== k)
|
23066 | {
|
23067 | if (z<0.0)
|
23068 | {
|
23069 | q[k]= -z
|
23070 | for (j=0; j < n; j++)
|
23071 | v[j][k] = -v[j][k]
|
23072 | }
|
23073 | break
|
23074 | }
|
23075 | if (iteration >= itmax-1)
|
23076 | throw 'Error: no convergence.'
|
23077 |
|
23078 | x= q[l]
|
23079 | y= q[k-1]
|
23080 | g= e[k-1]
|
23081 | h= e[k]
|
23082 | f= ((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y)
|
23083 | g= pythag(f,1.0)
|
23084 | if (f < 0.0)
|
23085 | f= ((x-z)*(x+z)+h*(y/(f-g)-h))/x
|
23086 | else
|
23087 | f= ((x-z)*(x+z)+h*(y/(f+g)-h))/x
|
23088 |
|
23089 | c= 1.0
|
23090 | s= 1.0
|
23091 | for (i=l+1; i< k+1; i++)
|
23092 | {
|
23093 | g= e[i]
|
23094 | y= q[i]
|
23095 | h= s*g
|
23096 | g= c*g
|
23097 | z= pythag(f,h)
|
23098 | e[i-1]= z
|
23099 | c= f/z
|
23100 | s= h/z
|
23101 | f= x*c+g*s
|
23102 | g= -x*s+g*c
|
23103 | h= y*s
|
23104 | y= y*c
|
23105 | for (j=0; j < n; j++)
|
23106 | {
|
23107 | x= v[j][i-1]
|
23108 | z= v[j][i]
|
23109 | v[j][i-1] = x*c+z*s
|
23110 | v[j][i] = -x*s+z*c
|
23111 | }
|
23112 | z= pythag(f,h)
|
23113 | q[i-1]= z
|
23114 | c= f/z
|
23115 | s= h/z
|
23116 | f= c*g+s*y
|
23117 | x= -s*g+c*y
|
23118 | for (j=0; j < m; j++)
|
23119 | {
|
23120 | y= u[j][i-1]
|
23121 | z= u[j][i]
|
23122 | u[j][i-1] = y*c+z*s
|
23123 | u[j][i] = -y*s+z*c
|
23124 | }
|
23125 | }
|
23126 | e[l]= 0.0
|
23127 | e[k]= f
|
23128 | q[k]= x
|
23129 | }
|
23130 | }
|
23131 |
|
23132 |
|
23133 |
|
23134 | for (i=0;i<q.length; i++)
|
23135 | if (q[i] < prec) q[i] = 0
|
23136 |
|
23137 |
|
23138 | for (i=0; i< n; i++)
|
23139 | {
|
23140 |
|
23141 | for (j=i-1; j >= 0; j--)
|
23142 | {
|
23143 | if (q[j] < q[i])
|
23144 | {
|
23145 |
|
23146 | c = q[j]
|
23147 | q[j] = q[i]
|
23148 | q[i] = c
|
23149 | for(k=0;k<u.length;k++) { temp = u[k][i]; u[k][i] = u[k][j]; u[k][j] = temp; }
|
23150 | for(k=0;k<v.length;k++) { temp = v[k][i]; v[k][i] = v[k][j]; v[k][j] = temp; }
|
23151 |
|
23152 |
|
23153 | i = j
|
23154 | }
|
23155 | }
|
23156 | }
|
23157 |
|
23158 | return {U:u,S:q,V:v}
|
23159 | };
|
23160 |
|
23161 |
|
23162 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
23163 | },{}],4:[function(require,module,exports){
|
23164 | var _ = require("lodash");
|
23165 | var J = require("jStat").jStat;
|
23166 | var M = require("numeric");
|
23167 | R = _;
|
23168 | R.M = M;
|
23169 | R.J = J;
|
23170 |
|
23171 | function _def(pair) {
|
23172 | _.mixin(pair, {chain:false});
|
23173 | }
|
23174 |
|
23175 | function _mix(pair) {
|
23176 | _.mixin(pair, {chain:true});
|
23177 | }
|
23178 |
|
23179 | var calls=function() {
|
23180 | var args = Array.prototype.slice.call(arguments);
|
23181 | var n = args[0];
|
23182 | var f = args[1];
|
23183 | var params = args.slice(2, args.length);
|
23184 | var a=[];
|
23185 | for (var i=0; i<n; i++)
|
23186 | a.push(f.apply(null, params));
|
23187 | return _.map(a);
|
23188 | }
|
23189 |
|
23190 | _mix({calls:calls});
|
23191 |
|
23192 | var fx = function() {
|
23193 | var args = Array.prototype.slice.call(arguments);
|
23194 | var f = args[0];
|
23195 | var fargs = args.slice(1, arguments.length);
|
23196 | return function(x) {
|
23197 | return f.apply(null, [x].concat(fargs));
|
23198 | };
|
23199 | }
|
23200 |
|
23201 | _mix({fx:fx});
|
23202 |
|
23203 | var samples=function(space, size, arg) {
|
23204 | var arg = _.defaults(arg, {replace:true});
|
23205 | if (arg.replace)
|
23206 | return R.calls(size, function() { return _.sample(space); });
|
23207 | else
|
23208 | return _.sampleSize(space, size);
|
23209 | }
|
23210 |
|
23211 | _mix({samples:samples});
|
23212 |
|
23213 | var steps=function(start, end, step) {
|
23214 | step = step || 1;
|
23215 | return _.range(start, end+0.00001*step, step);
|
23216 | }
|
23217 |
|
23218 | _mix({steps:steps});
|
23219 |
|
23220 |
|
23221 | R.setPrecision=function(n) {
|
23222 | R.precision = n;
|
23223 | R.M.precision = n;
|
23224 | }
|
23225 |
|
23226 | R.setPrecision(2);
|
23227 |
|
23228 |
|
23229 |
|
23230 | R.num2str=function(x) {
|
23231 | if (isNaN(x))
|
23232 | return "NaN";
|
23233 | else if (Math.floor(x) === x)
|
23234 | return x.toString();
|
23235 | else if (isFinite(x)) {
|
23236 |
|
23237 | return _.round(x, R.precision).toString();
|
23238 | } else if (x < 0)
|
23239 | return "-Infinity";
|
23240 | else
|
23241 | return "Infinity";
|
23242 | }
|
23243 |
|
23244 | R.ctrim=function(s, set, side) {
|
23245 | side = side||"both";
|
23246 | for (var b=0; b<s.length; b++)
|
23247 | if (set.indexOf(s[b])<0) break;
|
23248 | for (var e=s.length-1; e>=0; e--)
|
23249 | if (set.indexOf(s[e])<0) break;
|
23250 | if (side === "right") b=0;
|
23251 | if (side === "left") e=s.length-1;
|
23252 | return s.substring(b, e+1);
|
23253 | }
|
23254 |
|
23255 | R.array2str=function(x) {
|
23256 | var s = "";
|
23257 | for (var i in x)
|
23258 | s+= R.str(x[i])+", ";
|
23259 | return "["+R.ctrim(s, ", ")+"]";
|
23260 | }
|
23261 |
|
23262 | R.obj2str=function(x, sp) {
|
23263 | var s = "";
|
23264 | for (var k in x)
|
23265 | s+= k+":"+R.str(x[k])+sp;
|
23266 | return "{"+R.ctrim(s,sp)+"}";
|
23267 | }
|
23268 |
|
23269 | var str = function(x) {
|
23270 | if (typeof x === 'undefined') return 'undefined';
|
23271 | else if (x === null) return 'null';
|
23272 | else if (typeof x === "number") return R.num2str(x);
|
23273 | else if(typeof x === "string") return '\"'+x.toString()+'\"';
|
23274 | else if (x instanceof Array) return R.array2str(x);
|
23275 |
|
23276 | else if (typeof x === "object") return x.toString();
|
23277 | else if (typeof x === "function") return "";
|
23278 | else return x.toString();
|
23279 | }
|
23280 |
|
23281 |
|
23282 | Array.prototype.str = function() { return R.array2str(this); }
|
23283 |
|
23284 |
|
23285 | var _str = function(x) { return str(x); }
|
23286 |
|
23287 | _def({str:_str});
|
23288 |
|
23289 |
|
23290 |
|
23291 |
|
23292 | _def({sd:function(a, flag) { return J.stdev(a, flag || 1); }});
|
23293 |
|
23294 | _def({cov:function(x, y) { return J.stdev(x, y); }});
|
23295 |
|
23296 | _def({cor:function(x, y) { return J.corrcoeff(x, y); }});
|
23297 |
|
23298 | _def({factorial : function(n) { return J.factorial(n); }});
|
23299 |
|
23300 | _def({lfactorial : function(n) { return J.factorialln(n); }});
|
23301 |
|
23302 | _def({choose : function(n,m) { return J.combination(n, m); }});
|
23303 |
|
23304 | _def({lchoose : function(n,m) { return J.combinationln(n, m); }});
|
23305 |
|
23306 | _def({permutation : function(n,m) { return J.permutation(n, m); }});
|
23307 |
|
23308 | _def({lchoose : function(n,m) { return J.combinationln(n, m); }});
|
23309 |
|
23310 |
|
23311 | _mix({runif:function(n, a, b) { return R.calls(n, J.uniform.sample, a, b); }});
|
23312 | _def({dunif:function(x, a, b) { return J.uniform.pdf(x, a, b); }});
|
23313 | _def({punif:function(q, a, b) { return J.uniform.cdf(q, a, b); }});
|
23314 | _def({qunif:function(p, a, b) { return J.uniform.inv(p, a, b); }});
|
23315 |
|
23316 | _mix({rnorm:function(n, mean, sd) { return R.calls(n, J.normal.sample, mean, sd); }});
|
23317 | _def({dnorm:function(x, mean, sd) { return J.normal.pdf(x, mean, sd); }});
|
23318 | _def({pnorm:function(q, mean, sd) { return J.normal.cdf(q, mean, sd); }});
|
23319 | _def({qnorm:function(p, mean, sd) { return J.normal.inv(p, mean, sd); }});
|
23320 |
|
23321 | _mix({rpois:function(n, l) { return R.calls(n, J.poisson.sample, l); }});
|
23322 | _def({dpois:function(x, l) { return J.poisson.pdf(x, l); }});
|
23323 | _def({ppois:function(q, l) { return J.poisson.cdf(q, l); }});
|
23324 | _def({qpois:function(p, l) { return J.poisson.inv(p, l); }});
|
23325 |
|
23326 | _mix({rf:function(n, df1, df2) { return R.calls(n, J.centralF.sample, df1, df2); }});
|
23327 | _def({df:function(x, df1, df2) { return J.centralF.pdf(x, df1, df2); }});
|
23328 | _def({pf:function(q, df1, df2) { return J.centralF.cdf(q, df1, df2); }});
|
23329 | _def({qf:function(p, df1, df2) { return J.centralF.inv(p, df1, df2); }});
|
23330 |
|
23331 | _mix({rt:function(n, dof) { return R.calls(n, J.studentt.sample, dof); }});
|
23332 | _def({dt:function(x, dof) { return J.studentt.pdf(x, dof); }});
|
23333 | _def({pt:function(q, dof) { return J.studentt.cdf(q, dof); }});
|
23334 | _def({qt:function(p, dof) { return J.studentt.inv(p, dof); }});
|
23335 |
|
23336 | _mix({rbeta:function(n, alpha, beta) { return R.calls(n, J.beta.sample, alpha, beta); }});
|
23337 | _def({dbeta:function(x, alpha, beta) { return J.beta.pdf(x, alpha, beta); }});
|
23338 | _def({pbeta:function(q, alpha, beta) { return J.beta.cdf(q, alpha, beta); }});
|
23339 | _def({qbeta:function(p, alpha, beta) { return J.beta.inv(p, alpha, beta); }});
|
23340 |
|
23341 | _mix({rcauchy:function(n, local, scale) { return R.calls(n, J.cauchy.sample, local, scale); }});
|
23342 | _def({dcauchy:function(x, local, scale) { return J.cauchy.pdf(x, local, scale); }});
|
23343 | _def({pcauchy:function(q, local, scale) { return J.cauchy.cdf(q, local, scale); }});
|
23344 | _def({qcauchy:function(p, local, scale) { return J.cauchy.inv(p, local, scale); }});
|
23345 |
|
23346 | _mix({rchisq:function(n, dof) { return R.calls(n, J.chisquare.sample, dof); }});
|
23347 | _def({dchisq:function(x, dof) { return J.chisquare.pdf(x, dof); }});
|
23348 | _def({pchisq:function(q, dof) { return J.chisquare.cdf(q, dof); }});
|
23349 | _def({qchisq:function(p, dof) { return J.chisquare.inv(p, dof); }});
|
23350 |
|
23351 | _mix({rexp:function(n, rate) { return R.calls(n, J.exponential.sample, rate); }});
|
23352 | _def({dexp:function(x, rate) { return J.exponential.pdf(x, rate); }});
|
23353 | _def({pexp:function(q, rate) { return J.exponential.cdf(q, rate); }});
|
23354 | _def({qexp:function(p, rate) { return J.exponential.inv(p, rate); }});
|
23355 |
|
23356 | _mix({rgamma:function(n, shape, scale) { return R.calls(n, J.gamma.sample, shape, scale); }});
|
23357 | _def({dgamma:function(x, shape, scale) { return J.gamma.pdf(x, shape, scale); }});
|
23358 | _def({pgamma:function(q, shape, scale) { return J.gamma.cdf(q, shape, scale); }});
|
23359 | _def({qgamma:function(p, shape, scale) { return J.gamma.inv(p, shape, scale); }});
|
23360 |
|
23361 | _mix({rinvgamma:function(n, shape, scale) { return R.calls(n, J.invgamma.sample, shape, scale); }});
|
23362 | _def({dinvgamma:function(x, shape, scale) { return J.invgamma.pdf(x, shape, scale); }});
|
23363 | _def({pinvgamma:function(q, shape, scale) { return J.invgamma.cdf(q, shape, scale); }});
|
23364 | _def({qinvgamma:function(p, shape, scale) { return J.invgamma.inv(p, shape, scale); }});
|
23365 |
|
23366 | _mix({rlognormal:function(n, mu, sigma) { return R.calls(n, J.lognormal.sample, mu, sigma); }});
|
23367 | _def({dlognormal:function(x, mu, sigma) { return J.lognormal.pdf(x, mu, sigma); }});
|
23368 | _def({plognormal:function(q, mu, sigma) { return J.lognormal.cdf(q, mu, sigma); }});
|
23369 | _def({qlognormal:function(p, mu, sigma) { return J.lognormal.inv(p, mu, sigma); }});
|
23370 |
|
23371 | _mix({rpareto:function(n, scale, shape) { return R.calls(n, J.pareto.sample, scale, shape); }});
|
23372 | _def({dpareto:function(x, scale, shape) { return J.pareto.pdf(x, scale, shape); }});
|
23373 | _def({ppareto:function(q, scale, shape) { return J.pareto.cdf(q, scale, shape); }});
|
23374 | _def({qpareto:function(p, scale, shape) { return J.pareto.inv(p, scale, shape); }});
|
23375 |
|
23376 | _mix({rweibull:function(n, scale, shape) { return R.calls(n, J.weibull.sample, scale, shape); }});
|
23377 | _def({dweibull:function(x, scale, shape) { return J.weibull.pdf(x, scale, shape); }});
|
23378 | _def({pweibull:function(q, scale, shape) { return J.weibull.cdf(q, scale, shape); }});
|
23379 | _def({qweibull:function(p, scale, shape) { return J.weibull.inv(p, scale, shape); }});
|
23380 |
|
23381 | _mix({rtriangular:function(n, a, b, c) { return R.calls(n, J.triangular.sample, a, b, c); }});
|
23382 | _def({dtriangular:function(x, a, b, c) { return J.triangular.pdf(x, a, b, c); }});
|
23383 | _def({ptriangular:function(q, a, b, c) { return J.triangular.cdf(q, a, b, c); }});
|
23384 | _def({qtriangular:function(p, a, b, c) { return J.triangular.inv(p, a, b, c); }});
|
23385 |
|
23386 | _mix({rkumaraswamy:function(n, alpha, beta) { return R.calls(n, J.kumaraswamy.sample, alpha, beta); }});
|
23387 | _def({dkumaraswamy:function(x, alpha, beta) { return J.kumaraswamy.pdf(x, alpha, beta); }});
|
23388 | _def({pkumaraswamy:function(q, alpha, beta) { return J.kumaraswamy.cdf(q, alpha, beta); }});
|
23389 | _def({qkumaraswamy:function(p, alpha, beta) { return J.kumaraswamy.inv(p, alpha, beta); }});
|
23390 |
|
23391 |
|
23392 | var qf=function(cdf, q, N, p) {
|
23393 | for (var i=0; i<=N; i++) {
|
23394 | if (cdf(i, N, p) > q) return i;
|
23395 | }
|
23396 | return N;
|
23397 | }
|
23398 | var rf=function(cdf, n, N, p) {
|
23399 | var a = [];
|
23400 | for (var i=0; i<n; i++) {
|
23401 | var q = Math.random();
|
23402 | a.push(cdf(q, N, p));
|
23403 | }
|
23404 | return a;
|
23405 | }
|
23406 |
|
23407 | _def({dbinom:function(x, N, p) { return J.binomial.pdf(x, N, p); }});
|
23408 | _def({pbinom:function(k, N, p) { return J.binomial.cdf(k, N, p); }});
|
23409 | _def({qbinom:function(q, N, p) { return qf(R.pbinom, q, N, p); }});
|
23410 | _mix({rbinom:function(n, N, p) { return rf(R.qbinom, n, N, p); }});
|
23411 |
|
23412 | _def({dnbinom:function(x, N, p) { return jStat.negbin.pdf(x, N, p); }});
|
23413 | _def({pnbinom:function(k, N, p) { return jStat.negbin.cdf(k, N, p); }});
|
23414 | _def({qnbinom:function(q, N, p) { return qf(R.pnbinom, q, N, p); } });
|
23415 | _mix({rnbinom:function(n, N, p) { return rf(R.qnbinom, n, N, p); }});
|
23416 |
|
23417 | _def({dhyper:function(x, N, m, n) { return jStat.hypgeom.pdf(x, N, m, n); }});
|
23418 | _def({phyper:function(k, N, m, n) { return jStat.hypgeom.cdf(k, N, m, n); }});
|
23419 | _def({qhyper:function(q, N, m, n) { return qf(R.phyper, q, N, p); } });
|
23420 | _mix({rhyper:function(n, N, m, k) { return rf(R.qhyper, n, N, p); }});
|
23421 |
|
23422 |
|
23423 |
|
23424 |
|
23425 | function opAlt(op) {
|
23426 | if (op === "=") return "!=";
|
23427 | if (op === "<") return ">=";
|
23428 | if (op === ">") return "<=";
|
23429 | return null;
|
23430 | }
|
23431 |
|
23432 | R.test = function(o) {
|
23433 | o = R.defaults(o, {alpha:0.05, op:"="});
|
23434 | var alpha = o.alpha;
|
23435 | var pvalue, interval;
|
23436 | var D = o.D;
|
23437 | var q1 = D.o2q(o);
|
23438 |
|
23439 | if (o.op === "=") {
|
23440 | if (q1>0.5) q1 = 1-q1;
|
23441 | pvalue= 2*q1;
|
23442 | interval = [D.q2p(alpha/2, o, "L"), D.q2p(1-alpha/2, o, "R")];
|
23443 | } else {
|
23444 | if (o.op === "<") {
|
23445 | interval = [ D.q2p(alpha, o, "L"), Infinity ];
|
23446 | pvalue = 1-q1;
|
23447 | }
|
23448 | if (o.op === ">") {
|
23449 | interval=[-Infinity, D.q2p(1-alpha, o, "R")];
|
23450 | pvalue = q1;
|
23451 | }
|
23452 | }
|
23453 | return {
|
23454 | name: o.name,
|
23455 | h: D.h(o),
|
23456 | alpha: alpha,
|
23457 | op: o.op,
|
23458 | pvalue: pvalue,
|
23459 | ci : interval,
|
23460 | df : D.df(o),
|
23461 | report: function() { R.report(this) }
|
23462 | };
|
23463 | }
|
23464 |
|
23465 | var t1 = {
|
23466 | h:function(o) { return "H0:mu"+o.op+o.mu; },
|
23467 | o2q:function(o) {
|
23468 | var x = o.x, n = x.length;
|
23469 | var t = (R.mean(x)-o.mu)/(R.sd(x)/Math.sqrt(n));
|
23470 | return R.pt(t, n-1);
|
23471 | },
|
23472 |
|
23473 |
|
23474 | q2p:function(q, o) {
|
23475 | var x = o.x, n = x.length;
|
23476 | return R.mean(x) + R.qt(q, n-1) * R.sd(x) / Math.sqrt(n);
|
23477 | },
|
23478 | df:function(o) { return o.x.length-1; }
|
23479 | }
|
23480 |
|
23481 | var t2vareq = {
|
23482 | h:function(o) { return "H0:mu1"+o.op+"mu2" },
|
23483 |
|
23484 | sd:function(o) {
|
23485 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23486 | var S1= R.sd(x), S2 = R.sd(y);
|
23487 | var S = Math.sqrt(((n1-1)*S1*S1+(n2-1)*S2*S2)/(n1-1+n2-1));
|
23488 | return S;
|
23489 | },
|
23490 |
|
23491 | o2q:function(o) {
|
23492 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23493 | var S = this.sd(o);
|
23494 | var t = (R.mean(x)-R.mean(y)-o.mu)/(Math.sqrt(1/n1+1/n2)*S);
|
23495 | return R.pt(t, n1+n2-2);
|
23496 | },
|
23497 |
|
23498 | q2p:function(q, o) {
|
23499 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23500 | var S = this.sd(o);
|
23501 | return R.mean(x)-R.mean(y)+ R.qt(q, n1+n2-2)*Math.sqrt(1/n1+1/n2)*S;
|
23502 | },
|
23503 | df:function(o) {
|
23504 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23505 | return n1+n2-2;
|
23506 | }
|
23507 | }
|
23508 |
|
23509 | var t2paired = {
|
23510 | h:function(o) { return "H0:mu1"+o.op+"mu2" },
|
23511 | sd:function(o) {
|
23512 | var x = o.x, n = x.length, y=o.y;
|
23513 | var S= R.sd(R.sub(x,y));
|
23514 | return S;
|
23515 | },
|
23516 | o2q:function(o) {
|
23517 | var x = o.x, n = x.length, y=o.y;
|
23518 | var S = this.sd(o);
|
23519 | var t = (R.mean(R.sub(x,y))-o.mu)/(S/Math.sqrt(n));
|
23520 | return R.pt(t, n-1);
|
23521 | },
|
23522 |
|
23523 | q2p:function(q, o) {
|
23524 | var x = o.x, n = x.length, y=o.y;
|
23525 | var S = this.sd(o);
|
23526 | return R.mean(R.sub(x,y))+ R.qt(q, n-1)*S/Math.sqrt(n);
|
23527 | },
|
23528 | df:function(o) {
|
23529 | return o.x.length-1;
|
23530 | }
|
23531 | }
|
23532 |
|
23533 | var t2varneq = {
|
23534 |
|
23535 | h:function(o) { return "H0:mu1"+o.op+"mu2" },
|
23536 |
|
23537 | o2q:function(o) {
|
23538 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23539 | var S1 = R.sd(x), S2=R.sd(y);
|
23540 | var t = (R.mean(x)-R.mean(y)-o.mu)/Math.sqrt(S1*S1/n1+S2*S2/n2);
|
23541 | return R.pt(t, this.df(o));
|
23542 | },
|
23543 |
|
23544 | q2p:function(q, o) {
|
23545 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23546 | var S1 = R.sd(x), S2=R.sd(y);
|
23547 | return R.mean(x)-R.mean(y)+ R.qt(q, this.df(o))*Math.sqrt(S1*S1/n1+S2*S2/n2);
|
23548 | },
|
23549 | df:function(o) {
|
23550 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23551 | var S1 = R.sd(x), S2=R.sd(y);
|
23552 | var Sn1 = S1*S1/n1, Sn2 = S2*S2/n2, Sn12 = Sn1+Sn2;
|
23553 | var df = (Sn12*Sn12)/((Sn1*Sn1)/(n1-1)+(Sn2*Sn2)/(n2-1));
|
23554 | return df;
|
23555 | }
|
23556 | }
|
23557 |
|
23558 | R.ttest = function(o) {
|
23559 | var t;
|
23560 | if (typeof o.y === "undefined") {
|
23561 | o.name = "ttest(X)";
|
23562 | o.D = t1;
|
23563 | t = R.test(o);
|
23564 | t.mean = R.mean(o.x);
|
23565 | t.sd = R.sd(o.x);
|
23566 | } else {
|
23567 | var varequal = R.opt(o, "varequal", false);
|
23568 | var paired = R.opt(o, "paired", false);
|
23569 | if (varequal) {
|
23570 | o.name = "ttest(X,Y,mu="+o.mu+",varequal=true) (pooled)";
|
23571 | o.D = t2vareq;
|
23572 | t = R.test(o);
|
23573 | } else if (paired) {
|
23574 | o.name = "ttest(x,y,mu="+o.mu+",paired=true)";
|
23575 | o.D = t2paired;
|
23576 | t = R.test(o);
|
23577 | t.mean = "mean(x-y)="+R.str(R.mean(R.sub(o.x, o.y)));
|
23578 | t.sd = "sd(x-y)="+R.str(R.sd(R.sub(o.x, o.y)));
|
23579 | } else {
|
23580 | o.name = "ttest(x,y,mu="+o.mu+",varequal=false), Welch t-test";
|
23581 | o.D = t2varneq;
|
23582 | t = R.test(o);
|
23583 | }
|
23584 | if (typeof t.mean === "undefined") {
|
23585 | t.mean = "mean(x)="+R.str(R.mean(o.x))+" mean(y)="+R.str(R.mean(o.y));
|
23586 | t.sd = "sd(x)="+R.str(R.sd(o.x))+" sd(y)="+R.str(R.sd(o.y));
|
23587 | }
|
23588 | }
|
23589 | return t;
|
23590 | }
|
23591 |
|
23592 | var f2 = {
|
23593 | h:function(o) { return "H0:σ1/σ2"+o.op+"1"; },
|
23594 |
|
23595 | o2q:function(o) {
|
23596 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23597 | var S1 = R.sd(x), S2=R.sd(y);
|
23598 | var f = (S1*S1)/(S2*S2);
|
23599 | var pf = R.pf(f, n1-1, n2-1);
|
23600 | return pf;
|
23601 | },
|
23602 |
|
23603 |
|
23604 | q2p:function(q, o) {
|
23605 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23606 | var S1 = R.sd(x), S2=R.sd(y);
|
23607 | var qf = R.qf(1-q, n1-1, n2-1);
|
23608 | return (S1*S1)/(S2*S2*qf);
|
23609 | },
|
23610 | df:function(o) {
|
23611 | var x = o.x, n1 = x.length, y=o.y, n2=y.length;
|
23612 | return [n1-1, n2-1];
|
23613 | }
|
23614 | }
|
23615 |
|
23616 | R.ftest = function(o) {
|
23617 | o.name = "ftest(X, Y)";
|
23618 | o.D = f2;
|
23619 | var t = R.test(o);
|
23620 | var rsd = R.sd(o.x)/R.sd(o.y);
|
23621 | t.ratio = (rsd*rsd);
|
23622 | return t;
|
23623 | }
|
23624 |
|
23625 |
|
23626 | var chisq1 = {
|
23627 | h:function(o) { return "H0:σ1"+o.op+"σ"; },
|
23628 |
|
23629 | o2q:function(o) {
|
23630 | var x = o.x, n = x.length, S=R.sd(x);
|
23631 | var v = (n-1)*S*S/(o.sd*o.sd);
|
23632 | return R.pchisq(v, n-1);
|
23633 | },
|
23634 |
|
23635 | q2p:function(q, o) {
|
23636 | var x = o.x, n = x.length, S=R.sd(x);
|
23637 | return (n-1)*S*S/R.qchisq(1-q, n-1);
|
23638 | },
|
23639 | df:function(o) {
|
23640 | var x = o.x, n = x.length;
|
23641 | return n-1;
|
23642 | }
|
23643 | }
|
23644 |
|
23645 | R.chisqtest = function(o) {
|
23646 | o.name = "chisqtest(X)";
|
23647 | o.D = chisq1;
|
23648 | return R.test(o);
|
23649 | }
|
23650 |
|
23651 | R.vartest = function(o) {
|
23652 | if (typeof o.y === "undefined")
|
23653 | return R.chisqtest(o);
|
23654 | else
|
23655 | return R.ftest(o);
|
23656 | }
|
23657 |
|
23658 | var z1 = {
|
23659 | h:function(o) { return "H0:mu"+o.op+o.mu+" when sd="+o.sd; },
|
23660 | o2q:function(o) {
|
23661 | var x = o.x, n = x.length;
|
23662 | var z = (R.mean(x)-o.mu)/(o.sd/Math.sqrt(n));
|
23663 | return R.pnorm(z, 0, 1);
|
23664 | },
|
23665 | q2p:function(q, o) {
|
23666 | var x = o.x, n = x.length;
|
23667 | return R.mean(x) + R.qnorm(q, 0, 1) * R.sd(x) / Math.sqrt(n);
|
23668 | },
|
23669 | df:function(o) { return o.x.length; }
|
23670 | }
|
23671 |
|
23672 | R.ztest = function(o) {
|
23673 | o.name = "ztest(X)";
|
23674 | o.D = z1;
|
23675 | return R.test(o);
|
23676 | }
|
23677 |
|
23678 | var zprop1 = {
|
23679 | h:function(o) { return "H0:p"+o.op+o.p; },
|
23680 |
|
23681 | o2q:function(o) {
|
23682 | var x=o.x, n=o.n, p1=x/n, p=R.def(o.p, p1);
|
23683 | var z = (p1-p)/Math.sqrt(p*(1-p)/n);
|
23684 | return R.pnorm(z, 0, 1);
|
23685 | },
|
23686 |
|
23687 | q2p:function(q, o) {
|
23688 | var x=o.x, n=o.n, p1=x/n, p=p1;
|
23689 | var z = R.qnorm(q, 0, 1);
|
23690 | var z22n = z*z/(2*n);
|
23691 | return (p1+z22n+z*Math.sqrt( p*(1-p)/n + z22n/(2*n) ))/(1+2*z22n);
|
23692 |
|
23693 | },
|
23694 | df:function(o) { return 1; }
|
23695 | }
|
23696 |
|
23697 | var zprop2 = {
|
23698 | h:function(o) { return "H0:p1-p2"+o.op+o.p; },
|
23699 |
|
23700 | o2q:function(o) {
|
23701 | var x=o.x, y=o.y, n1=o.n1, n2=o.n2, p1=x/n1, p2=y/n2, p=(n1*p1+n2*p2)/(n1+n2);
|
23702 | var z = (p1-p2)/Math.sqrt(p*(1-p)*(1/n1+1/n2));
|
23703 | return R.pnorm(z, 0, 1);
|
23704 | },
|
23705 |
|
23706 | q2p:function(q, o) {
|
23707 | var x=o.x, y=o.y, n1=o.n1, n2=o.n2, p1=x/n1, p2=y/n2, p=(n1*p1+n2*p2)/(n1+n2);
|
23708 | var z = R.qnorm(q, 0, 1);
|
23709 | return p1-p2+z*Math.sqrt(p*(1-p)*(1/n1+1/n2));
|
23710 | },
|
23711 | df:function(o) { return 1; }
|
23712 | }
|
23713 |
|
23714 |
|
23715 |
|
23716 |
|
23717 |
|
23718 |
|
23719 |
|
23720 |
|
23721 |
|
23722 |
|
23723 |
|
23724 |
|
23725 |
|
23726 | R.proptest = function(o) {
|
23727 | o.p = R.opt(o, "p", 0.5);
|
23728 | o.name = "proptest("+R.str(o)+")";
|
23729 | o.correct = R.opt(o.correct, false);
|
23730 | if (o.correct) {
|
23731 | o.name += ", binomtest";
|
23732 | o.D += binom1;
|
23733 | } else {
|
23734 | if (typeof o.y === "undefined") {
|
23735 | o.name += ", zprop1";
|
23736 | o.D = zprop1;
|
23737 | } else {
|
23738 | o.p = 0;
|
23739 | o.name += ", zprop2";
|
23740 | o.D = zprop2;
|
23741 | }
|
23742 | }
|
23743 | var t=R.test(o);
|
23744 | if (typeof o.y === "undefined")
|
23745 | t.p = o.x/o.n;
|
23746 | else
|
23747 | t.p = [o.x/o.n1, o.y/o.n2];
|
23748 | return t;
|
23749 | }
|
23750 |
|
23751 |
|
23752 | var binom1 = {
|
23753 | h:function(o) { return "H0:p"+o.op+o.p; },
|
23754 |
|
23755 |
|
23756 | o2q:function(o) {
|
23757 | var x=o.x, n=o.n, p = o.p, q;
|
23758 | var dx = R.dbinom(x, n, p);
|
23759 | if (o.op === "=") {
|
23760 | var q = 0;
|
23761 | for (var i=0; i<=n; i++) {
|
23762 | var di = R.dbinom(i, n, p);
|
23763 | if (di > dx+1e-5) q += di;
|
23764 | }
|
23765 | q=1-((1-q)/2);
|
23766 | } else {
|
23767 | if (Math.abs(x - n*p)<1e-5)
|
23768 | q = 1;
|
23769 | else {
|
23770 | if (o.op === ">")
|
23771 | q = R.pbinom(x, n, p);
|
23772 | else
|
23773 | q = R.pbinom(x-1, n, p);
|
23774 | }
|
23775 | }
|
23776 | return q;
|
23777 | },
|
23778 |
|
23779 |
|
23780 |
|
23781 |
|
23782 |
|
23783 |
|
23784 |
|
23785 |
|
23786 |
|
23787 |
|
23788 |
|
23789 |
|
23790 |
|
23791 |
|
23792 |
|
23793 | q2p:function(q, o, side) {
|
23794 | var x=o.x, n=o.n, p=o.p, op=o.op;
|
23795 | if (side === "L")
|
23796 | return qbeta(q, x, n - x + 1);
|
23797 | else
|
23798 | return qbeta(q, x + 1, n - x);
|
23799 | },
|
23800 | df:function(o) { return 1; }
|
23801 | }
|
23802 |
|
23803 | R.binomtest = function(o) {
|
23804 | o.p = R.opt(o, "p", 0.5);
|
23805 | o.name = "binomtest("+R.str(o)+")";
|
23806 | o.D = binom1;
|
23807 | var t=R.test(o);
|
23808 | t.p = o.x/o.n;
|
23809 | t.ci[0]=(o.op === ">")?0:t.ci[0];
|
23810 | t.ci[1]=(o.op === "<")?1:t.ci[1];
|
23811 | return t;
|
23812 | }
|
23813 |
|
23814 | R.report = function(o) {
|
23815 | console.log("=========== report ==========");
|
23816 | for (var k in o) {
|
23817 | if (typeof o[k] !== "function")
|
23818 | console.log(k+"\t: "+str(o[k]));
|
23819 | }
|
23820 | }
|
23821 |
|
23822 |
|
23823 | R.anovaftest = function() {
|
23824 | return {
|
23825 | h0 : "σ1=σ2=...=σ"+arguments.length,
|
23826 | pvalue: J.anovaftest(),
|
23827 | score: J.anovafscore(),
|
23828 | };
|
23829 | }
|
23830 |
|
23831 |
|
23832 | M.str = M.prettyPrint;
|
23833 |
|
23834 | module.exports = R;
|
23835 |
|
23836 |
|
23837 |
|
23838 |
|
23839 |
|
23840 |
|
23841 |
|
23842 |
|
23843 |
|
23844 |
|
23845 |
|
23846 |
|
23847 |
|
23848 |
|
23849 |
|
23850 |
|
23851 |
|
23852 |
|
23853 |
|
23854 |
|
23855 |
|
23856 |
|
23857 |
|
23858 |
|
23859 |
|
23860 |
|
23861 |
|
23862 |
|
23863 |
|
23864 | },{"jStat":1,"lodash":2,"numeric":3}],5:[function(require,module,exports){
|
23865 | R=require("../rlab");
|
23866 | },{"../rlab":4}]},{},[5]);
|