2
2
3
3
import array as py_array
4
4
import ctypes
5
+ import enum
5
6
from dataclasses import dataclass
6
7
from typing import Any
7
8
@@ -125,21 +126,6 @@ def __init__(
125
126
ctypes .pointer (_cshape .c_array ), ctypes .pointer (strides_cshape ), dtype .c_api_value ,
126
127
pointer_source .value ))
127
128
128
- def __str__ (self ) -> str :
129
- # TODO change the look of array str. E.g., like np.array
130
- if not _in_display_dims_limit (self .shape ):
131
- return _metadata_string (self .dtype , self .shape )
132
-
133
- return _metadata_string (self .dtype ) + _array_as_str (self )
134
-
135
- def __repr__ (self ) -> str :
136
- # return _metadata_string(self.dtype, self.shape)
137
- # TODO change the look of array representation. E.g., like np.array
138
- return _array_as_str (self )
139
-
140
- def __len__ (self ) -> int :
141
- return self .shape [0 ] if self .shape else 0
142
-
143
129
# Arithmetic Operators
144
130
145
131
def __pos__ (self ) -> Array :
@@ -441,6 +427,36 @@ def __irshift__(self, other: int | Array, /) -> Array:
441
427
"""
442
428
return _process_c_function (self , other , backend .get ().af_bitshiftr )
443
429
430
+ # Methods
431
+
432
+ def __abs__ (self ) -> Array :
433
+ # TODO
434
+ return NotImplemented
435
+
436
+ def __array_namespace__ (self , * , api_version : None | str = None ) -> Any :
437
+ # TODO
438
+ return NotImplemented
439
+
440
+ def __bool__ (self ) -> bool :
441
+ # TODO
442
+ return NotImplemented
443
+
444
+ def __complex__ (self ) -> complex :
445
+ # TODO
446
+ return NotImplemented
447
+
448
+ def __dlpack__ (self , * , stream : None | int | Any = None ): # type: ignore[no-untyped-def]
449
+ # TODO implementation and expected return type -> PyCapsule
450
+ return NotImplemented
451
+
452
+ def __dlpack_device__ (self ) -> tuple [enum .Enum , int ]:
453
+ # TODO
454
+ return NotImplemented
455
+
456
+ def __float__ (self ) -> float :
457
+ # TODO
458
+ return NotImplemented
459
+
444
460
def __getitem__ (self , key : int | slice | tuple [int | slice ] | Array , / ) -> Array :
445
461
# TODO: API Specification - key: int | slice | ellipsis | tuple[int | slice] | Array
446
462
# TODO: refactor
@@ -456,6 +472,40 @@ def __getitem__(self, key: int | slice | tuple[int | slice] | Array, /) -> Array
456
472
ctypes .pointer (out .arr ), self .arr , c_dim_t (ndims ), _get_indices (key ).pointer ))
457
473
return out
458
474
475
+ def __index__ (self ) -> int :
476
+ # TODO
477
+ return NotImplemented
478
+
479
+ def __int__ (self ) -> int :
480
+ # TODO
481
+ return NotImplemented
482
+
483
+ def __len__ (self ) -> int :
484
+ return self .shape [0 ] if self .shape else 0
485
+
486
+ def __setitem__ (
487
+ self , key : int | slice | tuple [int | slice , ...] | Array , value : int | float | bool | Array , / ) -> None :
488
+ # TODO
489
+ return NotImplemented # type: ignore[return-value] # FIXME
490
+
491
+ def __str__ (self ) -> str :
492
+ # TODO change the look of array str. E.g., like np.array
493
+ if not _in_display_dims_limit (self .shape ):
494
+ return _metadata_string (self .dtype , self .shape )
495
+
496
+ return _metadata_string (self .dtype ) + _array_as_str (self )
497
+
498
+ def __repr__ (self ) -> str :
499
+ # return _metadata_string(self.dtype, self.shape)
500
+ # TODO change the look of array representation. E.g., like np.array
501
+ return _array_as_str (self )
502
+
503
+ def to_device (self , device : Any , / , * , stream : None | int | Any = None ) -> Array :
504
+ # TODO implementation and change device type from Any to Device
505
+ return NotImplemented
506
+
507
+ # Attributes
508
+
459
509
@property
460
510
def dtype (self ) -> Dtype :
461
511
out = ctypes .c_int ()
@@ -464,17 +514,23 @@ def dtype(self) -> Dtype:
464
514
465
515
@property
466
516
def device (self ) -> Any :
467
- raise NotImplementedError
517
+ # TODO
518
+ return NotImplemented
468
519
469
520
@property
470
521
def mT (self ) -> Array :
471
522
# TODO
472
- raise NotImplementedError
523
+ return NotImplemented
473
524
474
525
@property
475
526
def T (self ) -> Array :
476
- # TODO
477
- raise NotImplementedError
527
+ """
528
+ Transpose of the array.
529
+ """
530
+ out = Array ()
531
+ # NOTE conj support is removed because it is never used
532
+ safe_call (backend .get ().af_transpose (ctypes .pointer (out .arr ), self .arr , False ))
533
+ return out
478
534
479
535
@property
480
536
def size (self ) -> int :
@@ -507,6 +563,7 @@ def scalar(self) -> None | int | float | bool | complex:
507
563
"""
508
564
Return the first element of the array
509
565
"""
566
+ # TODO change the logic of this method
510
567
if self .is_empty ():
511
568
return None
512
569
0 commit comments