Skip to content

Commit 951f558

Browse files
committed
Updated code review comments.
1 parent 19fa289 commit 951f558

File tree

10 files changed

+40
-51
lines changed

10 files changed

+40
-51
lines changed

build/templates/session.py/numpy_write_method.py.mako

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
raise TypeError('${parameter['python_name']} must be in C-order')
3131
if ${parameter['python_name']}.dtype is not numpy.dtype('${parameter['numpy_type']}'):
3232
raise TypeError('${parameter['python_name']} must be numpy.ndarray of dtype=${parameter['numpy_type']}, is ' + str(${parameter['python_name']}.dtype))
33-
% if parameter['array_dimension'] > 1:
3433
if ${parameter['python_name']}.ndim != ${parameter['array_dimension']}:
3534
raise TypeError('${parameter['python_name']} must be numpy.ndarray of dimension=${parameter['array_dimension']}, is ' + str(${parameter['python_name']}.ndim))
36-
% endif
3735
% endfor
3836
% for p in helper.filter_parameters(parameters, helper.ParameterUsageOptions.INTERPRETER_METHOD_CALL):
3937
% if 'python_api_converter_name' in p:

build/unit_tests/test_codegen_helper.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
'type': 'ViSession',
4343
'numpy': False,
4444
'complex_type': None,
45-
'array_dimension': 1,
4645
'use_in_python_api': True,
4746
},
4847
{ # 1
@@ -72,7 +71,6 @@
7271
'type': 'ViInt64',
7372
'numpy': False,
7473
'complex_type': None,
75-
'array_dimension': 1,
7674
'use_in_python_api': True,
7775
},
7876
{ # 2
@@ -101,7 +99,6 @@
10199
'type': 'ViString',
102100
'numpy': False,
103101
'complex_type': None,
104-
'array_dimension': 1,
105102
'use_in_python_api': True,
106103
},
107104
{ # 3
@@ -131,7 +128,6 @@
131128
'type': 'custom_struct',
132129
'numpy': False,
133130
'complex_type': None,
134-
'array_dimension': 1,
135131
'use_in_python_api': True,
136132
},
137133
{ # 4
@@ -158,7 +154,6 @@
158154
'type': 'ViInt32',
159155
'numpy': False,
160156
'complex_type': None,
161-
'array_dimension': 1,
162157
'use_in_python_api': True,
163158
},
164159
{ # 5
@@ -187,7 +182,6 @@
187182
'type': 'ViInt16',
188183
'numpy': False,
189184
'complex_type': None,
190-
'array_dimension': 1,
191185
'use_in_python_api': True,
192186
},
193187
{ # 6
@@ -217,7 +211,6 @@
217211
'type': 'ViInt16',
218212
'numpy': False,
219213
'complex_type': None,
220-
'array_dimension': 1,
221214
'use_in_python_api': True,
222215
},
223216
{ # 7
@@ -246,7 +239,6 @@
246239
'type': 'ViInt64',
247240
'numpy': True,
248241
'complex_type': None,
249-
'array_dimension': 1,
250242
'numpy_type': 'int64',
251243
'numpy_type_library_call': 'numpy.int64',
252244
'use_in_python_api': True,
@@ -269,7 +261,6 @@
269261
'name': 'numberOfElementsPythonCode',
270262
'numpy': False,
271263
'complex_type': None,
272-
'array_dimension': 1,
273264
'python_name': 'number_of_elements_python_code',
274265
'python_name_with_default': 'number_of_elements_python_code',
275266
'python_name_with_doc_default': 'number_of_elements_python_code',
@@ -296,7 +287,6 @@
296287
'name': 'input',
297288
'numpy': False,
298289
'complex_type': None,
299-
'array_dimension': 1,
300290
'python_name': 'input',
301291
'python_name_with_default': 'input',
302292
'python_name_with_doc_default': 'input',
@@ -326,7 +316,6 @@
326316
'name': 'inputArray',
327317
'numpy': False,
328318
'complex_type': None,
329-
'array_dimension': 1,
330319
'python_name': 'input_array',
331320
'python_name_with_default': 'input_array=None',
332321
'python_name_with_doc_default': 'input_array=None',
@@ -353,7 +342,6 @@
353342
'name': 'inputArraySize',
354343
'numpy': False,
355344
'complex_type': None,
356-
'array_dimension': 1,
357345
'python_name': 'input_array_size',
358346
'python_name_with_default': 'input_array_size',
359347
'python_name_with_doc_default': 'input_array_size',
@@ -380,7 +368,6 @@
380368
'name': 'stringSize',
381369
'numpy': False,
382370
'complex_type': None,
383-
'array_dimension': 1,
384371
'python_name': 'string_size',
385372
'python_name_with_default': 'string_size',
386373
'python_name_with_doc_default': 'string_size',
@@ -407,7 +394,6 @@
407394
'name': 'aString',
408395
'numpy': False,
409396
'complex_type': None,
410-
'array_dimension': 1,
411397
'python_name': 'a_string',
412398
'python_name_with_default': 'a_string',
413399
'python_name_with_doc_default': 'a_string',
@@ -435,7 +421,6 @@
435421
'name': 'Timeout',
436422
'numpy': False,
437423
'complex_type': None,
438-
'array_dimension': 1,
439424
'python_name': 'timeout',
440425
'python_name_with_default': 'timeout=1.0',
441426
'python_name_with_doc_default': 'timeout=1.0',
@@ -465,7 +450,6 @@
465450
'name': 'channelList',
466451
'numpy': False,
467452
'complex_type': None,
468-
'array_dimension': 1,
469453
'original_type': 'ViChar[]',
470454
'python_name': 'channel_list',
471455
'python_name_with_default': 'channel_list',
@@ -493,7 +477,6 @@
493477
'name': 'aString',
494478
'numpy': False,
495479
'complex_type': None,
496-
'array_dimension': 1,
497480
'python_name': 'a_string',
498481
'python_name_with_default': 'a_string',
499482
'python_name_with_doc_default': 'a_string',
@@ -527,7 +510,6 @@
527510
'type': 'custom_struct',
528511
'numpy': False,
529512
'complex_type': None,
530-
'array_dimension': 1,
531513
'use_in_python_api': True,
532514
},
533515
{ # 18
@@ -558,7 +540,6 @@
558540
'type': 'ViInt16',
559541
'numpy': False,
560542
'complex_type': None,
561-
'array_dimension': 1,
562543
'use_in_python_api': True,
563544
},
564545
{ # 19
@@ -579,7 +560,6 @@
579560
'name': 'aString2',
580561
'numpy': False,
581562
'complex_type': None,
582-
'array_dimension': 1,
583563
'python_name': 'a_string_2',
584564
'python_name_with_default': 'a_string_2',
585565
'python_name_with_doc_default': 'a_string_2',
@@ -606,7 +586,6 @@
606586
'name': 'aStrin3g',
607587
'numpy': False,
608588
'complex_type': None,
609-
'array_dimension': 1,
610589
'python_name': 'a_string_3',
611590
'python_name_with_default': 'a_string_3',
612591
'python_name_with_doc_default': 'a_string_3',
@@ -633,7 +612,6 @@
633612
'name': 'aStringTwist',
634613
'numpy': False,
635614
'complex_type': None,
636-
'array_dimension': 1,
637615
'python_name': 'a_string_twist',
638616
'python_name_with_default': 'a_string_twist',
639617
'python_name_with_doc_default': 'a_string_twist',
@@ -669,7 +647,6 @@
669647
'type': 'ViInt64',
670648
'numpy': False,
671649
'complex_type': None,
672-
'array_dimension': 1,
673650
'use_in_python_api': True,
674651
},
675652
{ # 23
@@ -690,7 +667,6 @@
690667
'name': 'stringSizeTwist',
691668
'numpy': False,
692669
'complex_type': None,
693-
'array_dimension': 1,
694670
'python_name': 'string_size_twist',
695671
'python_name_with_default': 'string_size_twist',
696672
'python_name_with_doc_default': 'string_size_twist',
@@ -717,7 +693,6 @@
717693
'name': 'aBufferArray',
718694
'numpy': False,
719695
'complex_type': None,
720-
'array_dimension': 1,
721696
'python_name': 'a_buffer_array',
722697
'python_name_with_default': 'a_buffer_array',
723698
'python_name_with_doc_default': 'a_buffer_array',
@@ -746,7 +721,6 @@
746721
'name': 'aBufferList',
747722
'numpy': False,
748723
'complex_type': None,
749-
'array_dimension': 1,
750724
'python_name': 'a_buffer_list',
751725
'python_name_with_default': 'a_buffer_list',
752726
'python_name_with_doc_default': 'a_buffer_list',
@@ -775,7 +749,6 @@
775749
'name': 'aBufferTwistArray',
776750
'numpy': False,
777751
'complex_type': None,
778-
'array_dimension': 1,
779752
'python_name': 'a_buffer_twist_array',
780753
'python_name_with_default': 'a_buffer_twist_array',
781754
'python_name_with_doc_default': 'a_buffer_twist_array',
@@ -804,7 +777,6 @@
804777
'name': 'aBufferTwistList',
805778
'numpy': False,
806779
'complex_type': None,
807-
'array_dimension': 1,
808780
'python_name': 'a_buffer_twist_list',
809781
'python_name_with_default': 'a_buffer_twist_list',
810782
'python_name_with_doc_default': 'a_buffer_twist_list',
@@ -836,7 +808,6 @@
836808
'name': 'inputArray2',
837809
'numpy': False,
838810
'complex_type': None,
839-
'array_dimension': 1,
840811
'python_name': 'input_array_2',
841812
'python_name_with_default': 'input_array_2=None',
842813
'python_name_with_doc_default': 'input_array_2=None',
@@ -866,7 +837,6 @@
866837
'name': 'inputArray2',
867838
'numpy': False,
868839
'complex_type': None,
869-
'array_dimension': 1,
870840
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
871841
'python_name': 'input_array_2',
872842
'python_name_with_default': 'input_array_2=None',
@@ -897,7 +867,6 @@
897867
'name': 'inputArray3',
898868
'numpy': False,
899869
'complex_type': None,
900-
'array_dimension': 1,
901870
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
902871
'python_name': 'input_array_3',
903872
'python_name_with_default': 'input_array_3=None',
@@ -928,7 +897,6 @@
928897
'name': 'inputArray4',
929898
'numpy': False,
930899
'complex_type': None,
931-
'array_dimension': 1,
932900
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
933901
'python_name': 'input_array_4',
934902
'python_name_with_default': 'input_array_4=None',
@@ -959,7 +927,6 @@
959927
'name': 'inputArray4',
960928
'numpy': False,
961929
'complex_type': None,
962-
'array_dimension': 1,
963930
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
964931
'python_name': 'input_array_4',
965932
'python_name_with_default': 'input_array_4=None',
@@ -987,7 +954,6 @@
987954
'name': 'aStringEnum',
988955
'numpy': False,
989956
'complex_type': None,
990-
'array_dimension': 1,
991957
'python_name': 'a_string_enum',
992958
'python_name_with_default': 'a_string_enum',
993959
'python_name_with_doc_default': 'a_string_enum',
@@ -1016,7 +982,6 @@
1016982
'name': 'indices',
1017983
'numpy': False,
1018984
'complex_type': None,
1019-
'array_dimension': 1,
1020985
'original_type': 'ViChar[]',
1021986
'python_api_converter_name': 'convert_repeated_capabilities_without_prefix',
1022987
'python_name': 'indices',
@@ -1054,7 +1019,6 @@
10541019
'type': 'ViInt8',
10551020
'numpy': False,
10561021
'complex_type': None,
1057-
'array_dimension': 1,
10581022
'use_in_python_api': True,
10591023
},
10601024
]

