@@ -140,24 +140,24 @@ def test_numpy_array_out_exceptions():
140
140
lmb = se .Lambdify (args , exprs )
141
141
142
142
all_right = np .empty (len (exprs ))
143
- lmb (inp , all_right )
143
+ lmb (inp , out = all_right )
144
144
145
145
too_short = np .empty (len (exprs ) - 1 )
146
- raises (ValueError , lambda : (lmb (inp , too_short )))
146
+ raises (ValueError , lambda : (lmb (inp , out = too_short )))
147
147
148
148
wrong_dtype = np .empty (len (exprs ), dtype = int )
149
- raises (ValueError , lambda : (lmb (inp , wrong_dtype )))
149
+ raises (ValueError , lambda : (lmb (inp , out = wrong_dtype )))
150
150
151
151
read_only = np .empty (len (exprs ))
152
152
read_only .flags ['WRITEABLE' ] = False
153
- raises (ValueError , lambda : (lmb (inp , read_only )))
153
+ raises (ValueError , lambda : (lmb (inp , out = read_only )))
154
154
155
155
all_right_broadcast = np .empty ((4 , len (exprs )))
156
156
inp_bcast = [[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ], [10 , 11 , 12 ]]
157
- lmb (np .array (inp_bcast ), all_right_broadcast )
157
+ lmb (np .array (inp_bcast ), out = all_right_broadcast )
158
158
159
159
noncontig_broadcast = np .empty ((4 , len (exprs ), 3 )).transpose ((1 , 2 , 0 ))
160
- raises (ValueError , lambda : (lmb (inp_bcast , noncontig_broadcast )))
160
+ raises (ValueError , lambda : (lmb (inp_bcast , out = noncontig_broadcast )))
161
161
162
162
163
163
def test_broadcast ():
@@ -337,7 +337,7 @@ def test_jacobian():
337
337
lmb = se .Lambdify (args , jac )
338
338
out = np .empty ((2 , 2 ))
339
339
inp = X , Y = 7 , 11
340
- lmb (inp , out )
340
+ lmb (inp , out = out )
341
341
assert np .allclose (out , [[3 * X ** 2 * Y , X ** 3 ],
342
342
[Y + 1 , X + 1 ]])
343
343
@@ -355,7 +355,7 @@ def test_jacobian__broadcast():
355
355
inp1 = 8 , 13
356
356
inp2 = 5 , 9
357
357
inp = np .array ([inp0 , inp1 , inp2 ])
358
- lmb (inp , out )
358
+ lmb (inp , out = out )
359
359
for idx , (X , Y ) in enumerate ([inp0 , inp1 , inp2 ]):
360
360
assert np .allclose (out [idx , ...], [[3 * X ** 2 * Y , X ** 3 ],
361
361
[Y + 1 , X + 1 ]])
@@ -380,9 +380,8 @@ def test_excessive_out():
380
380
lmb = se .Lambdify ([x ], [- x ])
381
381
inp = np .ones (1 )
382
382
out = np .ones (2 )
383
- out = lmb (inp , out )
383
+ _ = lmb (inp , out = out [: inp . size ] )
384
384
assert np .allclose (inp , [1 , 1 ])
385
- assert out .shape == (2 ,)
386
385
assert out [0 ] == - 1
387
386
assert out [1 ] == 1
388
387
@@ -558,3 +557,46 @@ def test_lambdify__sympy():
558
557
import sympy as sp
559
558
_sympy_lambdify_heterogeneous_output (se .lambdify , se .DenseMatrix )
560
559
_sympy_lambdify_heterogeneous_output (sp .lambdify , sp .Matrix )
560
+
561
+
562
+ def _test_Lambdify_scalar_vector_matrix (Lambdify ):
563
+ if not have_numpy :
564
+ return
565
+ args = x , y = se .symbols ('x y' )
566
+ vec = se .DenseMatrix ([x + y , x * y ])
567
+ jac = vec .jacobian (se .DenseMatrix (args ))
568
+ f = Lambdify (args , x ** y , vec , jac )
569
+ assert f .n_exprs == 3
570
+ s , v , m = f ([2 , 3 ])
571
+ print (s , v , m )
572
+ assert s == 2 ** 3
573
+ assert np .allclose (v , [[2 + 3 ], [2 * 3 ]])
574
+ assert np .allclose (m , [
575
+ [1 , 1 ],
576
+ [3 , 2 ]
577
+ ])
578
+
579
+ s2 , v2 , m2 = f ([[2 , 3 ], [5 , 7 ]])
580
+ assert np .allclose (s2 , [2 ** 3 , 5 ** 7 ])
581
+ assert np .allclose (v2 , [
582
+ [[2 + 3 ], [2 * 3 ]],
583
+ [[5 + 7 ], [5 * 7 ]]
584
+ ])
585
+ assert np .allclose (m2 , [
586
+ [
587
+ [1 , 1 ],
588
+ [3 , 2 ]
589
+ ],
590
+ [
591
+ [1 , 1 ],
592
+ [7 , 5 ]
593
+ ]
594
+ ])
595
+
596
+
597
+ def test_Lambdify_scalar_vector_matrix ():
598
+ _test_Lambdify_scalar_vector_matrix (lambda * args : se .Lambdify (* args , backend = 'lambda' ))
599
+ _test_Lambdify_scalar_vector_matrix (lambda * args : se .LambdifyCSE (* args , backend = 'lambda' ))
600
+ if se .have_llvm :
601
+ _test_Lambdify_scalar_vector_matrix (lambda * args : se .Lambdify (* args , backend = 'llvm' ))
602
+ _test_Lambdify_scalar_vector_matrix (lambda * args : se .LambdifyCSE (* args , backend = 'llvm' ))
0 commit comments