add initial SimdShape.__add__
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 28 Oct 2021 04:06:15 +0000 (21:06 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 28 Oct 2021 04:06:15 +0000 (21:06 -0700)
src/ieee754/part/partsig.py

index d12c4398bbfa6c2d9a0c4edbea00186743228009..d85566dcbe6c4ae8075db16ac7fc89c2be40028e 100644 (file)
@@ -193,6 +193,25 @@ class SimdShape(Shape):
     def __rmul__(self, other):
         return self.__mul__(other)
 
+    def __add__(self, other):
+        if isinstance(other, int):
+            lane_shapes = {k: v + other for k, v in self.lane_shapes}
+            return SimdShape(self.scope, lane_shapes, signed=self.signed)
+        elif isinstance(other, SimdShape):
+            assert other.scope is self.scope, "scope mismatch"
+            o = other.lane_shapes
+            lane_shapes = {k: v + o[k] for k, v in self.lane_shapes}
+            # XXX not correct, we need a width-hint, not an overwrite
+            # lane_shapes argument...
+            return SimdShape(self.scope, lane_shapes, signed=self.signed,
+                             fixed_width=self.width + other.width)
+        else:
+            raise NotImplementedError(
+                f"Adding a SimdShape to {type(other)} isn't implemented")
+
+    def __radd__(self, other):
+        return self.__add__(other)
+
 
 class SimdSignal(UserValue):
     # XXX ################################################### XXX