61 def __init__(self, data=None, shape=None, dtype=None):
65 if isinstance(shape, tuple):
66 data = np.zeros(shape, dtype=dtype)
68 raise TypeError(
"shape must be a tuple")
71 if isinstance(data, list):
73 if isinstance(data, np.ndarray):
75 data = data.astype(dtype)
76 if data.dtype == np.int64
or data.dtype == np.int32:
77 self.__data = obj_int(context.context, data)
78 elif data.dtype == np.float32:
79 self.__data = obj_float(context.context, data)
80 elif data.dtype == np.float64:
81 self.__data = obj_double(context.context, data)
82 elif USE_HALF
and data.dtype == np.float16:
83 self.__data = obj_half(context.context, data)
84 elif data.dtype == np.complex64:
85 self.__data = obj_float_complex(context.context, data)
86 elif data.dtype == np.complex128:
87 self.__data = obj_double_complex(context.context, data)
89 raise TypeError(
"Data type not implemented")
90 self.__dtype = data.dtype
91 self.__shape = data.shape
92 elif isinstance(data, obj_int):
94 self.__dtype = np.int64
95 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
96 elif isinstance(data, obj_float):
98 self.__dtype = np.float32
99 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
100 elif isinstance(data, obj_double):
102 self.__dtype = np.float64
103 self._shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
104 elif USE_HALF
and isinstance(data, obj_half):
106 self.__dtype = np.float16
107 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
108 elif isinstance(data, obj_float_complex):
110 self.__dtype = np.complex64
111 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
112 elif isinstance(data, obj_double_complex):
114 self.__dtype = np.complex128
115 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
116 elif isinstance(data, obj_uint16):
118 self.__dtype = np.uint16
119 self.__shape = tuple(data.shape[k]
for k
in range(len(data.shape)))
121 raise TypeError(
"Data must be a list, a numpy array or a carmaWrap.obj")
122 self.__size = self.__data.nbElem
124 raise AttributeError(
"You must provide data or shape at least")