Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy functions on Syncopy Data objects #196

Closed
tensionhead opened this issue Jan 31, 2022 · 2 comments
Closed

Numpy functions on Syncopy Data objects #196

tensionhead opened this issue Jan 31, 2022 · 2 comments
Assignees
Labels
Minor Bug A flaw in the code or documentation that is clearly an error but does neither impede package functio

Comments

@tensionhead
Copy link
Contributor

Using functions like np.sum oder np.mean on spy.Analogdata does nothing, yet there is still a in place selection message emitted.
Reproducing code example:

mock_up_data = [np.arange(6, dtype=float).reshape(3,2) for _ in range(10)]
my_data = spy.AnalogData(mock_up_data)
my_data = np.sum(my_data)
my_data.show()

will output the unchanged original data:

array([[0., 1.],
       [2., 3.],
       [4., 5.],
       [0., 1.],
       ...
@tensionhead tensionhead added the Minor Bug A flaw in the code or documentation that is clearly an error but does neither impede package functio label Jan 31, 2022
@pantaray
Copy link
Member

With recent fixes in SpyArithmetic the output of np.sum(my_data) is simply:

In [4]: np.sum(my_data)
Out[4]: 
Syncopy AnalogData object with fields

            cfg : dictionary with keys ''
        channel : [2] element <class 'numpy.ndarray'>
      container : None
           data : 10 trials of length 3.0 defined on [30 x 2] float64 Dataset of size 0.00 MB
         dimord : time by channel
       filename : /home/fuertingers/.spy/spy_a319_6b9c3f40.analog
           mode : r+
     sampleinfo : [10 x 2] element <class 'numpy.ndarray'>
     samplerate : 1.0
      selection : None
            tag : None
           time : 10 element list
      trialinfo : [10 x 0] element <class 'numpy.ndarray'>
         trials : 10 element iterable

Use `.log` to see object history

which is consistent with, e.g.,

In [6]: np.sum([1])
Out[6]: 1

However, adding my_data to itself produces

In [5]: new_data = np.sum([my_data, my_data])
Syncopy <+> WARNING: Found existing in-place selection in operand. Shapes and trial counts of base and operand objects have to match up!
Syncopy <+> INFO: Allocating 0.00 MB AnalogData object on disk for result of + operation
100% |██████████████████████████████████| 10/10 [00:00<00:00]
In [8]: new_data.data[()]
Out[8]: 
array([[ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.],
       [ 0.,  2.],
       [ 4.,  6.],
       [ 8., 10.]])

Same behavior for np.prod et al. So I guess this is consistent now. I think we close this one @tensionhead ?

@tensionhead
Copy link
Contributor Author

Phew, ok this has gone under completely.. yet is related to #376 where this topic will be generally addressed, so I am closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A flaw in the code or documentation that is clearly an error but does neither impede package functio
Projects
None yet
Development

No branches or pull requests

2 participants