|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ***************************************************************************** |
| 3 | +# Copyright (c) 2020, Intel Corporation All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation |
| 13 | +# and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 | +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 19 | +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 25 | +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +# ***************************************************************************** |
| 27 | + |
| 28 | +from numba import types |
| 29 | +from numba.extending import ( |
| 30 | + models, |
| 31 | + register_model, |
| 32 | + make_attribute_wrapper |
| 33 | +) |
| 34 | + |
| 35 | + |
| 36 | +RangeIndexDataType = types.range_state64_type |
| 37 | + |
| 38 | + |
| 39 | +class RangeIndexType(types.IterableType): |
| 40 | + |
| 41 | + dtype = types.int64 |
| 42 | + |
| 43 | + def __init__(self, is_named=False): |
| 44 | + self.is_named = is_named |
| 45 | + super(RangeIndexType, self).__init__( |
| 46 | + name='RangeIndexType({})'.format(is_named)) |
| 47 | + |
| 48 | + # TODO: provide iteration support by adding getiter and iternext |
| 49 | + @property |
| 50 | + def iterator_type(self): |
| 51 | + return RangeIndexDataType.iterator_type() |
| 52 | + |
| 53 | + |
| 54 | +@register_model(RangeIndexType) |
| 55 | +class RangeIndexModel(models.StructModel): |
| 56 | + def __init__(self, dmm, fe_type): |
| 57 | + |
| 58 | + name_type = types.unicode_type if fe_type.is_named else types.none |
| 59 | + members = [ |
| 60 | + ('data', RangeIndexDataType), |
| 61 | + ('name', name_type) |
| 62 | + ] |
| 63 | + models.StructModel.__init__(self, dmm, fe_type, members) |
| 64 | + |
| 65 | + |
| 66 | +make_attribute_wrapper(RangeIndexType, 'data', '_data') |
| 67 | +make_attribute_wrapper(RangeIndexType, 'name', '_name') |
0 commit comments