How to use _callback method in Slash

Best Python code snippet using slash

monte.py

Source:monte.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3Wrapper for the Monte carlo integrators provided by GSL.4"""5import _callback6import gsl_function7gsl_monte_function = gsl_function.gsl_monte_function8VEGAS_MODE_IMPORTANCE = _callback.GSL_VEGAS_MODE_IMPORTANCE9VEGAS_MODE_IMPORTANCE_ONLY = _callback.GSL_VEGAS_MODE_IMPORTANCE_ONLY 10VEGAS_MODE_STRATIFIED = _callback.GSL_VEGAS_MODE_STRATIFIED 11class _Monte:12 """13 Base Wrapper class. This class does not implement any solver itself, 14 so you should use a derived class eg. miser, vegas, or plain.15 """16 _alloc = None17 _free = None18 _integrate = None19 _init = None20 21 def __init__(self, dim):22 """23 Input :24 dim ... the dimension of the integrator25 """26 self._ptr = None27 self._ptr = self._alloc(dim)28 def init(self):29 """30 (Re)initialises the solver31 """32 self._init(self._ptr)33 def integrate(self, func, xl, xu, ncalls, r):34 """35 Input:36 func ... the function to solve. Must be a gsl_monte_function37 xl ... the lower limits for the integration38 xu ... the upper limits for the integration39 ncalls ... number of calls 40 r ... random generator from pygsl.rng41 Output:42 val ... the value43 abserr ... the error estimate for that value44 """45 return self._integrate(func.get_ptr(), (xl, xu), ncalls, r, self._ptr)46 def get_name(self):47 """48 To be compatible with the other solvers I added this method 49 """50 return self.__class__.__name__51 52 def _GetPtr(self):53 """54 Direct access to the SWIG Pointer. Only use if you know what you are doing55 """56 return self._ptr57 58 def __del__(self):59 """60 """61 if hasattr(self, '_ptr'):62 if self._ptr != None:63 self._free(self._ptr)64 65class plain(_Monte):66 """67 """68 _alloc = _callback.gsl_monte_plain_alloc69 _free = _callback.gsl_monte_plain_free70 _integrate = _callback.gsl_monte_plain_integrate71 _init = _callback.gsl_monte_plain_init72 pass73class miser(_Monte):74 """75 """76 _alloc = _callback.gsl_monte_miser_alloc77 _free = _callback.gsl_monte_miser_free78 _integrate = _callback.gsl_monte_miser_integrate79 _init = _callback.gsl_monte_miser_init80 def get_min_calls (self): return _callback.pygsl_monte_miser_get_min_calls (self._ptr) 81 def get_min_calls_per_bisection (self): return _callback.pygsl_monte_miser_get_min_calls_per_bisection (self._ptr)82 def get_dither (self): return _callback.pygsl_monte_miser_get_dither (self._ptr)83 def get_estimate_frac (self): return _callback.pygsl_monte_miser_get_estimate_frac (self._ptr)84 def get_alpha (self): return _callback.pygsl_monte_miser_get_alpha (self._ptr)85 86 def set_min_calls (self, arg1): return _callback.pygsl_monte_miser_set_min_calls (self._ptr, arg1)87 def set_min_calls_per_bisection (self, arg1): return _callback.pygsl_monte_miser_set_min_calls_per_bisection (self._ptr, arg1)88 def set_dither (self, arg1): return _callback.pygsl_monte_miser_set_dither (self._ptr, arg1)89 def set_estimate_frac (self, arg1): return _callback.pygsl_monte_miser_set_estimate_frac (self._ptr, arg1)90 def set_alpha (self, arg1): return _callback.pygsl_monte_miser_set_alpha (self._ptr, arg1)91class vegas(_Monte):92 """93 """94 _alloc = _callback.gsl_monte_vegas_alloc95 _free = _callback.gsl_monte_vegas_free96 _integrate = _callback.gsl_monte_vegas_integrate97 _init = _callback.gsl_monte_vegas_init98 def get_result (self): return _callback.pygsl_monte_vegas_get_result (self._ptr)99 def get_sigma (self): return _callback.pygsl_monte_vegas_get_sigma (self._ptr)100 def get_chisq (self): return _callback.pygsl_monte_vegas_get_chisq (self._ptr)101 def get_alpha (self): return _callback.pygsl_monte_vegas_get_alpha (self._ptr)102 def get_iterations (self): return _callback.pygsl_monte_vegas_get_iterations(self._ptr)103 def get_stage (self): return _callback.pygsl_monte_vegas_get_stage (self._ptr)104 def get_mode (self): return _callback.pygsl_monte_vegas_get_mode (self._ptr)105 def get_verbose (self): return _callback.pygsl_monte_vegas_get_verbose (self._ptr)106 def get_ostream (self): return _callback.pygsl_monte_vegas_get_ostream (self._ptr)107 108 def set_result (self, arg1): return _callback.pygsl_monte_vegas_set_result (self._ptr, arg1)109 def set_sigma (self, arg1): return _callback.pygsl_monte_vegas_set_sigma (self._ptr, arg1)110 def set_chisq (self, arg1): return _callback.pygsl_monte_vegas_set_chisq (self._ptr, arg1)111 def set_alpha (self, arg1): return _callback.pygsl_monte_vegas_set_alpha (self._ptr, arg1)112 def set_iterations (self, arg1): return _callback.pygsl_monte_vegas_set_iterations(self._ptr, arg1)113 def set_stage (self, arg1): return _callback.pygsl_monte_vegas_set_stage (self._ptr, arg1)114 def set_mode (self, arg1): return _callback.pygsl_monte_vegas_set_mode (self._ptr, arg1)115 def set_verbose (self, arg1): return _callback.pygsl_monte_vegas_set_verbose (self._ptr, arg1)...

Full Screen

Full Screen

engine.py

Source:engine.py Github

copy

Full Screen

1import abc2from typing import Optional, Any, Dict3from pytools.pytorch.typing import Callback4__all__ = ['Engine']5class Engine(object, metaclass=abc.ABCMeta):6 def __init__(self, callback: Optional[Callback]):7 self._callback = callback8 @property9 @abc.abstractmethod10 def global_step(self):11 raise NotImplementedError12 @property13 def callback(self):14 return self._callback15 def _prior_all(self):16 if self._callback is not None:17 self._callback.prior_all(self)18 def _after_all(self):19 if self._callback is not None:20 self._callback.after_all(self)21 def _prior_batch(self, inputs):22 if self._callback is not None:23 self._callback.prior_batch(self, inputs)24 def _after_batch(self, inputs, outputs):25 if self._callback is not None:26 self._callback.after_batch(self, inputs, outputs)27 def _prior_epoch(self, data_loader):28 if self._callback is not None:29 self._callback.prior_epoch(self, data_loader)30 def _after_epoch(self, data_loader):31 if self._callback is not None:32 self._callback.after_epoch(self, data_loader)33 def _prior_forward(self):34 if self._callback is not None:35 self._callback.prior_forward(self)36 def _after_forward(self):37 if self._callback is not None:38 self._callback.after_forward(self)39 def _prior_backward(self):40 if self._callback is not None:41 self._callback.prior_backward(self)42 def _after_backward(self):43 if self._callback is not None:44 self._callback.after_backward(self)45 def state_dict(self) -> Dict[str, Any]:46 return {47 'callback': self._callback.state_dict()48 }49 def load_state_dict(self, state: Dict[str, Any]):50 if 'callback' in state:...

Full Screen

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 Slash 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