Skip to content

Commit 6aeda17

Browse files
committed
Updating the complex variables and code review comments incorporated
1 parent 3cfb37d commit 6aeda17

File tree

14 files changed

+83
-85
lines changed

14 files changed

+83
-85
lines changed

build/helper/codegen_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ def _get_ctype_variable_definition_snippet_for_scalar(parameter, parameters, ivi
366366
definition = '{}.{}({}) # case S150'.format(module_name, parameter['ctypes_type'], parameter['python_name'])
367367
elif corresponding_buffer_parameters and corresponding_buffer_parameters[0]['direction'] == 'in': # We are only looking at the first one to see if it is 'in'. Assumes all are the same here, assert below if not
368368
# Parameter denotes the size of another (the "corresponding") parameter.
369-
370-
# Interleaved array length is going to be double the length of number of samples
369+
# Interleaved array length is going to be double the length of number of samples.
370+
# This is used for complex waveforms, where the real and imaginary parts are interleaved in the array.
371371
if 'interleaved' in corresponding_buffer_parameters[0]['complex_type']:
372372
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2}) // 2) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
373373
else:

build/helper/helper.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77

88
# noqa statements because we want to format the table in a readable way
99
_type_map = {
10-
'ViConstString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
11-
'ViString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
12-
'ViInt8': { 'array_type': 'b', 'python_type': 'int', 'numpy_type': 'int8', }, # noqa: E201, E202, E241
13-
'ViUInt8': { 'array_type': 'B', 'python_type': 'int', 'numpy_type': 'uint8', }, # noqa: E201, E202, E241
14-
'ViInt16': { 'array_type': 'h', 'python_type': 'int', 'numpy_type': 'int16', }, # noqa: E201, E202, E241
15-
'ViUInt16': { 'array_type': 'H', 'python_type': 'int', 'numpy_type': 'uint16', }, # noqa: E201, E202, E241
16-
'ViInt32': { 'array_type': 'l', 'python_type': 'int', 'numpy_type': 'int32', }, # noqa: E201, E202, E241
17-
'ViUInt32': { 'array_type': 'L', 'python_type': 'int', 'numpy_type': 'uint32', }, # noqa: E201, E202, E241
18-
'ViInt64': { 'array_type': 'q', 'python_type': 'int', 'numpy_type': 'int64', }, # noqa: E201, E202, E241
19-
'ViUInt64': { 'array_type': 'Q', 'python_type': 'int', 'numpy_type': 'uint64', }, # noqa: E201, E202, E241
20-
'ViReal32': { 'array_type': 'f', 'python_type': 'float', 'numpy_type': 'float32', }, # noqa: E201, E202, E241
21-
'ViReal64': { 'array_type': 'd', 'python_type': 'float', 'numpy_type': 'float64', }, # noqa: E201, E202, E241
22-
'ViStatus': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
23-
'ViSession': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
24-
'ViAttr': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
25-
'ViChar': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
26-
'ViChar[]': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
27-
'ViBoolean': { 'array_type': None, 'python_type': 'bool', 'numpy_type': None, }, # noqa: E201, E202, E241
28-
'ViRsrc': { 'array_type': None, 'python_type': 'str', 'numpy_type': 'bool_', }, # noqa: E201, E202, E241
29-
'ComplexViReal64': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex128', }, # noqa: E201, E202, E241
30-
'ComplexViReal32': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex64', }, # noqa: E201, E202, E241
31-
'ComplexViInt16': { 'array_type': None, 'python_type': None, 'numpy_type': 'int16', }, # noqa: E201, E202, E241
10+
'ViConstString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
11+
'ViString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
12+
'ViInt8': { 'array_type': 'b', 'python_type': 'int', 'numpy_type': 'int8', }, # noqa: E201, E202, E241
13+
'ViUInt8': { 'array_type': 'B', 'python_type': 'int', 'numpy_type': 'uint8', }, # noqa: E201, E202, E241
14+
'ViInt16': { 'array_type': 'h', 'python_type': 'int', 'numpy_type': 'int16', }, # noqa: E201, E202, E241
15+
'ViUInt16': { 'array_type': 'H', 'python_type': 'int', 'numpy_type': 'uint16', }, # noqa: E201, E202, E241
16+
'ViInt32': { 'array_type': 'l', 'python_type': 'int', 'numpy_type': 'int32', }, # noqa: E201, E202, E241
17+
'ViUInt32': { 'array_type': 'L', 'python_type': 'int', 'numpy_type': 'uint32', }, # noqa: E201, E202, E241
18+
'ViInt64': { 'array_type': 'q', 'python_type': 'int', 'numpy_type': 'int64', }, # noqa: E201, E202, E241
19+
'ViUInt64': { 'array_type': 'Q', 'python_type': 'int', 'numpy_type': 'uint64', }, # noqa: E201, E202, E241
20+
'ViReal32': { 'array_type': 'f', 'python_type': 'float', 'numpy_type': 'float32', }, # noqa: E201, E202, E241
21+
'ViReal64': { 'array_type': 'd', 'python_type': 'float', 'numpy_type': 'float64', }, # noqa: E201, E202, E241
22+
'ViStatus': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
23+
'ViSession': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
24+
'ViAttr': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
25+
'ViChar': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
26+
'ViChar[]': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
27+
'ViBoolean': { 'array_type': None, 'python_type': 'bool', 'numpy_type': None, }, # noqa: E201, E202, E241
28+
'ViRsrc': { 'array_type': None, 'python_type': 'str', 'numpy_type': 'bool_', }, # noqa: E201, E202, E241
29+
'NIComplexNumber': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex128', }, # noqa: E201, E202, E241
30+
'NIComplexNumberF32': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex64', }, # noqa: E201, E202, E241
31+
'NIComplexI16': { 'array_type': None, 'python_type': None, 'numpy_type': 'int16', }, # noqa: E201, E202, E241
3232
}
3333

