[python-arrayfire] 70/250: Improve handling of negative steps in sequences
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:32 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.
commit f0d50c3e52f66ed35329caa81657a03a7a019ba0
Author: Filipe Maia <filipe.c.maia at gmail.com>
Date: Fri Aug 28 14:42:59 2015 +0200
Improve handling of negative steps in sequences
---
arrayfire/index.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arrayfire/index.py b/arrayfire/index.py
index 1a17100..1cacc65 100644
--- a/arrayfire/index.py
+++ b/arrayfire/index.py
@@ -10,6 +10,7 @@ from .library import *
from .util import *
from .base import *
from .broadcast import *
+import math
class Seq(ct.Structure):
_fields_ = [("begin", ct.c_double),
@@ -18,7 +19,6 @@ class Seq(ct.Structure):
def __init__ (self, S):
num = __import__("numbers")
-
self.begin = ct.c_double( 0)
self.end = ct.c_double(-1)
self.step = ct.c_double( 1)
@@ -27,12 +27,14 @@ class Seq(ct.Structure):
self.begin = ct.c_double(S)
self.end = ct.c_double(S)
elif isinstance(S, slice):
+ if (S.step is not None):
+ self.step = ct.c_double(S.step)
+ if(S.step < 0):
+ self.begin, self.end = self.end, self.begin
if (S.start is not None):
self.begin = ct.c_double(S.start)
if (S.stop is not None):
- self.end = ct.c_double(S.stop - 1)
- if (S.step is not None):
- self.step = ct.c_double(S.step)
+ self.end = ct.c_double(S.stop - math.copysign(1, self.step))
else:
raise IndexError("Invalid type while indexing arrayfire.array")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git
More information about the debian-science-commits
mailing list