Coverage for physioblocks / configuration / computing / quantities.py: 93%
14 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 16:40 +0100
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 16:40 +0100
1# SPDX-FileCopyrightText: Copyright INRIA
2#
3# SPDX-License-Identifier: LGPL-3.0-only
4#
5# Copyright INRIA
6#
7# This file is part of PhysioBlocks, a library mostly developed by the
8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA.
9#
10# Authors:
11# - Colin Drieu
12# - Dominique Chapelle
13# - François Kimmig
14# - Philippe Moireau
15#
16# PhysioBlocks is free software: you can redistribute it and/or modify it under the
17# terms of the GNU Lesser General Public License as published by the Free Software
18# Foundation, version 3 of the License.
19#
20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY
21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
23#
24# You should have received a copy of the GNU Lesser General Public License along with
25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>.
27from typing import Any
29import numpy as np
31from physioblocks.computing.quantities import Quantity
32from physioblocks.registers.load_function_register import loads
33from physioblocks.registers.save_function_register import saves
36@loads(Quantity)
37def load_quantity(
38 configuration: Any,
39 configuration_object: Quantity[Any] | None = None,
40 *args: Any,
41 **kwargs: Any,
42) -> Any:
43 if configuration_object is not None:
44 configuration_object.initialize(configuration)
45 else:
46 configuration_object = Quantity(configuration)
47 return configuration_object
50@saves(Quantity)
51def save_quantity(
52 quantity: Quantity[Any],
53 *args: Any,
54 **kwargs: Any,
55) -> Any:
56 return float(quantity) if quantity.size == 1 else np.asarray(quantity).tolist()