Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3797c61
Implementation of Complex Numbers
rahulr-NI May 9, 2025
d9fba59
Inclusion of test case for WriteWaveformComplexF64
rahulr-NI May 13, 2025
c8f4dfe
Implementation of f32 and i16 and respective test cases
rahulr-NI May 14, 2025
aaf9386
Updated changelog and included examples
rahulr-NI May 15, 2025
599c0df
Updated the metadata
rahulr-NI May 15, 2025
d7df61d
Remove log file
rahulr-NI May 15, 2025
aceaa16
Updated functions.py file and few minor cahnges
rahulr-NI May 15, 2025
37d092d
Update Changelog.md file
rahulr-NI May 15, 2025
9a411cf
Updated minor change.
rahulr-NI May 15, 2025
ac28335
Updated few minor fix
rahulr-NI May 15, 2025
9d8d534
Updated the waveform type as ctype
rahulr-NI May 15, 2025
a689934
Updated the seesion lock parameter for new arb functions
rahulr-NI May 15, 2025
7466bfd
Updated Code Review comments
rahulr-NI May 30, 2025
7363e36
Change log code review comments included
rahulr-NI Jun 6, 2025
d07653f
Removed RFSG specific changes and include complextype only if needed
rahulr-NI Jun 9, 2025
50ed57d
Removed RFSG specific changes
rahulr-NI Jun 9, 2025
2d030ce
Updated matchers and complextype file to be generated bsaed on condit…
rahulr-NI Jun 9, 2025
3cfb37d
Updating spacing issue
rahulr-NI Jun 9, 2025
6aeda17
Updating the complex variables and code review comments incorporated
rahulr-NI Jun 9, 2025
ebb27fa
Test case name change
rahulr-NI Jun 9, 2025
5394faf
Updating minor fixes
rahulr-NI Jun 9, 2025
59f87fc
Updating the test cases
rahulr-NI Jun 9, 2025
d77892d
Update i16 functions
rahulr-NI Jun 9, 2025
27db04c
Update duplicate entries
rahulr-NI Jun 9, 2025
53232bf
remove zone.identifier file changes.
rahulr-NI Jun 10, 2025
8071d7d
Updaed comments for are_complex_parameters_used
rahulr-NI Jun 10, 2025
e883c46
Updated the numpy api names and description.
rahulr-NI Jun 10, 2025
f2fc824
Updating default value of complext type as None rather than 'none'
rahulr-NI Jun 10, 2025
d2681cd
Moving the common lines in complex matchers into a function
rahulr-NI Jun 10, 2025
6da61f1
Merge branch 'ni:master' into complexNumberSupport
rahulr-NI Jun 10, 2025
f52aef8
Updaing the library.py.mako file to import complex type
rahulr-NI Jun 23, 2025
23ff306
Code Reivew Changes
rahulr-NI Jun 30, 2025
5669590
Updaed code review comments
rahulr-NI Jun 30, 2025
c1e19d2
Updaing only necessary fields in COMPLEX_NUMBER_PARAMETERS
rahulr-NI Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

from build.helper.metadata_add_all import add_all_metadata # noqa: F401

