-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
79 lines (64 loc) · 2.92 KB
/
vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
$Id: vector.h,v 1.1 2007/01/21 01:38:35 jp Exp $
vector.h
Vector datatype related function declarations for pnumeric
Python module.
Copyright (c) 2007 Jiří Popek <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __VECTOR_H__
#define __VECTOR_H__
#include "Python.h"
#include "m2/m2.h"
typedef struct {
PyObject_HEAD
// set this if vector stands for matrix row or a vector slice
PyObject *object; // pointer to another object (matrix, vector slice)
Float *p_data; // data pointer into existing data (if vector stands for matrix row of another vector)
// this is useless if vector is matrix row
int length;
Float *data;
} VectorObject;
PyAPI_DATA(PyTypeObject) VectorType;
#define Vector_Check(op) PyObject_TypeCheck(op, &VectorType)
// create new vector object
PyAPI_FUNC(VectorObject *) matrixrow2vector(PyObject *object, Float *p_data);
// create new vector object
PyAPI_FUNC(VectorObject *) vector_new(int length);
// return vector length
PyAPI_FUNC(Py_ssize_t) vector_length(VectorObject *v);
// return vector data pointer
Float * vector_dataptr(VectorObject *v);
// deallocating vector object form memory
PyAPI_FUNC(void) vector_dealloc(VectorObject *v);
// repr, printing of vector or vector row
PyAPI_FUNC(PyObject *) vector_repr(VectorObject *a);
// return vector + number
PyAPI_FUNC(PyObject *) vector_add(VectorObject *v, PyObject *val);
// return vector - number
PyAPI_FUNC(PyObject *) vector_sub(VectorObject *v, PyObject *val);
// return vector item
PyAPI_FUNC(PyObject *) vector_item(VectorObject *a, int i);
// set value to vector row item
PyAPI_FUNC(int) vector_ass_item(VectorObject *self, int idx, PyObject *val);
// comparison of two vectors
PyAPI_FUNC(int) vector_cmp(VectorObject *self, VectorObject *other);
// create new VectorObject from list (tuple)
PyAPI_FUNC(PyObject *) VectorObject_New(PyTypeObject *type, PyObject *args);
// to decide, if we can make arithmetic operation on current datatypes
int vector_coerce(PyObject **v, PyObject **w);
// returns ref (not copy) to current vector object
PyAPI_FUNC(PyObject *) vector_slice(VectorObject *self, int ilow, int ihigh);
// returns a range vector
PyAPI_FUNC(VectorObject *) vector_range(PyObject *self, PyObject *args, PyObject *kws);
#endif /* vector.h */