How to use fn method in wpt

Best JavaScript code snippet using wpt

estimator_test.py

Source:estimator_test.py Github

copy

Full Screen

...63from tensorflow.python.training import training64from tensorflow.python.util import compat65_TMP_DIR = '/tmp'66_ANOTHER_TMP_DIR = '/another_tmp'67def dummy_model_fn(features, labels, params):68 _, _, _ = features, labels, params69def check_eventfile_for_keyword(keyword, est):70 """Checks event files for the keyword."""71 writer_cache.FileWriterCache.clear()72 # Get last Event written.73 event_paths = glob.glob(os.path.join(est.model_dir, 'events*'))74 last_event = None75 for last_event in summary_iterator.summary_iterator(event_paths[-1]):76 if last_event.summary is not None:77 if last_event.summary.value:78 if keyword in last_event.summary.value[0].tag:79 return True80 return False81class EstimatorInheritanceConstraintTest(test.TestCase):82 """Tests that sub classes cannot override methods of Estimator."""83 def test_override_a_method(self):84 class _Estimator(estimator.Estimator):85 def __init__(self):86 super(_Estimator, self).__init__(model_fn=dummy_model_fn)87 def predict(self, input_fn, predict_keys=None, hooks=None):88 pass89 with self.assertRaisesRegexp(90 ValueError, 'cannot override members of Estimator.*predict'):91 _Estimator()92 def test_override_a_method_with_tricks(self):93 class _Estimator(estimator.Estimator):94 def __init__(self):95 super(_Estimator, self).__init__(model_fn=dummy_model_fn)96 def _assert_members_are_not_overridden(self):97 pass # HAHA! I tricked you!98 def predict(self, input_fn, predict_keys=None, hooks=None):99 pass100 with self.assertRaisesRegexp(101 ValueError, 'cannot override members of Estimator.*predict'):102 _Estimator()103 def test_extension_of_api_is_ok(self):104 class _Estimator(estimator.Estimator):105 def __init__(self):106 super(_Estimator, self).__init__(model_fn=dummy_model_fn)107 def predict_proba(self, input_fn, predict_keys=None, hooks=None):108 pass109 _Estimator()110 def test_override_allowed_method(self):111 class _Estimator(estimator.Estimator):112 def __init__(self):113 super(_Estimator, self).__init__(model_fn=dummy_model_fn)114 def _call_input_fn(self, input_fn, mode):115 return input_fn()116 def _create_global_step(self, graph):117 pass118 def _convert_train_steps_to_hooks(self, steps, max_steps):119 pass120 def _convert_eval_steps_to_hooks(self, steps):121 pass122 _Estimator()123class EstimatorConstructorTest(test.TestCase):124 def test_config_must_be_a_run_config(self):125 with self.assertRaisesRegexp(ValueError, 'an instance of RunConfig'):126 estimator.Estimator(model_fn=None, config='NotARunConfig')127 def test_model_fn_must_be_provided(self):128 with self.assertRaisesRegexp(ValueError, 'model_fn.* must be'):129 estimator.Estimator(model_fn=None)130 def test_property_accessors(self):131 def model_fn(features, labels, params):132 _, _, _ = features, labels, params133 class FakeConfig(run_config.RunConfig):134 pass135 params = {'hidden_layers': [3, 4]}136 est = estimator.Estimator(137 model_fn=model_fn, model_dir='bla', config=FakeConfig(), params=params)138 self.assertTrue(isinstance(est.config, FakeConfig))139 self.assertEqual(params, est.params)140 self.assertEqual('bla', est.model_dir)141 def test_default_config(self):142 def model_fn(features, labels):143 _, _ = features, labels144 est = estimator.Estimator(model_fn=model_fn)145 self.assertTrue(isinstance(est.config, run_config.RunConfig))146 def test_default_model_dir(self):147 def model_fn(features, labels):148 _, _ = features, labels149 with test.mock.patch.object(tempfile, 'mkdtemp', return_value=_TMP_DIR):150 est = estimator.Estimator(model_fn=model_fn)151 self.assertEqual(_TMP_DIR, est.config.model_dir)152 self.assertEqual(_TMP_DIR, est.model_dir)153 def test_model_dir_in_constructor(self):154 def model_fn(features, labels):155 _, _ = features, labels156 est = estimator.Estimator(model_fn=model_fn, model_dir=_TMP_DIR)157 self.assertEqual(_TMP_DIR, est.config.model_dir)158 self.assertEqual(_TMP_DIR, est.model_dir)159 def test_model_dir_in_run_config(self):160 class FakeConfig(run_config.RunConfig):161 @property162 def model_dir(self):163 return _TMP_DIR164 def model_fn(features, labels):165 _, _ = features, labels166 est = estimator.Estimator(model_fn=model_fn, config=FakeConfig())167 self.assertEqual(_TMP_DIR, est.config.model_dir)168 self.assertEqual(_TMP_DIR, est.model_dir)169 def test_same_model_dir_in_constructor_and_run_config(self):170 class FakeConfig(run_config.RunConfig):171 @property172 def model_dir(self):173 return _TMP_DIR174 def model_fn(features, labels):175 _, _ = features, labels176 est = estimator.Estimator(177 model_fn=model_fn, config=FakeConfig(), model_dir=_TMP_DIR)178 self.assertEqual(_TMP_DIR, est.config.model_dir)179 self.assertEqual(_TMP_DIR, est.model_dir)180 def test_different_model_dir_in_constructor_and_run_config(self):181 class FakeConfig(run_config.RunConfig):182 @property183 def model_dir(self):184 return _TMP_DIR185 def model_fn(features, labels):186 _, _ = features, labels187 with self.assertRaisesRegexp(188 ValueError,189 'model_dir are set both in constructor and RunConfig, but '190 'with different values'):191 estimator.Estimator(192 model_fn=model_fn, config=FakeConfig(), model_dir=_ANOTHER_TMP_DIR)193 def test_model_fn_args_must_include_features(self):194 def model_fn(x, labels):195 _, _ = x, labels196 with self.assertRaisesRegexp(ValueError, 'features'):197 estimator.Estimator(model_fn=model_fn)198 def test_model_fn_args_labels_is_optional(self):199 def model_fn(features):200 _ = features201 estimator.Estimator(model_fn=model_fn)202 def test_if_params_provided_then_model_fn_should_accept_it(self):203 def model_fn(features, labels):204 _, _ = features, labels205 estimator.Estimator(model_fn=model_fn)206 with self.assertRaisesRegexp(ValueError, 'params'):207 estimator.Estimator(model_fn=model_fn, params={'hidden_layers': 4})208 def test_internal_params_is_a_deepcopy(self):209 def model_fn(features, labels, params):210 _, _, _ = features, labels, params211 params = {'hidden_layers': 4}212 est = estimator.Estimator(model_fn=model_fn, params=params)213 params['hidden_layers'] = 5214 self.assertEqual(4, est.params['hidden_layers'])215 def test_not_known_model_fn_args(self):216 def model_fn(features, labels, something):217 _, _, _ = features, labels, something218 with self.assertRaisesRegexp(ValueError, 'something'):219 estimator.Estimator(model_fn=model_fn)220 def test_not_known_model_fn_args_handled_by_lambda(self):221 def model_fn(features, labels, something):222 _, _, _ = features, labels, something223 new_model_fn = lambda features, labels: model_fn( # pylint: disable=g-long-lambda224 features, labels, 'something')225 estimator.Estimator(model_fn=new_model_fn)226 def test_if_model_fn_is_a_member_function_of_a_class(self):227 class ModelFnClass(object):228 def __init__(self):229 estimator.Estimator(model_fn=self.model_fn)230 def model_fn(self, features, labels, mode):231 _, _, _ = features, labels, mode232 ModelFnClass()233 def test_model_fn_property_binds_params(self):234 def model_fn(features, labels, mode, config, params):235 _, _, _, _, _ = features, labels, mode, config, params236 est = estimator.Estimator(model_fn=model_fn)237 model_fn_args = util.fn_args(est.model_fn)238 self.assertEqual(239 set(['features', 'labels', 'mode', 'config']), set(model_fn_args))240 def test_model_fn_property_returns_fixed_signature(self):241 def model_fn(features, labels):242 _, _ = features, labels243 est = estimator.Estimator(model_fn=model_fn)244 model_fn_args = util.fn_args(est.model_fn)245 self.assertEqual(246 set(['features', 'labels', 'mode', 'config']), set(model_fn_args))247def dummy_input_fn():248 return ({'x': constant_op.constant([[1], [1]])},249 constant_op.constant([[1], [1]]))250def model_fn_global_step_incrementer(features, labels, mode):251 _, _ = features, labels252 global_step = training.get_global_step()253 return model_fn_lib.EstimatorSpec(254 mode,255 loss=constant_op.constant(1.),256 train_op=state_ops.assign_add(global_step, 1))257def assert_features_op(expected_features, actual_features):258 return [259 check_ops.assert_equal(260 expected_features[k], actual_features[k], name='assert_%s' % k)261 for k in expected_features262 ]263def _estimator_spec(264 expected_features, expected_labels, actual_features, actual_labels, mode):265 assert_ops = tuple(266 assert_features_op(expected_features, actual_features) + [267 check_ops.assert_equal(268 expected_labels, actual_labels, name='assert_labels')269 ])270 global_step = training.get_global_step()271 with ops.control_dependencies(assert_ops):272 return model_fn_lib.EstimatorSpec(273 mode=mode,274 predictions=constant_op.constant(0.),275 loss=constant_op.constant(0.),276 train_op=state_ops.assign_add(global_step, 1))277def _make_input_fn(features, labels):278 def _input_fn():279 return {280 k: constant_op.constant(v)281 for k, v in six.iteritems(features)282 }, constant_op.constant(labels)283 return _input_fn284class EstimatorTrainTest(test.TestCase):285 def test_callable_model_fn(self):286 expected_features = {'x': 42., 'y': 43.}287 expected_labels = 44.288 model_fn_call_count = [0]289 test_self = self290 class ModelFn(object):291 def __call__(self, features, labels):292 model_fn_call_count[0] += 1293 test_self.assertItemsEqual(expected_features.keys(), features.keys())294 return _estimator_spec(295 expected_features, expected_labels, features, labels,296 model_fn_lib.ModeKeys.TRAIN)297 with self.assertRaisesRegexp(ValueError, 'does not include params'):298 estimator.Estimator(model_fn=ModelFn(), params={'a': 'b'})299 est = estimator.Estimator(model_fn=ModelFn(), config=run_config.RunConfig())300 self.assertEqual(0, model_fn_call_count[0])301 est.train(302 input_fn=_make_input_fn(expected_features, expected_labels), steps=1)303 self.assertEqual(1, model_fn_call_count[0])304 def test_callable_input_fn(self):305 expected_params = {'batch_size': 10}306 expected_config = run_config.RunConfig().replace(tf_random_seed=4321)307 input_fn_call_count = [0]308 def _model_fn(features, labels, mode, params, config):309 del params, config310 return model_fn_global_step_incrementer(features, labels, mode)311 test_self = self312 class InputFn(object):313 def __call__(self, params, config):314 input_fn_call_count[0] += 1315 test_self.assertEqual(expected_params, params)316 test_self.assertEqual(4321, config.tf_random_seed)317 return dummy_input_fn()318 est = estimator.Estimator(model_fn=_model_fn,319 params=expected_params,320 config=expected_config)321 self.assertEqual(0, input_fn_call_count[0])322 est.train(InputFn(), steps=1)323 self.assertEqual(1, input_fn_call_count[0])324 def test_input_fn_args(self):325 expected_params = {'batch_size': 10}326 expected_config = run_config.RunConfig().replace(tf_random_seed=4321)327 input_fn_call_count = [0]328 def _model_fn(features, labels, mode, params, config):329 del params, config330 return model_fn_global_step_incrementer(features, labels, mode)331 def _input_fn(params, config):332 input_fn_call_count[0] += 1333 self.assertEqual(expected_params, params)334 self.assertEqual(4321, config.tf_random_seed)335 return dummy_input_fn()336 est = estimator.Estimator(model_fn=_model_fn,337 params=expected_params,338 config=expected_config)339 self.assertEqual(0, input_fn_call_count[0])340 est.train(_input_fn, steps=1)341 self.assertEqual(1, input_fn_call_count[0])342 def test_minimal_model_fn_args(self):343 expected_features = {'x': 4, 'y': 5}344 def _input_fn():345 return expected_features346 model_fn_call_count = [0]347 def _model_fn(features):348 model_fn_call_count[0] += 1349 self.assertItemsEqual(expected_features.keys(), features.keys())350 with ops.control_dependencies(351 assert_features_op(expected_features, features)):352 return model_fn_lib.EstimatorSpec(353 mode=None,354 predictions=constant_op.constant(0.),355 loss=constant_op.constant(0.),356 train_op=state_ops.assign_add(training.get_global_step(), 1))357 est = estimator.Estimator(model_fn=_model_fn)358 self.assertEqual(0, model_fn_call_count[0])359 est.train(input_fn=_input_fn, steps=1)360 self.assertEqual(1, model_fn_call_count[0])361 def test_labels_should_be_none_if_model_fn_does_not_use_labels(self):362 def _input_fn_with_labels():363 return {'x': 4, 'y': 5}, [4]364 def _model_fn(features):365 _ = features366 return model_fn_lib.EstimatorSpec(367 mode=None,368 predictions=constant_op.constant(0.),369 loss=constant_op.constant(0.),370 train_op=state_ops.assign_add(training.get_global_step(), 1))371 est = estimator.Estimator(model_fn=_model_fn)372 with self.assertRaisesRegexp(ValueError, 'model_fn does not take labels'):373 est.train(input_fn=_input_fn_with_labels, steps=1)374 def test_input_fn_len_should_be_2_if_tuple_or_list(self):375 def _input_fn():376 return 4, 5, 6377 def _model_fn(features):378 _ = features379 est = estimator.Estimator(model_fn=_model_fn)380 with self.assertRaisesRegexp(ValueError, 'len 2 tuple'):381 est.train(input_fn=_input_fn, steps=1)382 def test_all_model_fn_args(self):383 expected_features = {'x': 42., 'y': 43.}384 expected_labels = 44.385 expected_params = {'some_param': 'some_value'}386 expected_config = run_config.RunConfig()387 expected_config.i_am_test = True388 # TODO(ptucker): We have to roll our own mock since Estimator._get_arguments389 # doesn't work with mock fns.390 model_fn_call_count = [0]391 # Note that args are all passed by keyword, so can be in any order.392 def _model_fn(mode, params, features, labels, config):393 model_fn_call_count[0] += 1394 self.assertItemsEqual(expected_features.keys(), features.keys())395 self.assertEqual(model_fn_lib.ModeKeys.TRAIN, mode)396 self.assertEqual(expected_params, params)397 self.assertTrue(config.i_am_test)398 return _estimator_spec(399 expected_features, expected_labels, features, labels, mode)400 est = estimator.Estimator(401 model_fn=_model_fn, params=expected_params, config=expected_config)402 self.assertEqual(0, model_fn_call_count[0])403 est.train(404 input_fn=_make_input_fn(expected_features, expected_labels), steps=1)405 self.assertEqual(1, model_fn_call_count[0])406 def test_partial_model_fn_args(self):407 expected_features = {'x': 42., 'y': 43.}408 expected_labels = 44.409 expected_params = {'some_param': 'some_value'}410 expected_config = run_config.RunConfig()411 expected_config.i_am_test = True412 expected_foo = 45.413 expected_bar = 46.414 # TODO(ptucker): We have to roll our own mock since Estimator._get_arguments415 # doesn't work with mock fns.416 model_fn_call_count = [0]417 def _model_fn(features, labels, foo, mode, params, config, bar):418 model_fn_call_count[0] += 1419 self.assertEqual(expected_foo, foo)420 self.assertEqual(expected_bar, bar)421 self.assertItemsEqual(expected_features.keys(), features.keys())422 self.assertEqual(model_fn_lib.ModeKeys.TRAIN, mode)423 self.assertEqual(expected_params, params)424 self.assertTrue(config.i_am_test)425 return _estimator_spec(426 expected_features, expected_labels, features, labels, mode)427 partial_model_fn = functools.partial(428 _model_fn, foo=expected_foo, bar=expected_bar)429 est = estimator.Estimator(430 model_fn=partial_model_fn, params=expected_params,431 config=expected_config)432 self.assertEqual(0, model_fn_call_count[0])433 est.train(434 input_fn=_make_input_fn(expected_features, expected_labels), steps=1)435 self.assertEqual(1, model_fn_call_count[0])436 def test_model_fn_must_return_estimator_spec(self):437 def model_fn(features, labels):438 _, _ = features, labels439 return 'NotGoodNotGood'440 est = estimator.Estimator(model_fn=model_fn)441 with self.assertRaisesRegexp(ValueError, 'EstimatorSpec'):442 est.train(dummy_input_fn, steps=1)443 def test_run_train_op_and_saves_at_the_end(self):444 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)445 est.train(dummy_input_fn, steps=5)446 self.assertEqual(447 5, estimator._load_global_step_from_checkpoint_dir(est.model_dir))448 def test_loss_summary(self):449 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer,450 config=run_config.RunConfig(save_summary_steps=1))451 est.train(dummy_input_fn, steps=1)452 # Make sure nothing is stuck in limbo.453 writer_cache.FileWriterCache.clear()454 if check_eventfile_for_keyword('loss', est):455 return456 self.fail('{} should be part of reported summaries.'.format('loss'))457 def test_latest_checkpoint(self):458 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)459 self.assertIsNone(est.latest_checkpoint())460 est.train(dummy_input_fn, steps=5)461 self.assertIsNotNone(est.latest_checkpoint())462 self.assertTrue(est.latest_checkpoint().startswith(est.model_dir))463 def test_steps_and_saves_reloads(self):464 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)465 est.train(dummy_input_fn, steps=5)466 self.assertEqual(467 5, estimator._load_global_step_from_checkpoint_dir(est.model_dir))468 est.train(dummy_input_fn, steps=5)469 self.assertEqual(470 10, estimator._load_global_step_from_checkpoint_dir(est.model_dir))471 def test_max_step(self):472 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)473 est.train(dummy_input_fn, max_steps=5)474 self.assertEqual(475 5, estimator._load_global_step_from_checkpoint_dir(est.model_dir))476 est.train(dummy_input_fn, max_steps=5)477 self.assertEqual(478 5, estimator._load_global_step_from_checkpoint_dir(est.model_dir))479 def test_checkpoint_contains_relative_paths(self):480 tmpdir = tempfile.mkdtemp()481 est = estimator.Estimator(482 model_dir=tmpdir,483 model_fn=model_fn_global_step_incrementer)484 est.train(dummy_input_fn, steps=5)485 checkpoint_file_content = file_io.read_file_to_string(486 os.path.join(tmpdir, 'checkpoint'))487 ckpt = checkpoint_state_pb2.CheckpointState()488 text_format.Merge(checkpoint_file_content, ckpt)489 self.assertEqual(ckpt.model_checkpoint_path, 'model.ckpt-5')490 self.assertAllEqual(491 ['model.ckpt-1', 'model.ckpt-5'], ckpt.all_model_checkpoint_paths)492 def test_train_save_copy_reload(self):493 tmpdir = tempfile.mkdtemp()494 model_dir1 = os.path.join(tmpdir, 'model_dir1')495 est1 = estimator.Estimator(496 model_dir=model_dir1,497 model_fn=model_fn_global_step_incrementer)498 est1.train(dummy_input_fn, steps=5)499 # We have to clear the cache before we can rename the directory,500 # otherwise open file handles will prevent the delete on Windows.501 writer_cache.FileWriterCache.clear()502 model_dir2 = os.path.join(tmpdir, 'model_dir2')503 os.renames(model_dir1, model_dir2)504 est2 = estimator.Estimator(505 model_dir=model_dir2,506 model_fn=model_fn_global_step_incrementer)507 self.assertEqual(508 5, estimator._load_global_step_from_checkpoint_dir(est2.model_dir))509 est2.train(dummy_input_fn, steps=5)510 self.assertEqual(511 10, estimator._load_global_step_from_checkpoint_dir(est2.model_dir))512 def test_steps0_raises_error(self):513 est = estimator.Estimator(514 model_fn=_model_fn_with_eval_metric_ops)515 with self.assertRaisesRegexp(ValueError, 'Must specify steps > 0'):516 est.train(dummy_input_fn, steps=0)517 def test_steps_negative_raises_error(self):518 est = estimator.Estimator(519 model_fn=_model_fn_with_eval_metric_ops)520 with self.assertRaisesRegexp(ValueError, 'Must specify steps > 0'):521 est.train(dummy_input_fn, steps=-1)522 def test_max_steps0_raises_error(self):523 est = estimator.Estimator(524 model_fn=_model_fn_with_eval_metric_ops)525 with self.assertRaisesRegexp(ValueError, 'Must specify max_steps > 0'):526 est.train(dummy_input_fn, max_steps=0)527 def test_max_steps_negative_raises_error(self):528 est = estimator.Estimator(529 model_fn=_model_fn_with_eval_metric_ops)530 with self.assertRaisesRegexp(ValueError, 'Must specify max_steps > 0'):531 est.train(dummy_input_fn, max_steps=-1)532 def test_scaffold_is_used(self):533 self.is_init_fn_called = False534 def _init_fn(scaffold, sess):535 _, _ = scaffold, sess536 self.is_init_fn_called = True537 def _model_fn_scaffold(features, labels, mode):538 _, _ = features, labels539 return model_fn_lib.EstimatorSpec(540 mode=mode,541 loss=constant_op.constant(0.),542 train_op=state_ops.assign_add(training.get_global_step(), 1),543 scaffold=training.Scaffold(init_fn=_init_fn))544 est = estimator.Estimator(model_fn=_model_fn_scaffold)545 est.train(dummy_input_fn, steps=1)546 self.assertTrue(self.is_init_fn_called)547 def test_hooks_should_be_session_run_hook(self):548 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)549 with self.assertRaisesRegexp(TypeError, 'must be a SessionRunHook'):550 est.train(dummy_input_fn, steps=1, hooks=['NotAHook'])551 def test_training_hooks_are_used(self):552 chief_hook = test.mock.MagicMock(553 wraps=training.SessionRunHook(), spec=training.SessionRunHook)554 hook = test.mock.MagicMock(555 wraps=training.SessionRunHook(), spec=training.SessionRunHook)556 def _model_fn_hooks(features, labels, mode):557 _, _ = features, labels558 return model_fn_lib.EstimatorSpec(559 mode=mode,560 loss=constant_op.constant(0.),561 train_op=state_ops.assign_add(training.get_global_step(), 1),562 training_chief_hooks=[chief_hook],563 training_hooks=[hook])564 est = estimator.Estimator(model_fn=_model_fn_hooks)565 self.assertFalse(chief_hook.begin.called)566 self.assertFalse(hook.begin.called)567 est.train(dummy_input_fn, steps=1)568 self.assertTrue(chief_hook.begin.called)569 self.assertTrue(hook.begin.called)570 def test_saving_listeners_are_used(self):571 listener = test.mock.Mock(spec=training.CheckpointSaverListener)572 est = estimator.Estimator(573 model_fn=model_fn_global_step_incrementer,574 config=run_config.RunConfig(save_checkpoints_steps=10))575 est.train(dummy_input_fn, steps=26, saving_listeners=[listener])576 self.assertEqual(4, listener.before_save.call_count)577 self.assertEqual(4, listener.after_save.call_count)578 def test_saver_hook_should_exist_to_use_saving_listeners(self):579 listener = test.mock.Mock(spec=training.CheckpointSaverListener)580 est = estimator.Estimator(581 model_fn=model_fn_global_step_incrementer,582 config=run_config.RunConfig(save_checkpoints_steps=None,583 save_checkpoints_secs=None))584 with self.assertRaisesRegexp(585 ValueError, 'CheckpointSaverHook to use saving_listeners'):586 est.train(dummy_input_fn, steps=1, saving_listeners=[listener])587 def test_listeners_should_be_listeners(self):588 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)589 with self.assertRaisesRegexp(590 TypeError, 'must be a list of CheckpointSaverListener'):591 est.train(dummy_input_fn, steps=1, saving_listeners=['not-a-listener'])592 def test_chief_only_hook_should_not_be_called_on_non_chief(self):593 chief_hook = test.mock.MagicMock(594 wraps=training.SessionRunHook(), spec=training.SessionRunHook)595 hook = test.mock.MagicMock(596 wraps=training.SessionRunHook(), spec=training.SessionRunHook)597 def _model_fn_hooks(features, labels, mode):598 _, _ = features, labels599 return model_fn_lib.EstimatorSpec(600 mode=mode,601 loss=constant_op.constant(0.),602 train_op=state_ops.assign_add(training.get_global_step(), 1),603 training_chief_hooks=[chief_hook],604 training_hooks=[hook])605 class NonChiefRunConfig(run_config.RunConfig):606 @property607 def is_chief(self): # pylint: disable=g-wrong-blank-lines608 return False609 # Mocking the SessionManager.wait_for_session, so that worker doesn't wait610 # for chief.611 def get_initialized_session(*args, **kwargs):612 # Session doesn't take 'max_wait_secs' argument.613 kwargs.pop('max_wait_secs', None)614 scaffold = training.Scaffold().finalize()615 sess = session.Session(*args, **kwargs)616 sess.run(scaffold.init_op)617 return sess618 with test.mock.patch.object(619 training.SessionManager,620 'wait_for_session',621 side_effect=get_initialized_session):622 est = estimator.Estimator(623 model_fn=_model_fn_hooks, config=NonChiefRunConfig())624 self.assertFalse(chief_hook.begin.called)625 self.assertFalse(hook.begin.called)626 est.train(dummy_input_fn, steps=1)627 self.assertFalse(chief_hook.begin.called)628 self.assertTrue(hook.begin.called)629 def test_features_labels_mode(self):630 given_features = {'test-features': [[1], [1]]}631 given_labels = {'test-labels': [[1], [1]]}632 def _input_fn():633 return given_features, given_labels634 def _model_fn(features, labels, mode):635 self.features, self.labels, self.mode = features, labels, mode636 return model_fn_lib.EstimatorSpec(637 mode=mode,638 loss=constant_op.constant(0.),639 train_op=state_ops.assign_add(training.get_global_step(), 1),640 predictions=constant_op.constant([[0.]]))641 est = estimator.Estimator(model_fn=_model_fn)642 est.train(_input_fn, steps=1)643 self.assertEqual(given_features, self.features)644 self.assertEqual(given_labels, self.labels)645 self.assertEqual(model_fn_lib.ModeKeys.TRAIN, self.mode)646 def test_graph_initialization_global_step_and_random_seed(self):647 expected_random_seed = run_config.RunConfig().tf_random_seed648 def _model_fn(features, labels, mode):649 _, _, _ = features, labels, mode650 self.assertIsNotNone(training.get_global_step())651 self.assertEqual(expected_random_seed, ops.get_default_graph().seed)652 return model_fn_lib.EstimatorSpec(653 mode=mode,654 loss=constant_op.constant(0.),655 train_op=state_ops.assign_add(training.get_global_step(), 1),656 predictions=constant_op.constant([[0.]]))657 est = estimator.Estimator(model_fn=_model_fn)658 est.train(dummy_input_fn, steps=1)659def _model_fn_with_eval_metric_ops(features, labels, mode, params):660 _, _ = features, labels661 metric_name = params.get('metric_name') or 'metric'662 metric_value = params.get('metric_value') or 2.663 global_step = training.get_global_step()664 loss = constant_op.constant(1.)665 metric_update_op = loss.op666 metric_tensor = control_flow_ops.with_dependencies(667 [metric_update_op], constant_op.constant(metric_value))668 return model_fn_lib.EstimatorSpec(669 mode,670 loss=loss,671 predictions={'predictions': constant_op.constant(1.)},672 train_op=state_ops.assign_add(global_step, 1),673 eval_metric_ops={metric_name: (metric_tensor, metric_update_op)})674class _StepCounterHook(session_run_hook.SessionRunHook):675 """Hooks that counts the number of times it is called."""676 def __init__(self):677 self._steps = 0678 def before_run(self, run_context):679 del run_context680 self._steps += 1681 @property682 def steps(self):683 return self._steps684class EstimatorGetVariablesTest(test.TestCase):685 def test_model_should_be_trained(self):686 def _model_fn(features, labels, mode):687 _, _ = features, labels688 variables.Variable(1., name='one')689 return model_fn_lib.EstimatorSpec(690 mode=mode,691 loss=constant_op.constant(0.),692 train_op=state_ops.assign_add(training.get_global_step(), 1))693 est = estimator.Estimator(model_fn=_model_fn)694 with self.assertRaisesRegexp(ValueError, 'not find trained model'):695 est.get_variable_names()696 with self.assertRaisesRegexp(ValueError, 'not find trained model'):697 est.get_variable_value('one')698 def test_get_variable_utils(self):699 def _model_fn(features, labels, mode):700 _, _ = features, labels701 variables.Variable(1., name='one')702 variables.Variable(3., name='three')703 return model_fn_lib.EstimatorSpec(704 mode=mode,705 loss=constant_op.constant(0.),706 train_op=state_ops.assign_add(training.get_global_step(), 1))707 est = estimator.Estimator(model_fn=_model_fn)708 est.train(input_fn=dummy_input_fn, steps=1)709 self.assertEqual(710 set(['one', 'three', 'global_step']), set(est.get_variable_names()))711 self.assertEqual(1., est.get_variable_value('one'))712 self.assertEqual(3., est.get_variable_value('three'))713class EstimatorEvaluateTest(test.TestCase):714 def test_input_fn_args(self):715 expected_params = {'batch_size': 10}716 expected_config = run_config.RunConfig().replace(tf_random_seed=4321)717 input_fn_call_count = [0]718 def _model_fn(features, labels, mode, params, config):719 del params, config720 return model_fn_global_step_incrementer(features, labels, mode)721 def _input_fn(params, config):722 input_fn_call_count[0] += 1723 self.assertEqual(expected_params, params)724 self.assertEqual(4321, config.tf_random_seed)725 return dummy_input_fn()726 est = estimator.Estimator(model_fn=_model_fn,727 params=expected_params,728 config=expected_config)729 est.train(dummy_input_fn, steps=1)730 self.assertEqual(0, input_fn_call_count[0])731 est.evaluate(_input_fn, steps=1)732 self.assertEqual(1, input_fn_call_count[0])733 def test_model_fn_must_return_estimator_spec(self):734 def _model_fn(features, labels, mode):735 _, _ = features, labels736 if mode == model_fn_lib.ModeKeys.EVAL:737 return 'NotGoodNotGood'738 return model_fn_lib.EstimatorSpec(739 mode,740 loss=constant_op.constant(1.),741 train_op=state_ops.assign_add(training.get_global_step(), 1))742 est = estimator.Estimator(model_fn=_model_fn)743 est.train(dummy_input_fn, steps=1)744 with self.assertRaisesRegexp(745 ValueError, 'model_fn should return an EstimatorSpec'):746 est.evaluate(dummy_input_fn, steps=1)747 def test_no_trained_model(self):748 est = estimator.Estimator(model_fn=_model_fn_with_eval_metric_ops)749 with self.assertRaisesRegexp(750 ValueError, 'Could not find trained model in model_dir'):751 est.evaluate(dummy_input_fn, steps=1)752 def test_scores(self):753 est = estimator.Estimator(754 model_fn=_model_fn_with_eval_metric_ops,755 params={756 'metric_name': 'metric',757 'metric_value': 2.})758 est.train(dummy_input_fn, steps=5)759 scores = est.evaluate(dummy_input_fn, steps=1)760 self.assertIn('metric', scores)761 self.assertAlmostEqual(2., scores['metric'])762 def test_tuple_metrics(self):763 def _model_fn(features, labels, mode):764 del features # unused765 del labels766 return model_fn_lib.EstimatorSpec(767 mode,768 train_op=state_ops.assign_add(training.get_global_step(), 1),769 loss=constant_op.constant(1.),770 eval_metric_ops={771 'nested_metric': (772 ((constant_op.constant(2.), constant_op.constant(1)),773 constant_op.constant(3., dtype=dtypes.float64)),774 control_flow_ops.no_op())})775 est = estimator.Estimator(model_fn=_model_fn)776 est.train(dummy_input_fn, steps=1)777 evaluation = est.evaluate(dummy_input_fn, steps=1)778 ((two_float, one_integer), three_double) = evaluation['nested_metric']779 self.assertAlmostEqual(2., two_float)780 self.assertEqual(1, one_integer)781 self.assertAlmostEqual(3., three_double)782 def test_steps0_raises_error(self):783 est = estimator.Estimator(784 model_fn=_model_fn_with_eval_metric_ops)785 est.train(dummy_input_fn, steps=5)786 with self.assertRaisesRegexp(ValueError, 'Must specify steps > 0'):787 est.evaluate(dummy_input_fn, steps=0)788 def test_steps_negative_raises_error(self):789 est = estimator.Estimator(790 model_fn=_model_fn_with_eval_metric_ops)791 est.train(dummy_input_fn, steps=5)792 with self.assertRaisesRegexp(ValueError, 'Must specify steps > 0'):793 est.evaluate(dummy_input_fn, steps=-1)794 def test_global_step_metric_raises_error(self):795 est = estimator.Estimator(796 model_fn=_model_fn_with_eval_metric_ops,797 params={798 'metric_name': 'global_step',799 'metric_value': 2.})800 est.train(dummy_input_fn, steps=5)801 with self.assertRaisesRegexp(802 ValueError, 'Metric with name `global_step` is not allowed'):803 est.evaluate(dummy_input_fn, steps=1)804 def test_global_step_is_reported(self):805 est = estimator.Estimator(806 model_fn=_model_fn_with_eval_metric_ops,807 params={'metric_name': 'metric',808 'metric_value': 2.})809 est.train(dummy_input_fn, steps=5)810 scores = est.evaluate(dummy_input_fn, steps=1)811 self.assertIn('global_step', scores)812 self.assertEqual(5, scores['global_step'])813 def test_loss_metric_is_reported(self):814 def _model_fn_with_incremental_loss(features, labels, mode):815 _, _ = features, labels816 local_weight = variables.Variable(817 0., name='local_weight', collections=[ops.GraphKeys.LOCAL_VARIABLES])818 # Loss will be 2, 4, 6, ...819 loss = 2 * state_ops.assign_add(local_weight, 1.)820 return model_fn_lib.EstimatorSpec(821 mode,822 loss=loss,823 train_op=state_ops.assign_add(training.get_global_step(), 1))824 est = estimator.Estimator(model_fn=_model_fn_with_incremental_loss)825 est.train(dummy_input_fn, steps=1)826 scores = est.evaluate(dummy_input_fn, steps=5)827 self.assertIn(model_fn_lib.LOSS_METRIC_KEY, scores)828 # Average loss will be (2 + 4 + 6 + 8 + 10)/5=6829 self.assertAlmostEqual(6., scores[model_fn_lib.LOSS_METRIC_KEY])830 def test_hooks_should_be_session_run_hook(self):831 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)832 est.train(dummy_input_fn, steps=1)833 with self.assertRaisesRegexp(TypeError, 'must be a SessionRunHook'):834 est.evaluate(dummy_input_fn, steps=5, hooks=['NotAHook'])835 def test_hooks_are_used(self):836 step_counter_hook = _StepCounterHook()837 est = estimator.Estimator(model_fn=_model_fn_with_eval_metric_ops)838 est.train(dummy_input_fn, steps=1)839 est.evaluate(dummy_input_fn, steps=5, hooks=[step_counter_hook])840 self.assertEqual(5, step_counter_hook.steps)841 def test_evaluate_from_checkpoint(self):842 params = {843 'metric_name': 'metric',844 'metric_value': 2.}845 est1 = estimator.Estimator(846 model_fn=_model_fn_with_eval_metric_ops,847 params=params)848 est1.train(dummy_input_fn, steps=5)849 est2 = estimator.Estimator(850 model_fn=_model_fn_with_eval_metric_ops,851 params=params)852 scores = est2.evaluate(853 dummy_input_fn, steps=1, checkpoint_path=est1.latest_checkpoint())854 self.assertEqual(5, scores['global_step'])855 def test_scaffold_is_used(self):856 def _model_fn_scaffold(features, labels, mode):857 _, _ = features, labels858 variables.Variable(1., name='weight')859 real_saver = saver.Saver()860 self.mock_saver = test.mock.Mock(861 wraps=real_saver, saver_def=real_saver.saver_def)862 return model_fn_lib.EstimatorSpec(863 mode=mode,864 predictions=constant_op.constant([[1.]]),865 loss=constant_op.constant(0.),866 train_op=state_ops.assign_add(training.get_global_step(), 1),867 scaffold=training.Scaffold(saver=self.mock_saver))868 est = estimator.Estimator(model_fn=_model_fn_scaffold)869 est.train(dummy_input_fn, steps=1)870 est.evaluate(dummy_input_fn, steps=1)871 self.assertTrue(self.mock_saver.restore.called)872 def test_features_labels_mode(self):873 given_features = {'test-features': [[1], [1]]}874 given_labels = {'test-labels': [[1], [1]]}875 def _input_fn():876 return given_features, given_labels877 def _model_fn(features, labels, mode):878 self.features, self.labels, self.mode = features, labels, mode879 return model_fn_lib.EstimatorSpec(880 mode=mode,881 loss=constant_op.constant(0.),882 train_op=state_ops.assign_add(training.get_global_step(), 1),883 predictions=constant_op.constant([[0.]]))884 est = estimator.Estimator(model_fn=_model_fn)885 est.train(_input_fn, steps=1)886 est.evaluate(_input_fn, steps=1)887 self.assertEqual(given_features, self.features)888 self.assertEqual(given_labels, self.labels)889 self.assertEqual(model_fn_lib.ModeKeys.EVAL, self.mode)890 def test_graph_initialization_global_step_and_random_seed(self):891 expected_random_seed = run_config.RunConfig().tf_random_seed892 def _model_fn(features, labels, mode):893 _, _, _ = features, labels, mode894 self.assertIsNotNone(training.get_global_step())895 self.assertEqual(expected_random_seed, ops.get_default_graph().seed)896 return model_fn_lib.EstimatorSpec(897 mode=mode,898 loss=constant_op.constant(0.),899 train_op=state_ops.assign_add(training.get_global_step(), 1),900 predictions=constant_op.constant([[0.]]))901 est = estimator.Estimator(model_fn=_model_fn)902 est.train(dummy_input_fn, steps=1)903 est.evaluate(dummy_input_fn, steps=1)904 def test_evaluation_hooks_are_used(self):905 hook = test.mock.MagicMock(906 wraps=training.SessionRunHook(), spec=training.SessionRunHook)907 def _model_fn_hooks(features, labels, mode):908 _, _ = features, labels909 return model_fn_lib.EstimatorSpec(910 mode=mode,911 loss=constant_op.constant(0.),912 train_op=state_ops.assign_add(training.get_global_step(), 1),913 evaluation_hooks=[hook])914 est = estimator.Estimator(model_fn=_model_fn_hooks)915 est.train(dummy_input_fn, steps=1)916 self.assertFalse(hook.begin.called)917 est.evaluate(dummy_input_fn, steps=1)918 self.assertTrue(hook.begin.called)919 def test_summary_writing_with_summary_proto(self):920 def model_fn_global_step_incrementer_image(features, labels, mode):921 _, _ = features, labels922 global_step = training.get_global_step()923 image = array_ops.zeros([1, 3, 3, 1])924 eval_metric_ops = {925 'image': (summary.image('image', image, max_outputs=1),926 constant_op.constant(1))927 }928 return model_fn_lib.EstimatorSpec(929 mode,930 loss=constant_op.constant(1.),931 train_op=state_ops.assign_add(global_step, 1),932 eval_metric_ops=eval_metric_ops)933 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer_image,934 config=run_config.RunConfig(save_summary_steps=1))935 est.train(dummy_input_fn, steps=200)936 est.evaluate(937 input_fn=dummy_input_fn,938 steps=200,939 )940 # Make sure nothing is stuck in limbo.941 writer_cache.FileWriterCache.clear()942 # Get last Event written.943 if check_eventfile_for_keyword('image', est):944 return945 self.fail('{} should be part of reported summaries.'.format('image'))946class EstimatorPredictTest(test.TestCase):947 def test_input_fn_args(self):948 expected_params = {'batch_size': 10}949 expected_config = run_config.RunConfig().replace(tf_random_seed=4321)950 input_fn_call_count = [0]951 def _model_fn(features, labels, mode, params, config):952 del features, labels, params, config953 return model_fn_lib.EstimatorSpec(954 mode,955 loss=constant_op.constant(0.),956 train_op=state_ops.assign_add(training.get_global_step(), 1),957 predictions=constant_op.constant([[10.]]))958 def _input_fn(params, config):959 input_fn_call_count[0] += 1960 self.assertEqual(expected_params, params)961 self.assertEqual(4321, config.tf_random_seed)962 return dummy_input_fn()963 est = estimator.Estimator(model_fn=_model_fn,964 params=expected_params,965 config=expected_config)966 est.train(dummy_input_fn, steps=1)967 self.assertEqual(0, input_fn_call_count[0])968 next(est.predict(_input_fn))969 self.assertEqual(1, input_fn_call_count[0])970 def test_no_trained_model_in_model_dir(self):971 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)972 with self.assertRaisesRegexp(ValueError,973 'Could not find trained model in model_dir'):974 next(est.predict(dummy_input_fn))975 def test_no_trained_model_invalid_checkpoint_path(self):976 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)977 with self.assertRaises(ValueError):978 next(979 est.predict(980 dummy_input_fn,981 checkpoint_path=saver.latest_checkpoint('fakedir')))982 def test_tensor_predictions(self):983 def _model_fn(features, labels, mode):984 _, _ = features, labels985 return model_fn_lib.EstimatorSpec(986 mode,987 loss=constant_op.constant(0.),988 train_op=state_ops.assign_add(training.get_global_step(), 1),989 predictions=constant_op.constant([[10.]]))990 est = estimator.Estimator(model_fn=_model_fn)991 est.train(dummy_input_fn, steps=1)992 self.assertEqual(10., next(est.predict(dummy_input_fn)))993 def test_warn_if_no_queue_runner(self):994 def _model_fn(features, labels, mode):995 _, _ = features, labels996 return model_fn_lib.EstimatorSpec(997 mode,998 loss=constant_op.constant(0.),999 train_op=state_ops.assign_add(training.get_global_step(), 1),1000 predictions=constant_op.constant([[10.]]))1001 est = estimator.Estimator(model_fn=_model_fn)1002 est.train(dummy_input_fn, steps=1)1003 with test.mock.patch.object(logging, 'warning') as mock_log:1004 next(est.predict(dummy_input_fn))1005 self.assertRegexpMatches(1006 str(mock_log.call_args),1007 'Input graph does not.*contain a QueueRunner.')1008 def test_skip_warn_if_dataset_returns_features(self):1009 def _model_fn(features, labels, mode):1010 _, _ = features, labels1011 return model_fn_lib.EstimatorSpec(1012 mode,1013 loss=constant_op.constant(0.),1014 train_op=state_ops.assign_add(training.get_global_step(), 1),1015 predictions=constant_op.constant([[10.]]))1016 def _input_fn():1017 it = dataset_ops.Dataset.from_tensors([1]).make_one_shot_iterator()1018 return it.get_next()1019 est = estimator.Estimator(model_fn=_model_fn)1020 est.train(dummy_input_fn, steps=1)1021 with test.mock.patch.object(logging, 'warning') as mock_log:1022 next(est.predict(_input_fn))1023 # The warning should not have keyword QueueRunner.1024 self.assertRegexpMatches(str(mock_log.call_args), '^((?!QueueRunner).)*$')1025 def test_skip_warn_if_dataset_returns_features_dict(self):1026 def _model_fn(features, labels, mode):1027 _, _ = features, labels1028 return model_fn_lib.EstimatorSpec(1029 mode,1030 loss=constant_op.constant(0.),1031 train_op=state_ops.assign_add(training.get_global_step(), 1),1032 predictions=constant_op.constant([[10.]]))1033 def _input_fn():1034 it = dataset_ops.Dataset.from_tensors([1]).make_one_shot_iterator()1035 features = {'age': it.get_next()}1036 return features1037 est = estimator.Estimator(model_fn=_model_fn)1038 est.train(dummy_input_fn, steps=1)1039 with test.mock.patch.object(logging, 'warning') as mock_log:1040 next(est.predict(_input_fn))1041 # The warning should not have keyword QueueRunner.1042 self.assertRegexpMatches(str(mock_log.call_args), '^((?!QueueRunner).)*$')1043 def test_input_fn_can_return_just_features(self):1044 def _model_fn(features, labels, mode):1045 _, _ = features, labels1046 return model_fn_lib.EstimatorSpec(1047 mode,1048 loss=constant_op.constant(0.),1049 train_op=state_ops.assign_add(training.get_global_step(), 1),1050 predictions=constant_op.constant([[10.]]))1051 est = estimator.Estimator(model_fn=_model_fn)1052 est.train(dummy_input_fn, steps=1)1053 def _only_features():1054 return {'x': constant_op.constant([[0.]])}1055 self.assertEqual([10.], next(est.predict(_only_features)))1056 def test_batch_size_mismatch(self):1057 def _model_fn(features, labels, mode):1058 _, _ = features, labels1059 return model_fn_lib.EstimatorSpec(1060 mode,1061 loss=constant_op.constant(0.),1062 train_op=state_ops.assign_add(training.get_global_step(), 1),1063 predictions={1064 'y1': constant_op.constant([[10.]]),1065 'y2': constant_op.constant([[12.], [13]])1066 })1067 est = estimator.Estimator(model_fn=_model_fn)1068 est.train(dummy_input_fn, steps=1)1069 with self.assertRaisesRegexp(ValueError,1070 'Batch length of predictions should be same'):1071 next(est.predict(dummy_input_fn))1072 def test_predict_keys_defined_for_tensor(self):1073 def _model_fn(features, labels, mode):1074 _, _ = features, labels1075 return model_fn_lib.EstimatorSpec(1076 mode,1077 loss=constant_op.constant(0.),1078 train_op=state_ops.assign_add(training.get_global_step(), 1),1079 predictions=constant_op.constant([[10.]]))1080 est = estimator.Estimator(model_fn=_model_fn)1081 est.train(dummy_input_fn, steps=1)1082 with self.assertRaisesRegexp(1083 ValueError,1084 'predict_keys argument is not valid in case of non-dict predictions'):1085 next(est.predict(dummy_input_fn, predict_keys=['y']))1086 def test_predict_keys_does_not_exists(self):1087 def _model_fn(features, labels, mode):1088 _, _ = features, labels1089 return model_fn_lib.EstimatorSpec(1090 mode,1091 loss=constant_op.constant(0.),1092 train_op=state_ops.assign_add(training.get_global_step(), 1),1093 predictions={1094 'y1': constant_op.constant([[10.]]),1095 'y2': constant_op.constant([[12.]])1096 })1097 est = estimator.Estimator(model_fn=_model_fn)1098 est.train(dummy_input_fn, steps=1)1099 with self.assertRaisesRegexp(ValueError,1100 'Expected to run at least one output from'):1101 next(est.predict(dummy_input_fn, predict_keys=['y3']))1102 def test_return_given_predict_keys(self):1103 def _model_fn(features, labels, mode):1104 _, _ = features, labels1105 return model_fn_lib.EstimatorSpec(1106 mode,1107 loss=constant_op.constant(0.),1108 train_op=state_ops.assign_add(training.get_global_step(), 1),1109 predictions={1110 'y1': constant_op.constant([[10.]]),1111 'y2': constant_op.constant([[12.]])1112 })1113 est = estimator.Estimator(model_fn=_model_fn)1114 est.train(dummy_input_fn, steps=1)1115 results = next(est.predict(dummy_input_fn, predict_keys=['y1']))1116 self.assertIn('y1', results)1117 self.assertNotIn('y2', results)1118 def test_yield_rows_of_tensor(self):1119 def _model_fn(features, labels, mode):1120 _, _ = features, labels1121 return model_fn_lib.EstimatorSpec(1122 mode,1123 loss=constant_op.constant(0.),1124 train_op=state_ops.assign_add(training.get_global_step(), 1),1125 predictions=constant_op.constant([[10.], [12.]]))1126 est = estimator.Estimator(model_fn=_model_fn)1127 est.train(dummy_input_fn, steps=1)1128 results = est.predict(dummy_input_fn)1129 self.assertEqual([10.], next(results))1130 self.assertEqual([12.], next(results))1131 def test_yield_rows_of_dict(self):1132 def _model_fn(features, labels, mode):1133 _, _ = features, labels1134 return model_fn_lib.EstimatorSpec(1135 mode,1136 loss=constant_op.constant(0.),1137 train_op=state_ops.assign_add(training.get_global_step(), 1),1138 predictions={1139 'y1': constant_op.constant([[10.], [12]]),1140 'y2': constant_op.constant([[0.], [2.]])1141 })1142 est = estimator.Estimator(model_fn=_model_fn)1143 est.train(dummy_input_fn, steps=1)1144 results = est.predict(dummy_input_fn)1145 self.assertDictEqual({'y1': [10.], 'y2': [0.]}, next(results))1146 self.assertDictEqual({'y1': [12.], 'y2': [2.]}, next(results))1147 def test_hooks_should_be_session_run_hook(self):1148 est = estimator.Estimator(model_fn=model_fn_global_step_incrementer)1149 est.train(dummy_input_fn, steps=1)1150 with self.assertRaisesRegexp(TypeError, 'must be a SessionRunHook'):1151 next(est.predict(dummy_input_fn, hooks=['NotAHook']))1152 def test_hooks_are_used(self):1153 def _model_fn(features, labels, mode):1154 _, _ = features, labels1155 return model_fn_lib.EstimatorSpec(1156 mode,1157 loss=constant_op.constant(0.),1158 train_op=state_ops.assign_add(training.get_global_step(), 1),1159 predictions=constant_op.constant([[10.], [12.]]))1160 step_counter_hook = _StepCounterHook()1161 est = estimator.Estimator(model_fn=_model_fn)1162 est.train(dummy_input_fn, steps=1)1163 results = est.predict(dummy_input_fn, hooks=[step_counter_hook])1164 self.assertEqual(0, step_counter_hook.steps) # not called yet1165 next(results)1166 self.assertEqual(1, step_counter_hook.steps) # first call1167 next(results)1168 self.assertEqual(1, step_counter_hook.steps) # it's in same batch1169 next(results)1170 self.assertEqual(2, step_counter_hook.steps) # next batch1171 def test_predict_from_old_model_dir(self):1172 def _model_fn(features, labels, mode):1173 _, _ = features, labels1174 v = variables.Variable([[16.]], name='weight')1175 prediction = v * 21176 return model_fn_lib.EstimatorSpec(1177 mode,1178 loss=constant_op.constant(0.),1179 train_op=state_ops.assign_add(training.get_global_step(), 1),1180 predictions=prediction)1181 est1 = estimator.Estimator(model_fn=_model_fn)1182 est1.train(dummy_input_fn, steps=1)1183 est2 = estimator.Estimator(model_fn=_model_fn, model_dir=est1.model_dir)1184 self.assertEqual([32.], next(est2.predict(dummy_input_fn)))1185 def test_predict_from_checkpoint_path(self):1186 def _model_fn(features, labels, mode):1187 _, _ = features, labels1188 v = variables.Variable([[16.]], name='weight')1189 prediction = v * 21190 return model_fn_lib.EstimatorSpec(1191 mode,1192 loss=constant_op.constant(0.),1193 train_op=state_ops.assign_add(training.get_global_step(), 1),1194 predictions=prediction)1195 est1 = estimator.Estimator(model_fn=_model_fn)1196 est1.train(dummy_input_fn, steps=1)1197 est2 = estimator.Estimator(model_fn=_model_fn, model_dir=est1.model_dir)1198 self.assertEqual([32.],1199 next(1200 est2.predict(1201 dummy_input_fn,1202 checkpoint_path=est2.latest_checkpoint())))1203 def test_scaffold_is_used(self):1204 def _model_fn_scaffold(features, labels, mode):1205 _, _ = features, labels1206 variables.Variable(1., name='weight')1207 real_saver = saver.Saver()1208 self.mock_saver = test.mock.Mock(1209 wraps=real_saver, saver_def=real_saver.saver_def)1210 return model_fn_lib.EstimatorSpec(1211 mode=mode,1212 predictions=constant_op.constant([[1.]]),1213 loss=constant_op.constant(0.),1214 train_op=state_ops.assign_add(training.get_global_step(), 1),1215 scaffold=training.Scaffold(saver=self.mock_saver))1216 est = estimator.Estimator(model_fn=_model_fn_scaffold)1217 est.train(dummy_input_fn, steps=1)1218 next(est.predict(dummy_input_fn))1219 self.assertTrue(self.mock_saver.restore.called)1220 def test_features_labels_mode(self):1221 given_features = {'test-features': [[1], [1]]}1222 given_labels = {'test-labels': [[1], [1]]}1223 def _input_fn():1224 return given_features, given_labels1225 def _model_fn(features, labels, mode):1226 self.features, self.labels, self.mode = features, labels, mode1227 return model_fn_lib.EstimatorSpec(1228 mode=mode,1229 loss=constant_op.constant(0.),1230 train_op=state_ops.assign_add(training.get_global_step(), 1),1231 predictions=constant_op.constant([[0.]]))1232 est = estimator.Estimator(model_fn=_model_fn)1233 est.train(_input_fn, steps=1)1234 next(est.predict(_input_fn))1235 self.assertEqual(given_features, self.features)1236 self.assertIsNone(self.labels)1237 self.assertEqual(model_fn_lib.ModeKeys.PREDICT, self.mode)1238 def test_graph_initialization_global_step_and_random_seed(self):1239 expected_random_seed = run_config.RunConfig().tf_random_seed1240 def _model_fn(features, labels, mode):1241 _, _, _ = features, labels, mode1242 self.assertIsNotNone(training.get_global_step())1243 self.assertEqual(expected_random_seed, ops.get_default_graph().seed)1244 return model_fn_lib.EstimatorSpec(1245 mode=mode,1246 loss=constant_op.constant(0.),1247 train_op=state_ops.assign_add(training.get_global_step(), 1),1248 predictions=constant_op.constant([[0.]]))1249 est = estimator.Estimator(model_fn=_model_fn)1250 est.train(dummy_input_fn, steps=1)1251 next(est.predict(dummy_input_fn))1252def _model_fn_for_export_tests(features, labels, mode):1253 _, _ = features, labels1254 variables.Variable(1., name='weight')1255 scores = constant_op.constant([3.])1256 classes = constant_op.constant(['wumpus'])1257 update_global_step = state_ops.assign_add(training.get_global_step(), 1)1258 with ops.control_dependencies([update_global_step]):1259 train_op = constant_op.constant(2.)1260 return model_fn_lib.EstimatorSpec(1261 mode,1262 predictions=constant_op.constant(10.),1263 loss=constant_op.constant(1.),1264 train_op=train_op,1265 export_outputs={1266 'test': export_output.ClassificationOutput(scores, classes)})1267def _model_fn_with_saveables_for_export_tests(features, labels, mode):1268 _, _ = features, labels1269 table = saver_test_utils.CheckpointedOp(name='v2')1270 update_global_step = state_ops.assign_add(training.get_global_step(), 1)1271 with ops.control_dependencies([update_global_step]):1272 train_op = table.insert('k1', 30.0)1273 prediction = table.lookup('k1', 0.0)1274 return model_fn_lib.EstimatorSpec(1275 mode,1276 predictions=prediction,1277 loss=constant_op.constant(1.),1278 train_op=train_op,1279 export_outputs={1280 'test': export_output.PredictOutput({'prediction': prediction})})1281_VOCAB_FILE_CONTENT = 'emerson\nlake\npalmer\n'1282_EXTRA_FILE_CONTENT = 'kermit\npiggy\nralph\n'1283class EstimatorExportTest(test.TestCase):1284 def test_export_savedmodel_proto_roundtrip(self):1285 tmpdir = tempfile.mkdtemp()1286 est = estimator.Estimator(model_fn=_model_fn_for_export_tests)1287 est.train(input_fn=dummy_input_fn, steps=1)1288 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1289 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1290 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1291 feature_spec)1292 # Perform the export.1293 export_dir_base = os.path.join(1294 compat.as_bytes(tmpdir), compat.as_bytes('export'))1295 export_dir = est.export_savedmodel(1296 export_dir_base, serving_input_receiver_fn)1297 # Check that all the files are in the right places.1298 self.assertTrue(gfile.Exists(export_dir_base))1299 self.assertTrue(gfile.Exists(export_dir))1300 self.assertTrue(gfile.Exists(os.path.join(1301 compat.as_bytes(export_dir),1302 compat.as_bytes('saved_model.pb'))))1303 self.assertTrue(gfile.Exists(os.path.join(1304 compat.as_bytes(export_dir),1305 compat.as_bytes('variables'))))1306 self.assertTrue(gfile.Exists(os.path.join(1307 compat.as_bytes(export_dir),1308 compat.as_bytes('variables/variables.index'))))1309 self.assertTrue(gfile.Exists(os.path.join(1310 compat.as_bytes(export_dir),1311 compat.as_bytes('variables/variables.data-00000-of-00001'))))1312 # Restore, to validate that the export was well-formed.1313 with ops.Graph().as_default() as graph:1314 with session.Session(graph=graph) as sess:1315 loader.load(sess, [tag_constants.SERVING], export_dir)1316 graph_ops = [x.name for x in graph.get_operations()]1317 self.assertTrue('input_example_tensor' in graph_ops)1318 self.assertTrue('ParseExample/ParseExample' in graph_ops)1319 self.assertTrue('weight' in graph_ops)1320 # Clean up.1321 gfile.DeleteRecursively(tmpdir)1322 def test_export_savedmodel_with_saveables_proto_roundtrip(self):1323 tmpdir = tempfile.mkdtemp()1324 est = estimator.Estimator(1325 model_fn=_model_fn_with_saveables_for_export_tests)1326 est.train(input_fn=dummy_input_fn, steps=1)1327 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1328 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1329 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1330 feature_spec)1331 # Perform the export.1332 export_dir_base = os.path.join(1333 compat.as_bytes(tmpdir), compat.as_bytes('export'))1334 export_dir = est.export_savedmodel(1335 export_dir_base, serving_input_receiver_fn)1336 # Check that all the files are in the right places.1337 self.assertTrue(gfile.Exists(export_dir_base))1338 self.assertTrue(gfile.Exists(export_dir))1339 self.assertTrue(gfile.Exists(os.path.join(1340 compat.as_bytes(export_dir),1341 compat.as_bytes('saved_model.pb'))))1342 self.assertTrue(gfile.Exists(os.path.join(1343 compat.as_bytes(export_dir),1344 compat.as_bytes('variables'))))1345 self.assertTrue(gfile.Exists(os.path.join(1346 compat.as_bytes(export_dir),1347 compat.as_bytes('variables/variables.index'))))1348 self.assertTrue(gfile.Exists(os.path.join(1349 compat.as_bytes(export_dir),1350 compat.as_bytes('variables/variables.data-00000-of-00001'))))1351 # Restore, to validate that the export was well-formed.1352 with ops.Graph().as_default() as graph:1353 with session.Session(graph=graph) as sess:1354 loader.load(sess, [tag_constants.SERVING], export_dir)1355 graph_ops = [x.name for x in graph.get_operations()]1356 self.assertTrue('input_example_tensor' in graph_ops)1357 self.assertTrue('ParseExample/ParseExample' in graph_ops)1358 # Note that the SavedModel builder replaced the Saver with a new one1359 self.assertTrue('save_1/LookupTableImportV2' in graph_ops)1360 # Clean up.1361 gfile.DeleteRecursively(tmpdir)1362 def test_export_savedmodel_assets(self):1363 tmpdir = tempfile.mkdtemp()1364 est = estimator.Estimator(model_fn=_model_fn_for_export_tests)1365 est.train(input_fn=dummy_input_fn, steps=1)1366 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1367 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1368 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1369 feature_spec)1370 # Create a fake asset.1371 vocab_file_name = os.path.join(1372 compat.as_bytes(tmpdir), compat.as_bytes('my_vocab_file'))1373 vocab_file = gfile.GFile(vocab_file_name, mode='w')1374 vocab_file.write(_VOCAB_FILE_CONTENT)1375 vocab_file.close()1376 # hack in an op that uses the asset, in order to test asset export.1377 # this is not actually valid, of course.1378 def serving_input_receiver_with_asset_fn():1379 features, receiver_tensor, _ = serving_input_receiver_fn()1380 filename = ops.convert_to_tensor(vocab_file_name,1381 dtypes.string,1382 name='asset_filepath')1383 ops.add_to_collection(ops.GraphKeys.ASSET_FILEPATHS, filename)1384 features['bogus_filename'] = filename1385 return export.ServingInputReceiver(features, receiver_tensor)1386 # Perform the export.1387 export_dir_base = os.path.join(1388 compat.as_bytes(tmpdir), compat.as_bytes('export'))1389 export_dir = est.export_savedmodel(1390 export_dir_base, serving_input_receiver_with_asset_fn)1391 # Check that the asset files are in the right places.1392 expected_vocab_file_name = os.path.join(1393 compat.as_bytes(export_dir), compat.as_bytes('assets/my_vocab_file'))1394 self.assertTrue(gfile.Exists(os.path.join(1395 compat.as_bytes(export_dir), compat.as_bytes('assets'))))1396 self.assertTrue(gfile.Exists(expected_vocab_file_name))1397 self.assertEqual(1398 compat.as_bytes(_VOCAB_FILE_CONTENT),1399 compat.as_bytes(gfile.GFile(expected_vocab_file_name).read()))1400 # Restore, to validate that the export was well-formed.1401 with ops.Graph().as_default() as graph:1402 with session.Session(graph=graph) as sess:1403 loader.load(sess, [tag_constants.SERVING], export_dir)1404 assets = [1405 x.eval()1406 for x in graph.get_collection(ops.GraphKeys.ASSET_FILEPATHS)1407 ]1408 self.assertItemsEqual([vocab_file_name], assets)1409 graph_ops = [x.name for x in graph.get_operations()]1410 self.assertTrue('input_example_tensor' in graph_ops)1411 self.assertTrue('ParseExample/ParseExample' in graph_ops)1412 self.assertTrue('asset_filepath' in graph_ops)1413 self.assertTrue('weight' in graph_ops)1414 # cleanup1415 gfile.DeleteRecursively(tmpdir)1416 def test_export_savedmodel_extra_assets(self):1417 tmpdir = tempfile.mkdtemp()1418 est = estimator.Estimator(model_fn=_model_fn_for_export_tests)1419 est.train(input_fn=dummy_input_fn, steps=1)1420 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1421 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1422 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1423 feature_spec)1424 # Create a fake asset.1425 extra_file_name = os.path.join(1426 compat.as_bytes(tmpdir), compat.as_bytes('my_extra_file'))1427 extra_file = gfile.GFile(extra_file_name, mode='w')1428 extra_file.write(_EXTRA_FILE_CONTENT)1429 extra_file.close()1430 # Perform the export.1431 assets_extra = {'some/sub/directory/my_extra_file': extra_file_name}1432 export_dir_base = os.path.join(1433 compat.as_bytes(tmpdir), compat.as_bytes('export'))1434 export_dir = est.export_savedmodel(export_dir_base,1435 serving_input_receiver_fn,1436 assets_extra=assets_extra)1437 # Check that the asset files are in the right places.1438 expected_extra_path = os.path.join(1439 compat.as_bytes(export_dir),1440 compat.as_bytes('assets.extra/some/sub/directory/my_extra_file'))1441 self.assertTrue(gfile.Exists(os.path.join(1442 compat.as_bytes(export_dir), compat.as_bytes('assets.extra'))))1443 self.assertTrue(gfile.Exists(expected_extra_path))1444 self.assertEqual(1445 compat.as_bytes(_EXTRA_FILE_CONTENT),1446 compat.as_bytes(gfile.GFile(expected_extra_path).read()))1447 # cleanup1448 gfile.DeleteRecursively(tmpdir)1449 def test_scaffold_is_used_for_saver(self):1450 tmpdir = tempfile.mkdtemp()1451 def _model_fn_scaffold(features, labels, mode):1452 _, _ = features, labels1453 variables.Variable(1., name='weight')1454 real_saver = saver.Saver()1455 self.mock_saver = test.mock.Mock(1456 wraps=real_saver, saver_def=real_saver.saver_def)1457 scores = constant_op.constant([3.])1458 return model_fn_lib.EstimatorSpec(1459 mode=mode,1460 predictions=constant_op.constant([[1.]]),1461 loss=constant_op.constant(0.),1462 train_op=state_ops.assign_add(training.get_global_step(), 1),1463 scaffold=training.Scaffold(saver=self.mock_saver),1464 export_outputs={'test': export_output.ClassificationOutput(scores)})1465 est = estimator.Estimator(model_fn=_model_fn_scaffold)1466 est.train(dummy_input_fn, steps=1)1467 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1468 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1469 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1470 feature_spec)1471 # Perform the export.1472 export_dir_base = os.path.join(1473 compat.as_bytes(tmpdir), compat.as_bytes('export'))1474 est.export_savedmodel(export_dir_base, serving_input_receiver_fn)1475 self.assertTrue(self.mock_saver.restore.called)1476 def test_scaffold_is_used_for_local_init(self):1477 tmpdir = tempfile.mkdtemp()1478 def _model_fn_scaffold(features, labels, mode):1479 _, _ = features, labels1480 my_int = variables.Variable(1, name='my_int',1481 collections=[ops.GraphKeys.LOCAL_VARIABLES])1482 scores = constant_op.constant([3.])1483 with ops.control_dependencies([1484 variables.local_variables_initializer(),1485 lookup_ops.tables_initializer()1486 ]):1487 assign_op = state_ops.assign(my_int, 12345)1488 # local_initSop must be an Operation, not a Tensor.1489 custom_local_init_op = control_flow_ops.group(assign_op)1490 return model_fn_lib.EstimatorSpec(1491 mode=mode,1492 predictions=constant_op.constant([[1.]]),1493 loss=constant_op.constant(0.),1494 train_op=state_ops.assign_add(training.get_global_step(), 1),1495 scaffold=training.Scaffold(local_init_op=custom_local_init_op),1496 export_outputs={'test': export_output.ClassificationOutput(scores)})1497 est = estimator.Estimator(model_fn=_model_fn_scaffold)1498 est.train(dummy_input_fn, steps=1)1499 feature_spec = {'x': parsing_ops.VarLenFeature(dtype=dtypes.int64),1500 'y': parsing_ops.VarLenFeature(dtype=dtypes.int64)}1501 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1502 feature_spec)1503 # Perform the export.1504 export_dir_base = os.path.join(1505 compat.as_bytes(tmpdir), compat.as_bytes('export'))1506 export_dir = est.export_savedmodel(export_dir_base,1507 serving_input_receiver_fn)1508 # Restore, to validate that the custom local_init_op runs.1509 with ops.Graph().as_default() as graph:1510 with session.Session(graph=graph) as sess:1511 loader.load(sess, [tag_constants.SERVING], export_dir)1512 my_int = graph.get_tensor_by_name('my_int:0')1513 my_int_value = sess.run(my_int)1514 self.assertEqual(12345, my_int_value)1515 def test_features_labels_mode(self):1516 given_features = {'test-features': constant_op.constant([[1], [1]])}1517 def serving_input_receiver_fn():1518 return export.ServingInputReceiver(1519 given_features, array_ops.placeholder(dtype=dtypes.string))1520 def _model_fn(features, labels, mode):1521 self.features, self.labels, self.mode = features, labels, mode1522 return model_fn_lib.EstimatorSpec(1523 mode=mode,1524 loss=constant_op.constant(0.),1525 train_op=state_ops.assign_add(training.get_global_step(), 1),1526 predictions=constant_op.constant([[0.]]),1527 export_outputs={1528 'test': export_output.ClassificationOutput(1529 constant_op.constant([[0.]]))1530 })1531 est = estimator.Estimator(model_fn=_model_fn)1532 est.train(dummy_input_fn, steps=1)1533 est.export_savedmodel(tempfile.mkdtemp(), serving_input_receiver_fn)1534 self.assertEqual(given_features, self.features)1535 self.assertIsNone(self.labels)1536 self.assertEqual(model_fn_lib.ModeKeys.PREDICT, self.mode)1537 def test_graph_initialization_global_step_and_random_seed(self):1538 expected_random_seed = run_config.RunConfig().tf_random_seed1539 def _model_fn(features, labels, mode):1540 _, _, _ = features, labels, mode1541 self.assertIsNotNone(training.get_global_step())1542 self.assertEqual(expected_random_seed, ops.get_default_graph().seed)1543 return model_fn_lib.EstimatorSpec(1544 mode=mode,1545 loss=constant_op.constant(0.),1546 train_op=state_ops.assign_add(training.get_global_step(), 1),1547 predictions=constant_op.constant([[0.]]),1548 export_outputs={1549 'test': export_output.ClassificationOutput(1550 constant_op.constant([[0.]]))1551 })1552 def serving_input_receiver_fn():1553 return export.ServingInputReceiver(1554 {'test-features': constant_op.constant([[1], [1]])},1555 array_ops.placeholder(dtype=dtypes.string))1556 est = estimator.Estimator(model_fn=_model_fn)1557 est.train(dummy_input_fn, steps=1)1558 est.export_savedmodel(tempfile.mkdtemp(), serving_input_receiver_fn)1559class EstimatorHookOrderingTest(test.TestCase):1560 def testCustomHooksAreCalledBeforeNanTensorHook(self):1561 def nan_making_model_fn(mode, features, labels):1562 """A graph that generates NaN's for testing."""1563 del features, labels1564 global_step = variables.Variable(1565 0, dtype=dtypes.int64, name='global_step')1566 inc_global_step = state_ops.assign_add(global_step, 1)1567 nan_const = constant_op.constant(np.nan, dtype=dtypes.float32)1568 loss = control_flow_ops.cond(1569 inc_global_step > 1, lambda: nan_const, lambda: 1.0)1570 return model_fn_lib.EstimatorSpec(1571 mode=mode,1572 predictions=global_step.read_value(),1573 loss=loss,1574 train_op=inc_global_step)1575 def empty_input_fn():1576 return dict(), None1577 class AfterRunCountingHook(session_run_hook.SessionRunHook):1578 """Hooks that counts the number of times after_run() is called."""1579 def __init__(self):1580 self.after_run_count = 01581 def after_run(self, run_context, run_values):1582 del run_context, run_values1583 self.after_run_count += 11584 test_hook = AfterRunCountingHook()1585 est = estimator.Estimator(model_fn=nan_making_model_fn)1586 with self.assertRaises(basic_session_run_hooks.NanLossDuringTrainingError):1587 est.train(input_fn=empty_input_fn, steps=2, hooks=[test_hook])1588 self.assertEqual(2, test_hook.after_run_count)1589class EstimatorIntegrationTest(test.TestCase):1590 def test_complete_flow_with_a_simple_linear_model(self):1591 def _model_fn(features, labels, mode):1592 predictions = layers.dense(1593 features['x'], 1, kernel_initializer=init_ops.zeros_initializer())1594 export_outputs = {1595 'predictions': export_output.RegressionOutput(predictions)1596 }1597 if mode == model_fn_lib.ModeKeys.PREDICT:1598 return model_fn_lib.EstimatorSpec(1599 mode, predictions=predictions, export_outputs=export_outputs)1600 loss = losses.mean_squared_error(labels, predictions)1601 train_op = training.GradientDescentOptimizer(learning_rate=0.5).minimize(1602 loss, training.get_global_step())1603 eval_metric_ops = {1604 'absolute_error': metrics_lib.mean_absolute_error(1605 labels, predictions)1606 }1607 return model_fn_lib.EstimatorSpec(1608 mode,1609 predictions=predictions,1610 loss=loss,1611 train_op=train_op,1612 eval_metric_ops=eval_metric_ops,1613 export_outputs=export_outputs)1614 est = estimator.Estimator(model_fn=_model_fn)1615 data = np.linspace(0., 1., 100, dtype=np.float32).reshape(-1, 1)1616 # TRAIN1617 # learn y = x1618 train_input_fn = numpy_io.numpy_input_fn(1619 x={'x': data}, y=data, batch_size=50, num_epochs=None, shuffle=True)1620 est.train(train_input_fn, steps=200)1621 # EVALUTE1622 eval_input_fn = numpy_io.numpy_input_fn(1623 x={'x': data}, y=data, batch_size=50, num_epochs=1, shuffle=True)1624 scores = est.evaluate(eval_input_fn)1625 self.assertEqual(200, scores['global_step'])1626 self.assertGreater(0.1, scores['absolute_error'])1627 # PREDICT1628 predict_input_fn = numpy_io.numpy_input_fn(1629 x={'x': data}, y=None, batch_size=10, num_epochs=1, shuffle=False)1630 predictions = list(est.predict(predict_input_fn))1631 self.assertAllClose(data, predictions, atol=0.01)1632 # EXPORT1633 feature_spec = {'x': parsing_ops.FixedLenFeature([1], dtypes.float32)}1634 serving_input_receiver_fn = export.build_parsing_serving_input_receiver_fn(1635 feature_spec)1636 export_dir = est.export_savedmodel(tempfile.mkdtemp(),1637 serving_input_receiver_fn)1638 self.assertTrue(gfile.Exists(export_dir))1639if __name__ == '__main__':...

