>>> x = xnd([[, [2,3]], [, [5,6]]]) >>> y = x[:, 0] >>> y xnd([, ], type='var * var * int64') >>> print(y.type.ast_repr()) VarDim( VarDimElem( VarDim( Int64(access=Concrete, ndim=0, datasize=8, align=8, flags=), offsets=[0, 1, 3, 4, 6], slices=, itemsize=8, access=Concrete, ndim=1, datasize=48, align=8, flags= ), index=0, offsets=[0, 2, 4], slices=, itemsize=8, access=Concrete, ndim=2, datasize=48, align=8, flags= ), offsets=[0, 2], slices=[0:9223372036854775807:1], itemsize=8, access=Concrete, ndim=3, datasize=48, align=8, flags= )
[Stefan Krah] @wolfv
ndtypes two ways:
1) Named type constructors:
>>> ndt("Velocity(float32)") ndt("Velocity(float32)") >>> >>> ndt("Velocity(float32)") == ndt("float32") False
>>> typedef("velocity", "float32") >>> ndt("velocity") ndt("velocity") >>> ndt("velocity") == ndt("float32") False
[Stefan Krah] One could allow special characters in typedefs, this is currently not possible:
>>> typedef("m/s", "float32") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid character in typedef: '/'
But there's no fundamental reason.
XND#serializefunction is an instance method and not a class method like that in
NDT? For me its quite counter intuitive to see that it modifies
selfaccording to the value of the serialized string that it is passed. Might it not be better to implement it as a class method?
[Stefan Krah] Do you mean
deserialize? It is a class method:
"deserialize", (PyCFunction)pyxnd_deserialize, METH_O|METH_CLASS, NULL },
In Python you can also call class methods from instances, but the instance is not modified:
>>> x = Decimal("1.23") >>> y = x.from_float(100) >>> x Decimal('1.23') >>> y Decimal('100')
[Sameer Deshmukh] @stefan.krah question about NDT object deallocation:
You said that reducing the refcount of a NDT object 0 via
ndt_decref is supposed to be the only way of deallocating an NDT struct.
However in the python code I can see that you simply point to the default
PyObject_del for the deletion (without decreasing refcount). Can you please explain why this is so?
.tp_free = PyObject_Del is just the counterpart to
self = (NdtObject *)type->tp_alloc(type, 0)
It allocates and frees the *Python object structure*.
.tp_dealloc = (destructor) ndtype_dealloc is the part that deallocates the
ndt struct by calling
xnd-rubyand has future plans for XND in the Ruby community.