ni / ni/nitypes-python

AnalogWaveform.scaled_data makes an unnecessary copy

Open
#197 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
6
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Bug Report

Testing with nidaqmx in https://github.com/ni/nidaqmx-python/pull/828 revealed that AnalogWaveform.scaled_data always copies the data array.

Repro or Code Sample

>>> import numpy as np
>>> x = np.linspace(0.0, 5.0, 10, dtype=np.float64)
>>> y = x[::2]
>>> from nitypes.waveform import AnalogWaveform
>>> w = AnalogWaveform(raw_data=y)
>>> w.raw_data.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

>>> w.scaled_data.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

>>> w.raw_data.astype(np.float64).flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

>>> w.raw_data.astype(np.float64, copy=False).flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

Expected Behavior

When raw_data.dtype == np.float64 and scale_mode == NO_SCALING, scaled_data returns raw_data without making a copy.

Current Behavior

scaled_data always makes a copy.

Possible Solution

Add copy=False to the astype call in _convert_data.

Context

Reviewing nidaqmx changes.

Your Environment

N/A

AB#3262958

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at AnalogWaveform.scaled_data and follow its _convert_data call, using the reproduction with a non-contiguous float64 raw_data array and NO_SCALING. Done means scaled_data preserves the raw_data view instead of allocating a copy under the stated conditions, as shown by the array flags.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.