Repository: kornia/kornia

Issue:
Error when supplying `normalize_range` argument to `diamond_square`
### Describe the bug

When the `normalize_range` argument is supplied to `kornia.contrib.diamond_square`, it always produces the error:
```python
>>> kornia.contrib.diamond_square((1, 1, 128, 128), normalize_range=(0., 1.))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\nehn0\AppData\Local\pypoetry\Cache\virtualenvs\surfaceclutter-aKm1AMFl-py3.8\lib\site-packages\kornia\contrib\diamond_square.py", line 210, in diamond_square
    img = normalize_min_max(img, min_val, max_val)
  File "C:\Users\nehn0\AppData\Local\pypoetry\Cache\virtualenvs\surfaceclutter-aKm1AMFl-py3.8\lib\site-packages\kornia\enhance\normalize.py", line 284, in normalize_min_max
    x_min: torch.Tensor = x.view(B, C, -1).min(-1)[0].view(B, C, 1)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
```

Additionally, the type annotation for the argument is incorrect. It is annotated as `Optional[Tuple[int, int]]` but when `int`s are supplied instead of `float`s the following error is produced:
```python
kornia.contrib.diamond_square((1, 1, 128, 128), normalize_range=(0, 1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\nehn0\AppData\Local\pypoetry\Cache\virtualenvs\surfaceclutter-aKm1AMFl-py3.8\lib\site-packages\kornia\contrib\diamond_square.py", line 210, in diamond_square
    img = normalize_min_max(img, min_val, max_val)
  File "C:\Users\nehn0\AppData\Local\pypoetry\Cache\virtualenvs\surfaceclutter-aKm1AMFl-py3.8\lib\site-packages\kornia\enhance\normalize.py", line 273, in normalize_min_max
    raise TypeError(f"'min_val' should be a float. Got: {type(min_val)}.")
TypeError: 'min_val' should be a float. Got: <class 'int'>.
```

### Reproduction steps

```bash
import kornia

# call with ints
kornia.contrib.diamond_square((1, 1, 128, 128), normalize_range=(0, 1))

# call with floats
kornia.contrib.diamond_square((1, 1, 128, 128), normalize_range=(0., 1.))
```


### Expected behavior

Using the `normalize_range` argument should not produce an error and should normalize the output array to be between the two supplied values.

### Environment

```shell
- PyTorch Version (e.g., 1.0): 1.13.1
- OS (e.g., Linux): Windows 10
- How you installed PyTorch (`conda`, `pip`, source): pip
- Build command you used (if compiling from source):
- Python version: 3.8.7
- CUDA/cuDNN version: None
- GPU models and configuration: None
- Any other relevant information: None
```


### Additional context

_No response_


Discussion:
@hennels thanks! that's definitely a bug; the second it can be easily adjusted. Are you willing to send a PR with a fix ?

Resolving patch:
diff --git a/kornia/contrib/diamond_square.py b/kornia/contrib/diamond_square.py
--- a/kornia/contrib/diamond_square.py
+++ b/kornia/contrib/diamond_square.py
@@ -142,7 +142,7 @@ def diamond_square(
     roughness: Union[float, Tensor] = 0.5,
     random_scale: Union[float, Tensor] = 1.0,
     random_fn: Callable[..., Tensor] = torch.rand,
-    normalize_range: Optional[Tuple[int, int]] = None,
+    normalize_range: Optional[Tuple[float, float]] = None,
     device: Optional[torch.device] = None,
     dtype: Optional[torch.dtype] = None,
 ) -> Tensor:
@@ -207,5 +207,5 @@ def diamond_square(
     # normalize the output in the range using min-max
     if normalize_range is not None:
         min_val, max_val = normalize_range
-        img = normalize_min_max(img, min_val, max_val)
+        img = normalize_min_max(img.contiguous(), min_val, max_val)
     return img


Test patch:
diff --git a/test/test_contrib.py b/test/test_contrib.py
--- a/test/test_contrib.py
+++ b/test/test_contrib.py
@@ -21,6 +21,20 @@ def test_smoke(self, device, dtype):
         assert out.device == device
         assert out.dtype == dtype
 
+    def test_normalize(self, device, dtype):
+        torch.manual_seed(0)
+        output_size = (1, 1, 3, 4)
+        roughness = 0.5
+        random_scale = 1.0
+        normalize_range = (0.0, 1.0)
+        expected_min = torch.tensor(normalize_range[0], device=device, dtype=dtype)
+        expected_max = torch.tensor(normalize_range[1], device=device, dtype=dtype)
+        out = kornia.contrib.diamond_square(
+            output_size, roughness, random_scale, normalize_range=normalize_range, device=device, dtype=dtype
+        )
+        assert_close(out.min(), expected_min)
+        assert_close(out.max(), expected_max)
+
 
 class TestVisionTransformer:
     @pytest.mark.parametrize("B", [1, 2])