kopia lustrzana https://github.com/sepandhaghighi/samila
Generate method optimization (#163)
* fix : generate method optimized * doc : CHANGELOG updated * fix : missed_points_number added * doc : CHANGELOG updated * fix : tests updatedpull/165/head
rodzic
a2729fb9ab
commit
b8967acc28
|
@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
- `Marker` enum
|
||||
### Changed
|
||||
- `marker` parameter added to `plot` method
|
||||
- `generate` method optimized
|
||||
- Test system modified
|
||||
- `Python 3.11` added to `test.yml`
|
||||
### Removed
|
||||
- `fill_data` function
|
||||
## [0.9] - 2022-09-28
|
||||
### Added
|
||||
- Anaconda workflow
|
||||
|
|
|
@ -412,27 +412,6 @@ def generate_params_filter(
|
|||
g.seed, g.start, g.step, g.stop = seed, start, step, stop
|
||||
|
||||
|
||||
def fill_data(g, point):
|
||||
"""
|
||||
Fill data with functions in given points.
|
||||
|
||||
:param g: generative image instance
|
||||
:type g: GenerativeImage
|
||||
:param point: given point
|
||||
:type point: tuple
|
||||
:return: false if some exception occurred
|
||||
"""
|
||||
random.seed(g.seed)
|
||||
try:
|
||||
data1_ = g.function1(point[0], point[1]).real
|
||||
data2_ = g.function2(point[0], point[1]).real
|
||||
except Exception:
|
||||
return False
|
||||
g.data1.append(data1_)
|
||||
g.data2.append(data2_)
|
||||
return True
|
||||
|
||||
|
||||
def save_params_filter(g, depth=None):
|
||||
"""
|
||||
Filter save_image method parameters.
|
||||
|
@ -480,6 +459,7 @@ def _GI_initializer(g, function1, function2):
|
|||
g.alpha = DEFAULT_ALPHA
|
||||
g.linewidth = DEFAULT_LINEWIDTH
|
||||
g.depth = DEFAULT_DEPTH
|
||||
g.missed_points_number = 0
|
||||
|
||||
|
||||
def nft_storage_upload(api_key, data):
|
||||
|
|
|
@ -7,7 +7,7 @@ import matplotlib
|
|||
import matplotlib.pyplot as plt
|
||||
from .functions import _GI_initializer, plot_params_filter, generate_params_filter, save_params_filter
|
||||
from .functions import float_range, save_data_file, save_fig_file, save_fig_buf, save_config_file
|
||||
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload, fill_data
|
||||
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload
|
||||
from .functions import set_background
|
||||
from .params import *
|
||||
from warnings import warn
|
||||
|
@ -78,13 +78,19 @@ class GenerativeImage:
|
|||
generate_params_filter(self, seed, start, step, stop)
|
||||
self.data1 = []
|
||||
self.data2 = []
|
||||
self.missed_points_number = 0
|
||||
range1 = list(float_range(self.start, self.stop, self.step))
|
||||
range_prod = list(itertools.product(range1, range1))
|
||||
calc_exception = False
|
||||
range_prod = itertools.product(range1, range1)
|
||||
for point in range_prod:
|
||||
if not fill_data(self, point):
|
||||
calc_exception = True
|
||||
if calc_exception:
|
||||
random.seed(self.seed)
|
||||
try:
|
||||
data1_ = self.function1(point[0], point[1]).real
|
||||
data2_ = self.function2(point[0], point[1]).real
|
||||
self.data1.append(data1_)
|
||||
self.data2.append(data2_)
|
||||
except Exception:
|
||||
self.missed_points_number += 1
|
||||
if len(self.data1) < (len(range1) ** 2):
|
||||
warn(CALCULATION_EXCEPTION_WARNING, RuntimeWarning)
|
||||
|
||||
def plot(
|
||||
|
|
|
@ -29,6 +29,8 @@ True
|
|||
True
|
||||
>>> isinstance(g.data2, list)
|
||||
True
|
||||
>>> g.missed_points_number == 0
|
||||
True
|
||||
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
|
||||
>>> g.seed
|
||||
10
|
||||
|
|
|
@ -23,6 +23,8 @@ True
|
|||
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
|
||||
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):
|
||||
... g.generate(start=0, stop=2, step=0.1)
|
||||
>>> g.missed_points_number > 0
|
||||
True
|
||||
>>> with warns(RuntimeWarning, match=r"It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."):
|
||||
... g.plot(color='complement', bgcolor='complement')
|
||||
>>> with warns(RuntimeWarning, match=r"color 'rad' not found. Replacing it with 'red'"):
|
||||
|
|
Ładowanie…
Reference in New Issue