@@ -1494,36 +1494,30 @@ def c_code(self, node, name, inp, out, sub):
1494
1494
1495
1495
# Initialize shape
1496
1496
for i , shp_i in enumerate (inp [1 :]):
1497
- code += """
1498
- shape[%(i)s] = ((dtype_%(shp_i)s*) PyArray_DATA(%(shp_i)s))[0];
1499
- """ % dict (
1500
- i = i , shp_i = shp_i
1501
- )
1497
+ code += f"""
1498
+ shape[{ i } ] = ((dtype_{ shp_i } *) PyArray_DATA({ shp_i } ))[0];
1499
+ """
1502
1500
1503
- code += """
1504
- int need_new_out = (NULL == %(zz)s);
1505
- for (int i = 0; i < %(ndim)s; i++)
1506
- need_new_out = (need_new_out
1507
- || (PyArray_DIMS(%(zz)s)[i] != shape[i]));
1501
+ code += f"""
1502
+ int need_new_out = (NULL == { zz } );
1503
+ for (int i = 0; i < { ndim } ; i++)
1504
+ need_new_out = (need_new_out || (PyArray_DIMS({ zz } )[i] != shape[i]));
1508
1505
1509
1506
if (need_new_out)
1510
- {
1511
- Py_XDECREF(%(zz)s);
1512
- %(zz)s = (PyArrayObject*) PyArray_SimpleNew(%(ndim)s,
1513
- shape, PyArray_TYPE((PyArrayObject*) py_%(vv)s));
1514
- if (!%(zz)s)
1515
- {
1507
+ {{
1508
+ Py_XDECREF({ zz } );
1509
+ { zz } = (PyArrayObject*) PyArray_SimpleNew({ ndim } , shape, PyArray_TYPE((PyArrayObject*) py_{ vv } ));
1510
+ if (!{ zz } )
1511
+ {{
1516
1512
PyErr_SetString(PyExc_MemoryError, "alloc failed");
1517
- %( fail)s
1518
- }
1519
- }
1513
+ { fail }
1514
+ }}
1515
+ }}
1520
1516
1521
1517
// This function takes care of broadcasting
1522
- if (PyArray_CopyInto(%(zz)s, %(vv)s) == -1)
1523
- %(fail)s
1524
- """ % dict (
1525
- vv = vv , ndim = ndim , zz = zz , fail = fail
1526
- )
1518
+ if (PyArray_CopyInto({ zz } , { vv } ) == -1)
1519
+ { fail }
1520
+ """
1527
1521
1528
1522
return code
1529
1523
@@ -1568,7 +1562,7 @@ def grad(self, inputs, grads):
1568
1562
for idx , axis in enumerate (axis_kept ):
1569
1563
new_order [axis ] = idx
1570
1564
gx = gx .dimshuffle (new_order )
1571
- # Dimshuffle to add back the broadcasted dims
1565
+ # Dimshuffle to add back the broadcasted dims
1572
1566
# The *elements* of the output are not connected to
1573
1567
# the inputs that specify the shape. If you grow the
1574
1568
# shape by epsilon, the existing elements do not
0 commit comments