|
73 | 73 | "squeeze",
|
74 | 74 | "stack",
|
75 | 75 | "swapaxes",
|
| 76 | + "tile", |
76 | 77 | "transpose",
|
77 | 78 | "unique",
|
78 | 79 | "vstack",
|
@@ -945,7 +946,7 @@ def reshape(a, /, newshape, order="C", copy=None):
|
945 | 946 |
|
946 | 947 | Parameters
|
947 | 948 | ----------
|
948 |
| - a : {dpnp_array, usm_ndarray} |
| 949 | + a : {dpnp.ndarray, usm_ndarray} |
949 | 950 | Array to be reshaped.
|
950 | 951 | newshape : int or tuple of ints
|
951 | 952 | The new shape should be compatible with the original shape. If
|
@@ -1387,6 +1388,84 @@ def swapaxes(a, axis1, axis2):
|
1387 | 1388 | )
|
1388 | 1389 |
|
1389 | 1390 |
|
| 1391 | +def tile(A, reps): |
| 1392 | + """ |
| 1393 | + Construct an array by repeating `A` the number of times given by reps. |
| 1394 | +
|
| 1395 | + If `reps` has length ``d``, the result will have dimension of |
| 1396 | + ``max(d, A.ndim)``. |
| 1397 | +
|
| 1398 | + If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new |
| 1399 | + axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication, |
| 1400 | + or shape (1, 1, 3) for 3-D replication. If this is not the desired |
| 1401 | + behavior, promote `A` to d-dimensions manually before calling this |
| 1402 | + function. |
| 1403 | +
|
| 1404 | + If ``A.ndim > d``, `reps` is promoted to `A`.ndim by prepending 1's to it. |
| 1405 | + Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as |
| 1406 | + (1, 1, 2, 2). |
| 1407 | +
|
| 1408 | + Note : Although tile may be used for broadcasting, it is strongly |
| 1409 | + recommended to use dpnp's broadcasting operations and functions. |
| 1410 | +
|
| 1411 | + For full documentation refer to :obj:`numpy.tile`. |
| 1412 | +
|
| 1413 | + Parameters |
| 1414 | + ---------- |
| 1415 | + A : dpnp.ndarray |
| 1416 | + The input array. |
| 1417 | + reps : array_like |
| 1418 | + The number of repetitions of `A` along each axis. |
| 1419 | +
|
| 1420 | + Returns |
| 1421 | + ------- |
| 1422 | + c : dpnp.ndarray |
| 1423 | + The tiled output array. |
| 1424 | +
|
| 1425 | + See Also |
| 1426 | + -------- |
| 1427 | + :obj:`dpnp.repeat` : Repeat elements of an array. |
| 1428 | + :obj:`dpnp.broadcast_to` : Broadcast an array to a new shape |
| 1429 | +
|
| 1430 | + Examples |
| 1431 | + -------- |
| 1432 | + >>> import dpnp as np |
| 1433 | + >>> a = np.array([0, 1, 2]) |
| 1434 | + >>> np.tile(a, 2) |
| 1435 | + array([0, 1, 2, 0, 1, 2]) |
| 1436 | +
|
| 1437 | + >>> np.tile(a, (2, 2)) |
| 1438 | + array([[0, 1, 2, 0, 1, 2], |
| 1439 | + [0, 1, 2, 0, 1, 2]]) |
| 1440 | +
|
| 1441 | + >>> np.tile(a, (2, 1, 2)) |
| 1442 | + array([[[0, 1, 2, 0, 1, 2]], |
| 1443 | + [[0, 1, 2, 0, 1, 2]]]) |
| 1444 | +
|
| 1445 | + >>> b = np.array([[1, 2], [3, 4]]) |
| 1446 | + >>> np.tile(b, 2) |
| 1447 | + array([[1, 2, 1, 2], |
| 1448 | + [3, 4, 3, 4]]) |
| 1449 | +
|
| 1450 | + >>> np.tile(b, (2, 1)) |
| 1451 | + array([[1, 2], |
| 1452 | + [3, 4], |
| 1453 | + [1, 2], |
| 1454 | + [3, 4]]) |
| 1455 | +
|
| 1456 | + >>> c = np.array([1, 2, 3, 4]) |
| 1457 | + >>> np.tile(c, (4, 1)) |
| 1458 | + array([[1, 2, 3, 4], |
| 1459 | + [1, 2, 3, 4], |
| 1460 | + [1, 2, 3, 4], |
| 1461 | + [1, 2, 3, 4]]) |
| 1462 | +
|
| 1463 | + """ |
| 1464 | + |
| 1465 | + dpt_array = dpnp.get_usm_ndarray(A) |
| 1466 | + return dpnp_array._create_from_usm_ndarray(dpt.tile(dpt_array, reps)) |
| 1467 | + |
| 1468 | + |
1390 | 1469 | def transpose(a, axes=None):
|
1391 | 1470 | """
|
1392 | 1471 | Returns an array with axes transposed.
|
|
0 commit comments