1313import pyNastran
1414from pyNastran .femutils .io import loadtxt_nice , savetxt_nice
1515from pyNastran .femutils .matrix3d import dot_n33_n33 , transpose3d , triple_n33_n33 , triple_n33_33
16- from pyNastran .femutils .utils import augmented_identity , perpendicular_vector , perpendicular_vector2d
16+ from pyNastran .femutils .utils import (
17+ augmented_identity , perpendicular_vector ,
18+ perpendicular_vector2d , vstack_lists ,
19+ is_monotonic , duplicates , hstack_unique )
1720from pyNastran .femutils .coord_transforms import cylindrical_rotation_matrix
1821
1922from pyNastran .femutils .test .utils import is_array_close
@@ -103,7 +106,8 @@ def test_triple_n33_n33(self):
103106 [0. , 0. , 1. ],
104107 [1. , 0. , 9. ],],
105108 ])
106- TtAT_actual = triple_n33_n33 (A , T , transpose = False )
109+ TtAT_actual = triple_n33_n33 (A , T , transpose = False , debug = False )
110+ TtAT_actual = triple_n33_n33 (A , T , transpose = False , debug = True )
107111 TtAT_expected = [
108112 [[5. , 6. , 58. ],
109113 [8. , 9. , 88. ],
@@ -114,7 +118,8 @@ def test_triple_n33_n33(self):
114118 [74. , 84. , 820. ],],
115119 ]
116120 assert is_array_close (TtAT_expected , TtAT_actual )
117- TATt_actual = triple_n33_n33 (A , T , transpose = True )
121+ TATt_actual = triple_n33_n33 (A , T , transpose = True , debug = False )
122+ TATt_actual = triple_n33_n33 (A , T , transpose = True , debug = True )
118123 TATt_expected = [
119124 [[9. , 7. , 89. ],
120125 [3. , 1. , 29. ],
@@ -142,7 +147,8 @@ def test_triple_n33_33(self):
142147 [0. , 0. , 1. ],
143148 [1. , 0. , 9. ],
144149 ])
145- TtAT_actual = triple_n33_33 (A , T , transpose = False )
150+ TtAT_actual = triple_n33_33 (A , T , transpose = False , debug = False )
151+ TtAT_actual = triple_n33_33 (A , T , transpose = False , debug = True )
146152 TtAT_expected = [
147153 [[5. , 6. , 58. ],
148154 [8. , 9. , 88. ],
@@ -153,7 +159,8 @@ def test_triple_n33_33(self):
153159 [74. , 84. , 820. ],],
154160 ]
155161 assert is_array_close (TtAT_expected , TtAT_actual )
156- TATt_actual = triple_n33_33 (A , T , transpose = True )
162+ TATt_actual = triple_n33_33 (A , T , transpose = True , debug = False )
163+ TATt_actual = triple_n33_33 (A , T , transpose = True , debug = True )
157164 TATt_expected = [
158165 [[9. , 7. , 89. ],
159166 [3. , 1. , 29. ],
@@ -168,6 +175,70 @@ def test_triple_n33_33(self):
168175
169176class TestNumpyUtils (unittest .TestCase ):
170177 """tests functions in femutils.utils"""
178+ def test_hstack_unique (self ):
179+ list_of_arrays = [
180+ [1 , 2 , 3 ], [4 , 5 , 6 , 7 , 3 ],
181+ ]
182+ stacked = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 3 ]
183+ unique_stacked = [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
184+ a = hstack_unique (list_of_arrays , unique = False )
185+ b = hstack_unique (list_of_arrays , unique = True )
186+ assert np .array_equal (a , stacked )
187+ assert np .array_equal (b , unique_stacked )
188+
189+ list_of_arrays = [
190+ [1 , 2 , 3 , 4 , 5 , 6 , 7 , 3 ],
191+ ]
192+ c = hstack_unique (list_of_arrays , unique = False )
193+ d = hstack_unique (list_of_arrays , unique = True )
194+ assert np .array_equal (c , stacked )
195+ assert np .array_equal (d , unique_stacked )
196+
197+ def test_vstack_list (self ):
198+ list_of_arrays = [
199+ [[1 , 2 , 3 ]],
200+ [
201+ [1 , 2 , 3 ],
202+ [1 , 2 , 3 ],
203+ ]
204+ ]
205+ stacked = [
206+ [1 , 2 , 3 ],
207+ [1 , 2 , 3 ],
208+ [1 , 2 , 3 ],
209+ ]
210+ stacked_array = vstack_lists (list_of_arrays )
211+ assert np .array_equal (stacked_array , stacked )
212+
213+ list_of_arrays = [
214+ [[1 , 2 , 3 ]],
215+ ]
216+ stacked = [[1 , 2 , 3 ]]
217+ stacked_array = vstack_lists (list_of_arrays )
218+ assert np .array_equal (stacked_array , stacked ), stacked_array
219+
220+ def test_duplicates (self ):
221+ a = [1 , 2 , 3 , 4 , 5 , 2 , 3 ]
222+ b = duplicates (a )
223+ assert np .array_equal (b , [2 , 3 ])
224+
225+ a = [3 , 2 , 1 , 3 , 2 , 4 , 5 ]
226+ b = duplicates (a )
227+ assert np .array_equal (b , [2 , 3 ])
228+
229+ def test_is_monotonic (self ):
230+ a = np .array ([1 , 2 , 3 ])
231+ b = np .array ([1 , - 2 , 3 ])
232+ c = np .array ([1 , 2 , 2 , 3 ])
233+
234+ assert is_monotonic (a , is_strict = True ), (np .diff (a ), aa )
235+ assert not is_monotonic (b , is_strict = True ), np .diff (b )
236+ assert not is_monotonic (c , is_strict = True ), np .diff (c )
237+
238+ assert is_monotonic (a , is_strict = False )
239+ assert not is_monotonic (b , is_strict = False )
240+ assert is_monotonic (c , is_strict = False )
241+
171242 def test_perpendicular_vector (self ):
172243 """tests perpendicular_vector"""
173244 with self .assertRaises (ValueError ):
0 commit comments