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