Skip to content

AnalogWaveform.scaled_data makes an unnecessary copy #197

@bkeryan

Description

@bkeryan

Bug Report

Testing with nidaqmx in ni/nidaqmx-python#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions