Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 7 additions & 0 deletions build/helper/metadata_add_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def _add_complex_type(parameter):
parameter['complex_type'] = None


def _add_array_dimension(parameter):
'''Adds a array_dimension parameter to the metadata for multi dimensional arrays'''
if 'array_dimension' not in parameter:
parameter['array_dimension'] = 1


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

Expand Down Expand Up @@ -457,6 +463,7 @@ def add_all_function_metadata(functions, config):
_add_ctypes_variable_name(p)
_add_ctypes_type(p, config)
_add_complex_type(p)
_add_array_dimension(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
8 changes: 6 additions & 2 deletions build/templates/_library_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
% if are_complex_parameters_used:
if library_type in (_complextype.NIComplexI16, _complextype.NIComplexNumberF32, _complextype.NIComplexNumber):
complex_dtype = numpy.dtype(library_type)
structured_array = value.view(complex_dtype)
return structured_array.ctypes.data_as(ctypes.POINTER(library_type))
if value.ndim > 1:
# we create a flattened view of the multi-dimensional numpy array
restructured_array_view = value.ravel().view(complex_dtype)
else:
restructured_array_view = value.view(complex_dtype)
Comment thread
rahulr-NI marked this conversation as resolved.
return restructured_array_view.ctypes.data_as(ctypes.POINTER(library_type))
else:
return numpy.ctypeslib.as_ctypes(value)
% else:
Expand Down
4 changes: 4 additions & 0 deletions build/templates/session.py/numpy_write_method.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
raise TypeError('${parameter['python_name']} must be in C-order')
if ${parameter['python_name']}.dtype is not numpy.dtype('${parameter['numpy_type']}'):
raise TypeError('${parameter['python_name']} must be numpy.ndarray of dtype=${parameter['numpy_type']}, is ' + str(${parameter['python_name']}.dtype))
% if parameter['array_dimension'] > 1:
if ${parameter['python_name']}.ndim != ${parameter['array_dimension']}:
raise TypeError('${parameter['python_name']} must be numpy.ndarray of dimension=${parameter['array_dimension']}, is ' + str(${parameter['python_name']}.ndim))
% endif
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
% endfor
% for p in helper.filter_parameters(parameters, helper.ParameterUsageOptions.INTERPRETER_METHOD_CALL):
% if 'python_api_converter_name' in p:
Expand Down
36 changes: 36 additions & 0 deletions build/unit_tests/test_codegen_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'type': 'ViSession',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
'use_in_python_api': True,
},
{ # 1
Expand Down Expand Up @@ -71,6 +72,7 @@
'type': 'ViInt64',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 2
Expand Down Expand Up @@ -99,6 +101,7 @@
'type': 'ViString',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 3
Expand Down Expand Up @@ -128,6 +131,7 @@
'type': 'custom_struct',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 4
Expand All @@ -154,6 +158,7 @@
'type': 'ViInt32',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 5
Expand Down Expand Up @@ -182,6 +187,7 @@
'type': 'ViInt16',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 6
Expand Down Expand Up @@ -211,6 +217,7 @@
'type': 'ViInt16',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 7
Expand Down Expand Up @@ -239,6 +246,7 @@
'type': 'ViInt64',
'numpy': True,
'complex_type': None,
'array_dimension': 1,
'numpy_type': 'int64',
'numpy_type_library_call': 'numpy.int64',
'use_in_python_api': True,
Expand All @@ -261,6 +269,7 @@
'name': 'numberOfElementsPythonCode',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'number_of_elements_python_code',
'python_name_with_default': 'number_of_elements_python_code',
'python_name_with_doc_default': 'number_of_elements_python_code',
Expand All @@ -287,6 +296,7 @@
'name': 'input',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'input',
'python_name_with_default': 'input',
'python_name_with_doc_default': 'input',
Expand Down Expand Up @@ -316,6 +326,7 @@
'name': 'inputArray',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'input_array',
'python_name_with_default': 'input_array=None',
'python_name_with_doc_default': 'input_array=None',
Expand All @@ -342,6 +353,7 @@
'name': 'inputArraySize',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'input_array_size',
'python_name_with_default': 'input_array_size',
'python_name_with_doc_default': 'input_array_size',
Expand All @@ -368,6 +380,7 @@
'name': 'stringSize',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'string_size',
'python_name_with_default': 'string_size',
'python_name_with_doc_default': 'string_size',
Expand All @@ -394,6 +407,7 @@
'name': 'aString',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string',
'python_name_with_default': 'a_string',
'python_name_with_doc_default': 'a_string',
Expand Down Expand Up @@ -421,6 +435,7 @@
'name': 'Timeout',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'timeout',
'python_name_with_default': 'timeout=1.0',
'python_name_with_doc_default': 'timeout=1.0',
Expand Down Expand Up @@ -450,6 +465,7 @@
'name': 'channelList',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'original_type': 'ViChar[]',
'python_name': 'channel_list',
'python_name_with_default': 'channel_list',
Expand Down Expand Up @@ -477,6 +493,7 @@
'name': 'aString',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string',
'python_name_with_default': 'a_string',
'python_name_with_doc_default': 'a_string',
Expand Down Expand Up @@ -510,6 +527,7 @@
'type': 'custom_struct',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 18
Expand Down Expand Up @@ -540,6 +558,7 @@
'type': 'ViInt16',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 19
Expand All @@ -560,6 +579,7 @@
'name': 'aString2',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string_2',
'python_name_with_default': 'a_string_2',
'python_name_with_doc_default': 'a_string_2',
Expand All @@ -586,6 +606,7 @@
'name': 'aStrin3g',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string_3',
'python_name_with_default': 'a_string_3',
'python_name_with_doc_default': 'a_string_3',
Expand All @@ -612,6 +633,7 @@
'name': 'aStringTwist',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string_twist',
'python_name_with_default': 'a_string_twist',
'python_name_with_doc_default': 'a_string_twist',
Expand Down Expand Up @@ -647,6 +669,7 @@
'type': 'ViInt64',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
{ # 23
Expand All @@ -667,6 +690,7 @@
'name': 'stringSizeTwist',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'string_size_twist',
'python_name_with_default': 'string_size_twist',
'python_name_with_doc_default': 'string_size_twist',
Expand All @@ -693,6 +717,7 @@
'name': 'aBufferArray',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_buffer_array',
'python_name_with_default': 'a_buffer_array',
'python_name_with_doc_default': 'a_buffer_array',
Expand Down Expand Up @@ -721,6 +746,7 @@
'name': 'aBufferList',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_buffer_list',
'python_name_with_default': 'a_buffer_list',
'python_name_with_doc_default': 'a_buffer_list',
Expand Down Expand Up @@ -749,6 +775,7 @@
'name': 'aBufferTwistArray',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_buffer_twist_array',
'python_name_with_default': 'a_buffer_twist_array',
'python_name_with_doc_default': 'a_buffer_twist_array',
Expand Down Expand Up @@ -777,6 +804,7 @@
'name': 'aBufferTwistList',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_buffer_twist_list',
'python_name_with_default': 'a_buffer_twist_list',
'python_name_with_doc_default': 'a_buffer_twist_list',
Expand Down Expand Up @@ -808,6 +836,7 @@
'name': 'inputArray2',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'input_array_2',
'python_name_with_default': 'input_array_2=None',
'python_name_with_doc_default': 'input_array_2=None',
Expand Down Expand Up @@ -837,6 +866,7 @@
'name': 'inputArray2',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
'python_name': 'input_array_2',
'python_name_with_default': 'input_array_2=None',
Expand Down Expand Up @@ -867,6 +897,7 @@
'name': 'inputArray3',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
'python_name': 'input_array_3',
'python_name_with_default': 'input_array_3=None',
Expand Down Expand Up @@ -897,6 +928,7 @@
'name': 'inputArray4',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
'python_name': 'input_array_4',
'python_name_with_default': 'input_array_4=None',
Expand Down Expand Up @@ -927,6 +959,7 @@
'name': 'inputArray4',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_api_converter_name': 'convert_to_nitclk_session_num_list',
'python_name': 'input_array_4',
'python_name_with_default': 'input_array_4=None',
Expand Down Expand Up @@ -954,6 +987,7 @@
'name': 'aStringEnum',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'python_name': 'a_string_enum',
'python_name_with_default': 'a_string_enum',
'python_name_with_doc_default': 'a_string_enum',
Expand Down Expand Up @@ -982,6 +1016,7 @@
'name': 'indices',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'original_type': 'ViChar[]',
'python_api_converter_name': 'convert_repeated_capabilities_without_prefix',
'python_name': 'indices',
Expand Down Expand Up @@ -1019,6 +1054,7 @@
'type': 'ViInt8',
'numpy': False,
'complex_type': None,
'array_dimension': 1,
'use_in_python_api': True,
},
]
Expand Down
Loading