Full Screen

Full Screen

redux-saga_v1.x.x.js

Source:redux-saga_v1.x.x.js Github

copy

Full Screen

1// flow-typed signature: 689311caccb0db4742bdff80086a5a092// flow-typed version: c6154227d1/redux-saga_v1.x.x/flow_>=v0.104.x3declare module "redux-saga" {4 // These types are copied directly from the redux libdef.5 // Importing them in this libdef causes a loss in type coverage.6 // * uncomment next line:7 // import type { Middleware} from 'redux';8 // * remove next types9 declare type DispatchAPI<A> = (action: A) => A;10 declare type Dispatch<A: { type: string, ... }> = DispatchAPI<A>;11 declare type MiddlewareAPI<S, A, D = Dispatch<A>> = {12 dispatch: D,13 getState(): S,14 ...15 };16 declare type Middleware<S, A, D = Dispatch<A>> = (api: MiddlewareAPI<S, A, D>) => (next: D) => D;17 //////////////////////////////////////////////////////////////////////////18 declare export var SAGA_LOCATION: "@@redux-saga/LOCATION";19 declare export var CANCEL: "@@redux-saga/CANCEL_PROMISE";20 declare export type TEnd = {| +type: "@@redux-saga/CHANNEL_END" |};21 declare export var END: TEnd;22 declare export var isEnd: {23 (input: TEnd): true,24 (input: mixed): false,25 ...26 };27 declare export type Predicate<T> = (arg: T) => boolean;28 declare export type MulticastChannel<T> = $ReadOnly<{|29 take(cb: (message: T | TEnd) => void, matcher?: Predicate<T>): void,30 put(message: T | TEnd): void,31 close(): void32 |}>;33 declare export interface Buffer<T> {34 isEmpty(): boolean;35 put(message: T): void;36 take(): T | void;37 flush(): Array<T>;38 }39 declare export interface Task<RT> {40 isRunning: () => boolean;41 isCancelled: () => boolean;42 result: () => RT | void;43 error: () => Error | void;44 cancel: () => void;45 toPromise(): Promise<RT>;46 setContext<C: {...}>(props: $Shape<C>): void;47 }48 declare export interface SagaMonitor {49 effectTriggered?: (desc: {50 +effectId: number,51 +parentEffectId: number,52 +label: string,53 +root?: boolean,54 +effect: Effect,55 ...56 }) => void;57 effectResolved?: (effectId: number, result: mixed) => void;58 effectRejected?: (effectId: number, error: any) => void;59 effectCancelled?: (effectId: number) => void;60 actionDispatched?: <A>(action: A) => void;61 }62 declare export type Saga<T> = Generator<Effect, T, any>;63 declare export type Unsubscribe = () => void;64 declare export type Subscribe<T> = (cb: (input: T | TEnd) => void) => Unsubscribe;65 declare export interface TakeableChannel<T> {66 take(cb: (message: T | TEnd) => void): void67 }68 declare export interface PuttableChannel<T> {69 put(message: T | TEnd): void70 }71 declare export interface FlushableChannel<T> {72 flush(cb: (items: Array<T> | TEnd) => void): void73 }74 declare export interface EventChannel<T> {75 take(cb: (message: T | TEnd) => void): void;76 flush(cb: (items: Array<T> | TEnd) => void): void;77 close(): void;78 }79 declare export var eventChannel: <T>(80 subscribe: Subscribe<T>,81 buffer?: Buffer<T>82 ) => EventChannel<T>;83 declare export interface Channel<T> {84 take(cb: (message: T | TEnd) => void): void;85 put(message: T | TEnd): void;86 flush(cb: (items: Array<T> | TEnd) => void): void;87 close(): void;88 }89 declare export function channel<T>(buffer?: Buffer<T>): Channel<T>;90 declare export var buffers: $ReadOnly<{|91 none: <T>() => Buffer<T>,92 fixed: <T>(limit?: number) => Buffer<T>,93 dropping: <T>(limit?: number) => Buffer<T>,94 sliding: <T>(limit?: number) => Buffer<T>,95 expanding: <T>(initialSize?: number) => Buffer<T>96 |}>;97 declare export function multicastChannel<T>(): MulticastChannel<T>;98 declare export function stdChannel<T>(): MulticastChannel<T>;99 declare export type Logger = (level: "info" | "warning" | "error", ...args: Array<any>) => void;100 declare export type EffectMiddleware = (next: (effect: mixed) => void) => (effect: mixed) => void;101 declare export interface PredicateTakeableChannel<T> {102 take(cb: (message: T | TEnd) => void, matcher?: Predicate<T>): void;103 }104 declare type RunSagaOptions<A, S> = {|105 channel?: PredicateTakeableChannel<A>,106 dispatch?: (input: A) => mixed,107 getState?: () => S,108 context?: {...},109 sagaMonitor?: SagaMonitor,110 logger?: Logger,111 effectMiddlewares?: Array<EffectMiddleware>,112 onError?: (error: Error) => void113 |};114 declare export var runSaga: {115 <A, S, R, Fn: () => Saga<R>>(options: RunSagaOptions<A, S>, saga: Fn): Task<R>,116 <A, S, R, T1, Fn: T1 => Saga<R>>(options: RunSagaOptions<A, S>, saga: Fn, T1): Task<R>,117 <A, S, R, T1, T2, Fn: (T1, T2) => Saga<R>>(118 options: RunSagaOptions<A, S>,119 saga: Fn,120 T1,121 T2122 ): Task<R>,123 <A, S, R, T1, T2, T3, Fn: (T1, T2, T3) => Saga<R>>(124 options: RunSagaOptions<A, S>,125 saga: Fn,126 T1,127 T2,128 T3129 ): Task<R>,130 <A, S, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => Saga<R>>(131 options: RunSagaOptions<A, S>,132 saga: Fn,133 T1,134 T2,135 T3,136 T4137 ): Task<R>,138 <A, S, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => Saga<R>>(139 options: RunSagaOptions<A, S>,140 saga: Fn,141 T1,142 T2,143 T3,144 T4,145 T5146 ): Task<R>,147 <A, S, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => Saga<R>>(148 options: RunSagaOptions<A, S>,149 saga: Fn,150 T1,151 T2,152 T3,153 T4,154 T5,155 T6156 ): Task<R>,157 <A, S, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => Saga<R>>(158 options: RunSagaOptions<A, S>,159 saga: Fn,160 T1,161 T2,162 T3,163 T4,164 T5,165 T6,166 T7167 ): Task<R>,168 <A, S, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => Saga<R>>(169 options: RunSagaOptions<A, S>,170 saga: Fn,171 T1,172 T2,173 T3,174 T4,175 T5,176 T6,177 T7,178 T8179 ): Task<R>,180 ...181 };182 declare export type SagaMiddleware<C: {...}> =183 {184 <S, A, D>(api: MiddlewareAPI<S, A, D>): (next: D) => D,185 run: {186 <R, Fn: () => Saga<R>>(saga: Fn): Task<R>,187 <R, T1, Fn: T1 => Saga<R>>(saga: Fn, T1): Task<R>,188 <R, T1, T2, Fn: (T1, T2) => Saga<R>>(saga: Fn, T1, T2): Task<R>,189 <R, T1, T2, T3, Fn: (T1, T2, T3) => Saga<R>>(saga: Fn, T1, T2, T3): Task<R>,190 <R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => Saga<R>>(saga: Fn, T1, T2, T3, T4): Task<R>,191 <R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => Saga<R>>(192 saga: Fn,193 T1,194 T2,195 T3,196 T4,197 T5198 ): Task<R>,199 <R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => Saga<R>>(200 saga: Fn,201 T1,202 T2,203 T3,204 T4,205 T5,206 T6207 ): Task<R>,208 <R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => Saga<R>>(209 saga: Fn,210 T1,211 T2,212 T3,213 T4,214 T5,215 T6,216 T7217 ): Task<R>,218 <R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => Saga<R>>(219 saga: Fn,220 T1,221 T2,222 T3,223 T4,224 T5,225 T6,226 T7,227 T8228 ): Task<R>,229 ...230 },231 setContext: (props: $Shape<C>) => void,232 ...233 };234 declare export type Emit<T> = (input: T) => void;235 declare export type SagaMiddlewareOptions<C: {...}> = {|236 context?: C,237 sagaMonitor?: SagaMonitor,238 logger?: Logger,239 effectMiddlewares?: Array<EffectMiddleware>,240 emitter?: <A>(emit: Emit<A>) => Emit<any>,241 onError?: (error: Error) => void242 |};243 declare function sagaMiddlewareFactory<C>(options?: SagaMiddlewareOptions<C>): SagaMiddleware<C>;244 declare export default typeof sagaMiddlewareFactory;245 // Effect types246 declare export type SubPattern = string | (any => boolean);247 declare export type Pattern = SubPattern | Array<SubPattern>;248 declare export interface IEffect<T, P, C: boolean> {249 +type: T;250 +payload: P;251 +combinator: C;252 }253 declare export type AllTakeEffect<254 M: { maybe: true, ... } | void255 > = IEffect<256 "TAKE",257 $ReadOnly<{|258 pattern: '*',259 ...$Exact<M>260 |}>,261 false262 >;263 declare export type TakeEffect<264 P: { pattern: Pattern, ... } | void,265 C: { channel: TakeableChannel<*>, ... } | void,266 M: { maybe: true, ... } | void267 > = IEffect<268 "TAKE",269 $ReadOnly<{|270 ...$Exact<P>,271 ...$Exact<C>,272 ...$Exact<M>273 |}>,274 false275 >;276 declare export type PutEffect<277 A: {...},278 C: PuttableChannel<*> | null,279 R: { resolve: true, ... } | void280 > = IEffect<281 "PUT",282 $ReadOnly<{|283 action: A,284 channel: C,285 ...$Exact<R>286 |}>,287 false288 >;289 declare export type CallEffect<Ctx, Fn: Function | string, Args: $ReadOnlyArray<*>> = IEffect<290 "CALL",291 $ReadOnly<{|292 context: Ctx,293 fn: Fn,294 args: Args295 |}>,296 false297 >;298 declare export type ForkEffect<299 Ctx,300 Fn: (...args: Array<*>) => *,301 D: { detached: true, ... } | void,302 Args: $ReadOnlyArray<*>303 > = IEffect<304 "FORK",305 $ReadOnly<{|306 context: Ctx,307 fn: Fn,308 args: Args,309 ...$Exact<D>310 |}>,311 false312 >;313 declare export function detach<T1, T2, T3>(314 effect: ForkEffect<T1, T2, *, T3>315 ): ForkEffect<T1, T2, { detached: true, ... }, T3>;316 declare export type CpsEffect<Ctx, Fn: (...args: Array<*>) => *, Args: $ReadOnlyArray<*>> = IEffect<317 "CPS",318 $ReadOnly<{|319 context: Ctx,320 fn: Fn,321 args: Args322 |}>,323 false324 >;325 declare export type JoinEffect<T: Task<*> | Array<Task<*>>> = IEffect<"JOIN", T, false>;326 declare export type SELF_CANCELLATION = "@@redux-saga/SELF_CANCELLATION";327 declare export type CancelEffect<328 T: Task<*> | $ReadOnlyArray<Task<*>> | SELF_CANCELLATION329 > = IEffect<"CANCEL", T, false>;330 declare export type SelectEffect<Fn: Function | void, Args: $ReadOnlyArray<*>> = IEffect<331 "SELECT",332 $ReadOnly<{|333 selector: Fn,334 args: Args335 |}>,336 false337 >;338 declare export type ActionChannelEffect<T, P: Pattern | void, B: Buffer<T> | void> = IEffect<339 "ACTION_CHANNEL",340 $ReadOnly<{|341 buffer: B,342 pattern: P343 |}>,344 false345 >;346 declare export type FlushEffect<CH: FlushableChannel<*>> = IEffect<"FLUSH", CH, false>;347 declare export type CancelledEffect = IEffect<"CANCELLED", {||}, false>;348 declare export type SetContextEffect<T: {...}> = IEffect<"SET_CONTEXT", T, false>;349 declare export type GetContextEffect<T> = IEffect<"GET_CONTEXT", T, false>;350 declare export type RaceEffect<R: { +[name: string]: Effect, ... } | $ReadOnlyArray<Effect>> = IEffect<351 "RACE",352 R,353 true354 >;355 declare export type AllEffect = IEffect<356 "ALL",357 { +[name: string]: Effect, ... } | $ReadOnlyArray<Effect>,358 true359 >;360 declare export type Effect =361 | ActionChannelEffect<*, *, *>362 | AllEffect363 | CallEffect<*, *, *>364 | CancelEffect<*>365 | CancelledEffect366 | CpsEffect<*, *, *>367 | FlushEffect<*>368 | ForkEffect<*, *, *, *>369 | GetContextEffect<*>370 | JoinEffect<*>371 | PutEffect<*, *, *>372 | RaceEffect<*>373 | SelectEffect<*, *>374 | SetContextEffect<*>375 | TakeEffect<*, *, *>376 | AllTakeEffect<*>;377}378declare module "redux-saga/effects" {379 import type {380 ActionChannelEffect,381 AllEffect,382 Buffer,383 CallEffect,384 CancelEffect,385 CancelledEffect,386 Channel,387 CpsEffect,388 Effect,389 FlushEffect,390 ForkEffect,391 GetContextEffect,392 JoinEffect,393 Pattern,394 PutEffect,395 RaceEffect,396 Saga,397 SelectEffect,398 SetContextEffect,399 TakeEffect,400 Task,401 TakeableChannel,402 PuttableChannel,403 FlushableChannel,404 AllTakeEffect,405 } from "redux-saga";406 declare export var effectTypes: $ReadOnly<{|407 TAKE: 'TAKE',408 PUT: 'PUT',409 ALL: 'ALL',410 RACE: 'RACE',411 CALL: 'CALL',412 CPS: 'CPS',413 FORK: 'FORK',414 JOIN: 'JOIN',415 CANCEL: 'CANCEL',416 SELECT: 'SELECT',417 ACTION_CHANNEL: 'ACTION_CHANNEL',418 CANCELLED: 'CANCELLED',419 FLUSH: 'FLUSH',420 GET_CONTEXT: 'GET_CONTEXT',421 SET_CONTEXT: 'SET_CONTEXT'422 |}>;423 declare export var put: {424 <A: {...}>(action: A): PutEffect<A, null, void>,425 <A: {...}, T, CH: PuttableChannel<T>>(channel: CH, action: A): PutEffect<A, CH, void>,426 ...427 };428 declare export var putResolve: {429 <A: {...}>(action: A): PutEffect<A, null, { resolve: true, ... }>,430 <A: {...}, T, CH: PuttableChannel<T>>(channel: CH, action: A): PutEffect<A, CH, { resolve: true, ... }>,431 ...432 };433 declare export var call: {434 // call(fn, ...args)435 <R, Fn: () => R>(Fn): CallEffect<null, Fn, []>,436 <R, T1, Fn: T1 => R>(Fn, T1): CallEffect<null, Fn, [T1]>,437 <R, T1, T2, Fn: (T1, T2) => R>(Fn, T1, T2): CallEffect<null, Fn, [T1, T2]>,438 <R, T1, T2, T3, Fn: (T1, T2, T3) => R>(Fn, T1, T2, T3): CallEffect<null, Fn, [T1, T2, T3]>,439 <R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(440 Fn,441 T1,442 T2,443 T3,444 T4445 ): CallEffect<null, Fn, [T1, T2, T3, T4]>,446 <R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(447 Fn,448 T1,449 T2,450 T3,451 T4,452 T5453 ): CallEffect<null, Fn, [T1, T2, T3, T4, T5]>,454 <R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(455 Fn,456 T1,457 T2,458 T3,459 T4,460 T5,461 T6462 ): CallEffect<null, Fn, [T1, T2, T3, T4, T5, T6]>,463 <R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(464 Fn,465 T1,466 T2,467 T3,468 T4,469 T5,470 T6,471 T7472 ): CallEffect<null, Fn, [T1, T2, T3, T4, T5, T6, T7]>,473 <R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(474 Fn,475 T1,476 T2,477 T3,478 T4,479 T5,480 T6,481 T7,482 T8483 ): CallEffect<null, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,484 // call([context, fn], ...args)485 <Ctx, R, Fn: () => R>(cfn: [Ctx, Fn]): CallEffect<Ctx, Fn, []>,486 <Ctx, R, T1, Fn: T1 => R>(cfn: [Ctx, Fn], T1): CallEffect<Ctx, Fn, [T1]>,487 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(cfn: [Ctx, Fn], T1, T2): CallEffect<Ctx, Fn, [T1, T2]>,488 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(489 cfn: [Ctx, Fn],490 T1,491 T2,492 T3493 ): CallEffect<Ctx, Fn, [T1, T2, T3]>,494 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(495 cfn: [Ctx, Fn],496 T1,497 T2,498 T3,499 T4500 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4]>,501 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(502 cfn: [Ctx, Fn],503 T1,504 T2,505 T3,506 T4,507 T5508 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,509 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(510 cfn: [Ctx, Fn],511 T1,512 T2,513 T3,514 T4,515 T5,516 T6517 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,518 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(519 cfn: [Ctx, Fn],520 T1,521 T2,522 T3,523 T4,524 T5,525 T6,526 T7527 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,528 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(529 cfn: [Ctx, Fn],530 T1,531 T2,532 T3,533 T4,534 T5,535 T6,536 T7,537 T8538 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,539 // call([context, fnName], ...args)540 <R, FnName: string, Fn: () => R, Ctx: { [FnName]: Fn, ... }>(541 cfn: [Ctx, FnName]542 ): CallEffect<Ctx, Fn, []>,543 <R, FnName: string, T1, Fn: T1 => R, Ctx: { [FnName]: Fn, ... }>(544 cfn: [Ctx, FnName],545 T1546 ): CallEffect<Ctx, Fn, [T1]>,547 <R, FnName: string, T1, T2, Fn: (T1, T2) => R, Ctx: { [FnName]: Fn, ... }>(548 cfn: [Ctx, FnName],549 T1,550 T2551 ): CallEffect<Ctx, Fn, [T1, T2]>,552 <R, FnName: string, T1, T2, T3, Fn: (T1, T2, T3) => R, Ctx: { [FnName]: Fn, ... }>(553 cfn: [Ctx, FnName],554 T1,555 T2,556 T3557 ): CallEffect<Ctx, Fn, [T1, T2, T3]>,558 <R, FnName: string, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R, Ctx: { [FnName]: Fn, ... }>(559 cfn: [Ctx, FnName],560 T1,561 T2,562 T3,563 T4564 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4]>,565 <R, FnName: string, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R, Ctx: { [FnName]: Fn, ... }>(566 cfn: [Ctx, FnName],567 T1,568 T2,569 T3,570 T4,571 T5572 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,573 <574 R,575 FnName: string,576 T1,577 T2,578 T3,579 T4,580 T5,581 T6,582 Fn: (T1, T2, T3, T4, T5, T6) => R,583 Ctx: { [FnName]: Fn, ... }584 >(585 cfn: [Ctx, FnName],586 T1,587 T2,588 T3,589 T4,590 T5,591 T6592 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,593 <594 R,595 FnName: string,596 T1,597 T2,598 T3,599 T4,600 T5,601 T6,602 T7,603 Fn: (T1, T2, T3, T4, T5, T6, T7) => R,604 Ctx: { [FnName]: Fn, ... }605 >(606 cfn: [Ctx, FnName],607 T1,608 T2,609 T3,610 T4,611 T5,612 T6,613 T7614 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,615 <616 R,617 FnName: string,618 T1,619 T2,620 T3,621 T4,622 T5,623 T6,624 T7,625 T8,626 Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R,627 Ctx: { [FnName]: Fn, ... }628 >(629 cfn: [Ctx, FnName],630 T1,631 T2,632 T3,633 T4,634 T5,635 T6,636 T7,637 T8638 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,639 // call({context, fn}, ...args)640 <Ctx, R, Fn: () => R>(cfn: {641 context: Ctx,642 fn: Fn,643 ...644 }): CallEffect<Ctx, Fn, []>,645 <Ctx, R, T1, Fn: T1 => R>(cfn: {646 context: Ctx,647 fn: Fn,648 ...649 }, T1): CallEffect<Ctx, Fn, [T1]>,650 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(651 cfn: {652 context: Ctx,653 fn: Fn,654 ...655 },656 T1,657 T2658 ): CallEffect<Ctx, Fn, [T1, T2]>,659 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(660 cfn: {661 context: Ctx,662 fn: Fn,663 ...664 },665 T1,666 T2,667 T3668 ): CallEffect<Ctx, Fn, [T1, T2, T3]>,669 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(670 cfn: {671 context: Ctx,672 fn: Fn,673 ...674 },675 T1,676 T2,677 T3,678 T4679 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4]>,680 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(681 cfn: {682 context: Ctx,683 fn: Fn,684 ...685 },686 T1,687 T2,688 T3,689 T4,690 T5691 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,692 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(693 cfn: {694 context: Ctx,695 fn: Fn,696 ...697 },698 T1,699 T2,700 T3,701 T4,702 T5,703 T6704 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,705 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(706 cfn: {707 context: Ctx,708 fn: Fn,709 ...710 },711 T1,712 T2,713 T3,714 T4,715 T5,716 T6,717 T7718 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,719 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(720 cfn: {721 context: Ctx,722 fn: Fn,723 ...724 },725 T1,726 T2,727 T3,728 T4,729 T5,730 T6,731 T7,732 T8733 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,734 ...735 };736 declare export var apply: {737 // apply(context, fn, args)738 <Ctx, R, Fn: () => R>(Ctx, Fn): CallEffect<Ctx, Fn, []>,739 <Ctx, R, T1, Fn: T1 => R>(Ctx, Fn, T1): CallEffect<Ctx, Fn, [T1]>,740 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(Ctx, Fn, T1, T2): CallEffect<Ctx, Fn, [T1, T2]>,741 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(742 Ctx,743 Fn,744 T1,745 T2,746 T3747 ): CallEffect<Ctx, Fn, [T1, T2, T3]>,748 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(749 Ctx,750 Fn,751 T1,752 T2,753 T3,754 T4755 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4]>,756 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(757 Ctx,758 Fn,759 T1,760 T2,761 T3,762 T4,763 T5764 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,765 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(766 Ctx,767 Fn,768 T1,769 T2,770 T3,771 T4,772 T5,773 T6774 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,775 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(776 Ctx,777 Fn,778 T1,779 T2,780 T3,781 T4,782 T5,783 T6,784 T7785 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,786 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(787 Ctx,788 Fn,789 T1,790 T2,791 T3,792 T4,793 T5,794 T6,795 T7,796 T8797 ): CallEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,798 ...799 };800 declare type NodeCallback<R> = {801 (err: Error): void,802 (err: null | void | false, result: R): void,803 ...804 };805 declare export var cps: {806 // cps(fn, ...args)807 <R, Fn: (NodeCallback<R>) => void>(Fn): CpsEffect<null, Fn, []>,808 <R, T1, Fn: (T1, NodeCallback<R>) => void>(Fn, T1): CpsEffect<null, Fn, [T1]>,809 <R, T1, T2, Fn: (T1, T2, NodeCallback<R>) => void>(Fn, T1, T2): CpsEffect<null, Fn, [T1, T2]>,810 <R, T1, T2, T3, Fn: (T1, T2, T3, NodeCallback<R>) => void>(811 Fn,812 T1,813 T2,814 T3815 ): CpsEffect<null, Fn, [T1, T2, T3]>,816 <R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, NodeCallback<R>) => void>(817 Fn,818 T1,819 T2,820 T3,821 T4822 ): CpsEffect<null, Fn, [T1, T2, T3, T4]>,823 <R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, NodeCallback<R>) => void>(824 Fn,825 T1,826 T2,827 T3,828 T4,829 T5830 ): CpsEffect<null, Fn, [T1, T2, T3, T4, T5]>,831 <R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, NodeCallback<R>) => void>(832 Fn,833 T1,834 T2,835 T3,836 T4,837 T5,838 T6839 ): CpsEffect<null, Fn, [T1, T2, T3, T4, T5, T6]>,840 <R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7, NodeCallback<R>) => void>(841 Fn,842 T1,843 T2,844 T3,845 T4,846 T5,847 T6,848 T7849 ): CpsEffect<null, Fn, [T1, T2, T3, T4, T5, T6, T7]>,850 <851 R,852 T1,853 T2,854 T3,855 T4,856 T5,857 T6,858 T7,859 T8,860 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, NodeCallback<R>) => void861 >(862 Fn,863 T1,864 T2,865 T3,866 T4,867 T5,868 T6,869 T7,870 T8871 ): CpsEffect<null, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,872 // cps([context, fn], ...args)873 <Ctx, R, Fn: (NodeCallback<R>) => void>(cfn: [Ctx, Fn]): CpsEffect<Ctx, Fn, []>,874 <Ctx, R, T1, Fn: (T1, NodeCallback<R>) => void>(cfn: [Ctx, Fn], T1): CpsEffect<Ctx, Fn, [T1]>,875 <Ctx, R, T1, T2, Fn: (T1, T2, NodeCallback<R>) => void>(876 cfn: [Ctx, Fn],877 T1,878 T2879 ): CpsEffect<Ctx, Fn, [T1, T2]>,880 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3, NodeCallback<R>) => void>(881 cfn: [Ctx, Fn],882 T1,883 T2,884 T3885 ): CpsEffect<Ctx, Fn, [T1, T2, T3]>,886 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, NodeCallback<R>) => void>(887 cfn: [Ctx, Fn],888 T1,889 T2,890 T3,891 T4892 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4]>,893 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, NodeCallback<R>) => void>(894 cfn: [Ctx, Fn],895 T1,896 T2,897 T3,898 T4,899 T5900 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,901 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, NodeCallback<R>) => void>(902 cfn: [Ctx, Fn],903 T1,904 T2,905 T3,906 T4,907 T5,908 T6909 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,910 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7, NodeCallback<R>) => void>(911 cfn: [Ctx, Fn],912 T1,913 T2,914 T3,915 T4,916 T5,917 T6,918 T7919 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,920 <921 Ctx,922 R,923 T1,924 T2,925 T3,926 T4,927 T5,928 T6,929 T7,930 T8,931 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, NodeCallback<R>) => void932 >(933 cfn: [Ctx, Fn],934 T1,935 T2,936 T3,937 T4,938 T5,939 T6,940 T7,941 T8942 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,943 // cps({context, fn}, ...args)944 <Ctx, R, Fn: (NodeCallback<R>) => void>(cfn: {945 context: Ctx,946 fn: Fn,947 ...948 }): CpsEffect<Ctx, Fn, []>,949 <Ctx, R, T1, Fn: (T1, NodeCallback<R>) => void>(950 cfn: {951 context: Ctx,952 fn: Fn,953 ...954 },955 T1956 ): CpsEffect<Ctx, Fn, [T1]>,957 <Ctx, R, T1, T2, Fn: (T1, T2, NodeCallback<R>) => void>(958 cfn: {959 context: Ctx,960 fn: Fn,961 ...962 },963 T1,964 T2965 ): CpsEffect<Ctx, Fn, [T1, T2]>,966 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3, NodeCallback<R>) => void>(967 cfn: {968 context: Ctx,969 fn: Fn,970 ...971 },972 T1,973 T2,974 T3975 ): CpsEffect<Ctx, Fn, [T1, T2, T3]>,976 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, NodeCallback<R>) => void>(977 cfn: {978 context: Ctx,979 fn: Fn,980 ...981 },982 T1,983 T2,984 T3,985 T4986 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4]>,987 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, NodeCallback<R>) => void>(988 cfn: {989 context: Ctx,990 fn: Fn,991 ...992 },993 T1,994 T2,995 T3,996 T4,997 T5998 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5]>,999 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, NodeCallback<R>) => void>(1000 cfn: {1001 context: Ctx,1002 fn: Fn,1003 ...1004 },1005 T1,1006 T2,1007 T3,1008 T4,1009 T5,1010 T61011 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6]>,1012 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7, NodeCallback<R>) => void>(1013 cfn: {1014 context: Ctx,1015 fn: Fn,1016 ...1017 },1018 T1,1019 T2,1020 T3,1021 T4,1022 T5,1023 T6,1024 T71025 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7]>,1026 <1027 Ctx,1028 R,1029 T1,1030 T2,1031 T3,1032 T4,1033 T5,1034 T6,1035 T7,1036 T8,1037 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, NodeCallback<R>) => void1038 >(1039 cfn: {1040 context: Ctx,1041 fn: Fn,1042 ...1043 },1044 T1,1045 T2,1046 T3,1047 T4,1048 T5,1049 T6,1050 T7,1051 T81052 ): CpsEffect<Ctx, Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,1053 ...1054 };1055 declare export var fork: {1056 // fork(fn, ...args)1057 <R, Fn: () => R>(Fn): ForkEffect<null, Fn, void, []>,1058 <R, T1, Fn: T1 => R>(Fn, T1): ForkEffect<null, Fn, void, [T1]>,1059 <R, T1, T2, Fn: (T1, T2) => R>(Fn, T1, T2): ForkEffect<null, Fn, void, [T1, T2]>,1060 <R, T1, T2, T3, Fn: (T1, T2, T3) => R>(1061 Fn,1062 T1,1063 T2,1064 T31065 ): ForkEffect<null, Fn, void, [T1, T2, T3]>,1066 <R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1067 Fn,1068 T1,1069 T2,1070 T3,1071 T41072 ): ForkEffect<null, Fn, void, [T1, T2, T3, T4]>,1073 <R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1074 Fn,1075 T1,1076 T2,1077 T3,1078 T4,1079 T51080 ): ForkEffect<null, Fn, void, [T1, T2, T3, T4, T5]>,1081 <R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(1082 Fn,1083 T1,1084 T2,1085 T3,1086 T4,1087 T5,1088 T61089 ): ForkEffect<null, Fn, void, [T1, T2, T3, T4, T5, T6]>,1090 <R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(1091 Fn,1092 T1,1093 T2,1094 T3,1095 T4,1096 T5,1097 T6,1098 T71099 ): ForkEffect<null, Fn, void, [T1, T2, T3, T4, T5, T6, T7]>,1100 <R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(1101 Fn,1102 T1,1103 T2,1104 T3,1105 T4,1106 T5,1107 T6,1108 T7,1109 T81110 ): ForkEffect<null, Fn, void, [T1, T2, T3, T4, T5, T6, T7, T8]>,1111 // fork([context, fn], ...args)1112 <Ctx, R, Fn: () => R>(cfn: [Ctx, Fn]): ForkEffect<Ctx, Fn, void, []>,1113 <Ctx, R, T1, Fn: T1 => R>(cfn: [Ctx, Fn], T1): ForkEffect<Ctx, Fn, void, [T1]>,1114 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(1115 cfn: [Ctx, Fn],1116 T1,1117 T21118 ): ForkEffect<Ctx, Fn, void, [T1, T2]>,1119 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(1120 cfn: [Ctx, Fn],1121 T1,1122 T2,1123 T31124 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3]>,1125 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1126 cfn: [Ctx, Fn],1127 T1,1128 T2,1129 T3,1130 T41131 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4]>,1132 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1133 cfn: [Ctx, Fn],1134 T1,1135 T2,1136 T3,1137 T4,1138 T51139 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5]>,1140 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(1141 cfn: [Ctx, Fn],1142 T1,1143 T2,1144 T3,1145 T4,1146 T5,1147 T61148 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6]>,1149 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(1150 cfn: [Ctx, Fn],1151 T1,1152 T2,1153 T3,1154 T4,1155 T5,1156 T6,1157 T71158 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6, T7]>,1159 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(1160 cfn: [Ctx, Fn],1161 T1,1162 T2,1163 T3,1164 T4,1165 T5,1166 T6,1167 T7,1168 T81169 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6, T7, T8]>,1170 // fork({context, fn}, ...args)1171 <Ctx, R, Fn: () => R>(cfn: {1172 context: Ctx,1173 fn: Fn,1174 ...1175 }): ForkEffect<Ctx, Fn, void, []>,1176 <Ctx, R, T1, Fn: T1 => R>(cfn: {1177 context: Ctx,1178 fn: Fn,1179 ...1180 }, T1): ForkEffect<Ctx, Fn, void, [T1]>,1181 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(1182 cfn: {1183 context: Ctx,1184 fn: Fn,1185 ...1186 },1187 T1,1188 T21189 ): ForkEffect<Ctx, Fn, void, [T1, T2]>,1190 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(1191 cfn: {1192 context: Ctx,1193 fn: Fn,1194 ...1195 },1196 T1,1197 T2,1198 T31199 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3]>,1200 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1201 cfn: {1202 context: Ctx,1203 fn: Fn,1204 ...1205 },1206 T1,1207 T2,1208 T3,1209 T41210 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4]>,1211 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1212 cfn: {1213 context: Ctx,1214 fn: Fn,1215 ...1216 },1217 T1,1218 T2,1219 T3,1220 T4,1221 T51222 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5]>,1223 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(1224 cfn: {1225 context: Ctx,1226 fn: Fn,1227 ...1228 },1229 T1,1230 T2,1231 T3,1232 T4,1233 T5,1234 T61235 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6]>,1236 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(1237 cfn: {1238 context: Ctx,1239 fn: Fn,1240 ...1241 },1242 T1,1243 T2,1244 T3,1245 T4,1246 T5,1247 T6,1248 T71249 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6, T7]>,1250 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(1251 cfn: {1252 context: Ctx,1253 fn: Fn,1254 ...1255 },1256 T1,1257 T2,1258 T3,1259 T4,1260 T5,1261 T6,1262 T7,1263 T81264 ): ForkEffect<Ctx, Fn, void, [T1, T2, T3, T4, T5, T6, T7, T8]>,1265 ...1266 };1267 declare export var spawn: {1268 // spawn(fn, ...args)1269 <R, Fn: () => R>(Fn): ForkEffect<null, Fn, { detached: true, ... }, []>,1270 <R, T1, Fn: T1 => R>(Fn, T1): ForkEffect<null, Fn, { detached: true, ... }, [T1]>,1271 <R, T1, T2, Fn: (T1, T2) => R>(Fn, T1, T2): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2]>,1272 <R, T1, T2, T3, Fn: (T1, T2, T3) => R>(1273 Fn,1274 T1,1275 T2,1276 T31277 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3]>,1278 <R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1279 Fn,1280 T1,1281 T2,1282 T3,1283 T41284 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3, T4]>,1285 <R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1286 Fn,1287 T1,1288 T2,1289 T3,1290 T4,1291 T51292 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5]>,1293 <R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(1294 Fn,1295 T1,1296 T2,1297 T3,1298 T4,1299 T5,1300 T61301 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6]>,1302 <R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(1303 Fn,1304 T1,1305 T2,1306 T3,1307 T4,1308 T5,1309 T6,1310 T71311 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6, T7]>,1312 <R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(1313 Fn,1314 T1,1315 T2,1316 T3,1317 T4,1318 T5,1319 T6,1320 T7,1321 T81322 ): ForkEffect<null, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6, T7, T8]>,1323 // spawn([context, fn], ...args)1324 <Ctx, R, Fn: () => R>(cfn: [Ctx, Fn]): ForkEffect<Ctx, Fn, { detached: true, ... }, []>,1325 <Ctx, R, T1, Fn: T1 => R>(cfn: [Ctx, Fn], T1): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1]>,1326 <Ctx, R, T1, T2, Fn: (T1, T2) => R>(1327 cfn: [Ctx, Fn],1328 T1,1329 T21330 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2]>,1331 <Ctx, R, T1, T2, T3, Fn: (T1, T2, T3) => R>(1332 cfn: [Ctx, Fn],1333 T1,1334 T2,1335 T31336 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3]>,1337 <Ctx, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1338 cfn: [Ctx, Fn],1339 T1,1340 T2,1341 T3,1342 T41343 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3, T4]>,1344 <Ctx, R, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1345 cfn: [Ctx, Fn],1346 T1,1347 T2,1348 T3,1349 T4,1350 T51351 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5]>,1352 <Ctx, R, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(1353 cfn: [Ctx, Fn],1354 T1,1355 T2,1356 T3,1357 T4,1358 T5,1359 T61360 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6]>,1361 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(1362 cfn: [Ctx, Fn],1363 T1,1364 T2,1365 T3,1366 T4,1367 T5,1368 T6,1369 T71370 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6, T7]>,1371 <Ctx, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R>(1372 cfn: [Ctx, Fn],1373 T1,1374 T2,1375 T3,1376 T4,1377 T5,1378 T6,1379 T7,1380 T81381 ): ForkEffect<Ctx, Fn, { detached: true, ... }, [T1, T2, T3, T4, T5, T6, T7, T8]>,1382 ...1383 };1384 declare export var join: {1385 // join(task)1386 // join([...tasks])1387 <T: Task<*>>(task: T): JoinEffect<T>,1388 <T: Array<Task<*>>>(tasks: T): JoinEffect<T>,1389 ...1390 };1391 declare export var cancel: {1392 // cancel()1393 // cancel(task)1394 // cancel([...tasks])1395 (): CancelEffect<"@@redux-saga/SELF_CANCELLATION">,1396 <T: Task<*>>(task: T): CancelEffect<T>,1397 <T: Task<*>>(tasks: Array<T>): CancelEffect<$ReadOnlyArray<T>>,1398 ...1399 };1400 declare export var select: {1401 // select(selector, ...args)1402 (): SelectEffect<void, []>,1403 <S, R, Fn: S => R>(Fn): SelectEffect<Fn, []>,1404 <S, R, T1, Fn: (S, T1) => R>(Fn, T1): SelectEffect<Fn, [T1]>,1405 <S, R, T1, T2, Fn: (S, T1, T2) => R>(Fn, T1, T2): SelectEffect<Fn, [T1, T2]>,1406 <S, R, T1, T2, T3, Fn: (S, T1, T2, T3) => R>(Fn, T1, T2, T3): SelectEffect<Fn, [T1, T2, T3]>,1407 <S, R, T1, T2, T3, T4, Fn: (S, T1, T2, T3, T4) => R>(1408 Fn,1409 T1,1410 T2,1411 T3,1412 T41413 ): SelectEffect<Fn, [T1, T2, T3, T4]>,1414 <S, R, T1, T2, T3, T4, T5, Fn: (S, T1, T2, T3, T4, T5) => R>(1415 Fn,1416 T1,1417 T2,1418 T3,1419 T4,1420 T51421 ): SelectEffect<Fn, [T1, T2, T3, T4, T5]>,1422 <S, R, T1, T2, T3, T4, T5, T6, Fn: (S, T1, T2, T3, T4, T5, T6) => R>(1423 Fn,1424 T1,1425 T2,1426 T3,1427 T4,1428 T5,1429 T61430 ): SelectEffect<Fn, [T1, T2, T3, T4, T5, T6]>,1431 <S, R, T1, T2, T3, T4, T5, T6, T7, Fn: (S, T1, T2, T3, T4, T5, T6, T7) => R>(1432 Fn,1433 T1,1434 T2,1435 T3,1436 T4,1437 T5,1438 T6,1439 T71440 ): SelectEffect<Fn, [T1, T2, T3, T4, T5, T6, T7]>,1441 <S, R, T1, T2, T3, T4, T5, T6, T7, T8, Fn: (S, T1, T2, T3, T4, T5, T6, T7, T8) => R>(1442 Fn,1443 T1,1444 T2,1445 T3,1446 T4,1447 T5,1448 T6,1449 T7,1450 T81451 ): SelectEffect<Fn, [T1, T2, T3, T4, T5, T6, T7, T8]>,1452 ...1453 };1454 declare export var actionChannel: {1455 // actionChannel(pattern, [buffer])1456 <BT>(): ActionChannelEffect<BT, void, void>,1457 <BT, P: Pattern>(pattern: P): ActionChannelEffect<BT, P, void>,1458 <BT, T, P: Pattern, B: Buffer<T>>(pattern: P, buffer: B): ActionChannelEffect<BT, P, B>,1459 ...1460 };1461 declare export var flush: { // flush(channel)1462 <T, CH: FlushableChannel<T>>(channel: CH): FlushEffect<CH>, ... };1463 declare export var cancelled: { // cancelled()1464 (): CancelledEffect, ... };1465 declare export var setContext: { // setContext(props)1466 <T: {...}>(props: T): SetContextEffect<T>, ... };1467 declare export var getContext: { // getContext(prop)1468 <T: string>(prop: T): GetContextEffect<T>, ... };1469 declare export var race: {1470 // race(effects)1471 // race([...effects])1472 <R: { +[name: string]: Effect, ... }>(effects: R): RaceEffect<R>,1473 <R: $ReadOnlyArray<Effect>>(effects: R): RaceEffect<R>,1474 ...1475 };1476 declare export var all: {1477 // all(effects)1478 // all([...effects])1479 (effects: { +[name: string]: Effect, ... }): AllEffect,1480 (effects: $ReadOnlyArray<Effect>): AllEffect,1481 ...1482 };1483 declare export var take: {1484 // take(pattern)1485 // take(channel)1486 (): AllTakeEffect<void>,1487 <T, CH: TakeableChannel<T>>(channel: CH): TakeEffect<void, { channel: CH, ... }, void>,1488 <P: Pattern>(pattern: P): TakeEffect<{ pattern: P, ... }, void, void>,1489 ...1490 };1491 declare export var takeMaybe: {1492 // takeMaybe(pattern)1493 // takeMaybe(channel)1494 (): AllTakeEffect<{ maybe: true, ... }>,1495 <T, CH: TakeableChannel<T>>(channel: CH): TakeEffect<void, { channel: CH, ... }, { maybe: true, ... }>,1496 <P: Pattern>(pattern: P): TakeEffect<{ pattern: P, ... }, void, { maybe: true, ... }>,1497 ...1498 };1499 declare export var takeEvery: {1500 // takeEvery(pattern, saga, ...args)1501 // takeEvery(channel, saga, ...args)1502 <A, R, P: TakeableChannel<*> | Pattern, Fn: A => R>(P, Fn): ForkEffect<null, Fn, void, [P, Fn]>,1503 <A, R, P: TakeableChannel<*> | Pattern, T1, Fn: (T1, A) => R>(1504 P,1505 Fn,1506 T11507 ): ForkEffect<null, Fn, void, [P, Fn, T1]>,1508 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, Fn: (T1, T2, A) => R>(1509 P,1510 Fn,1511 T1,1512 T21513 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2]>,1514 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, Fn: (T1, T2, T3, A) => R>(1515 P,1516 Fn,1517 T1,1518 T2,1519 T31520 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3]>,1521 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, A) => R>(1522 P,1523 Fn,1524 T1,1525 T2,1526 T3,1527 T41528 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4]>,1529 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, A) => R>(1530 P,1531 Fn,1532 T1,1533 T2,1534 T3,1535 T4,1536 T51537 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5]>,1538 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, A) => R>(1539 P,1540 Fn,1541 T1,1542 T2,1543 T3,1544 T4,1545 T5,1546 T61547 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6]>,1548 <1549 A,1550 R,1551 P: TakeableChannel<*> | Pattern,1552 T1,1553 T2,1554 T3,1555 T4,1556 T5,1557 T6,1558 T7,1559 Fn: (T1, T2, T3, T4, T5, T6, T7, A) => R1560 >(1561 P,1562 Fn,1563 T1,1564 T2,1565 T3,1566 T4,1567 T5,1568 T6,1569 T71570 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7]>,1571 <1572 A,1573 R,1574 P: TakeableChannel<*> | Pattern,1575 T1,1576 T2,1577 T3,1578 T4,1579 T5,1580 T6,1581 T7,1582 T8,1583 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, A) => R1584 >(1585 P,1586 Fn,1587 T1,1588 T2,1589 T3,1590 T4,1591 T5,1592 T6,1593 T7,1594 T81595 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,1596 ...1597 };1598 declare export var takeLatest: {1599 // takeLatest(pattern, saga, ...args)1600 // takeLatest(channel, saga, ...args)1601 <A, R, P: TakeableChannel<*> | Pattern, Fn: A => R>(P, Fn): ForkEffect<null, Fn, void, [P, Fn]>,1602 <A, R, P: TakeableChannel<*> | Pattern, T1, Fn: (T1, A) => R>(1603 P,1604 Fn,1605 T11606 ): ForkEffect<null, Fn, void, [P, Fn, T1]>,1607 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, Fn: (T1, T2, A) => R>(1608 P,1609 Fn,1610 T1,1611 T21612 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2]>,1613 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, Fn: (T1, T2, T3, A) => R>(1614 P,1615 Fn,1616 T1,1617 T2,1618 T31619 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3]>,1620 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, A) => R>(1621 P,1622 Fn,1623 T1,1624 T2,1625 T3,1626 T41627 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4]>,1628 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, A) => R>(1629 P,1630 Fn,1631 T1,1632 T2,1633 T3,1634 T4,1635 T51636 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5]>,1637 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, A) => R>(1638 P,1639 Fn,1640 T1,1641 T2,1642 T3,1643 T4,1644 T5,1645 T61646 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6]>,1647 <1648 A,1649 R,1650 P: TakeableChannel<*> | Pattern,1651 T1,1652 T2,1653 T3,1654 T4,1655 T5,1656 T6,1657 T7,1658 Fn: (T1, T2, T3, T4, T5, T6, T7, A) => R1659 >(1660 P,1661 Fn,1662 T1,1663 T2,1664 T3,1665 T4,1666 T5,1667 T6,1668 T71669 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7]>,1670 <1671 A,1672 R,1673 P: TakeableChannel<*> | Pattern,1674 T1,1675 T2,1676 T3,1677 T4,1678 T5,1679 T6,1680 T7,1681 T8,1682 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, A) => R1683 >(1684 P,1685 Fn,1686 T1,1687 T2,1688 T3,1689 T4,1690 T5,1691 T6,1692 T7,1693 T81694 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,1695 ...1696 };1697 declare export var takeLeading: {1698 // takeLeading(pattern, saga, ...args)1699 // takeLeading(channel, saga, ...args)1700 <A, R, P: TakeableChannel<*> | Pattern, Fn: A => R>(P, Fn): ForkEffect<null, Fn, void, [P, Fn]>,1701 <A, R, P: TakeableChannel<*> | Pattern, T1, Fn: (T1, A) => R>(1702 P,1703 Fn,1704 T11705 ): ForkEffect<null, Fn, void, [P, Fn, T1]>,1706 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, Fn: (T1, T2, A) => R>(1707 P,1708 Fn,1709 T1,1710 T21711 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2]>,1712 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, Fn: (T1, T2, T3, A) => R>(1713 P,1714 Fn,1715 T1,1716 T2,1717 T31718 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3]>,1719 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, A) => R>(1720 P,1721 Fn,1722 T1,1723 T2,1724 T3,1725 T41726 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4]>,1727 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5, A) => R>(1728 P,1729 Fn,1730 T1,1731 T2,1732 T3,1733 T4,1734 T51735 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5]>,1736 <A, R, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6, A) => R>(1737 P,1738 Fn,1739 T1,1740 T2,1741 T3,1742 T4,1743 T5,1744 T61745 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6]>,1746 <1747 A,1748 R,1749 P: TakeableChannel<*> | Pattern,1750 T1,1751 T2,1752 T3,1753 T4,1754 T5,1755 T6,1756 T7,1757 Fn: (T1, T2, T3, T4, T5, T6, T7, A) => R1758 >(1759 P,1760 Fn,1761 T1,1762 T2,1763 T3,1764 T4,1765 T5,1766 T6,1767 T71768 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7]>,1769 <1770 A,1771 R,1772 P: TakeableChannel<*> | Pattern,1773 T1,1774 T2,1775 T3,1776 T4,1777 T5,1778 T6,1779 T7,1780 T8,1781 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, A) => R1782 >(1783 P,1784 Fn,1785 T1,1786 T2,1787 T3,1788 T4,1789 T5,1790 T6,1791 T7,1792 T81793 ): ForkEffect<null, Fn, void, [P, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,1794 ...1795 };1796 declare export var delay: {1797 // delay(ms, [val])1798 <T1: number>(timeout: T1): CallEffect<null, (ms: T1) => Promise<true>, [T1]>,1799 <T1: number, T2>(timeout: T1, T2): CallEffect<null, (ms: T1) => Promise<true>, [T1, T2]>,1800 ...1801 };1802 declare export var throttle: {1803 // throttle(ms, pattern, saga, ...args)1804 // throttle(ms, channel, saga, ...args)1805 <MS: number, P: TakeableChannel<*> | Pattern, A, R, Fn: A => R>(1806 MS,1807 P,1808 Fn1809 ): ForkEffect<null, Fn, void, [MS, P, Fn]>,1810 <MS: number, P: TakeableChannel<*> | Pattern, A, R, T1, Fn: (T1, A) => R>(1811 MS,1812 P,1813 Fn,1814 T11815 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1]>,1816 <MS: number, P: TakeableChannel<*> | Pattern, A, R, T1, T2, Fn: (T1, T2, A) => R>(1817 MS,1818 P,1819 Fn,1820 T1,1821 T21822 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2]>,1823 <MS: number, P: TakeableChannel<*> | Pattern, A, R, T1, T2, T3, Fn: (T1, T2, T3, A) => R>(1824 MS,1825 P,1826 Fn,1827 T1,1828 T2,1829 T31830 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3]>,1831 <MS: number, P: TakeableChannel<*> | Pattern, A, R, T1, T2, T3, T4, Fn: (T1, T2, T3, T4, A) => R>(1832 MS,1833 P,1834 Fn,1835 T1,1836 T2,1837 T3,1838 T41839 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4]>,1840 <1841 MS: number,1842 P: TakeableChannel<*> | Pattern,1843 A,1844 R,1845 T1,1846 T2,1847 T3,1848 T4,1849 T5,1850 Fn: (T1, T2, T3, T4, T5, A) => R1851 >(1852 MS,1853 P,1854 Fn,1855 T1,1856 T2,1857 T3,1858 T4,1859 T51860 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5]>,1861 <1862 MS: number,1863 P: TakeableChannel<*> | Pattern,1864 A,1865 R,1866 T1,1867 T2,1868 T3,1869 T4,1870 T5,1871 T6,1872 Fn: (T1, T2, T3, T4, T5, T6, A) => R1873 >(1874 MS,1875 P,1876 Fn,1877 T1,1878 T2,1879 T3,1880 T4,1881 T5,1882 T61883 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6]>,1884 <1885 MS: number,1886 P: TakeableChannel<*> | Pattern,1887 A,1888 R,1889 T1,1890 T2,1891 T3,1892 T4,1893 T5,1894 T6,1895 T7,1896 Fn: (T1, T2, T3, T4, T5, T6, T7, A) => R1897 >(1898 MS,1899 P,1900 Fn,1901 T1,1902 T2,1903 T3,1904 T4,1905 T5,1906 T6,1907 T71908 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6, T7]>,1909 <1910 MS: number,1911 P: TakeableChannel<*> | Pattern,1912 A,1913 R,1914 T1,1915 T2,1916 T3,1917 T4,1918 T5,1919 T6,1920 T7,1921 T8,1922 Fn: (T1, T2, T3, T4, T5, T6, T7, T8, A) => R1923 >(1924 MS,1925 P,1926 Fn,1927 T1,1928 T2,1929 T3,1930 T4,1931 T5,1932 T6,1933 T7,1934 T81935 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,1936 ...1937 };1938 declare export var debounce: {1939 // debounce(ms, pattern, saga, ...args)1940 // debounce(ms, channel, saga, ...args)1941 <R, MS: number, P: TakeableChannel<*> | Pattern, Fn: () => R>(1942 MS,1943 P,1944 Fn1945 ): ForkEffect<null, Fn, void, [MS, P, Fn]>,1946 <R, MS: number, P: TakeableChannel<*> | Pattern, T1, Fn: T1 => R>(1947 MS,1948 P,1949 Fn,1950 T11951 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1]>,1952 <R, MS: number, P: TakeableChannel<*> | Pattern, T1, T2, Fn: (T1, T2) => R>(1953 MS,1954 P,1955 Fn,1956 T1,1957 T21958 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2]>,1959 <R, MS: number, P: TakeableChannel<*> | Pattern, T1, T2, T3, Fn: (T1, T2, T3) => R>(1960 MS,1961 P,1962 Fn,1963 T1,1964 T2,1965 T31966 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3]>,1967 <R, MS: number, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(1968 MS,1969 P,1970 Fn,1971 T1,1972 T2,1973 T3,1974 T41975 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4]>,1976 <R, MS: number, P: TakeableChannel<*> | Pattern, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(1977 MS,1978 P,1979 Fn,1980 T1,1981 T2,1982 T3,1983 T4,1984 T51985 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5]>,1986 <1987 R,1988 MS: number,1989 P: TakeableChannel<*> | Pattern,1990 T1,1991 T2,1992 T3,1993 T4,1994 T5,1995 T6,1996 Fn: (T1, T2, T3, T4, T5, T6) => R1997 >(1998 MS,1999 P,2000 Fn,2001 T1,2002 T2,2003 T3,2004 T4,2005 T5,2006 T62007 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6]>,2008 <2009 R,2010 MS: number,2011 P: TakeableChannel<*> | Pattern,2012 T1,2013 T2,2014 T3,2015 T4,2016 T5,2017 T6,2018 T7,2019 Fn: (T1, T2, T3, T4, T5, T6, T7) => R2020 >(2021 MS,2022 P,2023 Fn,2024 T1,2025 T2,2026 T3,2027 T4,2028 T5,2029 T6,2030 T72031 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6, T7]>,2032 <2033 R,2034 MS: number,2035 P: TakeableChannel<*> | Pattern,2036 T1,2037 T2,2038 T3,2039 T4,2040 T5,2041 T6,2042 T7,2043 T8,2044 Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R2045 >(2046 MS,2047 P,2048 Fn,2049 T1,2050 T2,2051 T3,2052 T4,2053 T5,2054 T6,2055 T7,2056 T82057 ): ForkEffect<null, Fn, void, [MS, P, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,2058 ...2059 };2060 declare export var retry: {2061 // retry(maxTries, delay, fn, ...args)2062 <R, MT: number, D: number, Fn: () => R>(MT, D, Fn): CallEffect<null, Function, [MT, D, Fn]>,2063 <R, MT: number, D: number, T1, Fn: T1 => R>(2064 MT,2065 D,2066 Fn,2067 T12068 ): CallEffect<null, Function, [MT, D, Fn, T1]>,2069 <R, MT: number, D: number, T1, T2, Fn: (T1, T2) => R>(2070 MT,2071 D,2072 Fn,2073 T1,2074 T22075 ): CallEffect<null, Function, [MT, D, Fn, T1, T2]>,2076 <R, MT: number, D: number, T1, T2, T3, Fn: (T1, T2, T3) => R>(2077 MT,2078 D,2079 Fn,2080 T1,2081 T2,2082 T32083 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3]>,2084 <R, MT: number, D: number, T1, T2, T3, T4, Fn: (T1, T2, T3, T4) => R>(2085 MT,2086 D,2087 Fn,2088 T1,2089 T2,2090 T3,2091 T42092 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3, T4]>,2093 <R, MT: number, D: number, T1, T2, T3, T4, T5, Fn: (T1, T2, T3, T4, T5) => R>(2094 MT,2095 D,2096 Fn,2097 T1,2098 T2,2099 T3,2100 T4,2101 T52102 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3, T4, T5]>,2103 <R, MT: number, D: number, T1, T2, T3, T4, T5, T6, Fn: (T1, T2, T3, T4, T5, T6) => R>(2104 MT,2105 D,2106 Fn,2107 T1,2108 T2,2109 T3,2110 T4,2111 T5,2112 T62113 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3, T4, T5, T6]>,2114 <R, MT: number, D: number, T1, T2, T3, T4, T5, T6, T7, Fn: (T1, T2, T3, T4, T5, T6, T7) => R>(2115 MT,2116 D,2117 Fn,2118 T1,2119 T2,2120 T3,2121 T4,2122 T5,2123 T6,2124 T72125 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3, T4, T5, T6, T7]>,2126 <2127 R,2128 MT: number,2129 D: number,2130 T1,2131 T2,2132 T3,2133 T4,2134 T5,2135 T6,2136 T7,2137 T8,2138 Fn: (T1, T2, T3, T4, T5, T6, T7, T8) => R2139 >(2140 MT,2141 D,2142 Fn,2143 T1,2144 T2,2145 T3,2146 T4,2147 T5,2148 T6,2149 T7,2150 T82151 ): CallEffect<null, Function, [MT, D, Fn, T1, T2, T3, T4, T5, T6, T7, T8]>,2152 ...2153 };...

