Ejemplo n.º 1
0
def _test():
    import ClearMap.IO.MMP as mmp
    #reload(mmp);

    m = mmp.Source(location='test.npy', shape=4)
    print(m)

    m[:] = 5
    print(m)

    import ClearMap.IO.Slice as slc

    s = slc.Slice(source=m, slicing=slice(1, 3))
    print(s)

    s[:] = 3
    print(s)
    print(m)
Ejemplo n.º 2
0
def write(sink, data, slicing=None, **kwargs):
    """Write data to a memory map.
  
  Arguments
  ---------
  sink : str, memmap, or Source
    The sink to write the data to.
  data : array
    The data to write int the sink.
  slicing : slice specification or None
    Optional slice specification of an existing memmap to write to.
    
  Returns
  -------
  sink : str, memmap, or Source
    The sink.
  """
    if slc.is_trivial(slicing):
        slicing = (slice(None), )

    if isinstance(sink, (Source, np.memmap)):
        sink.__setitem__(slicing, data.array)

    elif isinstance(sink, str):
        if slicing == (slice(None), ):
            memmap = _memmap(location=sink, array=data.array)
        else:
            try:
                memmap = _memmap(location=sink, mode='r+')
            except:
                raise ValueError(
                    'Cannot write slice into non-existent memmap at location %r!'
                    % sink)
            memmap.__setitem__(slicing, data.array)

    else:
        raise ValueError('Cannot write memmap to sink %r!' % sink)

    return sink