3434

build/templates/_complextype.py.mako

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import ctypes
99
import ${module_name}._visatype as _visatype
1010

1111

12-
class ComplexViReal64(ctypes.Structure):
12+
class NIComplexNumber(ctypes.Structure):
1313
_fields_ = [("real", _visatype.ViReal64), ("imag", _visatype.ViReal64)]
1414

1515

16-
class ComplexViReal32(ctypes.Structure):
16+
class NIComplexNumberF32(ctypes.Structure):
1717
_fields_ = [("real", _visatype.ViReal32), ("imag", _visatype.ViReal32)]
1818

1919

20-
class ComplexViInt16(ctypes.Structure):
20+
class NIComplexI16(ctypes.Structure):
2121
_fields_ = [("real", _visatype.ViInt16), ("imag", _visatype.ViInt16)]

build/templates/_library_interpreter.py.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
5151
elif str(type(value)).find("'numpy.ndarray'") != -1:
5252
import numpy
5353
% if are_complex_parameters_used:
54-
if library_type in (_complextype.ComplexViInt16, _complextype.ComplexViReal32, _complextype.ComplexViReal64):
54+
if library_type in (_complextype.NIComplexI16, _complextype.NIComplexNumberF32, _complextype.NIComplexNumber):
5555
complex_dtype = numpy.dtype(library_type)
5656
structured_array = value.view(complex_dtype)
5757
return structured_array.ctypes.data_as(ctypes.POINTER(library_type))

build/templates/_matchers.py.mako

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ class ViReal64PointerMatcher(_PointerMatcher):
283283

284284

285285
% if are_complex_parameters_used:
286-
class ComplexViReal64PointerMatcher(_PointerMatcher):
286+
class NIComplexNumberPointerMatcher(_PointerMatcher):
287287
def __init__(self, expected_data, expected_size):
288-
_PointerMatcher.__init__(self, _complextype.ComplexViReal64)
288+
_PointerMatcher.__init__(self, _complextype.NIComplexNumber)
289289
self.expected_data = expected_data
290290
self.expected_size = expected_size
291291

@@ -300,12 +300,12 @@ class ComplexViReal64PointerMatcher(_PointerMatcher):
300300
return True
301301

302302
def __repr__(self):
303-
return f"ComplexViReal64PointerMatcher({self.expected_data})"
303+
return f"NIComplexNumberPointerMatcher({self.expected_data})"
304304

305305

306-
class ComplexViReal32PointerMatcher(_PointerMatcher):
306+
class NIComplexNumberF32PointerMatcher(_PointerMatcher):
307307
def __init__(self, expected_data, expected_size):
308-
_PointerMatcher.__init__(self, _complextype.ComplexViReal32)
308+
_PointerMatcher.__init__(self, _complextype.NIComplexNumberF32)
309309
self.expected_data = expected_data
310310
self.expected_size = expected_size
311311

@@ -320,12 +320,12 @@ class ComplexViReal32PointerMatcher(_PointerMatcher):
320320
return True
321321

322322
def __repr__(self):
323-
return f"ComplexViReal32PointerMatcher({self.expected_data})"
323+
return f"NIComplexNumberF32PointerMatcher({self.expected_data})"
324324

325325

