kopia lustrzana https://github.com/sepandhaghighi/samila
fix : pickle import problem fixed.
rodzic
c87333ae3c
commit
c2281fe197
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, NFT_STORAGE_SUCCESS_MESSAGE, OVERVIEW
|
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, NFT_STORAGE_SUCCESS_MESSAGE, OVERVIEW
|
||||||
import pickle
|
|
||||||
|
|
||||||
|
|
||||||
def float_range(start, stop, step):
|
def float_range(start, stop, step):
|
||||||
|
@ -123,18 +122,17 @@ def samila_help():
|
||||||
print("Repo : https://github.com/sepandhaghighi/samila")
|
print("Repo : https://github.com/sepandhaghighi/samila")
|
||||||
|
|
||||||
|
|
||||||
def isSimilarData(data, path2data, precision=10**-5):
|
def isSameData(data1, data2, precision=10**-5):
|
||||||
"""
|
"""
|
||||||
Compare the data is the same with given file.
|
Compare to data to be the same.
|
||||||
|
|
||||||
:param data: given data
|
:param data1: given data1
|
||||||
:type data: list
|
:type data1: list
|
||||||
:param path2data: comparing data path on storage
|
:param data2: given data2
|
||||||
:type path2data: str
|
:type data2: list
|
||||||
:param precision: comparing precision
|
:param precision: comparing precision
|
||||||
:type precision: float
|
:type precision: float
|
||||||
:return: True if they are the same
|
:return: True if they are the same
|
||||||
"""
|
"""
|
||||||
with open(path2data, "rb") as fp:
|
isSame = map(lambda x, y: abs(x - y) < precision, data1, data2)
|
||||||
temp_data = pickle.load(fp)
|
return all(isSame)
|
||||||
return all(map(lambda x, y: abs(x - y) < precision, data, temp_data))
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
"""
|
"""
|
||||||
>>> import random
|
>>> import random
|
||||||
>>> import math
|
>>> import math
|
||||||
|
>>> import pickle
|
||||||
>>> from samila import GenerativeImage, Projection
|
>>> from samila import GenerativeImage, Projection
|
||||||
>>> from samila.functions import isSimilarData
|
>>> from samila.functions import isSameData
|
||||||
>>> import pickle
|
>>> import pickle
|
||||||
>>> def f1(x,y):
|
>>> def f1(x,y):
|
||||||
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
|
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
|
||||||
|
@ -25,9 +26,13 @@ True
|
||||||
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
|
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
|
||||||
>>> g.seed
|
>>> g.seed
|
||||||
10
|
10
|
||||||
>>> isSimilarData(g.data1, "test/test1_1_d1.pkl")
|
>>> with open("test/test1_1_d1.pkl", "rb") as fp:
|
||||||
|
... temp_data = pickle.load(fp)
|
||||||
|
>>> isSameData(g.data1, temp_data)
|
||||||
True
|
True
|
||||||
>>> isSimilarData(g.data2, "test/test1_1_d2.pkl")
|
>>> with open("test/test1_1_d2.pkl", "rb") as fp:
|
||||||
|
... temp_data = pickle.load(fp)
|
||||||
|
>>> isSameData(g.data2, temp_data)
|
||||||
True
|
True
|
||||||
>>> g.plot()
|
>>> g.plot()
|
||||||
>>> g.plot(color='red')
|
>>> g.plot(color='red')
|
||||||
|
|
Ładowanie…
Reference in New Issue