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

python: scalar multiplication doesn't preserve type #114

Open
jcmgray opened this issue Nov 12, 2020 · 0 comments
Open

python: scalar multiplication doesn't preserve type #114

jcmgray opened this issue Nov 12, 2020 · 0 comments

Comments

@jcmgray
Copy link

jcmgray commented Nov 12, 2020

Currently, multiplying an array by a non-ctf scalar, doesn't preserve e.g. single precision:

import ctf
import numpy as np

x = ctf.random.random((2,)).astype(np.float32)
print(x.dtype)
# numpy.float32

test_cs = [
    2, 
    2., 
    2j,
]

# left multiply
for c in test_cs:
    print(c, (c * x).dtype)
# 2 <class 'numpy.float64'>
# 2.0 <class 'numpy.float64'>
# 2j <class 'numpy.complex128'>

# right multiply
for c in test_cs:
    print(c, (x * c).dtype)
# 2 <class 'numpy.float64'>
# 2.0 <class 'numpy.float64'>
# 2j <class 'numpy.complex128'>

I guess one expected behaviour, i.e. matching numpy, is to produce [float32, float32, complex64].
The current behaviour might be intentional but thought I'd note this here in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant