Skip to content

Commit bb2ebfa

Browse files
committed
Merge pull request libdynd#451 from izaid/gfunc
Removed remaining array_functions code from gfunc_callable
2 parents e615cc3 + 6b3ec99 commit bb2ebfa

File tree

5 files changed

+42
-134
lines changed

5 files changed

+42
-134
lines changed

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ skip_tags: true
33

44
clone_depth: 1
55

6+
os: Visual Studio 2015
7+
68
matrix:
79
fast_finish: true # immediately finish build once one of the jobs fails.
810

dynd/include/array_assign_from_py.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ namespace pydynd {
2121
* \param a The array which is being assigned to.
2222
* \param value value PyObject for the source data.
2323
*/
24-
void array_broadcast_assign_from_py(const dynd::nd::array &a, PyObject *value,
25-
const dynd::eval::eval_context *ectx);
24+
PYDYND_API void array_broadcast_assign_from_py(
25+
const dynd::nd::array &a, PyObject *value,
26+
const dynd::eval::eval_context *ectx = &dynd::eval::default_eval_context);
2627

2728
/**
2829
* Assigns the values from 'obj' to the 'dt/arrmeta/data' raw nd::array,

dynd/include/gfunc_callable_functions.hpp

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,6 @@
1616

1717
namespace pydynd {
1818

19-
struct array_callable_wrapper {
20-
dynd::nd::array n;
21-
dynd::nd::callable c;
22-
std::string funcname;
23-
};
24-
25-
/**
26-
* This is the typeobject and struct of w_array_callable from Cython.
27-
*/
28-
extern PyTypeObject *WArrayCallable_Type;
29-
30-
inline bool WArrayCallable_CheckExact(PyObject *obj)
31-
{
32-
return Py_TYPE(obj) == WArrayCallable_Type;
33-
}
34-
inline bool WArrayCallable_Check(PyObject *obj)
35-
{
36-
return PyObject_TypeCheck(obj, WArrayCallable_Type);
37-
}
38-
struct WArrayCallable {
39-
PyObject_HEAD;
40-
// This is array_placement_wrapper in Cython-land
41-
array_callable_wrapper v;
42-
};
43-
PYDYND_API void init_w_array_callable_typeobject(PyObject *type);
44-
45-
/**
46-
* This calls the callable in the array_callable_wrapper, which was
47-
* returned as a property of an array.
48-
*/
49-
PYDYND_API PyObject *array_callable_call(const array_callable_wrapper &ncw, PyObject *args,
50-
PyObject *kwargs);
51-
5219
struct _type_callable_wrapper {
5320
dynd::ndt::type d;
5421
dynd::nd::callable c;
@@ -77,8 +44,8 @@ PYDYND_API void init_w__type_callable_typeobject(PyObject *type);
7744
* This calls the callable in the _type_callable_wrapper, which was
7845
* returned as a property of a dynd type.
7946
*/
80-
PYDYND_API PyObject *_type_callable_call(const _type_callable_wrapper &ccw, PyObject *args,
81-
PyObject *kwargs);
47+
PYDYND_API PyObject *_type_callable_call(const _type_callable_wrapper &ccw,
48+
PyObject *args, PyObject *kwargs);
8249

8350
/**
8451
* This calls the dynamic __construct__ function attached to the dynd type.
@@ -96,22 +63,6 @@ void add__type_names_to_dir_dict(const dynd::ndt::type &dt, PyObject *dict);
9663
PYDYND_API PyObject *get__type_dynamic_property(const dynd::ndt::type &dt,
9764
PyObject *name);
9865

99-
/**
100-
* Adds all the dynamic names exposed by the array to the provided dict.
101-
*/
102-
PYDYND_API void add_array_names_to_dir_dict(const dynd::nd::array &n,
103-
PyObject *dict);
104-
/**
105-
* Retrieves a dynamic property from the nd::array.
106-
*/
107-
PYDYND_API PyObject *get_array_dynamic_property(const dynd::nd::array &n,
108-
PyObject *name);
109-
/**
110-
* Sets a dynamic property of the nd::array.
111-
*/
112-
PYDYND_API void set_array_dynamic_property(const dynd::nd::array &n,
113-
PyObject *name, PyObject *value);
114-
11566
/**
11667
* Returns a wrapper for the callable with the dynd type as the first parameter.
11768
*

dynd/nd/array.pyx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ from ..ndt.type cimport type
1717
from ..ndt import Unsupplied
1818

1919
cdef extern from 'array_functions.hpp' namespace 'pydynd':
20-
void init_w_array_typeobject(object)
21-
2220
void array_init_from_pyobject(_array&, object, object, bint, object) except +translate_exception
2321
void array_init_from_pyobject(_array&, object, object) except +translate_exception
2422

@@ -74,11 +72,8 @@ cdef extern from 'array_functions.hpp' namespace 'pydynd':
7472
int array_getbuffer_pep3118(object ndo, Py_buffer *buffer, int flags) except -1
7573
int array_releasebuffer_pep3118(object ndo, Py_buffer *buffer) except -1
7674

77-
cdef extern from 'gfunc_callable_functions.hpp' namespace 'pydynd':
78-
void add_array_names_to_dir_dict(_array&, object) except +translate_exception
79-
void set_array_dynamic_property(_array&, object, object) except +translate_exception
80-
81-
void init_w_array_callable_typeobject(object)
75+
cdef extern from 'array_assign_from_py.hpp' namespace 'pydynd':
76+
void array_broadcast_assign_from_py(_array &, object)
8277

8378
cdef class array(object):
8479
"""
@@ -199,7 +194,22 @@ cdef class array(object):
199194
# will show up in IPython tab-complete, for example.
200195
result = dict(array.__dict__)
201196
result.update(object.__dict__)
202-
add_array_names_to_dir_dict(self.v, result)
197+
198+
cdef map[string, _callable] properties
199+
200+
cdef _type dt = self.v.get_type()
201+
if (not dt.is_builtin()):
202+
dt.get().get_dynamic_array_properties(properties)
203+
else:
204+
get_builtin_type_dynamic_array_properties(dt.get_type_id(), properties);
205+
for pair in properties:
206+
result[pair.first] = wrap(pair.second)
207+
208+
if (not dt.is_builtin()):
209+
dt.get().get_dynamic_array_functions(properties)
210+
for pair in properties:
211+
result[pair.first] = wrap(pair.second)
212+
203213
return result.keys()
204214

205215
def __getattr__(self, name):
@@ -229,7 +239,23 @@ cdef class array(object):
229239
raise AttributeError(name)
230240

231241
def __setattr__(self, name, value):
232-
set_array_dynamic_property(self.v, name, value)
242+
if self.v.is_null():
243+
raise AttributeError(name)
244+
245+
cdef map[string, _callable] properties
246+
247+
cdef _type dt = self.v.get_type()
248+
if (not dt.is_builtin()):
249+
dt.get().get_dynamic_array_properties(properties)
250+
else:
251+
get_builtin_type_dynamic_array_properties(dt.get_type_id(), properties);
252+
253+
cdef _callable p = properties[name]
254+
if (not p.is_null()):
255+
array_broadcast_assign_from_py(p(self.v), value)
256+
return
257+
258+
raise AttributeError(name)
233259

234260
def __getitem__(self, x):
235261
from .. import ndt, nd
@@ -447,12 +473,6 @@ cdef array dynd_nd_array_from_cpp(_array a):
447473

448474
set_wrapper_type[_array](array)
449475

450-
cdef class array_callable:
451-
def __call__(self, *args, **kwargs):
452-
raise NotImplemented("array callable is not implemented")
453-
454-
init_w_array_callable_typeobject(array_callable)
455-
456476
cpdef array asarray(obj, access=None):
457477
"""
458478
nd.asarray(obj, access=None)

dynd/src/gfunc_callable_functions.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ using namespace std;
1717
using namespace dynd;
1818
using namespace pydynd;
1919

20-
PyTypeObject *pydynd::WArrayCallable_Type;
21-
22-
void pydynd::init_w_array_callable_typeobject(PyObject *type)
23-
{
24-
WArrayCallable_Type = (PyTypeObject *)type;
25-
}
26-
2720
PyTypeObject *pydynd::WTypeCallable_Type;
2821

2922
void pydynd::init_w__type_callable_typeobject(PyObject *type)
@@ -92,65 +85,6 @@ PyObject *pydynd::get__type_dynamic_property(const dynd::ndt::type &dt,
9285
return NULL;
9386
}
9487

95-
void pydynd::add_array_names_to_dir_dict(const dynd::nd::array &n,
96-
PyObject *dict)
97-
{
98-
ndt::type dt = n.get_type();
99-
if (!dt.is_builtin()) {
100-
std::map<std::string, nd::callable> properties;
101-
// Add the array properties
102-
dt.extended()->get_dynamic_array_properties(properties);
103-
for (const auto &pair : properties) {
104-
if (PyDict_SetItemString(dict, pair.first.c_str(), Py_None) < 0) {
105-
throw runtime_error("");
106-
}
107-
}
108-
// Add the array functions
109-
std::map<std::string, nd::callable> functions;
110-
dt.extended()->get_dynamic_array_functions(functions);
111-
for (const auto &pair : functions)
112-
if (PyDict_SetItemString(dict, pair.first.c_str(), Py_None) < 0) {
113-
throw runtime_error("");
114-
}
115-
}
116-
else {
117-
std::map<std::string, nd::callable> properties;
118-
// Add the array properties
119-
get_builtin_type_dynamic_array_properties(dt.get_type_id(), properties);
120-
for (const auto &pair : properties) {
121-
if (PyDict_SetItemString(dict, pair.first.c_str(), Py_None) < 0) {
122-
throw runtime_error("");
123-
}
124-
}
125-
// TODO: Add the array functions
126-
}
127-
}
128-
129-
void pydynd::set_array_dynamic_property(const dynd::nd::array &n,
130-
PyObject *name, PyObject *value)
131-
{
132-
ndt::type dt = n.get_type();
133-
std::map<std::string, nd::callable> properties;
134-
// Search for a property
135-
if (!dt.is_builtin()) {
136-
dt.extended()->get_dynamic_array_properties(properties);
137-
}
138-
else {
139-
get_builtin_type_dynamic_array_properties(dt.get_type_id(), properties);
140-
}
141-
142-
// TODO: We probably want to make some kind of acceleration structure for
143-
// the name lookup
144-
std::string nstr = pystring_as_string(name);
145-
nd::callable p = properties[nstr];
146-
if (!p.is_null()) {
147-
array_broadcast_assign_from_py(p(n), value, &eval::default_eval_context);
148-
}
149-
150-
PyErr_SetObject(PyExc_AttributeError, name);
151-
throw exception();
152-
}
153-
15488
static void set_single_parameter(const std::string &funcname,
15589
const std::string &paramname,
15690
const ndt::type &paramtype, char *arrmeta,

0 commit comments

Comments
 (0)