1. The first example should really throw an exception, because silent failures like this can be catastrophic:py> from numpy import randompy> r = random.randint(2, size=10)py> rarray([1, 0, 1, 1, 0, 1, 0, 1, 1, 1])py> list(flex.bool(r))[True, False, False, False, False, False, False, False, False, False]This example is clearly due to incorrect assumptions about the internal representations of numpy ndarrays.As far as I can tell, this is much worse than that as the numpy-to-flex conversion assumes the same element type in the source and target array. Thus converting a numpy array of int's into a flex array of bools is illegal but this precondition is not asserted unfortunately.
Nasty indeed. I do not understand numpy well enough to propose a solution, I am afraid.
py> numpy.complex is type(complex())Truepy> numpy.bool is type(bool())Truepy> numpy.int is type(int())Truepy> numpy.float is type(float())Truepy> numpy.long is type(long())True
py> numpy.array([1, 2, 3]).dtype is intFalsepy> numpy.array([1, 2, 3], dtype=int).dtype is intFalsepy> # same aspy> numpy.array([1, 2, 3], dtype=numpy.int).dtype is intFalse
py> numpy.arange(4)py> array([0, 1, 2, 3])py> list(flex.int(numpy.arange(4)))[0, 0, 1, 0]