Full Screen

Full Screen

common.py

Source:common.py Github

copy

Full Screen

...221 else:222 params.append('%s p%d' % (t, i))223 call_params.append('p%d' % (i))224 if len(fn['ret']) == 1 and fn['ret'][0] == 'void':225 print(commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \226 % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))227 else:228 print(commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \229 % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))230def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\n//'):231 f = open(inputFile, "r")232 if noteLine:233 print(noteLine)234 for line in f:235 if line.startswith('@'):236 assert line[-1] == '\n'237 line = line[:-1] # remove '\n'238 assert line[-1] == '@'239 name = line[1:-1]240 assert name in ctx, name241 line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '')242 sys.stdout.write(line)...

Full Screen

Full Screen

_getDataFunctions.js

Source:_getDataFunctions.js Github

copy

Full Screen

...11 oTest.fnTest(12 "Single object, single property",13 function () {14 fn = table.oApi._fnGetObjectDataFn('test');15 test = fn( { "test": true } );16 },17 function () { return test }18 );19 20 oTest.fnTest(21 "Single property from object",22 function () {23 fn = table.oApi._fnGetObjectDataFn('test');24 test = fn( { "test": true, "test2": false } );25 },26 function () { return test }27 );28 29 oTest.fnTest(30 "Single property from object - different property",31 function () {32 fn = table.oApi._fnGetObjectDataFn('test2');33 test = fn( { "test": true, "test2": false } );34 },35 function () { return test===false }36 );37 38 oTest.fnTest(39 "Undefined property from object",40 function () {41 fn = table.oApi._fnGetObjectDataFn('test3');42 test = fn( { "test": true, "test2": false } );43 },44 function () { return test===undefined }45 );46 47 // Array index access48 oTest.fnTest(49 "Array access - index 0",50 function () {51 fn = table.oApi._fnGetObjectDataFn(0);52 test = fn( [true, false, false, false] );53 },54 function () { return test }55 );56 57 oTest.fnTest(58 "Array access - index 1",59 function () {60 fn = table.oApi._fnGetObjectDataFn(2);61 test = fn( [false, false, true, false] );62 },63 function () { return test }64 );65 66 oTest.fnTest(67 "Array access - undefined",68 function () {69 fn = table.oApi._fnGetObjectDataFn(7);70 test = fn( [false, false, true, false] );71 },72 function () { return test===undefined }73 );74 // null source75 oTest.fnTest(76 "null source",77 function () {78 fn = table.oApi._fnGetObjectDataFn( null );79 test = fn( [false, false, true, false] );80 },81 function () { return test===null }82 );83 // nested objects84 oTest.fnTest(85 "Nested object property",86 function () {87 fn = table.oApi._fnGetObjectDataFn( 'a.b' );88 test = fn( {89 "a":{90 "b": true,91 "c": false,92 "d": 193 }94 } );95 },96 function () { return test }97 );98 oTest.fnTest(99 "Nested object property - different prop",100 function () {101 fn = table.oApi._fnGetObjectDataFn( 'a.d' );102 test = fn( {103 "a":{104 "b": true,105 "c": false,106 "d": 1107 }108 } );109 },110 function () { return test===1 }111 );112 113 oTest.fnTest(114 "Nested object property - undefined prop",115 function () {116 fn = table.oApi._fnGetObjectDataFn( 'a.z' );117 test = fn( {118 "a":{119 "b": true,120 "c": false,121 "d": 1122 }123 } );124 },125 function () { return test===undefined }126 );127 // Nested array128 oTest.fnTest(129 "Nested array index property",130 function () {131 fn = table.oApi._fnGetObjectDataFn( 'a.0' );132 test = fn( {133 "a": [134 true,135 false,136 1137 ]138 } );139 },140 function () { return test }141 );142 oTest.fnTest(143 "Nested array index property - different index",144 function () {145 fn = table.oApi._fnGetObjectDataFn( 'a.2' );146 test = fn( {147 "a": [148 true,149 false,150 1151 ]152 } );153 },154 function () { return test===1 }155 );156 oTest.fnTest(157 "Nested array index property - undefined index",158 function () {159 fn = table.oApi._fnGetObjectDataFn( 'a.10' );160 test = fn( {161 "a": [162 true,163 false,164 1165 ]166 } );167 },168 function () { return test===undefined }169 );170 // Nested array object property171 oTest.fnTest(172 "Nested array index object property",173 function () {174 fn = table.oApi._fnGetObjectDataFn( 'a.0.m' );175 test = fn( {176 "a": [177 { "m": true, "n": 1 },178 { "m": false, "n": 2 },179 { "m": false, "n": 3 }180 ]181 } );182 },183 function () { return test }184 );185 oTest.fnTest(186 "Nested array index object property - different index",187 function () {188 fn = table.oApi._fnGetObjectDataFn( 'a.2.n' );189 test = fn( {190 "a": [191 { "m": true, "n": 1 },192 { "m": false, "n": 2 },193 { "m": false, "n": 3 }194 ]195 } );196 },197 function () { return test===3 }198 );199 oTest.fnTest(200 "Nested array index object property - undefined index",201 function () {202 fn = table.oApi._fnGetObjectDataFn( 'a.0.z' );203 test = fn( {204 "a": [205 { "m": true, "n": 1 },206 { "m": false, "n": 2 },207 { "m": false, "n": 3 }208 ]209 } );210 },211 function () { return test===undefined }212 );213 // Array notation - no join214 oTest.fnTest(215 "Array notation - no join - property",216 function () {217 fn = table.oApi._fnGetObjectDataFn( 'a[].n' );218 test = fn( {219 "a": [220 { "m": true, "n": 1 },221 { "m": false, "n": 2 },222 { "m": false, "n": 3 }223 ]224 } );225 },226 function () {227 return test.length===3 && test[0]===1228 && test[1]===2 && test[2]===3;229 }230 );231 oTest.fnTest(232 "Array notation - no join - property (2)",233 function () {234 fn = table.oApi._fnGetObjectDataFn( 'a[].m' );235 test = fn( {236 "a": [237 { "m": true, "n": 1 },238 { "m": false, "n": 2 }239 ]240 } );241 },242 function () {243 return test.length===2 && test[0]===true244 && test[1]===false;245 }246 );247 oTest.fnTest(248 "Array notation - no join - undefined property",249 function () {250 fn = table.oApi._fnGetObjectDataFn( 'a[].z' );251 test = fn( {252 "a": [253 { "m": true, "n": 1 },254 { "m": false, "n": 2 }255 ]256 } );257 },258 function () {259 return test.length===2 && test[0]===undefined260 && test[1]===undefined;261 }262 );263 // Array notation - join264 oTest.fnTest(265 "Array notation - space join - property",266 function () {267 fn = table.oApi._fnGetObjectDataFn( 'a[ ].n' );268 test = fn( {269 "a": [270 { "m": true, "n": 1 },271 { "m": false, "n": 2 },272 { "m": false, "n": 3 }273 ]274 } );275 },276 function () { return test === '1 2 3'; }277 );278 oTest.fnTest(279 "Array notation - space join - property (2)",280 function () {281 fn = table.oApi._fnGetObjectDataFn( 'a[ ].m' );282 test = fn( {283 "a": [284 { "m": true, "n": 1 },285 { "m": false, "n": 2 }286 ]287 } );288 },289 function () { return test === 'true false'; }290 );291 oTest.fnTest(292 "Array notation - sapce join - undefined property",293 function () {294 fn = table.oApi._fnGetObjectDataFn( 'a[ ].z' );295 test = fn( {296 "a": [297 { "m": true, "n": 1 },298 { "m": false, "n": 2 }299 ]300 } );301 },302 function () { return test === ' '; }303 );304 oTest.fnTest(305 "Array notation - string join - property",306 function () {307 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].n' );308 test = fn( {309 "a": [310 { "m": true, "n": 1 },311 { "m": false, "n": 2 },312 { "m": false, "n": 3 }313 ]314 } );315 },316 function () { return test === '1qwerty2qwerty3'; }317 );318 oTest.fnTest(319 "Array notation - string join - property (2)",320 function () {321 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty].m' );322 test = fn( {323 "a": [324 { "m": true, "n": 1 },325 { "m": false, "n": 2 }326 ]327 } );328 },329 function () { return test === 'trueqwertyfalse'; }330 );331 332 // Array alone join333 oTest.fnTest(334 "Flat array join",335 function () {336 fn = table.oApi._fnGetObjectDataFn( 'a[ ]' );337 test = fn( {338 "a": [339 true,340 false,341 1342 ]343 } );344 },345 function () { return test==="true false 1"; }346 );347 oTest.fnTest(348 "Flat array string join",349 function () {350 fn = table.oApi._fnGetObjectDataFn( 'a[qwerty]' );351 test = fn( {352 "a": [353 true,354 false,355 1356 ]357 } );358 },359 function () { return test==="trueqwertyfalseqwerty1"; }360 );361 oTest.fnTest(362 "Flat array no join",363 function () {364 fn = table.oApi._fnGetObjectDataFn( 'a[]' );365 test = fn( {366 "a": [367 true,368 false,369 1370 ]371 } );372 },373 function () { return test.length===3 && test[0]===true &&374 test[1]===false && test[2]===1; }375 );376 377 378 379 oTest.fnComplete();...

