Skip to content

Commit 3277e44

Browse files
test
1 parent 0d1c5b2 commit 3277e44

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CPythonTensor/module.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ typedef struct
88
void* t;
99
} PyTensorObject;
1010

11-
static PyObject* Tensor_new(PyTypeObject* type, PyObject* args)
11+
static int Tensor_init(PyTensorObject* self, PyObject* args)
1212
{
1313
PyObject *input_array;
14-
PyArg_ParseTuple(args, "|O", &input_array);
14+
PyArg_ParseTuple(args, "O", &input_array);
1515

1616
PyArrayObject* np_array = PyArray_FROM_OTF(input_array, NPY_FLOAT, NPY_ARRAY_IN_ARRAY);
1717
if (np_array == NULL) {
@@ -26,15 +26,23 @@ static PyObject* Tensor_new(PyTypeObject* type, PyObject* args)
2626
c_dims[i] = dims[i];
2727
}
2828

29-
PyTensorObject* self;
30-
self = type->tp_alloc(type, 0);
3129
if (self != NULL) {
3230
self->t = call_tensor(ndims, c_dims, PyArray_DATA(np_array));
3331
}
3432
free(c_dims);
3533
return self;
3634
}
3735

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+
3846
static void Tensor_dealloc(PyTensorObject* self)
3947
{
4048
delete_tensor(self->t);
@@ -59,6 +67,7 @@ static PyTypeObject TensorType =
5967
.tp_basicsize = sizeof(PyTensorObject),
6068
.tp_itemsize = 0,
6169
.tp_flags = Py_TPFLAGS_DEFAULT,
70+
.tp_init = Tensor_init,
6271
.tp_new = Tensor_new,
6372
.tp_dealloc = Tensor_dealloc,
6473
.tp_methods = Tensor_methods,

CPythonTensor/py_tensor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ void delete_tensor(void* t)
1414
delete t;
1515
}
1616

17+
void add_tensor(const void* a, const void* b)
18+
{
19+
return;
20+
}
21+
1722
const char* to_string(void* t)
1823
{
1924
Tensor* t1 = static_cast<Tensor*>(t);

0 commit comments

Comments
 (0)