Coverage for src/ufig/array_util.py: 94%
26 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-12 19:08 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-12 19:08 +0000
1# Copyright (C) 2015 ETH Zurich, Institute for Astronomy
3"""
4Created on Dec 5, 2016
6author: tomaszk
7"""
9import numpy as np
12def set_flag_bit_single(value, bit):
13 return value | (1 << bit)
16def clear_flag_bit_single(value, bit):
17 return value & ~(1 << bit)
20def check_flag_bit_single(value, bit):
21 return bool(value & (1 << bit))
24def set_flag_bit(flags, select, field):
25 ones = np.ones(np.count_nonzero(select), dtype=flags.dtype)
26 flags[select] |= ones << (field * ones)
29def check_flag_bit(flags, flagbit):
30 isset = (flags & (1 << flagbit)) != 0
31 return isset
34def rec_float64_to_float32(cat):
35 list_new_dtype = []
36 all_ok = True
38 for i in range(len(cat.dtype)):
39 if cat.dtype[i] == np.float64:
40 list_new_dtype.append(np.float32)
41 all_ok = False
42 else:
43 list_new_dtype.append(cat.dtype[i])
45 if all_ok: 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true
46 return cat
48 else:
49 new_dtype = np.dtype(dict(formats=list_new_dtype, names=cat.dtype.names))
50 cat_new = cat.astype(new_dtype)
51 return cat_new