Full Screen

Full Screen

test_math.py

Source:test_math.py Github

copy

Full Screen

...17 cases=None,18 span=(-1., 1.), count=128,19 types=(np.float32, np.float64)):20 @hsa.jit21 def fn(dst, src):22 i = hsa.get_global_id(0)23 if i < dst.size:24 dst[i] = math_fn(src[i])25 for dtype in types:26 if cases is None:27 src = np.linspace(span[0], span[1], count).astype(dtype)28 else:29 src = np.array(cases, dtype=dtype)30 dst = np.zeros_like(src)31 fn[src.size, 1](dst, src)32 np.testing.assert_allclose(dst, npy_fn(src),33 rtol=self._get_tol(math_fn, dtype),34 err_msg='{0} ({1})'.format(35 math_fn.__name__,36 dtype.__name__))37 def _generic_test_binary(self, math_fn, npy_fn,38 cases=None,39 span=(-1., 1., 1., -1.), count=128,40 types=(np.float32, np.float64)):41 @hsa.jit42 def fn(dst, src1, src2):43 i = hsa.get_global_id(0)44 if i < dst.size:45 dst[i] = math_fn(src1[i], src2[i])46 for dtype in types:47 if cases is None:48 src1 = np.linspace(span[0], span[1], count).astype(dtype)49 src2 = np.linspace(span[2], span[3], count).astype(dtype)50 else:51 src1 = np.array(cases[0], dtype=dtype)52 src2 = np.array(cases[1], dtype=dtype)53 dst = np.zeros_like(src1)54 fn[dst.size, 1](dst, src1, src2)55 np.testing.assert_allclose(dst, npy_fn(src1, src2),56 rtol=self._get_tol(math_fn, dtype),57 err_msg='{0} ({1})'.format(58 math_fn.__name__,59 dtype.__name__))60 def test_trig(self):61 funcs = [math.sin, math.cos, math.tan]62 for fn in funcs:63 self._generic_test_unary(fn, getattr(np, fn.__name__),64 span=(-np.pi, np.pi))65 def test_trig_inv(self):66 funcs = [(math.asin, np.arcsin),67 (math.acos, np.arccos),68 (math.atan, np.arctan)]69 for fn, np_fn in funcs:...

