@@ -39,7 +39,7 @@ def allclose(vec1, vec2, rtol=1e-13, atol=1e-13):
39
39
40
40
41
41
def test_get_shape ():
42
- if not have_numpy : # nosetests work-around
42
+ if not have_numpy :
43
43
return
44
44
get_shape = se .lib .symengine_wrapper .get_shape
45
45
assert get_shape ([1 ]) == (1 ,)
@@ -54,7 +54,7 @@ def test_get_shape():
54
54
55
55
56
56
def test_ravel ():
57
- if not have_numpy : # nosetests work-around
57
+ if not have_numpy :
58
58
return
59
59
x = se .symbols ('x' )
60
60
ravel = se .lib .symengine_wrapper .ravel
@@ -64,7 +64,7 @@ def test_ravel():
64
64
65
65
66
66
def test_Lambdify ():
67
- if not have_numpy : # nosetests work-around
67
+ if not have_numpy :
68
68
return
69
69
n = 7
70
70
args = x , y , z = se .symbols ('x y z' )
@@ -74,7 +74,7 @@ def test_Lambdify():
74
74
75
75
76
76
def test_Lambdify_LLVM ():
77
- if not have_numpy : # nosetests work-around
77
+ if not have_numpy :
78
78
return
79
79
n = 7
80
80
args = x , y , z = se .symbols ('x y z' )
@@ -104,7 +104,7 @@ def check(A, inp):
104
104
105
105
106
106
def test_Lambdify_2dim ():
107
- if not have_numpy : # nosetests work-around
107
+ if not have_numpy :
108
108
return
109
109
lmb , check = _get_2_to_2by2 ()
110
110
for inp in [(5 , 7 ), np .array ([5 , 7 ]), [5.0 , 7.0 ]]:
@@ -125,7 +125,7 @@ def check(arr):
125
125
126
126
127
127
def test_array ():
128
- if not have_numpy : # nosetests work-around
128
+ if not have_numpy :
129
129
return
130
130
args , exprs , inp , check = _get_array ()
131
131
lmb = se .Lambdify (args , exprs )
@@ -134,7 +134,7 @@ def test_array():
134
134
135
135
136
136
def test_numpy_array_out_exceptions ():
137
- if not have_numpy : # nosetests work-around
137
+ if not have_numpy :
138
138
return
139
139
args , exprs , inp , check = _get_array ()
140
140
lmb = se .Lambdify (args , exprs )
@@ -161,7 +161,7 @@ def test_numpy_array_out_exceptions():
161
161
162
162
163
163
def test_broadcast ():
164
- if not have_numpy : # nosetests work-around
164
+ if not have_numpy :
165
165
return
166
166
a = np .linspace (- np .pi , np .pi )
167
167
inp = np .vstack ((np .cos (a ), np .sin (a ))).T # 50 rows 2 cols
@@ -174,7 +174,7 @@ def test_broadcast():
174
174
175
175
176
176
def test_broadcast_multiple_extra_dimensions ():
177
- if not have_numpy : # nosetests work-around
177
+ if not have_numpy :
178
178
return
179
179
inp = np .arange (12. ).reshape ((4 , 3 , 1 ))
180
180
x = se .symbols ('x' )
@@ -198,7 +198,7 @@ def _get_cse_exprs():
198
198
199
199
200
200
def test_cse ():
201
- if not have_numpy : # nosetests work-around
201
+ if not have_numpy :
202
202
return
203
203
args , exprs , inp , ref = _get_cse_exprs ()
204
204
lmb = se .LambdifyCSE (args , exprs )
@@ -232,7 +232,7 @@ def _get_cse_exprs_big():
232
232
233
233
234
234
def test_cse_big ():
235
- if not have_numpy : # nosetests work-around
235
+ if not have_numpy :
236
236
return
237
237
args , exprs , inp = _get_cse_exprs_big ()
238
238
lmb = se .LambdifyCSE (args , exprs )
@@ -242,7 +242,7 @@ def test_cse_big():
242
242
243
243
244
244
def test_broadcast_c ():
245
- if not have_numpy : # nosetests work-around
245
+ if not have_numpy :
246
246
return
247
247
n = 3
248
248
inp = np .arange (2 * n ).reshape ((n , 2 ))
@@ -254,7 +254,7 @@ def test_broadcast_c():
254
254
255
255
256
256
def test_broadcast_fortran ():
257
- if not have_numpy : # nosetests work-around
257
+ if not have_numpy :
258
258
return
259
259
n = 3
260
260
inp = np .arange (2 * n ).reshape ((n , 2 ), order = 'F' )
@@ -284,15 +284,15 @@ def check(A, inp):
284
284
285
285
286
286
def test_2dim_Matrix ():
287
- if not have_numpy : # nosetests work-around
287
+ if not have_numpy :
288
288
return
289
289
L , check = _get_1_to_2by3_matrix ()
290
290
inp = [7 ]
291
291
check (L (inp ), inp )
292
292
293
293
294
294
def test_2dim_Matrix__sympy ():
295
- if not have_numpy : # nosetests work-around
295
+ if not have_numpy :
296
296
return
297
297
import sympy as sp
298
298
L , check = _get_1_to_2by3_matrix (sp .Matrix )
@@ -311,13 +311,13 @@ def _test_2dim_Matrix_broadcast():
311
311
312
312
313
313
def test_2dim_Matrix_broadcast ():
314
- if not have_numpy : # nosetests work-around
314
+ if not have_numpy :
315
315
return
316
316
_test_2dim_Matrix_broadcast ()
317
317
318
318
319
319
def test_2dim_Matrix_broadcast_multiple_extra_dim ():
320
- if not have_numpy : # nosetests work-around
320
+ if not have_numpy :
321
321
return
322
322
L , check = _get_1_to_2by3_matrix ()
323
323
inp = np .arange (1 , 4 * 5 * 6 + 1 ).reshape ((4 , 5 , 6 ))
@@ -328,7 +328,7 @@ def test_2dim_Matrix_broadcast_multiple_extra_dim():
328
328
329
329
330
330
def test_jacobian ():
331
- if not have_numpy : # nosetests work-around
331
+ if not have_numpy :
332
332
return
333
333
x , y = se .symbols ('x, y' )
334
334
args = se .DenseMatrix (2 , 1 , [x , y ])
@@ -343,7 +343,7 @@ def test_jacobian():
343
343
344
344
345
345
def test_jacobian__broadcast ():
346
- if not have_numpy : # nosetests work-around
346
+ if not have_numpy :
347
347
return
348
348
x , y = se .symbols ('x, y' )
349
349
args = se .DenseMatrix (2 , 1 , [x , y ])
@@ -362,7 +362,7 @@ def test_jacobian__broadcast():
362
362
363
363
364
364
def test_excessive_args ():
365
- if not have_numpy : # nosetests work-around
365
+ if not have_numpy :
366
366
return
367
367
x = se .symbols ('x' )
368
368
lmb = se .Lambdify ([x ], [- x ])
@@ -374,7 +374,7 @@ def test_excessive_args():
374
374
375
375
376
376
def test_excessive_out ():
377
- if not have_numpy : # nosetests work-around
377
+ if not have_numpy :
378
378
return
379
379
x = se .symbols ('x' )
380
380
lmb = se .Lambdify ([x ], [- x ])
@@ -419,7 +419,7 @@ def check(A, inp):
419
419
420
420
421
421
def test_2_to_2by2 ():
422
- if not have_numpy : # nosetests work-around
422
+ if not have_numpy :
423
423
return
424
424
L , check = _get_2_to_2by2_list ()
425
425
inp = [13 , 17 ]
@@ -428,7 +428,7 @@ def test_2_to_2by2():
428
428
429
429
430
430
def test_unsafe_real ():
431
- if not have_numpy : # nosetests work-around
431
+ if not have_numpy :
432
432
return
433
433
L , check = _get_2_to_2by2_list ()
434
434
inp = np .array ([13. , 17. ])
@@ -438,7 +438,7 @@ def test_unsafe_real():
438
438
439
439
440
440
def test_unsafe_complex ():
441
- if not have_numpy : # nosetests work-around
441
+ if not have_numpy :
442
442
return
443
443
L , check = _get_2_to_2by2_list (real = False )
444
444
assert not L .real
@@ -449,7 +449,7 @@ def test_unsafe_complex():
449
449
450
450
451
451
def test_itertools_chain ():
452
- if not have_numpy : # nosetests work-around
452
+ if not have_numpy :
453
453
return
454
454
args , exprs , inp , check = _get_array ()
455
455
L = se .Lambdify (args , exprs )
@@ -460,7 +460,7 @@ def test_itertools_chain():
460
460
461
461
# @pytest.mark.xfail(not have_numpy, reason='array.array lacks "Zd"')
462
462
def test_complex_1 ():
463
- if not have_numpy : # nosetests work-around
463
+ if not have_numpy :
464
464
return
465
465
x = se .Symbol ('x' )
466
466
lmb = se .Lambdify ([x ], [1j + x ], real = False )
@@ -470,7 +470,7 @@ def test_complex_1():
470
470
471
471
# @pytest.mark.xfail(not have_numpy, reason='array.array lacks "Zd"')
472
472
def test_complex_2 ():
473
- if not have_numpy : # nosetests work-around
473
+ if not have_numpy :
474
474
return
475
475
x = se .Symbol ('x' )
476
476
lmb = se .Lambdify ([x ], [3 + x - 1j ], real = False )
@@ -482,7 +482,7 @@ def test_more_than_255_args():
482
482
# SymPy's lambdify can handle at most 255 arguments
483
483
# this is a proof of concept that this limitation does
484
484
# not affect SymEngine's Lambdify class
485
- if not have_numpy : # nosetests work-around
485
+ if not have_numpy :
486
486
return
487
487
n = 257
488
488
x = se .symarray ('x' , n )
@@ -507,7 +507,7 @@ def _Lambdify_heterogeneous_output(Lambdify):
507
507
v = se .DenseMatrix (2 , 1 , [x ** 3 * y , (x + 1 )* (y + 1 )])
508
508
jac = v .jacobian (args )
509
509
exprs = [jac , x + y , v , (x + 1 )* (y + 1 )]
510
- lmb = se . Lambdify (args , * exprs )
510
+ lmb = Lambdify (args , * exprs )
511
511
inp0 = 7 , 11
512
512
inp1 = 8 , 13
513
513
inp2 = 5 , 9
@@ -522,12 +522,39 @@ def _Lambdify_heterogeneous_output(Lambdify):
522
522
523
523
524
524
def test_Lambdify_heterogeneous_output ():
525
- if not have_numpy : # nosetests work-around
525
+ if not have_numpy :
526
526
return
527
527
_Lambdify_heterogeneous_output (se .Lambdify )
528
528
529
529
530
530
def test_LambdifyCSE_heterogeneous_output ():
531
- if not have_numpy : # nosetests work-around
531
+ if not have_numpy :
532
532
return
533
533
_Lambdify_heterogeneous_output (se .LambdifyCSE )
534
+
535
+
536
+ def _sympy_lambdify_heterogeneous_output (cb , Mtx ):
537
+ x , y = se .symbols ('x, y' )
538
+ args = Mtx (2 , 1 , [x , y ])
539
+ v = Mtx (2 , 1 , [x ** 3 * y , (x + 1 )* (y + 1 )])
540
+ jac = v .jacobian (args )
541
+ exprs = [jac , x + y , v , (x + 1 )* (y + 1 )]
542
+ lmb = cb (args , exprs )
543
+ inp0 = 7 , 11
544
+ inp1 = 8 , 13
545
+ inp2 = 5 , 9
546
+ for idx , (X , Y ) in enumerate ([inp0 , inp1 , inp2 ]):
547
+ o_j , o_xpy , o_v , o_xty = lmb (X , Y )
548
+ assert np .allclose (o_j , [[3 * X ** 2 * Y , X ** 3 ],
549
+ [Y + 1 , X + 1 ]])
550
+ assert np .allclose (o_xpy , [X + Y ])
551
+ assert np .allclose (o_v , [[X ** 3 * Y ], [(X + 1 )* (Y + 1 )]])
552
+ assert np .allclose (o_xty , [(X + 1 )* (Y + 1 )])
553
+
554
+
555
+ def test_lambdify__sympy ():
556
+ if not have_numpy :
557
+ return
558
+ import sympy as sp
559
+ _sympy_lambdify_heterogeneous_output (se .lambdify , se .DenseMatrix )
560
+ _sympy_lambdify_heterogeneous_output (sp .lambdify , sp .Matrix )
0 commit comments