UNPKG

cifar-10

Version:
1,690 lines (1,621 loc) 31.8 kB
'use strict'; var cov_1fj4aexxlh = function () { var path = '/Users/kp/workspace/playground/cifar-10-js/src/index.js', hash = '058f1d751749e53b078643f8aafc9971f3fc4afe', global = new Function('return this')(), gcv = '__coverage__', coverageData = { path: '/Users/kp/workspace/playground/cifar-10-js/src/index.js', statementMap: { '0': { start: { line: 5, column: 15 }, end: { line: 5, column: 50 } }, '1': { start: { line: 9, column: 2 }, end: { line: 9, column: 38 } }, '2': { start: { line: 10, column: 19 }, end: { line: 10, column: 40 } }, '3': { start: { line: 11, column: 2 }, end: { line: 11, column: 77 } }, '4': { start: { line: 11, column: 33 }, end: { line: 11, column: 75 } }, '5': { start: { line: 15, column: 2 }, end: { line: 22, column: 5 } }, '6': { start: { line: 16, column: 4 }, end: { line: 16, column: 28 } }, '7': { start: { line: 17, column: 4 }, end: { line: 17, column: 28 } }, '8': { start: { line: 18, column: 4 }, end: { line: 18, column: 15 } }, '9': { start: { line: 26, column: 2 }, end: { line: 26, column: 31 } }, '10': { start: { line: 26, column: 21 }, end: { line: 26, column: 31 } }, '11': { start: { line: 27, column: 17 }, end: { line: 27, column: 19 } }, '12': { start: { line: 29, column: 2 }, end: { line: 30, column: 19 } }, '13': { start: { line: 30, column: 4 }, end: { line: 30, column: 19 } }, '14': { start: { line: 32, column: 2 }, end: { line: 32, column: 16 } }, '15': { start: { line: 36, column: 2 }, end: { line: 38, column: 38 } }, '16': { start: { line: 42, column: 23 }, end: { line: 66, column: 1 } }, '17': { start: { line: 45, column: 4 }, end: { line: 45, column: 51 } }, '18': { start: { line: 48, column: 4 }, end: { line: 48, column: 52 } }, '19': { start: { line: 48, column: 31 }, end: { line: 48, column: 50 } }, '20': { start: { line: 51, column: 4 }, end: { line: 51, column: 42 } }, '21': { start: { line: 58, column: 4 }, end: { line: 58, column: 65 } }, '22': { start: { line: 61, column: 14 }, end: { line: 61, column: 22 } }, '23': { start: { line: 62, column: 14 }, end: { line: 63, column: 46 } }, '24': { start: { line: 63, column: 26 }, end: { line: 63, column: 45 } }, '25': { start: { line: 64, column: 4 }, end: { line: 64, column: 20 } }, '26': { start: { line: 71, column: 2 }, end: { line: 73, column: 3 } }, '27': { start: { line: 72, column: 6 }, end: { line: 72, column: 87 } }, '28': { start: { line: 75, column: 17 }, end: { line: 75, column: 73 } }, '29': { start: { line: 77, column: 2 }, end: { line: 77, column: 16 } }, '30': { start: { line: 81, column: 15 }, end: { line: 81, column: 17 } }, '31': { start: { line: 83, column: 2 }, end: { line: 117, column: 5 } }, '32': { start: { line: 85, column: 6 }, end: { line: 85, column: 39 } }, '33': { start: { line: 89, column: 18 }, end: { line: 96, column: 8 } }, '34': { start: { line: 90, column: 8 }, end: { line: 90, column: 22 } }, '35': { start: { line: 91, column: 8 }, end: { line: 91, column: 22 } }, '36': { start: { line: 92, column: 8 }, end: { line: 92, column: 19 } }, '37': { start: { line: 97, column: 6 }, end: { line: 97, column: 19 } }, '38': { start: { line: 98, column: 6 }, end: { line: 98, column: 20 } }, '39': { start: { line: 99, column: 6 }, end: { line: 99, column: 24 } }, '40': { start: { line: 103, column: 6 }, end: { line: 103, column: 46 } }, '41': { start: { line: 104, column: 6 }, end: { line: 104, column: 44 } }, '42': { start: { line: 105, column: 6 }, end: { line: 105, column: 46 } }, '43': { start: { line: 108, column: 4 }, end: { line: 116, column: 5 } }, '44': { start: { line: 109, column: 6 }, end: { line: 109, column: 35 } }, '45': { start: { line: 110, column: 6 }, end: { line: 110, column: 33 } }, '46': { start: { line: 111, column: 6 }, end: { line: 111, column: 35 } }, '47': { start: { line: 121, column: 13 }, end: { line: 122, column: 56 } }, '48': { start: { line: 121, column: 31 }, end: { line: 121, column: 58 } }, '49': { start: { line: 122, column: 29 }, end: { line: 122, column: 55 } }, '50': { start: { line: 123, column: 2 }, end: { line: 123, column: 63 } }, '51': { start: { line: 123, column: 46 }, end: { line: 123, column: 61 } }, '52': { start: { line: 127, column: 37 }, end: { line: 127, column: 79 } }, '53': { start: { line: 128, column: 35 }, end: { line: 128, column: 76 } }, '54': { start: { line: 130, column: 2 }, end: { line: 135, column: 3 } } }, fnMap: { '0': { name: 'bufferSplit', decl: { start: { line: 8, column: 16 }, end: { line: 8, column: 27 } }, loc: { start: { line: 8, column: 42 }, end: { line: 12, column: 1 } }, line: 8 }, '1': { name: '(anonymous_1)', decl: { start: { line: 11, column: 28 }, end: { line: 11, column: 29 } }, loc: { start: { line: 11, column: 33 }, end: { line: 11, column: 75 } }, line: 11 }, '2': { name: 'flatten', decl: { start: { line: 14, column: 9 }, end: { line: 14, column: 16 } }, loc: { start: { line: 14, column: 22 }, end: { line: 23, column: 1 } }, line: 14 }, '3': { name: '(anonymous_3)', decl: { start: { line: 15, column: 20 }, end: { line: 15, column: 21 } }, loc: { start: { line: 15, column: 37 }, end: { line: 19, column: 3 } }, line: 15 }, '4': { name: 'range', decl: { start: { line: 25, column: 9 }, end: { line: 25, column: 14 } }, loc: { start: { line: 25, column: 33 }, end: { line: 33, column: 1 } }, line: 25 }, '5': { name: 'isStream', decl: { start: { line: 35, column: 16 }, end: { line: 35, column: 24 } }, loc: { start: { line: 35, column: 33 }, end: { line: 39, column: 1 } }, line: 35 }, '6': { name: '(anonymous_6)', decl: { start: { line: 44, column: 16 }, end: { line: 44, column: 17 } }, loc: { start: { line: 44, column: 34 }, end: { line: 46, column: 3 } }, line: 44 }, '7': { name: '(anonymous_7)', decl: { start: { line: 48, column: 26 }, end: { line: 48, column: 27 } }, loc: { start: { line: 48, column: 31 }, end: { line: 48, column: 50 } }, line: 48 }, '8': { name: '(anonymous_8)', decl: { start: { line: 60, column: 10 }, end: { line: 60, column: 11 } }, loc: { start: { line: 60, column: 27 }, end: { line: 65, column: 3 } }, line: 60 }, '9': { name: '(anonymous_9)', decl: { start: { line: 63, column: 19 }, end: { line: 63, column: 20 } }, loc: { start: { line: 63, column: 26 }, end: { line: 63, column: 45 } }, line: 63 }, '10': { name: 'createStream', decl: { start: { line: 70, column: 16 }, end: { line: 70, column: 28 } }, loc: { start: { line: 70, column: 51 }, end: { line: 78, column: 1 } }, line: 70 }, '11': { name: 'createPromise', decl: { start: { line: 80, column: 16 }, end: { line: 80, column: 29 } }, loc: { start: { line: 80, column: 46 }, end: { line: 118, column: 1 } }, line: 80 }, '12': { name: '(anonymous_12)', decl: { start: { line: 83, column: 21 }, end: { line: 83, column: 22 } }, loc: { start: { line: 83, column: 42 }, end: { line: 117, column: 3 } }, line: 83 }, '13': { name: 'converter', decl: { start: { line: 84, column: 13 }, end: { line: 84, column: 22 } }, loc: { start: { line: 84, column: 29 }, end: { line: 86, column: 5 } }, line: 84 }, '14': { name: 'resolver', decl: { start: { line: 88, column: 13 }, end: { line: 88, column: 21 } }, loc: { start: { line: 88, column: 24 }, end: { line: 100, column: 5 } }, line: 88 }, '15': { name: '(anonymous_15)', decl: { start: { line: 89, column: 32 }, end: { line: 89, column: 33 } }, loc: { start: { line: 89, column: 49 }, end: { line: 93, column: 7 } }, line: 89 }, '16': { name: 'removeListeners', decl: { start: { line: 102, column: 13 }, end: { line: 102, column: 28 } }, loc: { start: { line: 102, column: 31 }, end: { line: 106, column: 5 } }, line: 102 }, '17': { name: 'combine', decl: { start: { line: 120, column: 22 }, end: { line: 120, column: 29 } }, loc: { start: { line: 120, column: 46 }, end: { line: 124, column: 1 } }, line: 120 }, '18': { name: '(anonymous_18)', decl: { start: { line: 121, column: 23 }, end: { line: 121, column: 24 } }, loc: { start: { line: 121, column: 31 }, end: { line: 121, column: 58 } }, line: 121 }, '19': { name: '(anonymous_19)', decl: { start: { line: 122, column: 23 }, end: { line: 122, column: 24 } }, loc: { start: { line: 122, column: 29 }, end: { line: 122, column: 55 } }, line: 122 }, '20': { name: '(anonymous_20)', decl: { start: { line: 123, column: 36 }, end: { line: 123, column: 37 } }, loc: { start: { line: 123, column: 46 }, end: { line: 123, column: 61 } }, line: 123 }, '21': { name: 'load', decl: { start: { line: 126, column: 22 }, end: { line: 126, column: 26 } }, loc: { start: { line: 126, column: 44 }, end: { line: 136, column: 1 } }, line: 126 } }, branchMap: { '0': { loc: { start: { line: 25, column: 22 }, end: { line: 25, column: 31 } }, type: 'default-arg', locations: [{ start: { line: 25, column: 26 }, end: { line: 25, column: 31 } }], line: 25 }, '1': { loc: { start: { line: 26, column: 2 }, end: { line: 26, column: 31 } }, type: 'if', locations: [{ start: { line: 26, column: 2 }, end: { line: 26, column: 31 } }, { start: { line: 26, column: 2 }, end: { line: 26, column: 31 } }], line: 26 }, '2': { loc: { start: { line: 36, column: 9 }, end: { line: 38, column: 37 } }, type: 'binary-expr', locations: [{ start: { line: 36, column: 9 }, end: { line: 36, column: 24 } }, { start: { line: 37, column: 4 }, end: { line: 37, column: 30 } }, { start: { line: 38, column: 4 }, end: { line: 38, column: 37 } }], line: 36 }, '3': { loc: { start: { line: 71, column: 2 }, end: { line: 73, column: 3 } }, type: 'if', locations: [{ start: { line: 71, column: 2 }, end: { line: 73, column: 3 } }, { start: { line: 71, column: 2 }, end: { line: 73, column: 3 } }], line: 71 }, '4': { loc: { start: { line: 126, column: 27 }, end: { line: 126, column: 42 } }, type: 'default-arg', locations: [{ start: { line: 126, column: 35 }, end: { line: 126, column: 42 } }], line: 126 } }, s: { '0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0, '11': 0, '12': 0, '13': 0, '14': 0, '15': 0, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0, '21': 0, '22': 0, '23': 0, '24': 0, '25': 0, '26': 0, '27': 0, '28': 0, '29': 0, '30': 0, '31': 0, '32': 0, '33': 0, '34': 0, '35': 0, '36': 0, '37': 0, '38': 0, '39': 0, '40': 0, '41': 0, '42': 0, '43': 0, '44': 0, '45': 0, '46': 0, '47': 0, '48': 0, '49': 0, '50': 0, '51': 0, '52': 0, '53': 0, '54': 0 }, f: { '0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0, '11': 0, '12': 0, '13': 0, '14': 0, '15': 0, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0, '21': 0 }, b: { '0': [0], '1': [0, 0], '2': [0, 0, 0], '3': [0, 0], '4': [0] }, _coverageSchema: '332fd63041d2c1bcb487cc26dd0d5f7d97098a6c' }, coverage = global[gcv] || (global[gcv] = {}); if (coverage[path] && coverage[path].hash === hash) { return coverage[path]; } coverageData.hash = hash; return coverage[path] = coverageData; }(); Object.defineProperty(exports, "__esModule", { value: true }); exports.load = exports.combine = exports.cifar10 = undefined; var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _promise = require('babel-runtime/core-js/promise'); var _promise2 = _interopRequireDefault(_promise); var _typeof2 = require('babel-runtime/helpers/typeof'); var _typeof3 = _interopRequireDefault(_typeof2); var combine = exports.combine = function () { var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(files, options) { var ps; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: cov_1fj4aexxlh.f[17]++; ps = (cov_1fj4aexxlh.s[47]++, files.map(function (name) { cov_1fj4aexxlh.f[18]++; cov_1fj4aexxlh.s[48]++; return createStream(name, options); }).map(function (sr) { cov_1fj4aexxlh.f[19]++; cov_1fj4aexxlh.s[49]++; return createPromise(sr, options); })); cov_1fj4aexxlh.s[50]++; _context.next = 5; return _promise2.default.all(ps).then(function (values) { cov_1fj4aexxlh.f[20]++; cov_1fj4aexxlh.s[51]++; return flatten(values); }); case 5: return _context.abrupt('return', _context.sent); case 6: case 'end': return _context.stop(); } } }, _callee, this); })); return function combine(_x2, _x3) { return _ref4.apply(this, arguments); }; }(); var load = exports.load = function () { var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (cov_1fj4aexxlh.b[4][0]++, cifar10); var _ref6, X_train, y_train, _ref7, X_test, y_test; return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: cov_1fj4aexxlh.f[21]++; cov_1fj4aexxlh.s[52]++; _context2.next = 4; return combine(options.trainFiles, options); case 4: _ref6 = _context2.sent; X_train = _ref6.X; y_train = _ref6.y; cov_1fj4aexxlh.s[53]++; _context2.next = 10; return combine(options.testFiles, options); case 10: _ref7 = _context2.sent; X_test = _ref7.X; y_test = _ref7.y; cov_1fj4aexxlh.s[54]++; return _context2.abrupt('return', { X_train: X_train, y_train: y_train, X_test: X_test, y_test: y_test }); case 15: case 'end': return _context2.stop(); } } }, _callee2, this); })); return function load() { return _ref5.apply(this, arguments); }; }(); exports.bufferSplit = bufferSplit; exports.isStream = isStream; exports.createStream = createStream; exports.createPromise = createPromise; var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _assert = require('assert'); var _assert2 = _interopRequireDefault(_assert); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var appDir = (cov_1fj4aexxlh.s[0]++, _path2.default.dirname(require.main.filename)); /* Library */ function bufferSplit(bufs, divider) { cov_1fj4aexxlh.f[0]++; cov_1fj4aexxlh.s[1]++; (0, _assert2.default)(bufs.length % divider === 0); var quotient = (cov_1fj4aexxlh.s[2]++, bufs.length / divider); cov_1fj4aexxlh.s[3]++; return range(divider).map(function (i) { cov_1fj4aexxlh.f[1]++; cov_1fj4aexxlh.s[4]++; return bufs.slice(quotient * i, quotient * (i + 1)); }); } function flatten(arr) { cov_1fj4aexxlh.f[2]++; cov_1fj4aexxlh.s[5]++; return arr.reduce(function (acc, _ref) { var X = _ref.X, y = _ref.y; cov_1fj4aexxlh.f[3]++; cov_1fj4aexxlh.s[6]++; acc.X = acc.X.concat(X); cov_1fj4aexxlh.s[7]++; acc.y = acc.y.concat(y); cov_1fj4aexxlh.s[8]++; return acc; }, { X: [], y: [] }); } function range(start) { var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (cov_1fj4aexxlh.b[0][0]++, start); cov_1fj4aexxlh.f[4]++; cov_1fj4aexxlh.s[9]++; if (start === end) { cov_1fj4aexxlh.b[1][0]++; cov_1fj4aexxlh.s[10]++; start = 0; } else { cov_1fj4aexxlh.b[1][1]++; }var result = (cov_1fj4aexxlh.s[11]++, []); cov_1fj4aexxlh.s[12]++; for (var i = start; i < end; i++) { cov_1fj4aexxlh.s[13]++; result.push(i); }cov_1fj4aexxlh.s[14]++; return result; } function isStream(stream) { cov_1fj4aexxlh.f[5]++; cov_1fj4aexxlh.s[15]++; return (cov_1fj4aexxlh.b[2][0]++, stream !== null) && (cov_1fj4aexxlh.b[2][1]++, (typeof stream === 'undefined' ? 'undefined' : (0, _typeof3.default)(stream)) === 'object') && (cov_1fj4aexxlh.b[2][2]++, typeof stream.pipe === 'function'); } /* Configuration CIFAR-10 */ var cifar10 = exports.cifar10 = (cov_1fj4aexxlh.s[16]++, { dir: _path2.default.join(appDir, 'cifar-10-batches-bin'), getFileName: function getFileName(postfix) { cov_1fj4aexxlh.f[6]++; cov_1fj4aexxlh.s[17]++; return this.dir + '/data_batch_' + postfix + '.bin'; }, get trainFiles() { var _this = this; cov_1fj4aexxlh.s[18]++; return range(1, 6).map(function (i) { cov_1fj4aexxlh.f[7]++; cov_1fj4aexxlh.s[19]++; return _this.getFileName(i); }); }, get testFiles() { cov_1fj4aexxlh.s[20]++; return [this.dir + '/test_batch.bin']; }, cols: 32, rows: 32, channel: 3, valueSize: 1, get totalSize() { cov_1fj4aexxlh.s[21]++; return this.valueSize + this.channel * this.cols * this.rows; }, mapper: function mapper(chunk) { cov_1fj4aexxlh.f[8]++; var y = (cov_1fj4aexxlh.s[22]++, chunk[0]); var X = (cov_1fj4aexxlh.s[23]++, bufferSplit(chunk.slice(this.valueSize), this.channel).map(function (buf) { cov_1fj4aexxlh.f[9]++; cov_1fj4aexxlh.s[24]++; return new Uint8Array(buf); })); cov_1fj4aexxlh.s[25]++; return { X: X, y: y }; } /* Main */ });function createStream(filename, _ref2) { var totalSize = _ref2.totalSize; cov_1fj4aexxlh.f[10]++; cov_1fj4aexxlh.s[26]++; if (!_fs2.default.existsSync(filename)) { cov_1fj4aexxlh.b[3][0]++; cov_1fj4aexxlh.s[27]++; throw new Error('Data files are not existed. Run \'' + __dirname + '/get_datasets.sh\''); } else { cov_1fj4aexxlh.b[3][1]++; } var stream = (cov_1fj4aexxlh.s[28]++, _fs2.default.createReadStream(filename, { highWaterMark: totalSize })); cov_1fj4aexxlh.s[29]++; return stream; } function createPromise(stream, config) { cov_1fj4aexxlh.f[11]++; var output = (cov_1fj4aexxlh.s[30]++, []); cov_1fj4aexxlh.s[31]++; return new _promise2.default(function (resolve, reject) { cov_1fj4aexxlh.f[12]++; function converter(data) { cov_1fj4aexxlh.f[13]++; cov_1fj4aexxlh.s[32]++; output.push(config.mapper(data)); } function resolver() { cov_1fj4aexxlh.f[14]++; var ret = (cov_1fj4aexxlh.s[33]++, output.reduce(function (acc, _ref3) { var X = _ref3.X, y = _ref3.y; cov_1fj4aexxlh.f[15]++; cov_1fj4aexxlh.s[34]++; acc.X.push(X); cov_1fj4aexxlh.s[35]++; acc.y.push(y); cov_1fj4aexxlh.s[36]++; return acc; }, { X: [], y: [] })); cov_1fj4aexxlh.s[37]++; resolve(ret); cov_1fj4aexxlh.s[38]++; output = null; cov_1fj4aexxlh.s[39]++; removeListeners(); } function removeListeners() { cov_1fj4aexxlh.f[16]++; cov_1fj4aexxlh.s[40]++; stream.removeListener('data', converter); cov_1fj4aexxlh.s[41]++; stream.removeListener('end', resolver); cov_1fj4aexxlh.s[42]++; stream.removeListener('close', resolver); } cov_1fj4aexxlh.s[43]++; try { cov_1fj4aexxlh.s[44]++; stream.on('data', converter); // stream.on('data', function(data) { cov_1fj4aexxlh.s[45]++; stream.on('end', resolver); cov_1fj4aexxlh.s[46]++; stream.on('close', resolver); } catch (e) /*istanbul ignore next*/{ removeListeners(); reject(e); } }); } exports.default = { createStream: createStream, createPromise: createPromise, combine: combine, load: load }; //# sourceMappingURL=index.js.map