-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fe566b
commit 05140f0
Showing
14 changed files
with
218 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
patreon: GreenWizard | ||
buy_me_a_coffee: greenwizard89 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Support and Funding | ||
|
||
If you want to support my quest for sarcastic humor, brilliant software achievements, and witty commentary, here’s how you can do it: | ||
|
||
1. **Patreon**: All my amazing content there is free. But if you feel an irresistible urge to support me with monthly donations, head over to [my Patreon page](https://www.patreon.com/GreenWizard). Your support will help me keep delighting you with sarcasm and software revelations. | ||
|
||
2. **Buy Me a Coffee**: Prefer one-time acts of generosity? You can buy me a coffee at [Buy Me a Coffee](https://buymeacoffee.com/greenwizard89). Because, honestly, my level of sarcasm and ability to write genius code directly correlate with the amount of caffeine I consume. | ||
|
||
By supporting me, you ensure a continuous flow of sarcasm, wit, and cutting-edge software insights. And who wouldn't want more of that in their life? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
from .ISamplingAlgorithm import ISamplingAlgorithm | ||
from .ISamplerWatcher import ISamplerWatcher | ||
|
||
class CSamplingInterceptor(ISamplingAlgorithm): | ||
class CSamplingInterceptor(ISamplingAlgorithm, ISamplerWatcher): | ||
def __init__(self, watcher, algorithm): | ||
assert issubclass(type(watcher), ISamplerWatcher), f'Invalid watcher: {watcher}' | ||
self._watcher = watcher | ||
self._algorithm = algorithm | ||
return | ||
|
||
def interceptor(self): | ||
def F(algorithm): | ||
if isinstance(self._watcher, ISamplerWatcher): | ||
self._watcher = algorithm = self._watcher.interceptor()(algorithm) | ||
|
||
if callable(self._watcher): # replace the watcher with the interceptor | ||
self._watcher = algorithm = self._watcher(algorithm) | ||
|
||
# if self._algorithm is not None: | ||
# assert isinstance(algorithm, ISamplingAlgorithm), f'algorithm is not an instance of ISamplingAlgorithm: {algorithm}' | ||
return self | ||
return F | ||
|
||
def firstStep(self, **kwargs): | ||
res = self._algorithm.firstStep(**kwargs) | ||
res = self._algorithm.firstStep(**kwargs) if self._algorithm is not None else None | ||
self._watcher._onStart(value=kwargs['value'], kwargs=kwargs) | ||
return res | ||
|
||
def _onStart(self, value, kwargs): | ||
return self._watcher._onStart(value=value, kwargs=kwargs) | ||
|
||
def nextStep(self, **kwargs): | ||
self._watcher._onNextStep(iteration=kwargs['iteration'], kwargs=kwargs) | ||
res = self._algorithm.nextStep(**kwargs) | ||
res = self._algorithm.nextStep(**kwargs) if self._algorithm is not None else None | ||
return res | ||
|
||
def _onNextStep(self, iteration, kwargs): | ||
return self._watcher._onNextStep(iteration=iteration, kwargs=kwargs) | ||
|
||
def inference(self, **kwargs): | ||
return self._algorithm.inference(**kwargs) | ||
return self._algorithm.inference(**kwargs) if self._algorithm is not None else None | ||
|
||
def solve(self, **kwargs): | ||
return self._algorithm.solve(**kwargs) | ||
return self._algorithm.solve(**kwargs) if self._algorithm is not None else None | ||
|
||
def tracked(self, name): | ||
return self._watcher.tracked(name) | ||
# End of CSamplingInterceptor |
Oops, something went wrong.