generated/nifake/nifake/_grpc_stub_interpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def fetch_waveform(self, number_of_samples): # noqa: N802
144144
def fetch_waveform_into(self, number_of_samples): # noqa: N802
145145
raise NotImplementedError('numpy-specific methods are not supported over gRPC')
146146

147-
def function_with3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array): # noqa: N802
147+
def function_with_3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array): # noqa: N802
148148
raise NotImplementedError('numpy-specific methods are not supported over gRPC')
149149

150150
def function_with_intflag_parameter(self, flag): # noqa: N802

generated/nifake/nifake/_library_interpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def fetch_waveform_into(self, waveform_data): # noqa: N802
222222
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
223223
return
224224

225-
def function_with3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array): # noqa: N802
225+
def function_with_3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array): # noqa: N802
226226
vi_ctype = _visatype.ViSession(self._vi) # case S110
227227
multidimensional_array_ctype = _get_ctypes_pointer_for_buffer(value=multidimensional_array, library_type=_complextype.NIComplexNumber) # case B510
228228
error_code = self._library.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter(vi_ctype, multidimensional_array_ctype)

generated/nifake/nifake/session.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,8 @@ def fetch_waveform_into(self, waveform_data):
945945
raise TypeError('waveform_data must be numpy.ndarray of dtype=float64, is ' + str(waveform_data.dtype))
946946
self._interpreter.fetch_waveform_into(waveform_data)
947947

