Coverage for src/foapy/characteristics/ma/_volume.py: 100%

3 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-17 20:45 +0000

1import numpy as np 

2 

3 

4def volume(intervals, dtype=None): 

5 """ 

6 Calculates volumes of the intervals grouped by congeneric sequence. 

7 

8 $$ 

9 \\left[ V_j \\right]_{1 \\le j \\le m} = 

10 \\left[ 

11 \\prod_{i=1}^{n_j} \\Delta_{ij} 

12 \\right]_{1 \\le j \\le m} 

13 $$ 

14 

15 where \\( \\Delta_{ij} \\) represents $i$-th interval of $j$-th 

16 congeneric intervals array, \\( n_j \\) is the total 

17 number of intervals in $j$-th congeneric intervals array 

18 and $m$ is number of congeneric intervals arrays. 

19 

20 Parameters 

21 ---------- 

22 intervals : array_like 

23 An array of congeneric intervals array 

24 dtype : dtype, optional 

25 The dtype of the output 

26 

27 Returns 

28 ------- 

29 : array 

30 An array of the volumes of congeneric intervals. 

31 

32 Examples 

33 -------- 

34 

35 Calculate the volumes of a sequence. 

36 

37 ``` py linenums="1" 

38 import foapy 

39 import numpy as np 

40 

41 source = np.array(['a', 'b', 'a', 'c', 'a', 'd']) 

42 order = foapy.ma.order(source) 

43 intervals = foapy.ma.intervals(order, foapy.binding.start, foapy.mode.normal) 

44 result = foapy.characteristics.ma.volume(intervals) 

45 print(result) 

46 # [4 2 4 6] 

47 ``` 

48 

49 Calculate the volumes of congeneric intervals of a sequence. 

50 

51 ``` py linenums="1" 

52 import foapy 

53 

54 X = [] 

55 X.append([1, 1, 4, 4]) 

56 X.append([3, 1, 3]) 

57 X.append([5, 3, 1]) 

58 

59 result = foapy.characteristics.ma.volume(X) 

60 print(result) 

61 # [16 9 15] 

62 ``` 

63 """ # noqa: W605 

64 

65 return np.asanyarray([np.prod(line, dtype=dtype) for line in intervals])