326-
class ComplexViInt16PointerMatcher(_PointerMatcher):
326+
class NIComplexI16PointerMatcher(_PointerMatcher):
327327
def __init__(self, expected_data, expected_size):
328-
_PointerMatcher.__init__(self, _complextype.ComplexViInt16)
328+
_PointerMatcher.__init__(self, _complextype.NIComplexI16)
329329
self.expected_data = expected_data
330330
self.expected_size = expected_size
331331

@@ -340,7 +340,7 @@ class ComplexViInt16PointerMatcher(_PointerMatcher):
340340
return True
341341

342342
def __repr__(self):
343-
return f"ComplexViInt16PointerMatcher({self.expected_data})"
343+
return f"NIComplexI16PointerMatcher({self.expected_data})"
344344

345345

346346
% endif

generated/nifake/nifake/_complextype.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import nifake._visatype as _visatype
55

66

7-
class ComplexViReal64(ctypes.Structure):
7+
class NIComplexNumber(ctypes.Structure):
88
_fields_ = [("real", _visatype.ViReal64), ("imag", _visatype.ViReal64)]
99

1010

11-
class ComplexViReal32(ctypes.Structure):
11+
class NIComplexNumberF32(ctypes.Structure):
1212
_fields_ = [("real", _visatype.ViReal32), ("imag", _visatype.ViReal32)]
1313

1414

15-
class ComplexViInt16(ctypes.Structure):
15+
class NIComplexI16(ctypes.Structure):
1616
_fields_ = [("real", _visatype.ViInt16), ("imag", _visatype.ViInt16)]

generated/nifake/nifake/_library.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,23 +647,23 @@ def niFake_WriteWaveformComplexF32(self, vi, number_of_samples, waveform_data_ar
647647
with self._func_lock:
648648
if self.niFake_WriteWaveformComplexF32_cfunc is None:
649649
self.niFake_WriteWaveformComplexF32_cfunc = self._get_library_function('niFake_WriteWaveformComplexF32')
650-
self.niFake_WriteWaveformComplexF32_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(ComplexViReal32)] # noqa: F405
650+
self.niFake_WriteWaveformComplexF32_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(NIComplexNumberF32)] # noqa: F405
651651
self.niFake_WriteWaveformComplexF32_cfunc.restype = ViStatus # noqa: F405
652652
return self.niFake_WriteWaveformComplexF32_cfunc(vi, number_of_samples, waveform_data_array)
653653

654654
def niFake_WriteWaveformComplexF64(self, vi, number_of_samples, waveform_data_array): # noqa: N802
655655
with self._func_lock:
656656
if self.niFake_WriteWaveformComplexF64_cfunc is None:
657657
self.niFake_WriteWaveformComplexF64_cfunc = self._get_library_function('niFake_WriteWaveformComplexF64')
658-
self.niFake_WriteWaveformComplexF64_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(ComplexViReal64)] # noqa: F405
658+
self.niFake_WriteWaveformComplexF64_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(NIComplexNumber)] # noqa: F405
659659
self.niFake_WriteWaveformComplexF64_cfunc.restype = ViStatus # noqa: F405
660660
return self.niFake_WriteWaveformComplexF64_cfunc(vi, number_of_samples, waveform_data_array)
661661

662662
def niFake_WriteWaveformComplexI16(self, vi, number_of_samples, waveform_data_array): # noqa: N802
663663
with self._func_lock:
664664
if self.niFake_WriteWaveformComplexI16_cfunc is None:
665665
self.niFake_WriteWaveformComplexI16_cfunc = self._get_library_function('niFake_WriteWaveformComplexI16')
666-
self.niFake_WriteWaveformComplexI16_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(ComplexViInt16)] # noqa: F405
666+
self.niFake_WriteWaveformComplexI16_cfunc.argtypes = [ViSession, ViInt32, ctypes.POINTER(NIComplexI16)] # noqa: F405
667667
self.niFake_WriteWaveformComplexI16_cfunc.restype = ViStatus # noqa: F405
668668
return self.niFake_WriteWaveformComplexI16_cfunc(vi, number_of_samples, waveform_data_array)
669669

