Skip to content

Commit 1388283

Browse files
committed
Fixes bugs in real and imag properties
The logic in these properties did not work for float16 data types, returning None instead of `self` or an array of zeros
1 parent 871646b commit 1388283

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

dpctl/tensor/_usmarray.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,8 @@ cdef class usm_ndarray:
687687
""" Returns real component for arrays with complex data-types
688688
and returns itself for all other data-types.
689689
"""
690-
if (self.typenum_ < UAR_CFLOAT):
690+
# explicitly check for UAR_HALF, which is greater than UAR_CFLOAT
691+
if (self.typenum_ < UAR_CFLOAT or self.typenum_ == UAR_HALF):
691692
# elements are real
692693
return self
693694
if (self.typenum_ < UAR_TYPE_SENTINEL):
@@ -698,7 +699,8 @@ cdef class usm_ndarray:
698699
""" Returns imaginary component for arrays with complex data-types
699700
and returns zero array for all other data-types.
700701
"""
701-
if (self.typenum_ < UAR_CFLOAT):
702+
# explicitly check for UAR_HALF, which is greater than UAR_CFLOAT
703+
if (self.typenum_ < UAR_CFLOAT or self.typenum_ == UAR_HALF):
702704
# elements are real
703705
return _zero_like(self)
704706
if (self.typenum_ < UAR_TYPE_SENTINEL):

0 commit comments

Comments
 (0)