Révision 117
pobysoPythonSage/src/testPobyso.sage (revision 117) | ||
---|---|---|
13 | 13 |
# |
14 | 14 |
import inspect |
15 | 15 |
import resource |
16 |
import timeit |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
def memory_usage_resource(): |
... | ... | |
24 | 25 |
return mem |
25 | 26 |
# End memory_usage_resource() |
26 | 27 |
|
28 |
def test_pobyso_wrapper(func, *args, **kwargs): |
|
29 |
def wrapped(): |
|
30 |
return func(*args, **kwargs) |
|
31 |
return wrapped |
|
32 |
|
|
27 | 33 |
# |
28 | 34 |
def test_pobyso_absolute_so_so(): |
29 | 35 |
for index in xrange(0,1000000): |
... | ... | |
38 | 44 |
sollya_lib_clear_obj(absoluteSo) |
39 | 45 |
# End test_pobyso_autoprint |
40 | 46 |
|
41 |
def test_pobyso_bounds_to_range_sa_so(iterationsNum=10000):
|
|
42 |
global t
|
|
43 |
print "Running", inspect.stack()[0][3] |
|
47 |
def test_pobyso_bounds_to_range_sa_so(repeat=1000, number=10):
|
|
48 |
functionName = inspect.stack()[0][3]
|
|
49 |
print "Running", inspect.stack()[0][3], "..."
|
|
44 | 50 |
lowerBoundSa = RR(1) |
45 | 51 |
upperBoundSa = RR(2) |
46 | 52 |
precSo = pobyso_get_prec_so() |
47 |
pobyso_autoprint(precSo) |
|
48 |
for index in xrange(0,iterationsNum): |
|
53 |
#pobyso_autoprint(precSo) |
|
54 |
# |
|
55 |
def test(lowerBoundSa, upperBoundSa): |
|
49 | 56 |
rangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa) |
50 | 57 |
sollya_lib_clear_obj(rangeSo) |
58 |
# |
|
59 |
wrapped = test_pobyso_wrapper(test,lowerBoundSa, upperBoundSa) |
|
60 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
61 |
# |
|
51 | 62 |
precSo = pobyso_get_prec_so() |
52 |
pobyso_autoprint(precSo) |
|
63 |
#pobyso_autoprint(precSo)
|
|
53 | 64 |
sollya_lib_clear_obj(precSo) |
65 |
print "\t...", functionName, "done." |
|
66 |
return timing |
|
54 | 67 |
# End test_pobyso_bounds_to_range_sa_so |
55 | 68 |
|
69 |
def test_pobyso_get_list_elements_so_so(repeat = 1000, number=10): |
|
70 |
functionName = inspect.stack()[0][3] |
|
71 |
print "Running", functionName, "..." |
|
72 |
def test(): |
|
73 |
listSo = pobyso_parse_string_sa_so("[|0,1,2,3,4,5,6|];") |
|
74 |
(listSaSo, elementsNumSa, isEndEllipticSa) = \ |
|
75 |
pobyso_get_list_elements(listSo) |
|
76 |
for elementSo in listSaSo: |
|
77 |
sollya_lib_clear_obj(elementSo) |
|
78 |
# Notice that we use sollya_lib_clear_obj and not |
|
79 |
# sollya_lib_clear_object_list. |
|
80 |
sollya_lib_clear_obj(listSo, None) |
|
81 |
# |
|
82 |
wrapped = test_pobyso_wrapper(test) |
|
83 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
84 |
print "\t...", functionName, "done." |
|
85 |
return timing |
|
86 |
# End test_pobyso_get_list_elements |
|
87 |
|
|
56 | 88 |
def test_pobyso_get_prec_so_sa(iterationsNum=10000): |
57 | 89 |
print "Running", inspect.stack()[0][3] |
58 | 90 |
for index in xrange(0,iterationsNum): |
... | ... | |
84 | 116 |
sollya_lib_clear_obj(expressionSo) |
85 | 117 |
# End pobyso_parse_string_sa_so |
86 | 118 |
|
87 |
def test_pobyso_taylor_expansion_no_change_var_so_so(iterationsNum=10000): |
|
119 |
def test_pobyso_taylor_expansion_no_change_var_so_so(repeat=1000, number=10): |
|
120 |
functionName = inspect.stack()[0][3] |
|
121 |
print "Running", functionName, "..." |
|
88 | 122 |
functionSo = pobyso_parse_string('exp(x)') |
89 | 123 |
degreeSo = pobyso_constant_from_int_sa_so(20) |
90 | 124 |
rangeSo = pobyso_bounds_to_range_sa_so(RR(1),RR(2)) |
91 | 125 |
errorTypeSo = pobyso_absolute_so_so() |
92 |
for index in xrange(0,iterationsNum):
|
|
126 |
def test(functionSo, degreeSo, rangeSo, errorTypeSo):
|
|
93 | 127 |
teSo = pobyso_taylor_expansion_no_change_var_so_so(functionSo, |
94 | 128 |
degreeSo, |
95 | 129 |
rangeSo, |
... | ... | |
97 | 131 |
sollya_lib_clear_obj(teSo[0]) |
98 | 132 |
sollya_lib_clear_obj(teSo[1]) |
99 | 133 |
sollya_lib_clear_obj(teSo[2]) |
134 |
# End test |
|
135 |
wrapped = test_pobyso_wrapper(test, |
|
136 |
functionSo, |
|
137 |
degreeSo, |
|
138 |
rangeSo, |
|
139 |
errorTypeSo) |
|
140 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
100 | 141 |
sollya_lib_clear_obj(functionSo) |
101 | 142 |
sollya_lib_clear_obj(degreeSo) |
102 | 143 |
sollya_lib_clear_obj(rangeSo) |
103 | 144 |
sollya_lib_clear_obj(errorTypeSo) |
145 |
print "\t...", functionName, "done." |
|
146 |
return timing |
|
104 | 147 |
# End test_pobyso_taylor_expansion_no_change_var_so_so |
105 | 148 |
|
149 |
def test_pobyso_taylor_form_so_so_2(repeat=1000, number=10): |
|
150 |
functionName = inspect.stack()[0][3] |
|
151 |
print "Running", functionName, "..." |
|
152 |
functionSo = pobyso_parse_string('exp(x)') |
|
153 |
degreeSo = pobyso_constant_from_int_sa_so(20) |
|
154 |
rangeSo = pobyso_bounds_to_range_sa_so(RR(1),RR(2)) |
|
155 |
intervalCenterSo = sollya_lib_mid(rangeSo, None) |
|
156 |
errorTypeSo = pobyso_absolute_so_so() |
|
157 |
|
|
158 |
def test(functionSo, degreeSo, intervalCenterSo, errorTypeSo): |
|
159 |
taylorformSo = pobyso_taylorform_so_so(functionSo, |
|
160 |
degreeSo, |
|
161 |
intervalCenterSo, |
|
162 |
errorTypeSo) |
|
163 |
sollya_lib_clear_obj(taylorformSo) |
|
164 |
wrapped = test_pobyso_wrapper(test, |
|
165 |
functionSo, |
|
166 |
degreeSo, |
|
167 |
intervalCenterSo, |
|
168 |
errorTypeSo) |
|
169 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
170 |
sollya_lib_clear_obj(functionSo,None) |
|
171 |
sollya_lib_clear_obj(degreeSo,None) |
|
172 |
sollya_lib_clear_obj(rangeSo,None) |
|
173 |
sollya_lib_clear_obj(intervalCenterSo,None) |
|
174 |
sollya_lib_clear_obj(errorTypeSo,None) |
|
175 |
return timing |
|
176 |
# End test_pobyso_taylor_so_so_2 |
|
177 |
|
|
178 |
def test_pobyso_dummy_test(iterationsNum=1, executionsNum=1): |
|
179 |
aString = "2+3" |
|
180 |
def test(): |
|
181 |
return 2+3 |
|
182 |
wrapped = test_pobyso_wrapper(test) |
|
183 |
timing = timeit.timeit(wrapped, number=executionsNum) |
|
184 |
return timing |
|
106 | 185 |
print "\t...testPobyso loaded" |
pobysoPythonSage/src/pobyso.py (revision 117) | ||
---|---|---|
147 | 147 |
return(resultSo) |
148 | 148 |
# End pobyso_chebyshevform_so_so. |
149 | 149 |
|
150 |
def pobyso_clear_taylorform_sa_so(taylorFormSaSo): |
|
151 |
""" |
|
152 |
This method is necessary to correctly clean up the memory from Taylor forms. |
|
153 |
These are made of a Sollya object, a Sollya object list, a Sollya object. |
|
154 |
For no clearly understood reason, sollya_lib_clear_object_list crashed |
|
155 |
when applied to the object list. |
|
156 |
Here, we decompose it into Sage list of Sollya objects references and we |
|
157 |
clear them one by one. |
|
158 |
""" |
|
159 |
sollya_lib_clear_obj(taylorFormSaSo[0]) |
|
160 |
(coefficientsErrorsListSaSo, numElementsSa, isEndEllipticSa) = \ |
|
161 |
pobyso_get_list_elements_so_so(taylorFormSaSo[1]) |
|
162 |
for element in coefficientsErrorsListSaSo: |
|
163 |
sollya_lib_clear_obj(element) |
|
164 |
sollya_lib_clear_obj(taylorFormSaSo[1]) |
|
165 |
sollya_lib_clear_obj(taylorFormSaSo[2]) |
|
166 |
# End pobyso_clear_taylorform_sa_so |
|
167 |
|
|
150 | 168 |
def pobyso_cmp(rnArgSa, cteSo): |
151 | 169 |
""" |
152 | 170 |
Compare the MPFR value a RealNumber with that of a Sollya constant. |
... | ... | |
262 | 280 |
|
263 | 281 |
def pobyso_constant_from_int_so_sa(constSo): |
264 | 282 |
""" |
265 |
Get Sage int from a Sollya int constant. |
|
283 |
Get a Sage int from a Sollya int constant.
|
|
266 | 284 |
Usefull for precision or powers in polynomials. |
267 | 285 |
""" |
268 | 286 |
constSa = c_int(0) |
... | ... | |
479 | 497 |
""" Legacy function. See pobyso_get_list_elements_so_so. """ |
480 | 498 |
return(pobyso_get_list_elements_so_so(soObj)) |
481 | 499 |
|
482 |
def pobyso_get_list_elements_so_so(objSo): |
|
500 |
def pobyso_get_list_elements_so_so(objectListSo):
|
|
483 | 501 |
""" |
484 | 502 |
Get the list elements as a Sage/Python array of Sollya objects. |
485 | 503 |
The other data returned are Sage/Python objects. |
... | ... | |
487 | 505 |
listAddress = POINTER(c_longlong)() |
488 | 506 |
numElements = c_int(0) |
489 | 507 |
isEndElliptic = c_int(0) |
490 |
listAsList = [] |
|
508 |
listAsSageList = []
|
|
491 | 509 |
result = sollya_lib_get_list_elements(byref(listAddress),\ |
492 | 510 |
byref(numElements),\ |
493 | 511 |
byref(isEndElliptic),\ |
494 |
objSo) |
|
512 |
objectListSo)
|
|
495 | 513 |
if result == 0 : |
496 | 514 |
return None |
497 | 515 |
for i in xrange(0, numElements.value, 1): |
498 |
listAsList.append(sollya_lib_copy_obj(listAddress[i])) |
|
499 |
return(listAsList, numElements.value, isEndElliptic.value) |
|
516 |
listAsSageList.append(sollya_lib_copy_obj(listAddress[i])) |
|
517 |
# Clear each of the elements returned by Sollya. |
|
518 |
sollya_lib_clear_obj(listAddress[i]) |
|
519 |
# Free the list itself. |
|
520 |
sollya_lib_free(listAddress) |
|
521 |
return(listAsSageList, numElements.value, isEndElliptic.value) |
|
500 | 522 |
|
501 | 523 |
def pobyso_get_max_prec_of_exp(soExp): |
502 | 524 |
""" Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """ |
... | ... | |
988 | 1010 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \ |
989 | 1011 |
intervalCenterSo, \ |
990 | 1012 |
rangeSo, errorTypeSo, None) |
1013 |
# taylorFormListSaSo is a Python list of Sollya objects references that |
|
1014 |
# are copies of the elements of taylorFormSo. |
|
1015 |
# pobyso_get_list_elements_so_so clears taylorFormSo. |
|
991 | 1016 |
(taylorFormListSo, numElements, isEndElliptic) = \ |
992 | 1017 |
pobyso_get_list_elements_so_so(taylorFormSo) |
993 | 1018 |
polySo = taylorFormListSo[0] |
... | ... | |
1009 | 1034 |
return((polyVarChangedSo, intervalCenterSo, maxErrorSo)) |
1010 | 1035 |
# end pobyso_taylor_expansion_with_change_var_so_so |
1011 | 1036 |
|
1012 |
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, \
|
|
1013 |
errorTypeSo=None, \
|
|
1037 |
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, |
|
1038 |
errorTypeSo=None, |
|
1014 | 1039 |
sollyaPrecSo=None): |
1015 | 1040 |
""" |
1016 | 1041 |
Compute the Taylor expansion without the variable change |
... | ... | |
1026 | 1051 |
errorTypeSo = sollya_lib_absolute(None) |
1027 | 1052 |
else: |
1028 | 1053 |
errorTypeIsNone = False |
1029 |
intervalCenterSo = sollya_lib_mid(rangeSo) |
|
1030 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
|
|
1031 |
intervalCenterSo, \
|
|
1054 |
intervalCenterSo = sollya_lib_mid(rangeSo, None)
|
|
1055 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, |
|
1056 |
intervalCenterSo, |
|
1032 | 1057 |
rangeSo, errorTypeSo, None) |
1033 | 1058 |
# taylorFormListSaSo is a Python list of Sollya objects references that |
1034 | 1059 |
# are copies of the elements of taylorFormSo. |
1035 | 1060 |
# pobyso_get_list_elements_so_so clears taylorFormSo. |
1036 | 1061 |
(taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \ |
1037 | 1062 |
pobyso_get_list_elements_so_so(taylorFormSo) |
1063 |
sollya_lib_clear_obj(taylorFormSo) |
|
1038 | 1064 |
polySo = sollya_lib_copy_obj(taylorFormListSaSo[0]) |
1065 |
#polySo = taylorFormListSaSo[0] |
|
1039 | 1066 |
#errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2]) |
1040 |
#polySo = taylorFormListSaSo[0] |
|
1041 | 1067 |
errorRangeSo = taylorFormListSaSo[2] |
1042 | 1068 |
# No copy_obj needed here: a new object is created. |
1043 | 1069 |
maxErrorSo = sollya_lib_sup(errorRangeSo) |
... | ... | |
1047 | 1073 |
sollya_lib_clear_obj(initialPrecSo) |
1048 | 1074 |
if errorTypeIsNone: |
1049 | 1075 |
sollya_lib_clear_obj(errorTypeSo) |
1050 |
for element in taylorFormListSaSo: |
|
1051 |
sollya_lib_clear_obj(element) |
|
1076 |
pobyso_clear_taylorform_sa_so(taylorFormListSaSo) |
|
1052 | 1077 |
return((polySo, intervalCenterSo, maxErrorSo)) |
1053 | 1078 |
# end pobyso_taylor_expansion_no_change_var_so_so |
1054 | 1079 |
|
pobysoPythonSage/src/sollya_lib.sage (revision 117) | ||
---|---|---|
33 | 33 |
sollya_lib_copy_obj = sollya.sollya_lib_copy_obj |
34 | 34 |
sollya_lib_cos = sollya.sollya_lib_cos |
35 | 35 |
sollya_lib_evaluate = sollya.sollya_lib_evaluate |
36 |
sollya_lib_free = sollya.sollya_lib_free |
|
36 | 37 |
sollya_lib_get_canonical = sollya.sollya_lib_get_canonical |
37 | 38 |
sollya_lib_get_constant = sollya.sollya_lib_get_constant |
38 | 39 |
sollya_lib_get_constant_as_int = \ |
Formats disponibles : Unified diff