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

Expand Down Expand Up @@ -2140,7 +2141,6 @@
- [0.2.0](#nise-020---2018-10-25)
- [0.1.0](#nise-010---2018-10-17)

#### [nise] Unreleased
Comment thread
ni-jfitzger marked this conversation as resolved.
- Added
- Changed
- Removed
Expand Down Expand Up @@ -2296,7 +2296,6 @@
- [0.3.0](#niswitch-030---2017-10-13)
- [0.2.0](#niswitch-020---2017-09-20)

#### [niswitch] Unreleased
Comment thread
ni-jfitzger marked this conversation as resolved.
- Added
- Changed
- Removed
Expand Down Expand Up @@ -2547,7 +2546,6 @@
- [0.3.0](#nitclk-030---2019-11-19)
- [0.1.0](#nitclk-010---2019-10-21)

#### [nitclk] Unreleased
Comment thread
ni-jfitzger marked this conversation as resolved.
- Added
- Changed
- Removed
Expand Down
1 change: 1 addition & 0 deletions build/defines.mak
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ DEFAULT_PY_FILES_TO_GENERATE := \
unit_tests/_matchers.py \
__init__.py \
_converters.py \
_complextype.py \
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
VERSION \
$(if $(GRPC_SUPPORTED), \
_grpc_stub_interpreter.py \
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'] != 'none':
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
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
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
if 'interleaved' in corresponding_buffer_parameters[0]['complex_type']:
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']))
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
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'] == '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'])
Comment thread
ni-jfitzger marked this conversation as resolved.
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
'ComplexViReal64': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex128', }, # noqa: E201, E202, E241
Comment thread
ni-jfitzger marked this conversation as resolved.
Outdated
'ComplexViReal32': { 'array_type': None, 'python_type': None, 'numpy_type': 'complex64', }, # noqa: E201, E202, E241
'ComplexViInt16': { 'array_type': None, 'python_type': None, 'numpy_type': 'int16', }, # noqa: E201, E202, E241
Comment thread
ni-jfitzger marked this conversation as resolved.
Outdated
}


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:
Comment thread
ni-jfitzger marked this conversation as resolved.
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
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 ComplexViReal64(ctypes.Structure):
_fields_ = [("real", _visatype.ViReal64), ("imag", _visatype.ViReal64)]


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


class ComplexViInt16(ctypes.Structure):
_fields_ = [("real", _visatype.ViInt16), ("imag", _visatype.ViInt16)]
1 change: 1 addition & 0 deletions build/templates/_library.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ctypes
import ${module_name}.errors as errors
import threading

from ${module_name}._complextype import * # noqa: F401,F403,H303
from ${module_name}._visatype import * # noqa: F403,H303
Comment thread
rahulr-NI marked this conversation as resolved.
% for c in config['custom_types']:

Expand Down
8 changes: 7 additions & 1 deletion build/templates/_library_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import hightime # noqa: F401
import platform

% endif
import ${module_name}._complextype as _complextype # noqa: F401
Comment thread
rahulr-NI marked this conversation as resolved.
Outdated
import ${module_name}._library_singleton as _library_singleton
import ${module_name}._visatype as _visatype
% if config['enums']:
Expand All @@ -46,7 +47,12 @@ def _get_ctypes_pointer_for_buffer(value=None, library_type=None, size=None):
return ctypes.cast(addr, ctypes.POINTER(library_type))
elif str(type(value)).find("'numpy.ndarray'") != -1:
import numpy
return numpy.ctypeslib.as_ctypes(value)
if library_type in (_complextype.ComplexViInt16, _complextype.ComplexViReal32, _complextype.ComplexViReal64):
complex_dtype = numpy.dtype(library_type)
structured_array = value.view(complex_dtype)
return structured_array.ctypes.data_as(ctypes.POINTER(library_type))
else:
return numpy.ctypeslib.as_ctypes(value)
elif isinstance(value, bytes):
return ctypes.cast(value, ctypes.POINTER(library_type))
elif isinstance(value, list):
Expand Down
60 changes: 60 additions & 0 deletions build/templates/_matchers.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ These work well with our visatype definitions.
'''

import ctypes
import ${template_parameters['metadata'].config['module_name']}._complextype as _complextype
import ${template_parameters['metadata'].config['module_name']}._visatype as _visatype
import pprint

Expand Down Expand Up @@ -271,6 +272,65 @@ class ViReal64PointerMatcher(_PointerMatcher):
_PointerMatcher.__init__(self, _visatype.ViReal64)


class ComplexViReal64PointerMatcher(_PointerMatcher):
Comment thread
ni-jfitzger marked this conversation as resolved.
Outdated
def __init__(self, expected_data, expected_size):
_PointerMatcher.__init__(self, _complextype.ComplexViReal64)
self.expected_data = expected_data
self.expected_size = expected_size

def __eq__(self, other):
_PointerMatcher.__eq__(self, other)

for i in range(self.expected_size):
expected_value = self.expected_data[i]
actual_value = other[i]
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
return False
return True

def __repr__(self):
return f"ComplexViReal64PointerMatcher({self.expected_data})"


class ComplexViReal32PointerMatcher(_PointerMatcher):
def __init__(self, expected_data, expected_size):
_PointerMatcher.__init__(self, _complextype.ComplexViReal32)
self.expected_data = expected_data
self.expected_size = expected_size

def __eq__(self, other):
_PointerMatcher.__eq__(self, other)

for i in range(self.expected_size):
expected_value = self.expected_data[i]
actual_value = other[i]
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
return False
return True

def __repr__(self):
return f"ComplexViReal32PointerMatcher({self.expected_data})"


class ComplexViInt16PointerMatcher(_PointerMatcher):
def __init__(self, expected_data, expected_size):
_PointerMatcher.__init__(self, _complextype.ComplexViInt16)
self.expected_data = expected_data
self.expected_size = expected_size

def __eq__(self, other):
_PointerMatcher.__eq__(self, other)

for i in range(self.expected_size):
expected_value = self.expected_data[i]
actual_value = other[i]
if expected_value.real != actual_value.real or expected_value.imag != actual_value.imag:
return False
return True

def __repr__(self):
return f"ComplexViInt16PointerMatcher({self.expected_data})"

# Buffers


Expand Down
Loading