Coverage for src/bob/bio/vein/database/__init__.py: 90%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-12 23:27 +0200

1#!/usr/bin/env python 

2# vim: set fileencoding=utf-8 : 

3# isort: skip_file 

4 

5"""Database definitions for Vein Recognition""" 

6 

7 

8import numpy 

9 

10 

11class AnnotatedArray(numpy.ndarray): 

12 """Defines a numpy array subclass that can carry its own metadata 

13 

14 Copied from: https://docs.scipy.org/doc/numpy-1.12.0/user/basics.subclassing.html#slightly-more-realistic-example-attribute-added-to-existing-array 

15 """ 

16 

17 def __new__(cls, input_array, metadata=None): 

18 obj = numpy.asarray(input_array).view(cls) 

19 obj.metadata = metadata if metadata is not None else dict() 

20 return obj 

21 

22 def __array_finalize__(self, obj): 

23 if obj is None: 

24 return 

25 self.metadata = getattr(obj, "metadata", dict())