Save Int8/UInt8 reference outputs to native dtypes

* Int8/UInt8 reference outputs were previously saved to INT32
* Save those in their native dtypes and updated other affected code

Signed-off-by: Jerry Ge <jerry.ge@arm.com>
Georgios Pinitas <georgios.pinitas@arm.com>

Change-Id: Id65fc8773150d3c56bc2c72789a6a0d3c78cd363
diff --git a/verif/generator/tosa_test_gen.py b/verif/generator/tosa_test_gen.py
index b9352ac..28cf392 100644
--- a/verif/generator/tosa_test_gen.py
+++ b/verif/generator/tosa_test_gen.py
@@ -191,6 +191,10 @@
 
         if dtype == DType.BOOL:
             return np.bool_(self.rng.choice(a=[False, True], size=shape))
+        elif dtype == DType.INT8:
+            return np.int8(self.rng.integers(low=low, high=high, size=shape))
+        elif dtype == DType.UINT8:
+            return np.uint8(self.rng.integers(low=low, high=high, size=shape))
         elif dtype in (DType.INT48, DType.SHAPE):
             return np.int64(self.rng.integers(low=low, high=high, size=shape))
         elif dtype in (DType.FP16, DType.BF16, DType.FP32):
@@ -2079,7 +2083,16 @@
             val_adj = np.subtract(values, input_zp, dtype=np.int64)
             val_adj = np.maximum(val_adj, min_shift_value_arr, dtype=np.int64)
             val_adj = np.minimum(val_adj, max_shift_value_arr, dtype=np.int64)
-            val_adj = np.add(val_adj, input_zp, dtype=values.dtype)
+            val_adj = np.add(val_adj, input_zp, dtype=np.int64)
+            # Check we can safely convert to the expected dtype
+            assert (
+                val_adj.all() >= np.iinfo(values.dtype).min
+                and val_adj.all() <= np.iinfo(values.dtype).max
+            )
+
+            # Force casting to output datatype
+            val_adj = val_adj.astype(values.dtype, casting="unsafe")
+
             if not np.all(np.array_equal(values, val_adj)):
                 # Values changed so overwrite file with new values
                 np.save(