COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
naga.array.Array Class Reference
Collaboration diagram for naga.array.Array:

Public Member Functions

def __init__ (self, data=None, shape=None, dtype=None)
 
def __repr__ (self)
 
def __add__ (self, idata)
 
def __sub__ (self, idata)
 
def __mul__ (self, idata)
 
def __getitem__ (self, indices)
 
def copy (self)
 
def dot (self, idata)
 
def argmax (self)
 
def max (self)
 
def argmin (self)
 
def min (self)
 
def sum (self)
 
def toarray (self)
 

Properties

 shape = property(lambda x: x.__shape)
 
 dtype = property(lambda x: x.__dtype)
 
 data = property(lambda x: x.__data)
 

Detailed Description

Definition at line 59 of file array.py.

Constructor & Destructor Documentation

◆ __init__()

def naga.array.Array.__init__ (   self,
  data = None,
  shape = None,
  dtype = None 
)

Definition at line 61 of file array.py.

61  def __init__(self, data=None, shape=None, dtype=None):
62  if shape is not None:
63  if dtype is None:
64  dtype = np.float32
65  if isinstance(shape, tuple):
66  data = np.zeros(shape, dtype=dtype)
67  else:
68  raise TypeError("shape must be a tuple")
69 
70  if data is not None:
71  if isinstance(data, list):
72  data = np.array(data)
73  if isinstance(data, np.ndarray):
74  if dtype is not None:
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)
88  else:
89  raise TypeError("Data type not implemented")
90  self.__dtype = data.dtype
91  self.__shape = data.shape
92  elif isinstance(data, obj_int):
93  self.__data = data
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):
97  self.__data = data
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):
101  self.__data = data
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):
105  self.__data = data
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):
109  self.__data = data
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):
113  self.__data = data
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):
117  self.__data = data
118  self.__dtype = np.uint16
119  self.__shape = tuple(data.shape[k] for k in range(len(data.shape)))
120  else:
121  raise TypeError("Data must be a list, a numpy array or a carmaWrap.obj")
122  self.__size = self.__data.nbElem
123  else:
124  raise AttributeError("You must provide data or shape at least")
125 

Member Function Documentation

◆ __add__()

def naga.array.Array.__add__ (   self,
  idata 
)

Definition at line 133 of file array.py.

133  def __add__(self, idata):
134  tmp = self.copy()
135  if isinstance(idata, Array):
136  tmp.data.axpy(1, idata.data)
137  elif isinstance(idata, np.ndarray):
138  tmp.data.axpy(1, Array(idata).data)
139  else:
140  raise TypeError("operator + is defined only between Arrays and np.arrays")
141  return tmp
142 
Here is the call graph for this function:

◆ __getitem__()

def naga.array.Array.__getitem__ (   self,
  indices 
)

Definition at line 161 of file array.py.

161  def __getitem__(self, indices):
162  return self.toarray().__getitem__(indices)
163 
Here is the call graph for this function:

◆ __mul__()

def naga.array.Array.__mul__ (   self,
  idata 
)

Definition at line 153 of file array.py.

153  def __mul__(self, idata):
154  if isinstance(idata, float) or isinstance(idata, int):
155  tmp = self.copy()
156  tmp.data.scale(idata)
157  return tmp
158  else:
159  raise NotImplementedError("Operator not implemented yet")
160 
Here is the call graph for this function:

◆ __repr__()

def naga.array.Array.__repr__ (   self)

Definition at line 130 of file array.py.

130  def __repr__(self):
131  return "GPU" + self.toarray().__repr__()
132 
Here is the call graph for this function:

◆ __sub__()

def naga.array.Array.__sub__ (   self,
  idata 
)

Definition at line 143 of file array.py.

143  def __sub__(self, idata):
144  tmp = self.copy()
145  if isinstance(idata, Array):
146  tmp.data.axpy(-1, idata.data)
147  elif isinstance(idata, np.ndarray):
148  tmp.data.axpy(-1, Array(idata).data)
149  else:
150  raise TypeError("operator + is defined only between Arrays and np.arrays")
151  return tmp
152 
Here is the call graph for this function:

◆ argmax()

def naga.array.Array.argmax (   self)

Definition at line 205 of file array.py.

205  def argmax(self):
206  return self.data.aimax()
207 
Here is the caller graph for this function:

◆ argmin()

def naga.array.Array.argmin (   self)

Definition at line 211 of file array.py.

211  def argmin(self):
212  return self.data.aimin()
213 
Here is the caller graph for this function:

◆ copy()

def naga.array.Array.copy (   self)

Definition at line 164 of file array.py.

164  def copy(self):
165  tmp = Array(shape=self.shape, dtype=self.dtype)
166  tmp.data.copy_from(self.data)
167  return tmp
168 
Here is the caller graph for this function:

◆ dot()

def naga.array.Array.dot (   self,
  idata 
)

Definition at line 169 of file array.py.

169  def dot(self, idata):
170  if isinstance(idata, np.ndarray):
171  if idata.dtype == self.dtype:
172  idata = Array(idata)
173  else:
174  raise TypeError("Data types must be the same for both arrays")
175  if isinstance(idata, Array):
176  if len(self.shape) == 1:
177  if len(idata.shape) == 1:
178  if idata.shape == self.shape:
179  result = self.data.dot(idata.data, 1, 1)
180  else:
181  raise DimensionsError("Dimensions mismatch")
182  elif len(idata.shape) == 2:
183  if idata.shape[0] == self.shape[0]:
184  result = Array(idata.data.gemv(self.data, op='T'))
185  else:
186  raise DimensionsError("Dimensions mismatch")
187  else:
188  raise DimensionsError("Arrays must be 1D or 2D max")
189  elif len(self.shape) == 2:
190  if len(idata.shape) == 1:
191  if idata.shape[0] == self.shape[1]:
192  result = Array(self.data.gemv(idata.data))
193  else:
194  raise DimensionsError("Dimensions mismatch")
195  elif len(idata.shape) == 2:
196  if self.shape[1] == idata.shape[0]:
197  result = Array(self.data.gemm(idata.data))
198  else:
199  raise DimensionsError("Dimensions mismatch")
200  else:
201  raise DimensionsError("Arrays must be 1D or 2D max")
202 
203  return result
204 

◆ max()

def naga.array.Array.max (   self)

Definition at line 208 of file array.py.

208  def max(self):
209  return self.toarray()[self.argmax()]
210 
Here is the call graph for this function:

◆ min()

def naga.array.Array.min (   self)

Definition at line 214 of file array.py.

214  def min(self):
215  return self.toarray()[self.argmin()]
216 
Here is the call graph for this function:

◆ sum()

def naga.array.Array.sum (   self)

Definition at line 217 of file array.py.

217  def sum(self):
218  return self.data.sum()
219 

◆ toarray()

def naga.array.Array.toarray (   self)

Definition at line 220 of file array.py.

220  def toarray(self):
221  tmp = np.array(self.data)
222  return tmp
223 
224 
Here is the caller graph for this function:

Property Documentation

◆ data

naga.array.Array.data = property(lambda x: x.__data)
static

Definition at line 128 of file array.py.

◆ dtype

naga.array.Array.dtype = property(lambda x: x.__dtype)
static

Definition at line 127 of file array.py.

◆ shape

naga.array.Array.shape = property(lambda x: x.__shape)
static

Definition at line 126 of file array.py.


The documentation for this class was generated from the following file: