Coverage for install/scipp/core/unary.py: 40%

15 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-04-28 01:28 +0000

1# SPDX-License-Identifier: BSD-3-Clause 

2# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 

3# @author Matthew Andrew 

4from typing import Union as _Union 

5 

6from .._scipp import core as _cpp 

7from ._cpp_wrapper_util import call_func as _call_cpp_func 

8 

9 

10def isnan(x: _cpp.Variable) -> _cpp.Variable: 

11 """Element-wise isnan (true if an element is nan).""" 

12 return _call_cpp_func(_cpp.isnan, x) 

13 

14 

15def isinf(x: _cpp.Variable) -> _cpp.Variable: 

16 """Element-wise isinf (true if an element is inf).""" 

17 return _call_cpp_func(_cpp.isinf, x) 

18 

19 

20def isfinite(x: _cpp.Variable) -> _cpp.Variable: 

21 """Element-wise isfinite (true if an element is finite).""" 

22 return _call_cpp_func(_cpp.isfinite, x) 

23 

24 

25def isposinf(x: _cpp.Variable) -> _cpp.Variable: 

26 """Element-wise isposinf (true if an element is a positive infinity).""" 

27 return _call_cpp_func(_cpp.isposinf, x) 

28 

29 

30def isneginf(x: _cpp.Variable) -> _cpp.Variable: 

31 """Element-wise isneginf (true if an element is a negative infinity).""" 

32 return _call_cpp_func(_cpp.isneginf, x) 

33 

34 

35def to_unit( 

36 x: _cpp.Variable, unit: _Union[_cpp.Unit, str], *, copy: bool = True 

37) -> _cpp.Variable: 

38 """Convert the variable to a different unit. 

39 

40 Raises a :class:`scipp.UnitError` if the input unit is not compatible 

41 with the provided unit, e.g., `m` cannot be converted to `s`. 

42 

43 If the input dtype is an integer type or datetime64, the output is rounded 

44 and returned with the same dtype as the input. 

45 

46 Parameters 

47 ---------- 

48 x: 

49 Input variable. 

50 unit: 

51 Desired target unit. 

52 copy: 

53 If `False`, return the input object if possible, i.e. 

54 if the unit is unchanged. 

55 If `True`, the function always returns a new object. 

56 

57 Returns 

58 ------- 

59 : 

60 Input converted to the given unit. 

61 

62 Examples 

63 -------- 

64 

65 >>> var = 1.2 * sc.Unit('m') 

66 >>> sc.to_unit(var, unit='mm') 

67 <scipp.Variable> () float64 [mm] 1200 

68 """ 

69 return _call_cpp_func(_cpp.to_unit, x=x, unit=unit, copy=copy)