All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joannah Nanjekye <nanjekyejoannah@gmail.com>
To: stefanha@redhat.com
Cc: qemu-devel@nongnu.org, Joannah Nanjekye <nanjekyejoannah@gmail.com>
Subject: [Qemu-devel] [PATCH WIP] replace numpy with struct
Date: Thu, 26 Oct 2017 15:14:14 +0300	[thread overview]
Message-ID: <1509020054-25434-1-git-send-email-nanjekyejoannah@gmail.com> (raw)

This patch replaces the use of numpy with the standard Library struct module where possible.

Signed-off-by: Joannah Nanjekye <nanjekyejoannah@gmail.com>
---
 
 scripts/analyze-migration.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index 1455387..f421012 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -36,23 +36,28 @@ class MigrationFile(object):
         self.file = open(self.filename, "rb")
 
     def read64(self):
-        return np.asscalar(np.fromfile(self.file, count=1, dtype='>i8')[0])
+        buffer = file.read(64)
+        return struct.unpack('>i16', buffer)[0]
 
     def read32(self):
-        return np.asscalar(np.fromfile(self.file, count=1, dtype='>i4')[0])
+        buffer = file.read(32)
+        return struct.unpack('>i8', buffer)[0]
 
     def read16(self):
-        return np.asscalar(np.fromfile(self.file, count=1, dtype='>i2')[0])
+        buffer = file.read(16)
+        return struct.unpack('>i4', buffer)[0]
 
     def read8(self):
-        return np.asscalar(np.fromfile(self.file, count=1, dtype='>i1')[0])
+        buffer = file.read(8)
+        return struct.unpack('>i2', buffer)[0]
 
     def readstr(self, len = None):
+        buffer = file.read(8)
         if len is None:
             len = self.read8()
         if len == 0:
             return ""
-        return np.fromfile(self.file, count=1, dtype=('S%d' % len))[0]
+        return np.array(struct.unpack(str(len) + 'd', buffer)[0])
 
     def readvar(self, size = None):
         if size is None:
@@ -303,8 +308,8 @@ class VMSDFieldInt(VMSDFieldGeneric):
 
     def read(self):
         super(VMSDFieldInt, self).read()
-        self.sdata = np.fromstring(self.data, count=1, dtype=(self.sdtype))[0]
-        self.udata = np.fromstring(self.data, count=1, dtype=(self.udtype))[0]
+        self.sdata = np.array(struct.unpack(self.sdtype, self.data)[0])
+        self.udata = np.array(struct.unpack(self.udtype, self.data)[0])
         self.data = self.sdata
         return self.data
 
-- 
2.7.4

             reply	other threads:[~2017-10-26 12:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26 12:14 Joannah Nanjekye [this message]
2017-10-26 13:50 ` [Qemu-devel] [PATCH WIP] replace numpy with struct Philippe Mathieu-Daudé
2017-11-03 11:24   ` Stefan Hajnoczi
2017-11-03 12:34     ` joannah nanjekye
2017-11-03 13:10     ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509020054-25434-1-git-send-email-nanjekyejoannah@gmail.com \
    --to=nanjekyejoannah@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.