generated/nifake/nifake/_library_interpreter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
3030
return ctypes.cast(addr, ctypes.POINTER(library_type))
3131
elif str(type(value)).find("'numpy.ndarray'") != -1:
3232
import numpy
33-
if library_type in (_complextype.ComplexViInt16, _complextype.ComplexViReal32, _complextype.ComplexViReal64):
33+
if library_type in (_complextype.NIComplexI16, _complextype.NIComplexNumberF32, _complextype.NIComplexNumber):
3434
complex_dtype = numpy.dtype(library_type)
3535
structured_array = value.view(complex_dtype)
3636
return structured_array.ctypes.data_as(ctypes.POINTER(library_type))
@@ -741,23 +741,23 @@ def write_waveform_numpy(self, waveform): # noqa: N802
741741
def write_waveform_complex_f32(self, waveform_data_array): # noqa: N802
742742
vi_ctype = _visatype.ViSession(self._vi) # case S110
743743
number_of_samples_ctype = _visatype.ViInt32(0 if waveform_data_array is None else len(waveform_data_array)) # case S160
744-
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.ComplexViReal32) # case B510
744+
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.NIComplexNumberF32) # case B510
745745
error_code = self._library.niFake_WriteWaveformComplexF32(vi_ctype, number_of_samples_ctype, waveform_data_array_ctype)
746746
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
747747
return
748748

749749
def write_waveform_complex_f64(self, waveform_data_array): # noqa: N802
750750
vi_ctype = _visatype.ViSession(self._vi) # case S110
751751
number_of_samples_ctype = _visatype.ViInt32(0 if waveform_data_array is None else len(waveform_data_array)) # case S160
752-
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.ComplexViReal64) # case B510
752+
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.NIComplexNumber) # case B510
753753
error_code = self._library.niFake_WriteWaveformComplexF64(vi_ctype, number_of_samples_ctype, waveform_data_array_ctype)
754754
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
755755
return
756756

757757
def write_waveform_complex_i16(self, waveform_data_array): # noqa: N802
758758
vi_ctype = _visatype.ViSession(self._vi) # case S110
759759
number_of_samples_ctype = _visatype.ViInt32(0 if waveform_data_array is None else len(waveform_data_array) // 2) # case S160
760-
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.ComplexViInt16) # case B510
760+
waveform_data_array_ctype = _get_ctypes_pointer_for_buffer(value=waveform_data_array, library_type=_complextype.NIComplexI16) # case B510
761761
error_code = self._library.niFake_WriteWaveformComplexI16(vi_ctype, number_of_samples_ctype, waveform_data_array_ctype)
762762
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
763763
return

generated/nifake/nifake/unit_tests/_matchers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ def __init__(self):
272272
_PointerMatcher.__init__(self, _visatype.ViReal64)
273273

274274

275-
class ComplexViReal64PointerMatcher(_PointerMatcher):
275+
class NIComplexNumberPointerMatcher(_PointerMatcher):
276276
def __init__(self, expected_data, expected_size):
277-
_PointerMatcher.__init__(self, _complextype.ComplexViReal64)
277+
_PointerMatcher.__init__(self, _complextype.NIComplexNumber)
278278
self.expected_data = expected_data
279279
self.expected_size = expected_size
280280

@@ -289,12 +289,12 @@ def __eq__(self, other):
289289
return True
290290

291291
def __repr__(self):
292-
return f"ComplexViReal64PointerMatcher({self.expected_data})"
292+
return f"NIComplexNumberPointerMatcher({self.expected_data})"
293293

294294

295-
class ComplexViReal32PointerMatcher(_PointerMatcher):
295+
class NIComplexNumberF32PointerMatcher(_PointerMatcher):
296296
def __init__(self, expected_data, expected_size):
297-
_PointerMatcher.__init__(self, _complextype.ComplexViReal32)
297+
_PointerMatcher.__init__(self, _complextype.NIComplexNumberF32)
298298
self.expected_data = expected_data
299299
self.expected_size = expected_size
300300

@@ -309,12 +309,12 @@ def __eq__(self, other):
309309
return True
310310

311311
def __repr__(self):
312-
return f"ComplexViReal32PointerMatcher({self.expected_data})"
312+
return f"NIComplexNumberF32PointerMatcher({self.expected_data})"
313313

314314

315-
class ComplexViInt16PointerMatcher(_PointerMatcher):
315+
class NIComplexI16PointerMatcher(_PointerMatcher):
316316
def __init__(self, expected_data, expected_size):
317-
_PointerMatcher.__init__(self, _complextype.ComplexViInt16)
317+
_PointerMatcher.__init__(self, _complextype.NIComplexI16)
318318
self.expected_data = expected_data
319319
self.expected_size = expected_size
320320

@@ -329,7 +329,7 @@ def __eq__(self, other):
329329
return True
330330

331331
def __repr__(self):
332-
return f"ComplexViInt16PointerMatcher({self.expected_data})"
332+
return f"NIComplexI16PointerMatcher({self.expected_data})"
333333

334334

335335
# Buffers

0 commit comments

Comments
 (0)