| 212 | |
| 213 | @add_backend |
| 214 | class ArrayNumPy(BaseArray): |
| 215 | backend = "numpy" |
| 216 | |
| 217 | TypeMap = make_typemap([]) |
| 218 | TypeMap.update(TypeMapBool) |
| 219 | TypeMap.update(TypeMapInteger) |
| 220 | TypeMap.update(TypeMapUnsigned) |
| 221 | TypeMap.update(TypeMapFloat) |
| 222 | TypeMap.update(TypeMapComplex) |
| 223 | |
| 224 | def __init__(self, arg, typecode, shape=None): |
| 225 | if isinstance(arg, (int, float, complex)): |
| 226 | if shape is None: |
| 227 | shape = () |
| 228 | else: |
| 229 | if shape is None: |
| 230 | shape = len(arg) |
| 231 | self.array = numpy.zeros(shape, typecode) |
| 232 | if isinstance(arg, (int, float, complex)): |
| 233 | arg = numpy.asarray(arg).astype(typecode) |
| 234 | self.array.fill(arg) |
| 235 | else: |
| 236 | arg = numpy.asarray(arg).astype(typecode) |
| 237 | self.array[...] = arg |
| 238 | |
| 239 | @property |
| 240 | def address(self): |
| 241 | return self.array.__array_interface__["data"][0] |
| 242 | |
| 243 | @property |
| 244 | def typecode(self): |
| 245 | return self.array.dtype.char |
| 246 | |
| 247 | @property |
| 248 | def itemsize(self): |
| 249 | return self.array.itemsize |
| 250 | |
| 251 | @property |
| 252 | def flat(self): |
| 253 | return self.array.flat |
| 254 | |
| 255 | @property |
| 256 | def size(self): |
| 257 | return self.array.size |
| 258 | |
| 259 | |
| 260 | try: |
nothing calls this directly
no test coverage detected
searching dependent graphs…