rainwoodman / sharedmem

A different flavor of multiprocessing in Python
GNU General Public License v3.0
81 stars 9 forks source link

Add a function `asarray` #4

Closed syrte closed 9 years ago

syrte commented 9 years ago

Add a function asarray which can create a shared memory copy of given array. It's useful for who wants to share existing array to multi-processes.

rainwoodman commented 9 years ago

Two queqstions:

  1. What does
sa = sharedmem.asarray(a)

do more than

sa = sharedmem.copy(numpy.asarray(a))
  1. How similar is sharedmem.asarray comparing to numpy.asarray? It would be nice to add test cases in test_sharedmem.py to assert the examples in numpy.asarray works with sharedmem.asarray.
syrte commented 9 years ago

Sorry, I didn't notice the function copy, so asarray is not necessary. And I agree that the function name copy is better.

syrte commented 9 years ago

sa = sharedmem.asarray(a) is just the same as sa = sharedmem.copy(numpy.asarray(a)), only difference is you don't convert a to numpy array first when a is a list or something similar.

numpy.asarray can convert any array-like object to numpy array, and sharedmem.asarray would convert (copy actually) array-like object to sharedmem array. In this sense I think the name asarray is suit for this function.

rainwoodman commented 9 years ago

It may not be worthwhile to avoid the first conversion from a list. the argument goes:

syrte commented 9 years ago

OK, I agree. For the function copy is a better name, as it would always create a new buffer.