from build.helper.metadata_filters import are_complex_parameters_used # noqa: F401
from build.helper.metadata_filters import filter_codegen_attributes # noqa: F401
from build.helper.metadata_filters import filter_codegen_attributes_public_only # noqa: F401
from build.helper.metadata_filters import filter_codegen_enums # noqa: F401
Expand Down
16 changes: 14 additions & 2 deletions build/helper/codegen_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def get_ctype_variable_declaration_snippet(parameter, parameters, ivi_dance_step
else:
module_name = '_visatype'

# Use _complextype.py file for complex parameter
if parameter['complex_type'] is not None:
module_name = '_complextype'

if parameter['is_string'] is True:
definitions = _get_ctype_variable_definition_snippet_for_string(parameter, parameters, ivi_dance_step, module_name)
elif parameter['is_buffer'] is True:
Expand Down Expand Up @@ -362,7 +366,12 @@ def _get_ctype_variable_definition_snippet_for_scalar(parameter, parameters, ivi
definition = '{}.{}({}) # case S150'.format(module_name, parameter['ctypes_type'], parameter['python_name'])
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
# Parameter denotes the size of another (the "corresponding") parameter.
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2})) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
# Interleaved array length is going to be double the length of number of samples.
# This is used for complex waveforms, where the real and imaginary parts are interleaved in the array.
if corresponding_buffer_parameters[0]['complex_type'] == 'interleaved':
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']))
else:
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2})) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
else:
if corresponding_buffer_parameters[0]['size']['mechanism'] == 'ivi-dance': # We are only looking at the first one. Assumes all are the same here, assert below if not
# Verify all corresponding_buffer_parameters are 'out' and 'ivi-dance'
Expand Down Expand Up @@ -426,7 +435,10 @@ def _get_ctype_variable_definition_snippet_for_buffers(parameter, parameters, iv
definition = None

if parameter['numpy'] is True and use_numpy_array is True:
definition = '_get_ctypes_pointer_for_buffer(value={}) # case B510'.format(parameter['python_name'])
if parameter['complex_type'] is None:
definition = '_get_ctypes_pointer_for_buffer(value={}) # case B510'.format(parameter['python_name'])
else:
definition = '_get_ctypes_pointer_for_buffer(value={}, library_type={}.{}) # case B510'.format(parameter['python_name'], module_name, parameter['ctypes_type'])
elif parameter['direction'] == 'in':
if custom_type is not None:
definition = '_get_ctypes_pointer_for_buffer([{0}.{1}(c) for c in {2}], library_type={0}.{1}) # case B540'.format(module_name, parameter['ctypes_type'], parameter['python_name'])
Expand Down
41 changes: 22 additions & 19 deletions build/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@

# noqa statements because we want to format the table in a readable way
_type_map = {
'ViConstString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViInt8': { 'array_type': 'b', 'python_type': 'int', 'numpy_type': 'int8', }, # noqa: E201, E202, E241
'ViUInt8': { 'array_type': 'B', 'python_type': 'int', 'numpy_type': 'uint8', }, # noqa: E201, E202, E241
'ViInt16': { 'array_type': 'h', 'python_type': 'int', 'numpy_type': 'int16', }, # noqa: E201, E202, E241
'ViUInt16': { 'array_type': 'H', 'python_type': 'int', 'numpy_type': 'uint16', }, # noqa: E201, E202, E241
'ViInt32': { 'array_type': 'l', 'python_type': 'int', 'numpy_type': 'int32', }, # noqa: E201, E202, E241
'ViUInt32': { 'array_type': 'L', 'python_type': 'int', 'numpy_type': 'uint32', }, # noqa: E201, E202, E241
'ViInt64': { 'array_type': 'q', 'python_type': 'int', 'numpy_type': 'int64', }, # noqa: E201, E202, E241
'ViUInt64': { 'array_type': 'Q', 'python_type': 'int', 'numpy_type': 'uint64', }, # noqa: E201, E202, E241
'ViReal32': { 'array_type': 'f', 'python_type': 'float', 'numpy_type': 'float32', }, # noqa: E201, E202, E241
'ViReal64': { 'array_type': 'd', 'python_type': 'float', 'numpy_type': 'float64', }, # noqa: E201, E202, E241
'ViStatus': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViSession': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViAttr': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViChar': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViChar[]': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViBoolean': { 'array_type': None, 'python_type': 'bool', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViRsrc': { 'array_type': None, 'python_type': 'str', 'numpy_type': 'bool_', }, # noqa: E201, E202, E241
'ViConstString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViString': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViInt8': { 'array_type': 'b', 'python_type': 'int', 'numpy_type': 'int8', }, # noqa: E201, E202, E241
'ViUInt8': { 'array_type': 'B', 'python_type': 'int', 'numpy_type': 'uint8', }, # noqa: E201, E202, E241
'ViInt16': { 'array_type': 'h', 'python_type': 'int', 'numpy_type': 'int16', }, # noqa: E201, E202, E241
'ViUInt16': { 'array_type': 'H', 'python_type': 'int', 'numpy_type': 'uint16', }, # noqa: E201, E202, E241
'ViInt32': { 'array_type': 'l', 'python_type': 'int', 'numpy_type': 'int32', }, # noqa: E201, E202, E241
'ViUInt32': { 'array_type': 'L', 'python_type': 'int', 'numpy_type': 'uint32', }, # noqa: E201, E202, E241
'ViInt64': { 'array_type': 'q', 'python_type': 'int', 'numpy_type': 'int64', }, # noqa: E201, E202, E241
'ViUInt64': { 'array_type': 'Q', 'python_type': 'int', 'numpy_type': 'uint64', }, # noqa: E201, E202, E241
'ViReal32': { 'array_type': 'f', 'python_type': 'float', 'numpy_type': 'float32', }, # noqa: E201, E202, E241
'ViReal64': { 'array_type': 'd', 'python_type': 'float', 'numpy_type': 'float64', }, # noqa: E201, E202, E241
'ViStatus': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViSession': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViAttr': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViChar': { 'array_type': None, 'python_type': 'int', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViChar[]': { 'array_type': None, 'python_type': 'str', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViBoolean': { 'array_type': None, 'python_type': 'bool', 'numpy_type': None, }, # noqa: E201, E202, E241
'ViRsrc': { 'array_type': None, 'python_type': 'str', 'numpy_type': 'bool_', }, # noqa: E201, E202, E241
'NIComplexNumber': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex128', }, # noqa: E201, E202, E241
'NIComplexNumberF32': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex64', }, # noqa: E201, E202, E241
'NIComplexI16': { 'array_type': None, 'python_type': None, 'numpy_type': 'int16', }, # noqa: E201, E202, E241
}


Expand Down
7 changes: 7 additions & 0 deletions build/helper/metadata_add_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def _add_ctypes_type(parameter, config):
parameter['ctypes_type_library_call'] = module_name + parameter['ctypes_type']


def _add_complex_type(parameter):
'''Adds a complex_type parameter to the metadata for complex numbers'''
if 'complex_type' not in parameter:
parameter['complex_type'] = None


def _add_numpy_info(parameter, parameters, config):
'''Adds the following numpy-related information:

Expand Down Expand Up @@ -450,6 +456,7 @@ def add_all_function_metadata(functions, config):
_add_python_type(p, config)
_add_ctypes_variable_name(p)
_add_ctypes_type(p, config)
_add_complex_type(p)
_add_numpy_info(p, functions[f]['parameters'], config)
_add_default_value_name(p)
_add_default_value_name_for_docs(p, config['module_name'])
Expand Down
47 changes: 47 additions & 0 deletions build/helper/metadata_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in, len',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.SESSION_METHOD_PASSTHROUGH_CALL: {
'skip_session_handle': True,
Expand All @@ -33,6 +34,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in, len',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.SESSION_NUMPY_INTO_METHOD_DECLARATION: {
'skip_session_handle': True,
Expand All @@ -47,6 +49,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in',
'python_api_list': False,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.INTERPRETER_NUMPY_INTO_METHOD_DECLARATION: {
'skip_session_handle': True,
Expand All @@ -61,6 +64,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in',
'python_api_list': False,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.SESSION_METHOD_CALL: {
'skip_session_handle': True,
Expand All @@ -75,6 +79,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.DOCUMENTATION_SESSION_METHOD: {
'skip_session_handle': True,
Expand All @@ -89,6 +94,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.LIBRARY_METHOD_DECLARATION: {
'skip_session_handle': False,
Expand All @@ -103,6 +109,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.LIBRARY_METHOD_CALL: {
'skip_session_handle': False,
Expand All @@ -117,6 +124,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.GRPC_REQUEST_PARAMETERS: {
'skip_session_handle': False,
Expand All @@ -131,6 +139,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.CTYPES_ARGTYPES: {
'skip_session_handle': False,
Expand All @@ -145,6 +154,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.INTERPRETER_METHOD_DECLARATION: {
'skip_session_handle': True,
Expand All @@ -159,6 +169,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'fixed, passed-in, len',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.INPUT_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -173,6 +184,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.LIBRARY_OUTPUT_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -187,6 +199,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.API_OUTPUT_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -201,6 +214,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': False,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.API_NUMPY_OUTPUT_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -215,6 +229,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': False,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.GRPC_OUTPUT_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -229,6 +244,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': False,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.NUMPY_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -243,6 +259,7 @@
'skip_all_except_numpy_parameters': True,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.IVI_DANCE_PARAMETER: {
'skip_session_handle': True,
Expand All @@ -257,6 +274,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'ivi-dance, ivi-dance-with-a-twist',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.LEN_PARAMETER: {
'skip_session_handle': True,
Expand All @@ -271,6 +289,7 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'len',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.INPUT_ENUM_PARAMETERS: {
'skip_session_handle': True,
Expand All @@ -285,6 +304,22 @@
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': False,
},
ParameterUsageOptions.COMPLEX_NUMBER_PARAMETERS: {
'skip_session_handle': True,
'skip_input_parameters': False,
'skip_output_parameters': False,
'but_keep_output_numpy_array_parameters': False,
'skip_size_parameter': False,
'reordered_for_default_values': False,
'skip_repeated_capability_parameter': False,
'skip_non_enum_parameter': False,
'skip_numpy_parameters': False,
'skip_all_except_numpy_parameters': False,
'mechanism': 'any',
'python_api_list': True,
'skip_all_except_complex_type_parameters': True,
},
}

Expand Down Expand Up @@ -349,6 +384,8 @@ def filter_parameters(parameters, parameter_usage_options):
skip = False
if not options_to_use['python_api_list'] and not x['use_in_python_api']:
skip = True
if options_to_use['skip_all_except_complex_type_parameters'] and x['complex_type'] is None:
skip = True
if not skip:
parameters_to_use.append(x)

Expand Down Expand Up @@ -451,3 +488,13 @@ def filter_codegen_enums(enums):
return {k: v for k, v in enums.items() if v['codegen_method'] != 'no'}


def are_complex_parameters_used(functions):
'''Returns bool based on whether any complex parameters are used in the functions metadata.'''
are_complex_parameters_used = False
complex_parameters = []
for k, v in functions.items():
complex_parameters = filter_parameters(v['parameters'], ParameterUsageOptions.COMPLEX_NUMBER_PARAMETERS)
if complex_parameters != []:
are_complex_parameters_used = True
break
return are_complex_parameters_used
2 changes: 2 additions & 0 deletions build/helper/parameter_usage_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ class ParameterUsageOptions(AutoNumber):
'''Get the len parameter'''
INPUT_ENUM_PARAMETERS = ()
'''Get any input parameters whose type is enum'''
COMPLEX_NUMBER_PARAMETERS = ()
'''Get all parameters of complex type'''
21 changes: 21 additions & 0 deletions build/templates/_complextype.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
${template_parameters['encoding_tag']}
# This file was generated
<%
import build.helper as helper
config = template_parameters['metadata'].config
module_name = config['module_name']
%>\
import ctypes
import ${module_name}._visatype as _visatype


class NIComplexNumber(ctypes.Structure):
_fields_ = [("real", _visatype.ViReal64), ("imag", _visatype.ViReal64)]


class NIComplexNumberF32(ctypes.Structure):
_fields_ = [("real", _visatype.ViReal32), ("imag", _visatype.ViReal32)]


class NIComplexI16(ctypes.Structure):
_fields_ = [("real", _visatype.ViInt16), ("imag", _visatype.ViInt16)]
4 changes: 4 additions & 0 deletions build/templates/_library.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ driver_name = config['driver_name']

functions = config['functions']
functions = helper.filter_library_functions(functions)
are_complex_parameters_used = helper.are_complex_parameters_used(functions)
%>\

import ctypes
import ${module_name}.errors as errors
import threading

% if are_complex_parameters_used:
from ${module_name}._complextype import * # noqa: F403
% endif
from ${module_name}._visatype import * # noqa: F403,H303
% for c in config['custom_types']:

Expand Down
Loading