Ticket #303 (closed defect: fixed)

Opened 17 months ago

Last modified 14 months ago

extension type member of type numpy.float_t looses its value

Reported by: NNemec Owned by: somebody
Priority: major Milestone: 0.11.3
Component: Code Generation Keywords: numerics
Cc: dagss@…

Description (last modified by dagss) (diff)

The numpy.float_t type is not handled correctly. The snippet

cdef class myclass:
    cdef readonly:
        double var_d
        numpy.float_t var_nf
    def __init__(self):
        self.var_d = 42.0
        self.var_nf = 42.0

c = myclass()

print "double (correctly given as 42.0):",c.var_d
print "numpy.float_t (should be 42.0):",c.var_nf

compiles fine, but prints

    double (correctly given as 42.0): 42.0
    numpy.float_t (should be 42.0): 0.0

so the value of var_nf seems to be lost somewhere on the way.

Change History

Changed 17 months ago by NNemec

  • keywords numerics added

Changed 17 months ago by dagss

  • owner set to somebody
  • component changed from Invalid to Code Generation
  • milestone set to 0.11.2

Changed 16 months ago by dagss

  • description modified (diff)

Changed 16 months ago by dagss

This is related to the PyMemberDef? generation:

static struct PyMemberDef __pyx_members_18typedfieldbug_T303_MyClass[] = {
  {(char *)"var_d", T_DOUBLE, offsetof(struct __pyx_obj_18typedfieldbug_T303_MyClass, var_d), READONLY, 0},
  {(char *)"var_nf", T_FLOAT, offsetof(struct __pyx_obj_18typedfieldbug_T303_MyClass, var_nf), READONLY, 0},
  {0, 0, 0, 0, 0}
};

Instead of hard-coding T_DOUBLE and T_FLOAT, this should be dynamically selected at runtime using sizeof. Same with integers.

Changed 16 months ago by dagss

  • milestone changed from 0.11.2 to 0.12

Fixed in  http://hg.cython.org/cython-devel/rev/dcc78ab6a498 and  http://hg.cython.org/cython-devel/rev/ddaf43291b55

However see also ML discussion; might want to change the solution in 0.12.

Changed 16 months ago by dagss

This fix also led to a regression, see ML yesterday.

Changed 16 months ago by dagss

  • milestone changed from 0.12 to 0.11.3

Changed 14 months ago by dagss

  • status changed from new to closed
  • resolution set to fixed

This is fixed now.

Note: See TracTickets for help on using tickets.