948-
def function_with3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array):
949-
r'''function_with3d_numpy_array_of_numpy_complex128_input_parameter
948+
def function_with_3d_numpy_array_of_numpy_complex128_input_parameter(self, multidimensional_array):
949+
r'''function_with_3d_numpy_array_of_numpy_complex128_input_parameter
950950
951951
Method that takes a 3D numpy array of numpy complex128 as an input parameter.
952952
@@ -964,7 +964,7 @@ def function_with3d_numpy_array_of_numpy_complex128_input_parameter(self, multid
964964
raise TypeError('multidimensional_array must be numpy.ndarray of dtype=complex128, is ' + str(multidimensional_array.dtype))
965965
if multidimensional_array.ndim != 3:
966966
raise TypeError('multidimensional_array must be numpy.ndarray of dimension=3, is ' + str(multidimensional_array.ndim))
967-
self._interpreter.function_with3d_numpy_array_of_numpy_complex128_input_parameter(multidimensional_array)
967+
self._interpreter.function_with_3d_numpy_array_of_numpy_complex128_input_parameter(multidimensional_array)
968968

969969
@ivi_synchronized
970970
def function_with_intflag_parameter(self, flag):
@@ -1703,6 +1703,8 @@ def write_waveform_numpy(self, waveform):
17031703
raise TypeError('waveform must be in C-order')
17041704
if waveform.dtype is not numpy.dtype('float64'):
17051705
raise TypeError('waveform must be numpy.ndarray of dtype=float64, is ' + str(waveform.dtype))
1706+
if waveform.ndim != 1:
1707+
raise TypeError('waveform must be numpy.ndarray of dimension=1, is ' + str(waveform.ndim))
17061708
self._interpreter.write_waveform_numpy(waveform)
17071709

17081710
@ivi_synchronized
@@ -1723,6 +1725,8 @@ def write_waveform_numpy_complex128(self, waveform_data_array):
17231725
raise TypeError('waveform_data_array must be in C-order')
17241726
if waveform_data_array.dtype is not numpy.dtype('complex128'):
17251727
raise TypeError('waveform_data_array must be numpy.ndarray of dtype=complex128, is ' + str(waveform_data_array.dtype))
1728+
if waveform_data_array.ndim != 1:
1729+
raise TypeError('waveform_data_array must be numpy.ndarray of dimension=1, is ' + str(waveform_data_array.ndim))
17261730
self._interpreter.write_waveform_numpy_complex128(waveform_data_array)
17271731

17281732
@ivi_synchronized
@@ -1743,6 +1747,8 @@ def write_waveform_numpy_complex64(self, waveform_data_array):
17431747
raise TypeError('waveform_data_array must be in C-order')
17441748
if waveform_data_array.dtype is not numpy.dtype('complex64'):
17451749
raise TypeError('waveform_data_array must be numpy.ndarray of dtype=complex64, is ' + str(waveform_data_array.dtype))
1750+
if waveform_data_array.ndim != 1:
1751+
raise TypeError('waveform_data_array must be numpy.ndarray of dimension=1, is ' + str(waveform_data_array.ndim))
17461752
self._interpreter.write_waveform_numpy_complex64(waveform_data_array)
17471753

17481754
@ivi_synchronized
@@ -1763,6 +1769,8 @@ def write_waveform_numpy_complex_interleaved_i16(self, waveform_data_array):
17631769
raise TypeError('waveform_data_array must be in C-order')
17641770
if waveform_data_array.dtype is not numpy.dtype('int16'):
17651771
raise TypeError('waveform_data_array must be numpy.ndarray of dtype=int16, is ' + str(waveform_data_array.dtype))
1772+
if waveform_data_array.ndim != 1:
1773+
raise TypeError('waveform_data_array must be numpy.ndarray of dimension=1, is ' + str(waveform_data_array.ndim))
17661774
self._interpreter.write_waveform_numpy_complex_interleaved_i16(waveform_data_array)
17671775

17681776
def _close(self):

generated/nifake/nifake/unit_tests/test_library_interpreter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,20 +908,20 @@ def test_write_3d_numpy_array_of_numpy_complex128(self):
908908
complex_array = (NIComplexNumber * len(flattened_array))()
909909
for i, value in enumerate(flattened_array):
910910
complex_array[i] = NIComplexNumber(value.real, value.imag)
911-
array_3d_ptr = ctypes.cast(complex_array, ctypes.POINTER(NIComplexNumber))
911+
flattened_array_ptr = ctypes.cast(complex_array, ctypes.POINTER(NIComplexNumber))
912912
self.patched_library.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter.side_effect = self.side_effects_helper.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter
913913
interpreter = self.get_initialized_library_interpreter()
914-
interpreter.function_with3d_numpy_array_of_numpy_complex128_input_parameter(array_3d)
914+
interpreter.function_with_3d_numpy_array_of_numpy_complex128_input_parameter(array_3d)
915915
self.patched_library.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter.assert_called_once_with(
916916
_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST),
917-
_matchers.NIComplexNumberPointerMatcher(array_3d_ptr, number_of_samples)
917+
_matchers.NIComplexNumberPointerMatcher(flattened_array_ptr, number_of_samples)
918918
)
919919

920920
def test_no_memorycopy_with_multi_dimensional_numpy_complex128_array(self):
921921
array_3d = numpy.full((2, 3, 4), 1.0 + 2.0j, dtype=numpy.complex128)
922922
self.patched_library.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter.side_effect = self.side_effects_helper.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter
923923
interpreter = self.get_initialized_library_interpreter()
924-
interpreter.function_with3d_numpy_array_of_numpy_complex128_input_parameter(array_3d)
924+
interpreter.function_with_3d_numpy_array_of_numpy_complex128_input_parameter(array_3d)
925925
args, kwargs = self.patched_library.niFake_FunctionWith3dNumpyArrayOfNumpyComplex128InputParameter.call_args
926926
actual_pointer = args[1]
927927
input_address = array_3d.__array_interface__['data'][0]

0 commit comments

Comments
 (0)