From e1607cec465038f067627c9f46fad47a1da9e782 Mon Sep 17 00:00:00 2001 From: Tugrul Agrikli Date: Thu, 23 Apr 2026 01:47:22 +0300 Subject: [PATCH] Fix NumPy 2.x scalar type errors in locomotion demos - Use .item() to extract Python scalars from Tensor.Clamp results in Sequence.GetIndexPair - Update Rectangle.Tuple() to convert tensor/array scalars before passing to raylib Fixes #12 --- Demos/Locomotion/Biped/Sequence.py | 4 ++-- Demos/Locomotion/Quadruped/Sequence.py | 4 ++-- ai4animation/Standalone/GUI.py | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Demos/Locomotion/Biped/Sequence.py b/Demos/Locomotion/Biped/Sequence.py index 4205551..4411846 100644 --- a/Demos/Locomotion/Biped/Sequence.py +++ b/Demos/Locomotion/Biped/Sequence.py @@ -59,11 +59,11 @@ def GetIndexPair(self, timestamp: float): 0.0, self.Timestamps.size - 1, ) - ratio = Tensor.Clamp(ratio, 0.0, self.Timestamps.size - 1) + ratio = Tensor.Clamp(ratio, 0.0, self.Timestamps.size - 1).item() a = int(math.floor(ratio)) b = int(math.ceil(ratio)) w = Utility.Ratio(timestamp, self.Timestamps[a], self.Timestamps[b]) - w = Tensor.Clamp(w, 0.0, 1.0) + w = Tensor.Clamp(w, 0.0, 1.0).item() return a, b, w def GetLength(self): diff --git a/Demos/Locomotion/Quadruped/Sequence.py b/Demos/Locomotion/Quadruped/Sequence.py index 4205551..4411846 100644 --- a/Demos/Locomotion/Quadruped/Sequence.py +++ b/Demos/Locomotion/Quadruped/Sequence.py @@ -59,11 +59,11 @@ def GetIndexPair(self, timestamp: float): 0.0, self.Timestamps.size - 1, ) - ratio = Tensor.Clamp(ratio, 0.0, self.Timestamps.size - 1) + ratio = Tensor.Clamp(ratio, 0.0, self.Timestamps.size - 1).item() a = int(math.floor(ratio)) b = int(math.ceil(ratio)) w = Utility.Ratio(timestamp, self.Timestamps[a], self.Timestamps[b]) - w = Tensor.Clamp(w, 0.0, 1.0) + w = Tensor.Clamp(w, 0.0, 1.0).item() return a, b, w def GetLength(self): diff --git a/ai4animation/Standalone/GUI.py b/ai4animation/Standalone/GUI.py index 59e9715..6b660fd 100644 --- a/ai4animation/Standalone/GUI.py +++ b/ai4animation/Standalone/GUI.py @@ -494,7 +494,11 @@ def Screen(self): return Rectangle(x, y, w, h) def Tuple(self): - return (self.x, self.y, self.width, self.height) + def to_scalar(v): + if hasattr(v, "item"): + return v.item() + return float(v) + return (to_scalar(self.x), to_scalar(self.y), to_scalar(self.width), to_scalar(self.height)) def Copy(self): return Rectangle(self.x, self.y, self.width, self.height)