1
- from typing import List , Tuple
1
+ from typing import Tuple
2
2
3
3
import numba # type:ignore
4
4
import numpy as np
5
+ from nptyping import Int32 , NDArray , Shape
5
6
6
7
from classy_blocks .cbtyping import NPPointListType , NPPointType , NPVectorType
7
8
from classy_blocks .util .constants import VSMALL
8
9
10
+ NPIndexType = NDArray [Shape ["*, 1" ], Int32 ]
11
+
9
12
10
13
@numba .jit (nopython = True , cache = True )
11
14
def scale_quality (base : float , exponent : float , factor : float , value : float ) -> float :
@@ -27,6 +30,19 @@ def scale_aspect(ratio: float) -> float:
27
30
return scale_quality (3 , 2.5 , 3 , np .log10 (ratio ))
28
31
29
32
33
+ @numba .jit (nopython = True , cache = True )
34
+ def take (points : NPPointListType , indexes : NPIndexType ):
35
+ n_points = len (indexes )
36
+ dim = points .shape [1 ]
37
+ result = np .empty ((n_points , dim ), dtype = points .dtype )
38
+
39
+ for i in range (n_points ):
40
+ for j in range (dim ):
41
+ result [i , j ] = points [indexes [i ], j ]
42
+
43
+ return result
44
+
45
+
30
46
@numba .jit (nopython = True , cache = True )
31
47
def get_center_point (points : NPPointListType ) -> NPPointType :
32
48
return np .sum (points , axis = 0 ) / len (points )
@@ -103,8 +119,8 @@ def get_quad_angle_quality(quad_points: NPPointListType) -> float:
103
119
104
120
105
121
@numba .jit (nopython = True , cache = True )
106
- def get_quad_quality (grid_points : NPPointListType , cell_indexes : List [ int ] ) -> float :
107
- cell_points = np . take (grid_points , cell_indexes , axis = 0 )
122
+ def get_quad_quality (grid_points : NPPointListType , cell_indexes : NPIndexType ) -> float :
123
+ cell_points = take (grid_points , cell_indexes )
108
124
cell_center , cell_normal , cell_aspect = get_quad_normal (cell_points )
109
125
110
126
# non-ortho
@@ -119,8 +135,8 @@ def get_quad_quality(grid_points: NPPointListType, cell_indexes: List[int]) -> f
119
135
120
136
121
137
@numba .jit (nopython = True , cache = True )
122
- def get_hex_quality (grid_points : NPPointListType , cell_indexes : List [ int ] ) -> float :
123
- cell_points = np . take (grid_points , cell_indexes , axis = 0 )
138
+ def get_hex_quality (grid_points : NPPointListType , cell_indexes : NPIndexType ) -> float :
139
+ cell_points = take (grid_points , cell_indexes )
124
140
cell_center = get_center_point (cell_points )
125
141
126
142
side_indexes = np .array ([[0 , 1 , 2 , 3 ], [7 , 6 , 5 , 4 ], [4 , 0 , 3 , 7 ], [6 , 2 , 1 , 5 ], [0 , 4 , 5 , 1 ], [7 , 3 , 2 , 6 ]])
@@ -136,7 +152,7 @@ def get_hex_quality(grid_points: NPPointListType, cell_indexes: List[int]) -> fl
136
152
# For this kind of optimization it is quite sufficient to take
137
153
# only the latter as it's not much different and we'll optimize
138
154
# other cells too.
139
- side_points = np . take (cell_points , side , axis = 0 )
155
+ side_points = take (cell_points , side )
140
156
side_center , side_normal , side_aspect = get_quad_normal (side_points )
141
157
center_vector = cell_center - side_center
142
158
0 commit comments