@@ -8,10 +8,10 @@ typedef struct
8
8
void * t ;
9
9
} PyTensorObject ;
10
10
11
- static PyObject * Tensor_new ( PyTypeObject * type , PyObject * args )
11
+ static int Tensor_init ( PyTensorObject * self , PyObject * args )
12
12
{
13
13
PyObject * input_array ;
14
- PyArg_ParseTuple (args , "| O" , & input_array );
14
+ PyArg_ParseTuple (args , "O" , & input_array );
15
15
16
16
PyArrayObject * np_array = PyArray_FROM_OTF (input_array , NPY_FLOAT , NPY_ARRAY_IN_ARRAY );
17
17
if (np_array == NULL ) {
@@ -26,15 +26,23 @@ static PyObject* Tensor_new(PyTypeObject* type, PyObject* args)
26
26
c_dims [i ] = dims [i ];
27
27
}
28
28
29
- PyTensorObject * self ;
30
- self = type -> tp_alloc (type , 0 );
31
29
if (self != NULL ) {
32
30
self -> t = call_tensor (ndims , c_dims , PyArray_DATA (np_array ));
33
31
}
34
32
free (c_dims );
35
33
return self ;
36
34
}
37
35
36
+ static PyObject * Tensor_new (PyTypeObject * type , PyObject * args )
37
+ {
38
+ PyTensorObject * self ;
39
+ self = type -> tp_alloc (type , 0 );
40
+ if (self != NULL ) {
41
+ self -> t = 0 ;
42
+ }
43
+ return self ;
44
+ }
45
+
38
46
static void Tensor_dealloc (PyTensorObject * self )
39
47
{
40
48
delete_tensor (self -> t );
@@ -59,6 +67,7 @@ static PyTypeObject TensorType =
59
67
.tp_basicsize = sizeof (PyTensorObject ),
60
68
.tp_itemsize = 0 ,
61
69
.tp_flags = Py_TPFLAGS_DEFAULT ,
70
+ .tp_init = Tensor_init ,
62
71
.tp_new = Tensor_new ,
63
72
.tp_dealloc = Tensor_dealloc ,
64
73
.tp_methods = Tensor_methods ,
0 commit comments