Full Screen

Full Screen

single_return_test.py

Source:single_return_test.py Github

copy

Full Screen

...20from tensorflow.contrib.autograph.converters import single_return21from tensorflow.python.framework.ops import name_scope22from tensorflow.python.platform import test23class SingleReturnTest(converter_test_base.TestCase):24 def compiled_fn(self, test_fn, *args):25 node = self.parse_and_analyze(test_fn, {})26 node = single_return.transform(node, self.ctx)27 module = self.compiled(node, *args)28 return module29 def test_noop(self):30 # Noop31 def test_fn(x):32 return x33 with self.compiled_fn(test_fn) as result:34 self.assertEqual(test_fn(2.0), result.test_fn(2.0))35 def test_return_expression(self):36 # ANF37 def test_fn(x):38 return x * x39 with self.compiled_fn(test_fn) as result:40 x = 241 self.assertEqual(test_fn(x), result.test_fn(x))42 def test_merge(self):43 # Simple merge44 def test_fn(x):45 if x > 0:46 return x47 else:48 return x * x49 with self.compiled_fn(test_fn) as result:50 for x in [-2, 2]:51 self.assertEqual(test_fn(x), result.test_fn(x))52 def test_orphan_branch(self):53 def test_fn(x):54 if x > 0:55 return x56 with self.assertRaises(ValueError):57 self.compiled_fn(test_fn)58 def test_lift_body_into_false_branch(self):59 def test_fn(x):60 if x > 0:61 return x62 return x * x63 with self.compiled_fn(test_fn) as result:64 for x in [-2, 2]:65 self.assertEqual(test_fn(x), result.test_fn(x))66 def test_lift_body_into_true_branch(self):67 def test_fn(x):68 if x < 0:69 x *= x70 else:71 # TODO(alexbw): linter bug here that requires us suppress this warning.72 return x # pylint: disable=undefined-loop-variable73 return x74 with self.compiled_fn(test_fn) as result:75 for x in [-2, 2]:76 self.assertEqual(test_fn(x), result.test_fn(x))77 def test_nested_if(self):78 def test_fn(x):79 if x > 0:80 if x < 5:81 return x82 else:83 return x * x84 else:85 return x * x * x86 with self.compiled_fn(test_fn) as result:87 for x in [-2, 2, 5]:88 self.assertEqual(test_fn(x), result.test_fn(x))89 def test_context_manager(self):90 def test_fn(x):91 with name_scope(''):92 return x * x93 with self.compiled_fn(test_fn) as result:94 result.name_scope = name_scope95 for x in [-2, 2]:96 self.assertEqual(test_fn(x), result.test_fn(x))97 def test_context_manager_in_conditional(self):98 def test_fn(x):99 if x > 0:100 with name_scope(''):101 return x * x102 else:103 return x104 with self.compiled_fn(test_fn, name_scope) as result:105 result.name_scope = name_scope106 for x in [-2, 2]:107 self.assertEqual(test_fn(x), result.test_fn(x))108 def text_conditional_in_context_manager(self):109 def test_fn(x):110 with name_scope(''):111 if x > 0:112 return x * x113 else:114 return x115 with self.compiled_fn(test_fn) as result:116 result.name_scope = name_scope117 for x in [-2, 2]:118 self.assertEqual(test_fn(x), result.test_fn(x))119 def test_no_return(self):120 def test_fn(x):121 x *= x122 with self.compiled_fn(test_fn) as result:123 self.assertEqual(test_fn(2), result.test_fn(2))124 def test_nested_functiondefs(self):125 def test_fn(x):126 def inner_fn(y):127 if y > 0:128 return y * y129 else:130 return y131 return inner_fn(x)132 with self.compiled_fn(test_fn) as result:133 for x in [-2, 2]:134 self.assertEqual(test_fn(x), result.test_fn(x))135 def test_loop(self):136 def test_fn(x):137 for _ in range(10):138 return x139 return x140 with self.assertRaises(ValueError):141 self.compiled_fn(test_fn)142if __name__ == '__main__':...

