Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
remove jshape
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Oct 11, 2018
1 parent 673ad27 commit b2ec560
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 23 deletions.
4 changes: 0 additions & 4 deletions awkward/array/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ def __bool__(self):

__nonzero__ = __bool__

@property
def jshape(self):
return self.type.jshape

@property
def size(self):
return len(self)
Expand Down
19 changes: 0 additions & 19 deletions awkward/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,6 @@ def dtype(self):
else:
return self._to.dtype

@property
def jshape(self):
if isinstance(self._to, awkward.util.numpy.dtype):
return (self._takes, self._to)
else:
return (self._takes,) + self._to.jshape

def _isnumpy(self, seen):
if id(self) in seen:
return False
Expand Down Expand Up @@ -394,10 +387,6 @@ def dtype(self):
out.append((n, x.dtype))
return awkward.util.numpy.dtype(out)

@property
def jshape(self):
return (dict((n, x if isinstance(x, awkward.util.numpy.dtype) else x.jshape) for n, x in self._fields.items()),)

def _isnumpy(self, seen):
if id(self) in seen:
return False
Expand Down Expand Up @@ -474,10 +463,6 @@ def shape(self):
def dtype(self):
raise TypeError("Union has no Numpy dtype")

@property
def jshape(self):
return ([x.jshape for x in self._possibilities],)

def _isnumpy(self, seen):
return False

Expand Down Expand Up @@ -557,10 +542,6 @@ def shape(self):
def dtype(self):
return self._type.dtype

@property
def jshape(self):
return ([self._type.jshape, None],)

def _isnumpy(self, seen):
if id(self) in seen:
return False
Expand Down
112 changes: 112 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python

# Copyright (c) 2018, DIANA-HEP
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import struct
import unittest

import numpy

from awkward import *

class Test(unittest.TestCase):
def runTest(self):
pass

def test_object_floats(self):
class Point(object):
def __init__(self, array):
self.x, self.y, self.z = array
def __repr__(self):
return "<Point {0} {1} {2}>".format(self.x, self.y, self.z)
def __eq__(self, other):
return isinstance(other, Point) and self.x == other.x and self.y == other.y and self.z == other.z

a = ObjectArray([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6], [7.7, 8.8, 9.9]], Point)
self.assertEqual(a[0], Point([1.1, 2.2, 3.3]))
self.assertEqual(a[1], Point([4.4, 5.5, 6.6]))
self.assertEqual(a[2], Point([7.7, 8.8, 9.9]))
self.assertEqual(a[:].tolist(), [Point([1.1, 2.2, 3.3]), Point([4.4, 5.5, 6.6]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[::2].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[True, False, True]].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[2, 0]].tolist(), [Point([7.7, 8.8, 9.9]), Point([1.1, 2.2, 3.3])])

def test_object_bytes(self):
class Point(object):
def __init__(self, bytes):
self.x, self.y, self.z = struct.unpack("ddd", bytes)
def __repr__(self):
return "<Point {0} {1} {2}>".format(self.x, self.y, self.z)
def __eq__(self, other):
return isinstance(other, Point) and self.x == other.x and self.y == other.y and self.z == other.z

a = ObjectArray(numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]).view("u1").reshape(-1, 24), Point)
self.assertEqual(a[0], Point(numpy.array([1.1, 2.2, 3.3]).tobytes()))
self.assertEqual(a[1], Point(numpy.array([4.4, 5.5, 6.6]).tobytes()))
self.assertEqual(a[2], Point(numpy.array([7.7, 8.8, 9.9]).tobytes()))
self.assertEqual(a[:].tolist(), [Point(numpy.array([1.1, 2.2, 3.3]).tobytes()), Point(numpy.array([4.4, 5.5, 6.6]).tobytes()), Point(numpy.array([7.7, 8.8, 9.9]).tobytes())])
self.assertEqual(a[::2].tolist(), [Point(numpy.array([1.1, 2.2, 3.3]).tobytes()), Point(numpy.array([7.7, 8.8, 9.9]).tobytes())])
self.assertEqual(a[[True, False, True]].tolist(), [Point(numpy.array([1.1, 2.2, 3.3]).tobytes()), Point(numpy.array([7.7, 8.8, 9.9]).tobytes())])
self.assertEqual(a[[2, 0]].tolist(), [Point(numpy.array([7.7, 8.8, 9.9]).tobytes()), Point(numpy.array([1.1, 2.2, 3.3]).tobytes())])

def test_object_indexedbytes(self):
class Point(object):
def __init__(self, array):
self.x, self.y, self.z = array
def __repr__(self):
return "<Point {0} {1} {2}>".format(self.x, self.y, self.z)
def __eq__(self, other):
return isinstance(other, Point) and self.x == other.x and self.y == other.y and self.z == other.z

a = ObjectArray(ByteIndexedArray([0, 24, 48], numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]).view("u1"), numpy.dtype((float, 3))), Point)
self.assertEqual(a[0], Point([1.1, 2.2, 3.3]))
self.assertEqual(a[1], Point([4.4, 5.5, 6.6]))
self.assertEqual(a[2], Point([7.7, 8.8, 9.9]))
self.assertEqual(a[:].tolist(), [Point([1.1, 2.2, 3.3]), Point([4.4, 5.5, 6.6]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[::2].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[True, False, True]].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[2, 0]].tolist(), [Point([7.7, 8.8, 9.9]), Point([1.1, 2.2, 3.3])])

def test_object_jaggedbytes(self):
class Point(object):
def __init__(self, array):
self.x, self.y, self.z = array
def __repr__(self):
return "<Point {0} {1} {2}>".format(self.x, self.y, self.z)
def __eq__(self, other):
return isinstance(other, Point) and self.x == other.x and self.y == other.y and self.z == other.z

a = ObjectArray(ByteJaggedArray.fromoffsets([0, 24, 48, 72], numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]).view("u1"), float), Point)
self.assertEqual(a[0], Point([1.1, 2.2, 3.3]))
self.assertEqual(a[1], Point([4.4, 5.5, 6.6]))
self.assertEqual(a[2], Point([7.7, 8.8, 9.9]))
self.assertEqual(a[:].tolist(), [Point([1.1, 2.2, 3.3]), Point([4.4, 5.5, 6.6]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[::2].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[True, False, True]].tolist(), [Point([1.1, 2.2, 3.3]), Point([7.7, 8.8, 9.9])])
self.assertEqual(a[[2, 0]].tolist(), [Point([7.7, 8.8, 9.9]), Point([1.1, 2.2, 3.3])])

0 comments on commit b2ec560

Please sign in to comment.