Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32316

Re: Fast forward-backward (write-read)

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'binary': 0.05; 'float': 0.05; 'conversions': 0.07; 'pursuing': 0.07; 'array.': 0.09; 'backwards': 0.09; 'wraps': 0.09; 'cc:addr:python-list': 0.10; 'file,': 0.15; 'binary.': 0.16; 'dave.': 0.16; 'inverse': 0.16; 'mapped': 0.16; 'mmap': 0.16; 'numpy': 0.16; 'query,': 0.16; 'simplest': 0.16; 'time"': 0.16; 'wrote:': 0.17; 'bytes': 0.17; '>>>': 0.18; 'windows': 0.19; 'issue.': 0.20; 'import': 0.21; '4.0': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'paul': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '---': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'post': 0.28; 'record': 0.28; '>>>>': 0.29; 'writes:': 0.29; 'file': 0.32; 'function.': 0.33; 'handle': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'subject: (': 0.36; 'possible': 0.37; 'october': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'performance': 0.39; 'little': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'map': 0.61; 'first': 0.61; "you'll": 0.62; 'skip:n 10': 0.63; 'more': 0.63; 'tricks': 0.65; 'forward': 0.66; 'wish': 0.70; 'now...': 0.84; 'oscar': 0.84; 'subject:Fast': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'findings': 0.91; 'try.': 0.91; 'angel': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wstS8uB8YF9oGScFx8s/RF9K3WGxD9NVJRGO9F7OvTw=; b=Vtv0p0lLM9+IZTtncTbtkcAEkMOH+WoEk7DoNdWtl68hLQb6cpz5LYLZSE64R0d+8V W2DQxWsXL9cbZdm3te++C9uoI2hUy2nApgHBASBU2+PTGqaRXvfaSenYAefIdWT/ZXoz /5rw/hhuKAwtiLEAP+2N6YLAXpHxIbtUpvtIaePtUI/GupAoxynzGKv8dZBQGDAf3Mc7 eGwpGPendciWVddNWGx+e4NdhqWqNivQbh5+Z1fOPpZmVDrWqbeCfxQ/LDtz4CAIPh02 1mJeALXDaI1mH8GhVBYbWkE9auFACopVm0+lrm8qkj/cSOtq9NDGMteUnGKxMRcT9XDG zudg==
MIME-Version 1.0
In-Reply-To <508D3F3D.9020303@it.uu.se>
References <5086AA35.4000509@it.uu.se> <5086C156.40707@tim.thechases.com> <5086D13F.80006@it.uu.se> <5086DA4D.4060204@tim.thechases.com> <mailman.2683.1351018926.27098.python-list@python.org> <7xr4ooah0t.fsf@ruckus.brouhaha.com> <50879555.7000200@it.uu.se> <508D1469.5060109@davea.name> <508D3F3D.9020303@it.uu.se>
Date Sun, 28 Oct 2012 18:21:45 +0000
Subject Re: Fast forward-backward (write-read)
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To Virgil Stokes <vs@it.uu.se>
Content-Type text/plain; charset=ISO-8859-1
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2975.1351448514.27098.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351448514 news.xs4all.nl 6932 [2001:888:2000:d::a6]:53417
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32316

Show key headers only | View raw


On 28 October 2012 14:20, Virgil Stokes <vs@it.uu.se> wrote:
> On 28-Oct-2012 12:18, Dave Angel wrote:
>>
>> On 10/24/2012 03:14 AM, Virgil Stokes wrote:
>>>
>>> On 24-Oct-2012 01:46, Paul Rubin wrote:
>>>>
>>>> Virgil Stokes <vs@it.uu.se> writes:
>>>>>
>>>>> Yes, I do wish to inverse the order,  but the "forward in time" file
>>>>> will be in binary.
>>>>
>>>> I really think it will be simplest to just write the file in forward
>>>> order, then use mmap to read it one record at a time.  It might be
>>>> possible to squeeze out a little more performance with reordering tricks
>>>> but that's the first thing to try.
>>>
>>> Thanks Paul,
>>> I am working on this approach now...
>>
>> If you're using mmap to map the whole file, you'll need 64bit Windows to
>> start with.  I'd be interested to know if Windows will allow you to mmap
>> 100gb at one stroke.  Have you tried it, or are you starting by figuring
>> how to access the data from the mmap?
>
> Thanks very much for pursuing my query, Dave.
>
> I have not tried it yet --- temporarily side-tracked; but, I will post my
> findings on this issue.

If you are going to use mmap then look at the numpy.memmap function.
This wraps pythons mmap so that you can access the contents of the
mapped binary file as if it was a numpy array. This means that you
don't need to handle the bytes -> float conversions yourself.

>>> import numpy
>>> a = numpy.array([4,5,6], numpy.float64)
>>> a
array([ 4.,  5.,  6.])
>>> with open('tmp.bin', 'wb') as f:  # write forwards
...   a.tofile(f)
...   a.tofile(f)
...
>>> a2 = numpy.memmap('tmp.bin', numpy.float64)
>>> a2
memmap([ 4.,  5.,  6.,  4.,  5.,  6.])
>>> a2[3]
4.0
>>> a2[5:2:-1] # read backwards
memmap([ 6.,  5.,  4.])


Oscar

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Fast forward-backward (write-read) Virgil Stokes <vs@it.uu.se> - 2012-10-23 20:37 +0200
  Re: Fast forward-backward (write-read) Paul Rubin <no.email@nospam.invalid> - 2012-10-23 16:46 -0700
    Re: Fast forward-backward (write-read) Dave Angel <d@davea.name> - 2012-10-28 07:18 -0400
    Re: Fast forward-backward (write-read) Virgil Stokes <vs@it.uu.se> - 2012-10-28 15:20 +0100
    Re: Fast forward-backward (write-read) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-28 18:21 +0000
    Re: Fast forward-backward (write-read) Virgil Stokes <vs@it.uu.se> - 2012-10-28 23:36 +0100

csiph-web