Full Screen

Full Screen

api.internal.js

Source:api.internal.js Github

copy

Full Screen

1/*2 * This is really a good bit rubbish this method of exposing the internal methods3 * publicly... - To be fixed in 2.0 using methods on the prototype4 */5/**6 * Create a wrapper function for exporting an internal functions to an external API.7 * @param {string} sFunc API function name8 * @returns {function} wrapped function9 * @memberof DataTable#oApi10 */11function _fnExternApiFunc (sFunc)12{13 return function() {14 var aArgs = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat( 15 Array.prototype.slice.call(arguments) );16 return DataTable.ext.oApi[sFunc].apply( this, aArgs );17 };18}19/**20 * Reference to internal functions for use by plug-in developers. Note that these21 * methods are references to internal functions and are considered to be private.22 * If you use these methods, be aware that they are liable to change between versions23 * (check the upgrade notes).24 * @namespace25 */26this.oApi = {27 "_fnExternApiFunc": _fnExternApiFunc,28 "_fnInitialise": _fnInitialise,29 "_fnInitComplete": _fnInitComplete,30 "_fnLanguageCompat": _fnLanguageCompat,31 "_fnAddColumn": _fnAddColumn,32 "_fnColumnOptions": _fnColumnOptions,33 "_fnAddData": _fnAddData,34 "_fnCreateTr": _fnCreateTr,35 "_fnGatherData": _fnGatherData,36 "_fnBuildHead": _fnBuildHead,37 "_fnDrawHead": _fnDrawHead,38 "_fnDraw": _fnDraw,39 "_fnReDraw": _fnReDraw,40 "_fnAjaxUpdate": _fnAjaxUpdate,41 "_fnAjaxParameters": _fnAjaxParameters,42 "_fnAjaxUpdateDraw": _fnAjaxUpdateDraw,43 "_fnServerParams": _fnServerParams,44 "_fnAddOptionsHtml": _fnAddOptionsHtml,45 "_fnFeatureHtmlTable": _fnFeatureHtmlTable,46 "_fnScrollDraw": _fnScrollDraw,47 "_fnAdjustColumnSizing": _fnAdjustColumnSizing,48 "_fnFeatureHtmlFilter": _fnFeatureHtmlFilter,49 "_fnFilterComplete": _fnFilterComplete,50 "_fnFilterCustom": _fnFilterCustom,51 "_fnFilterColumn": _fnFilterColumn,52 "_fnFilter": _fnFilter,53 "_fnBuildSearchArray": _fnBuildSearchArray,54 "_fnBuildSearchRow": _fnBuildSearchRow,55 "_fnFilterCreateSearch": _fnFilterCreateSearch,56 "_fnDataToSearch": _fnDataToSearch,57 "_fnSort": _fnSort,58 "_fnSortAttachListener": _fnSortAttachListener,59 "_fnSortingClasses": _fnSortingClasses,60 "_fnFeatureHtmlPaginate": _fnFeatureHtmlPaginate,61 "_fnPageChange": _fnPageChange,62 "_fnFeatureHtmlInfo": _fnFeatureHtmlInfo,63 "_fnUpdateInfo": _fnUpdateInfo,64 "_fnFeatureHtmlLength": _fnFeatureHtmlLength,65 "_fnFeatureHtmlProcessing": _fnFeatureHtmlProcessing,66 "_fnProcessingDisplay": _fnProcessingDisplay,67 "_fnVisibleToColumnIndex": _fnVisibleToColumnIndex,68 "_fnColumnIndexToVisible": _fnColumnIndexToVisible,69 "_fnNodeToDataIndex": _fnNodeToDataIndex,70 "_fnVisbleColumns": _fnVisbleColumns,71 "_fnCalculateEnd": _fnCalculateEnd,72 "_fnConvertToWidth": _fnConvertToWidth,73 "_fnCalculateColumnWidths": _fnCalculateColumnWidths,74 "_fnScrollingWidthAdjust": _fnScrollingWidthAdjust,75 "_fnGetWidestNode": _fnGetWidestNode,76 "_fnGetMaxLenString": _fnGetMaxLenString,77 "_fnStringToCss": _fnStringToCss,78 "_fnDetectType": _fnDetectType,79 "_fnSettingsFromNode": _fnSettingsFromNode,80 "_fnGetDataMaster": _fnGetDataMaster,81 "_fnGetTrNodes": _fnGetTrNodes,82 "_fnGetTdNodes": _fnGetTdNodes,83 "_fnEscapeRegex": _fnEscapeRegex,84 "_fnDeleteIndex": _fnDeleteIndex,85 "_fnReOrderIndex": _fnReOrderIndex,86 "_fnColumnOrdering": _fnColumnOrdering,87 "_fnLog": _fnLog,88 "_fnClearTable": _fnClearTable,89 "_fnSaveState": _fnSaveState,90 "_fnLoadState": _fnLoadState,91 "_fnCreateCookie": _fnCreateCookie,92 "_fnReadCookie": _fnReadCookie,93 "_fnDetectHeader": _fnDetectHeader,94 "_fnGetUniqueThs": _fnGetUniqueThs,95 "_fnScrollBarWidth": _fnScrollBarWidth,96 "_fnApplyToChildren": _fnApplyToChildren,97 "_fnMap": _fnMap,98 "_fnGetRowData": _fnGetRowData,99 "_fnGetCellData": _fnGetCellData,100 "_fnSetCellData": _fnSetCellData,101 "_fnGetObjectDataFn": _fnGetObjectDataFn,102 "_fnSetObjectDataFn": _fnSetObjectDataFn,103 "_fnApplyColumnDefs": _fnApplyColumnDefs,104 "_fnBindAction": _fnBindAction,105 "_fnExtend": _fnExtend,106 "_fnCallbackReg": _fnCallbackReg,107 "_fnCallbackFire": _fnCallbackFire,108 "_fnJsonString": _fnJsonString,109 "_fnRender": _fnRender,110 "_fnNodeToColumnIndex": _fnNodeToColumnIndex,111 "_fnInfoMacros": _fnInfoMacros,112 "_fnBrowserDetect": _fnBrowserDetect,113 "_fnGetColumns": _fnGetColumns114};115$.extend( DataTable.ext.oApi, this.oApi );116for ( var sFunc in DataTable.ext.oApi )117{118 if ( sFunc )119 {120 this[sFunc] = _fnExternApiFunc(sFunc);121 }...

Full Screen

Full Screen

_setDataFunctions.js

Source:_setDataFunctions.js Github

copy

Full Screen

...12 "Create property",13 function () {14 fn = table.oApi._fnSetObjectDataFn('test');15 o = {};16 fn( o, true );17 },18 function () { return o.test }19 );20 21 oTest.fnTest(22 "Single property doesn't kill other properties",23 function () {24 fn = table.oApi._fnSetObjectDataFn('test');25 o = {26 "test2": false27 };28 fn( o, true );29 },30 function () { return o.test && o.test2===false; }31 );32 33 oTest.fnTest(34 "Single property overwrite old property",35 function () {36 fn = table.oApi._fnSetObjectDataFn('test');37 o = {38 "test": false,39 "test2": false40 };41 fn( o, true );42 },43 function () { return o.test && o.test2===false; }44 );45 // Nested46 oTest.fnTest(47 "Create nested property",48 function () {49 fn = table.oApi._fnSetObjectDataFn('test.inner');50 o = {51 "test": {}52 };53 fn( o, true );54 },55 function () { return o.test.inner }56 );57 oTest.fnTest(58 "Deep create nested property",59 function () {60 fn = table.oApi._fnSetObjectDataFn('test.inner');61 o = {};62 fn( o, true );63 },64 function () { return o.test.inner }65 );66 67 oTest.fnTest(68 "Nested property doesn't kill other properties",69 function () {70 fn = table.oApi._fnSetObjectDataFn('test.inner');71 o = {72 "test": {73 "test2": false74 }75 };76 fn( o, true );77 },78 function () { return o.test.inner && o.test.test2===false; }79 );80 81 oTest.fnTest(82 "Single property overwrite old property",83 function () {84 fn = table.oApi._fnSetObjectDataFn('nested.test');85 o = {86 "nested": {87 "test": false,88 "test2": false89 }90 };91 fn( o, true );92 },93 function () { return o.nested.test && o.nested.test2===false; }94 );95 // Set arrays / objects96 oTest.fnTest(97 "Create object",98 function () {99 fn = table.oApi._fnSetObjectDataFn('test');100 o = {};101 fn( o, {"a":true, "b":false} );102 },103 function () { return o.test.a && o.test.b===false }104 );105 oTest.fnTest(106 "Create nested object",107 function () {108 fn = table.oApi._fnSetObjectDataFn('nested.test');109 o = {};110 fn( o, {"a":true, "b":false} );111 },112 function () { return o.nested.test.a && o.nested.test.b===false }113 );114 oTest.fnTest(115 "Create array",116 function () {117 fn = table.oApi._fnSetObjectDataFn('test');118 o = {};119 fn( o, [1,2,3] );120 },121 function () { return o.test[0]===1 && o.test[2]===3 }122 );123 oTest.fnTest(124 "Create nested array",125 function () {126 fn = table.oApi._fnSetObjectDataFn('nested.test');127 o = {};128 fn( o, [1,2,3] );129 },130 function () { return o.nested.test[0]===1 && o.nested.test[2]===3 }131 );132 // Array notation133 oTest.fnTest(134 "Create array of objects",135 function () {136 fn = table.oApi._fnSetObjectDataFn('test[].a');137 o = {};138 fn( o, [1,2,3] );139 },140 function () { return o.test.length===3 && o.test[0].a===1 && o.test[1].a===2; }141 );142 oTest.fnTest(143 "Create array of nested objects",144 function () {145 fn = table.oApi._fnSetObjectDataFn('test[].a.b');146 o = {};147 fn( o, [1,2,3] );148 },149 function () { return o.test.length===3 && o.test[0].a.b===1 && o.test[1].a.b===2; }150 );151 oTest.fnTest(152 "Create array",153 function () {154 fn = table.oApi._fnSetObjectDataFn('test[]');155 o = {};156 fn( o, [1,2,3] );157 },158 function () { return o.test.length===3 && o.test[0]===1 && o.test[1]===2; }159 );160 161 oTest.fnComplete();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err)4 console.log(err);5 console.log(data);6});7### wpt.runTest(url, options, callback)8### wpt.getLocations(callback)9### wpt.getTesters(callback)10### wpt.getTestStatus(testId, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test submitted. Poll for results at %s/jsonResult.php?test=%s', api.serverUrl, data.data.testId);5 var poll = function() {6 api.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 if (data.statusCode == 200) {9 console.log('Test completed:');10 console.log(' First View: %s', data.data.average.firstView.loadTime);11 console.log(' Repeat View: %s', data.data.average.repeatView.loadTime);12 } else {13 console.log('Test not completed yet. Status %d. Retrying in 10 seconds.', data.statusCode);14 setTimeout(poll, 10000);15 }16 });17 };18 poll();19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./lib/webpagetest.js');2var fs = require('fs');3var util = require('util');4var wpt = new wpt('www.webpagetest.org');5var options = {6};7wpt.runTest(url, options, function(err, data) {8 if (err) return console.error(err);9 console.log('Test status: ' + data.statusText);10});11wpt.getTestStatus('141107_8M_6e5c3a7b3e3f9b8f1b0d1e2f2b2e6d8e', function(err, data) {12 if (err) return console.error(err);13 console.log('Test status: ' + data.statusText);14});15wpt.getTestResults('141107_8M_6e5c3a7b3e3f9b8f1b0d1e2f2b2e6d8e', function(err, data) {16 if (err) return console.error(err);17 console.log('Test results: ' + data.data.median.firstView.loadTime);18});19wpt.getLocations(function(err, data) {20 if (err) return console.error(err);21 console.log('Locations: ' + data);22});23wpt.getTesters(function(err, data) {24 if (err) return console.error(err);25 console.log('Testers: ' + data);26});27wpt.getTesters('Dulles', function(err, data) {28 if (err) return console.error(err);29 console.log('Dulles testers: ' + data);30});31wpt.getTesters('Dulles', 'Chrome', function(err, data) {32 if (err) return console.error(err);33 console.log('Dulles Chrome testers: ' + data);34});35wpt.getTesters('Dulles', 'Chrome', 'Cable', function(err, data) {36 if (err) return console.error(err);37 console.log('Dulles Chrome Cable testers: ' +

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if(err){3 console.log(err);4 }5 else{6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptool = require('wptool');2 console.log(data.title);3});4### wptool.fn(url, callback)5const wptool = require('wptool');6 console.log(data.title);7});8### wptool.get(url, callback)9const wptool = require('wptool');10 console.log(data);11});12### wptool.getSummary(url, callback)13const wptool = require('wptool');14 console.log(data);15});16### wptool.getImages(url, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3f5e5d5a4f4e4b4c4d4e4f5a6b6c6d7');3 if (err) return console.error(err);4 console.log('Test ID: %s', data.data.testId);5 console.log('From: %s', data.data.from);6 console.log('Location: %s', data.data.location);7 console.log('Runs: %s', data.data.runs);8 console.log('Average First View (ms): %s', data.data.average.firstView);9 console.log('Average Repeat View (ms): %s', data.data.average.repeatView);10});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful