Python numpy.uint64() Examples
The following are 30 code examples for showing how to use numpy.uint64(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: recruit Author: Frank-qlu File: test_hashing.py License: Apache License 2.0 | 7 votes |
def test_hash_collisions(): # Hash collisions are bad. # # https://github.com/pandas-dev/pandas/issues/14711#issuecomment-264885726 hashes = ["Ingrid-9Z9fKIZmkO7i7Cn51Li34pJm44fgX6DYGBNj3VPlOH50m7HnBlPxfIwFMrcNJNMP6PSgLmwWnInciMWrCSAlLEvt7JkJl4IxiMrVbXSa8ZQoVaq5xoQPjltuJEfwdNlO6jo8qRRHvD8sBEBMQASrRa6TsdaPTPCBo3nwIBpE7YzzmyH0vMBhjQZLx1aCT7faSEx7PgFxQhHdKFWROcysamgy9iVj8DO2Fmwg1NNl93rIAqC3mdqfrCxrzfvIY8aJdzin2cHVzy3QUJxZgHvtUtOLxoqnUHsYbNTeq0xcLXpTZEZCxD4PGubIuCNf32c33M7HFsnjWSEjE2yVdWKhmSVodyF8hFYVmhYnMCztQnJrt3O8ZvVRXd5IKwlLexiSp4h888w7SzAIcKgc3g5XQJf6MlSMftDXm9lIsE1mJNiJEv6uY6pgvC3fUPhatlR5JPpVAHNSbSEE73MBzJrhCAbOLXQumyOXigZuPoME7QgJcBalliQol7YZ9", # noqa "Tim-b9MddTxOWW2AT1Py6vtVbZwGAmYCjbp89p8mxsiFoVX4FyDOF3wFiAkyQTUgwg9sVqVYOZo09Dh1AzhFHbgij52ylF0SEwgzjzHH8TGY8Lypart4p4onnDoDvVMBa0kdthVGKl6K0BDVGzyOXPXKpmnMF1H6rJzqHJ0HywfwS4XYpVwlAkoeNsiicHkJUFdUAhG229INzvIAiJuAHeJDUoyO4DCBqtoZ5TDend6TK7Y914yHlfH3g1WZu5LksKv68VQHJriWFYusW5e6ZZ6dKaMjTwEGuRgdT66iU5nqWTHRH8WSzpXoCFwGcTOwyuqPSe0fTe21DVtJn1FKj9F9nEnR9xOvJUO7E0piCIF4Ad9yAIDY4DBimpsTfKXCu1vdHpKYerzbndfuFe5AhfMduLYZJi5iAw8qKSwR5h86ttXV0Mc0QmXz8dsRvDgxjXSmupPxBggdlqUlC828hXiTPD7am0yETBV0F3bEtvPiNJfremszcV8NcqAoARMe"] # noqa # These should be different. result1 = hash_array(np.asarray(hashes[0:1], dtype=object), "utf8") expected1 = np.array([14963968704024874985], dtype=np.uint64) tm.assert_numpy_array_equal(result1, expected1) result2 = hash_array(np.asarray(hashes[1:2], dtype=object), "utf8") expected2 = np.array([16428432627716348016], dtype=np.uint64) tm.assert_numpy_array_equal(result2, expected2) result = hash_array(np.asarray(hashes, dtype=object), "utf8") tm.assert_numpy_array_equal(result, np.concatenate([expected1, expected2], axis=0))
Example 2
Project: pyscf Author: pyscf File: hci.py License: Apache License 2.0 | 6 votes |
def argunique_ctypes(strs): nstrs, nset = strs.shape sort_idx = numpy.empty(nstrs, dtype=numpy.uint64) strs = numpy.asarray(strs, order='C') sort_idx = numpy.asarray(sort_idx, order='C') nstrs_ = numpy.array([nstrs]) libhci.argunique(strs.ctypes.data_as(ctypes.c_void_p), sort_idx.ctypes.data_as(ctypes.c_void_p), nstrs_.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nset)) sort_idx = sort_idx[:nstrs_[0]] return sort_idx.tolist()
Example 3
Project: me-ica Author: ME-ICA File: test_casting.py License: GNU Lesser General Public License v2.1 | 6 votes |
def test_able_int_type(): # The integer type cabable of containing values for vals, exp_out in ( ([0, 1], np.uint8), ([0, 255], np.uint8), ([-1, 1], np.int8), ([0, 256], np.uint16), ([-1, 128], np.int16), ([0.1, 1], None), ([0, 2**16], np.uint32), ([-1, 2**15], np.int32), ([0, 2**32], np.uint64), ([-1, 2**31], np.int64), ([-1, 2**64-1], None), ([0, 2**64-1], np.uint64), ([0, 2**64], None)): assert_equal(able_int_type(vals), exp_out)
Example 4
Project: hsds Author: HDFGroup File: chunkUtilTest.py License: Apache License 2.0 | 6 votes |
def testChunkReadPoints2D(self): chunk_id = "c-00de6a9c-6aff5c35-15d5-3864dd-0740f8_3_4" chunk_layout = (100,100) chunk_arr = np.zeros((100,100)) chunk_arr[:,12] = 69 chunk_arr[12,:] = 96 point_arr = np.array([[312,498],[312,412],[355,412],[398,497]], dtype=np.uint64) arr = chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertEqual(arr.tolist(), [96,96,69,0]) point_arr = np.array([[312,498],[312,412],[355,412],[398,397]], dtype=np.uint64) try: chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertTrue(False) # expected exception except IndexError: pass # expected
Example 5
Project: baseband Author: mhvk File: utils.py License: GNU General Public License v3.0 | 6 votes |
def check(self, stream): """Check that the CRC at the end of athe stream is correct. Parameters ---------- stream : int or array of unsigned int For an integer, the value is the stream to check the CRC for. For arrays, the dimension is treated as the index into the bits. A single stream would thus be of type `bool`. Unsigned integers represent multiple streams. E.g., for a 64-track Mark 4 header, the stream would be an array of ``np.uint64`` words. Returns ------- ok : bool `True` if the calculated CRC is all zero (which should be the case if the CRC at the end of the stream is correct). """ return self._crc(stream) == 0
Example 6
Project: baseband Author: mhvk File: payload.py License: GNU General Public License v3.0 | 6 votes |
def reorder64_Ft(x): """Reorder 64-track bits to bring signs & magnitudes together. Special version for the Ft station, which has unusual settings. """ return (((x & 0xFFFFFAAFFFFFFAAF)) | ((x & 0x0000050000000500) >> 4) | ((x & 0x0000005000000050) << 4)) # Check on 2015-JUL-12: C code: 738811025863578102 -> 738829572664316278 # 118, 209, 53, 244, 148, 217, 64, 10 # reorder64(np.array([738811025863578102], dtype=np.uint64)) # # array([738829572664316278], dtype=uint64) # reorder64(np.array([738811025863578102], dtype=np.uint64)).view(np.uint8) # # array([118, 209, 53, 244, 148, 217, 64, 10], dtype=uint8) # decode_2bit_64track_fanout4( # np.array([738811025863578102], dtype=np.int64)).astype(int).T # -1 1 3 1 array([[-1, 1, 3, 1], # 1 1 3 -3 [ 1, 1, 3, -3], # 1 -3 1 3 [ 1, -3, 1, 3], # -3 1 3 3 [-3, 1, 3, 3], # -3 1 1 -1 [-3, 1, 1, -1], # -3 -3 -3 1 [-3, -3, -3, 1], # 1 -1 1 3 [ 1, -1, 1, 3], # -1 -1 -3 -3 [-1, -1, -3, -3]])
Example 7
Project: baseband Author: mhvk File: payload.py License: GNU General Public License v3.0 | 6 votes |
def encode_16chan_2bit_fanout2_ft(values): """Encode payload for 16 channels using 2 bits, fan-out 2 (64 tracks).""" # words encode 32 values (above) in order ch&0x8, ch&0x3, sample, ch&0x4 # First reshape goes to time, sample, ch&0x8, ch&0x4, ch&0x3, # transpose makes this time, ch&0x8, ch&0x3, sample, ch&0x4. # second reshape future bytes, sample+ch&0x4. values = (values.reshape(-1, 2, 2, 2, 4).transpose(0, 2, 4, 1, 3) .reshape(-1, 4)) bitvalues = encode_2bit_base(values) # values are -3, -1, +1, 3 -> 00, 01, 10, 11; # get first bit (sign) as 1, second bit (magnitude) as 16 reorder_bits = np.array([0, 16, 1, 17], dtype=np.uint8) reorder_bits.take(bitvalues, out=bitvalues) bitvalues <<= np.array([0, 1, 2, 3], dtype=np.uint8) out = np.bitwise_or.reduce(bitvalues, axis=-1).ravel().view(np.uint64) return reorder64_Ft(out).view('<u8')
Example 8
Project: modelforge Author: src-d File: model.py License: Apache License 2.0 | 6 votes |
def squeeze_bits(arr: numpy.ndarray) -> numpy.ndarray: """Return a copy of an integer numpy array with the minimum bitness.""" assert arr.dtype.kind in ("i", "u") if arr.size == 0: return arr if arr.dtype.kind == "i": assert arr.min() >= 0 mlbl = int(arr.max()).bit_length() if mlbl <= 8: dtype = numpy.uint8 elif mlbl <= 16: dtype = numpy.uint16 elif mlbl <= 32: dtype = numpy.uint32 else: dtype = numpy.uint64 return arr.astype(dtype)
Example 9
Project: recruit Author: Frank-qlu File: test_random.py License: Apache License 2.0 | 6 votes |
def test_int64_uint64_corner_case(self): # When stored in Numpy arrays, `lbnd` is casted # as np.int64, and `ubnd` is casted as np.uint64. # Checking whether `lbnd` >= `ubnd` used to be # done solely via direct comparison, which is incorrect # because when Numpy tries to compare both numbers, # it casts both to np.float64 because there is # no integer superset of np.int64 and np.uint64. However, # `ubnd` is too large to be represented in np.float64, # causing it be round down to np.iinfo(np.int64).max, # leading to a ValueError because `lbnd` now equals # the new `ubnd`. dt = np.int64 tgt = np.iinfo(np.int64).max lbnd = np.int64(np.iinfo(np.int64).max) ubnd = np.uint64(np.iinfo(np.int64).max + 1) # None of these function calls should # generate a ValueError now. actual = np.random.randint(lbnd, ubnd, dtype=dt) assert_equal(actual, tgt)
Example 10
Project: recruit Author: Frank-qlu File: test_numeric.py License: Apache License 2.0 | 6 votes |
def test_constructor(self): idx = UInt64Index([1, 2, 3]) res = Index([1, 2, 3], dtype=np.uint64) tm.assert_index_equal(res, idx) idx = UInt64Index([1, 2**63]) res = Index([1, 2**63], dtype=np.uint64) tm.assert_index_equal(res, idx) idx = UInt64Index([1, 2**63]) res = Index([1, 2**63]) tm.assert_index_equal(res, idx) idx = Index([-1, 2**63], dtype=object) res = Index(np.array([-1, 2**63], dtype=object)) tm.assert_index_equal(res, idx)
Example 11
Project: recruit Author: Frank-qlu File: test_other.py License: Apache License 2.0 | 6 votes |
def test_sum_uint64_overflow(): # see gh-14758 # Convert to uint64 and don't overflow df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], dtype=object) df = df + 9223372036854775807 index = pd.Index([9223372036854775808, 9223372036854775810, 9223372036854775812], dtype=np.uint64) expected = pd.DataFrame({1: [9223372036854775809, 9223372036854775811, 9223372036854775813]}, index=index) expected.index.name = 0 result = df.groupby(0).sum() tm.assert_frame_equal(result, expected)
Example 12
Project: recruit Author: Frank-qlu File: test_indexing.py License: Apache License 2.0 | 6 votes |
def test_setitem(self): df = self.df idx = self.idx # setitem df['C'] = idx assert_series_equal(df['C'], Series(idx, name='C')) df['D'] = 'foo' df['D'] = idx assert_series_equal(df['D'], Series(idx, name='D')) del df['D'] # With NaN: because uint64 has no NaN element, # the column should be cast to object. df2 = df.copy() df2.iloc[1, 1] = pd.NaT df2.iloc[1, 2] = pd.NaT result = df2['B'] assert_series_equal(notna(result), Series( [True, False, True], name='B')) assert_series_equal(df2.dtypes, Series([np.dtype('uint64'), np.dtype('O'), np.dtype('O')], index=['A', 'B', 'C']))
Example 13
Project: recruit Author: Frank-qlu File: test_constructors.py License: Apache License 2.0 | 6 votes |
def test_constructor_overflow_int64(self): # see gh-14881 values = np.array([2 ** 64 - i for i in range(1, 10)], dtype=np.uint64) result = DataFrame({'a': values}) assert result['a'].dtype == np.uint64 # see gh-2355 data_scores = [(6311132704823138710, 273), (2685045978526272070, 23), (8921811264899370420, 45), (long(17019687244989530680), 270), (long(9930107427299601010), 273)] dtype = [('uid', 'u8'), ('score', 'u8')] data = np.zeros((len(data_scores),), dtype=dtype) data[:] = data_scores df_crawls = DataFrame(data) assert df_crawls['uid'].dtype == np.uint64
Example 14
Project: recruit Author: Frank-qlu File: test_numeric.py License: Apache License 2.0 | 6 votes |
def test_coerce_uint64_conflict(self): # see gh-17007 and gh-17125 # # Still returns float despite the uint64-nan conflict, # which would normally force the casting to object. df = pd.DataFrame({"a": [200, 300, "", "NaN", 30000000000000000000]}) expected = pd.Series([200, 300, np.nan, np.nan, 30000000000000000000], dtype=float, name="a") result = to_numeric(df["a"], errors="coerce") tm.assert_series_equal(result, expected) s = pd.Series(["12345678901234567890", "1234567890", "ITEM"]) expected = pd.Series([12345678901234567890, 1234567890, np.nan], dtype=float) result = to_numeric(s, errors="coerce") tm.assert_series_equal(result, expected) # For completeness, check against "ignore" and "raise" result = to_numeric(s, errors="ignore") tm.assert_series_equal(result, s) msg = "Unable to parse string" with pytest.raises(ValueError, match=msg): to_numeric(s, errors="raise")
Example 15
Project: recruit Author: Frank-qlu File: test_inference.py License: Apache License 2.0 | 6 votes |
def test_maybe_convert_objects_uint64(self): # see gh-4471 arr = np.array([2**63], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) # NumPy bug: can't compare uint64 to int64, as that # results in both casting to float64, so we should # make sure that this function is robust against it arr = np.array([np.uint64(2**63)], dtype=object) exp = np.array([2**63], dtype=np.uint64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) arr = np.array([2, -1], dtype=object) exp = np.array([2, -1], dtype=np.int64) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp) arr = np.array([2**63, -1], dtype=object) exp = np.array([2**63, -1], dtype=object) tm.assert_numpy_array_equal(lib.maybe_convert_objects(arr), exp)
Example 16
Project: recruit Author: Frank-qlu File: multi.py License: Apache License 2.0 | 6 votes |
def _engine(self): # Calculate the number of bits needed to represent labels in each # level, as log2 of their sizes (including -1 for NaN): sizes = np.ceil(np.log2([len(l) + 1 for l in self.levels])) # Sum bit counts, starting from the _right_.... lev_bits = np.cumsum(sizes[::-1])[::-1] # ... in order to obtain offsets such that sorting the combination of # shifted codes (one for each level, resulting in a unique integer) is # equivalent to sorting lexicographically the codes themselves. Notice # that each level needs to be shifted by the number of bits needed to # represent the _previous_ ones: offsets = np.concatenate([lev_bits[1:], [0]]).astype('uint64') # Check the total number of bits needed for our representation: if lev_bits[0] > 64: # The levels would overflow a 64 bit uint - use Python integers: return MultiIndexPyIntEngine(self.levels, self.codes, offsets) return MultiIndexUIntEngine(self.levels, self.codes, offsets)
Example 17
Project: Caffe-Python-Data-Layer Author: liuxianming File: bcfstore.py License: BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, filename): self._filename = filename print 'Loading BCF file to memory ... '+filename file = open(filename, 'rb') size = numpy.fromstring(file.read(8), dtype=numpy.uint64) file_sizes = numpy.fromstring(file.read(8*size), dtype=numpy.uint64) self._offsets = numpy.append(numpy.uint64(0), numpy.add.accumulate(file_sizes)) self._memory = file.read() file.close()
Example 18
Project: Caffe-Python-Data-Layer Author: liuxianming File: bcfstore.py License: BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, filename): self._filename = filename print 'Opening BCF file ... '+filename self._file = open(filename, 'rb') size = numpy.fromstring(self._file.read(8), dtype=numpy.uint64) file_sizes = numpy.fromstring(self._file.read(8*size), dtype=numpy.uint64) self._offsets = numpy.append(numpy.uint64(0), numpy.add.accumulate(file_sizes))
Example 19
Project: vergeml Author: mme File: env.py License: MIT License | 5 votes |
def _toscalar(v): if isinstance(v, (np.float16, np.float32, np.float64, np.uint8, np.uint16, np.uint32, np.uint64, np.int8, np.int16, np.int32, np.int64)): return np.asscalar(v) else: return v
Example 20
Project: dynamic-training-with-apache-mxnet-on-aws Author: awslabs File: io.py License: Apache License 2.0 | 5 votes |
def getindex(self): index_size = ctypes.c_uint64(0) index_data = ctypes.POINTER(ctypes.c_uint64)() check_call(_LIB.MXDataIterGetIndex(self.handle, ctypes.byref(index_data), ctypes.byref(index_size))) if index_size.value: address = ctypes.addressof(index_data.contents) dbuffer = (ctypes.c_uint64* index_size.value).from_address(address) np_index = np.frombuffer(dbuffer, dtype=np.uint64) return np_index.copy() else: return None
Example 21
Project: pyscf Author: pyscf File: hci.py License: Apache License 2.0 | 5 votes |
def cre_des_sign(p, q, string): nset = len(string) pg, pb = p//64, p%64 qg, qb = q//64, q%64 if pg > qg: n1 = 0 for i in range(nset-pg, nset-qg-1): n1 += bin(string[i]).count('1') n1 += bin(string[-1-pg] & numpy.uint64((1<<pb) - 1)).count('1') n1 += string[-1-qg] >> numpy.uint64(qb+1) elif pg < qg: n1 = 0 for i in range(nset-qg, nset-pg-1): n1 += bin(string[i]).count('1') n1 += bin(string[-1-qg] & numpy.uint64((1<<qb) - 1)).count('1') n1 += string[-1-pg] >> numpy.uint64(pb+1) else: if p > q: mask = numpy.uint64((1 << pb) - (1 << (qb+1))) else: mask = numpy.uint64((1 << qb) - (1 << (pb+1))) n1 = bin(string[-1-pg]&mask).count('1') if n1 % 2: return -1 else: return 1
Example 22
Project: pyscf Author: pyscf File: hci.py License: Apache License 2.0 | 5 votes |
def toggle_bit(s, place): g, b = place//64, place%64 s[-1-g] ^= numpy.uint64(1<<b) return s
Example 23
Project: pyscf Author: pyscf File: hci.py License: Apache License 2.0 | 5 votes |
def str2orblst(string, norb): occ = [] vir = [] nset = len(string) off = 0 for k in reversed(range(nset)): s = string[k] occ.extend([x+off for x in find1(s)]) for i in range(0, min(64, norb-off)): if not (s & numpy.uint64(1<<i)): vir.append(i+off) off += 64 return occ, vir
Example 24
Project: me-ica Author: ME-ICA File: test_arraywriters.py License: GNU Lesser General Public License v2.1 | 5 votes |
def test_high_int2uint(): # Need to take care of high values when testing whether values are already # in range. There was a bug here were the comparison was in floating point, # and therefore not exact, and 2**63 appeared to be in range for np.int64 arr = np.array([2**63], dtype=np.uint64) out_type = np.int64 aw = SlopeInterArrayWriter(arr, out_type) assert_equal(aw.inter, 2**63)
Example 25
Project: me-ica Author: ME-ICA File: test_arraywriters.py License: GNU Lesser General Public License v2.1 | 5 votes |
def test_byte_orders(): arr = np.arange(10, dtype=np.int32) # Test endian read/write of types not requiring scaling for tp in (np.uint64, np.float, np.complex): dt = np.dtype(tp) for code in '<>': ndt = dt.newbyteorder(code) for klass in (SlopeInterArrayWriter, SlopeArrayWriter, ArrayWriter): aw = klass(arr, ndt) data_back = round_trip(aw) assert_array_almost_equal(arr, data_back)
Example 26
Project: me-ica Author: ME-ICA File: test_utils.py License: GNU Lesser General Public License v2.1 | 5 votes |
def test_array_to_file(): arr = np.arange(10).reshape(5,2) str_io = BytesIO() for tp in (np.uint64, np.float, np.complex): dt = np.dtype(tp) for code in '<>': ndt = dt.newbyteorder(code) for allow_intercept in (True, False): scale, intercept, mn, mx = calculate_scale(arr, ndt, allow_intercept) data_back = write_return(arr, str_io, ndt, 0, intercept, scale) assert_array_almost_equal(arr, data_back)
Example 27
Project: me-ica Author: ME-ICA File: test_utils.py License: GNU Lesser General Public License v2.1 | 5 votes |
def test__inter_type(): # Test routine to get intercept type bf = best_float() for in_type, inter, out_type, exp_out in ( (np.int8, 0, None, np.int8), (np.int8, 0, np.int8, np.int8), (np.int8, 1, None, np.int16), (np.int8, 1, np.int8, bf), (np.int8, 1, np.int16, np.int16), (np.uint8, 0, None, np.uint8), (np.uint8, 1, None, np.uint16), (np.uint8, -1, None, np.int16), (np.int16, 1, None, np.int32), (np.uint16, 0, None, np.uint16), (np.uint16, 1, None, np.uint32), (np.int32, 1, None, np.int64), (np.uint32, 1, None, np.uint64), (np.int64, 1, None, bf), (np.uint64, 1, None, bf), ): assert_dt_equal(_inter_type(in_type, inter, out_type), exp_out) # Check that casting is as expected A = np.zeros((1,), dtype=in_type) B = np.array([inter], dtype=exp_out) ApBt = (A + B).dtype.type assert_dt_equal(ApBt, exp_out)
Example 28
Project: hsds Author: HDFGroup File: chunkUtilTest.py License: Apache License 2.0 | 5 votes |
def testChunkReadPoints1D(self): chunk_id = "c-00de6a9c-6aff5c35-15d5-3864dd-0740f8_12" chunk_layout = (100,) chunk_arr = np.array(list(range(100))) point_arr = np.array([[1200],[1299],[1244],[1222]], dtype=np.uint64) arr = chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertEqual(arr.tolist(), [0, 99, 44, 22]) point_arr = np.array([[1200],[1299],[1244],[1322]], dtype=np.uint64) try: chunkReadPoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertTrue(False) # expected exception except IndexError: pass # expected
Example 29
Project: hsds Author: HDFGroup File: chunkUtilTest.py License: Apache License 2.0 | 5 votes |
def testChunkWritePoints1D(self): chunk_id = "c-00de6a9c-6aff5c35-15d5-3864dd-0740f8_12" chunk_layout = (100,) chunk_arr = np.zeros((100,)) rank = 1 # (coord1, coord2, ...) | dset_dtype point_dt = np.dtype([("coord", np.uint64), ("val", chunk_arr.dtype)]) # point_dt = np.dtype([("coord", np.uint64, (rank,)), ("val", chunk_arr.dtype)]) indexes = (1203,1245,1288,1212,1299) num_points = len(indexes) point_arr = np.zeros((num_points,), dtype=point_dt) print("point_arr.shape:", point_arr.shape) print("point_arr.dtype:", point_arr.dtype) for i in range(num_points): e = point_arr[i] e[0] = indexes[i] e[1] = 42 chunkWritePoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) for i in range(100): if i + 1200 in indexes: self.assertEqual(chunk_arr[i], 42) else: self.assertEqual(chunk_arr[i], 0) e = point_arr[1] e[0] = 99 # index out of range try: chunkWritePoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertTrue(False) # expected exception except IndexError: pass # expected
Example 30
Project: hsds Author: HDFGroup File: chunkUtilTest.py License: Apache License 2.0 | 5 votes |
def testChunkWritePoints2D(self): chunk_id = "c-00de6a9c-6aff5c35-15d5-3864dd-0740f8_3_2" chunk_layout = (10,20) chunk_arr = np.zeros((10,20)) rank = 2 # (coord1, coord2, ...) | dset_dtype point_dt = np.dtype([("coord", np.uint64, (2,)), ("val", chunk_arr.dtype)]) indexes =((32,46),(38,52),(35,53)) num_points = len(indexes) point_arr = np.zeros((num_points,), dtype=point_dt) for i in range(num_points): e = point_arr[i] e[0] = indexes[i] e[1] = 42 chunkWritePoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) chunk_index = (30,40) for i in range(num_points): index = indexes[i] x = index[0]- chunk_index[0] y = index[1] - chunk_index[1] self.assertEqual(chunk_arr[x,y], 42) e = point_arr[0] e[0] = (42,46) # index out of range try: chunkWritePoints(chunk_id=chunk_id, chunk_layout=chunk_layout, chunk_arr=chunk_arr, point_arr=point_arr) self.assertTrue(False) # expected exception except IndexError: pass # expected