def empty_like(self, shape=None, cparams=None, rootdir=None): ''' Create an empty bdot.carray container matching this one ''' p_dtype = self.dtype if shape == None: shape = self.shape if cparams == None: cparams = self.cparams if(len(shape) == 1): result_template = np.ndarray(shape=(0), dtype=p_dtype) return bdot.carray(result_template, expectedlen=shape[0], cparams=cparams, rootdir=rootdir) elif(len(self.shape) == 2): result_template = np.ndarray((0, shape[1]), dtype=p_dtype) return bdot.carray(result_template, expectedlen=shape[0], cparams=cparams, rootdir=rootdir) else: raise ValueError("Can't create a carray like that. Only one and two dimensions supported.")
def test_dot_matrix_int64(): matrix = np.random.random_integers(0, 120, size=(1000, 100)) bcarray1 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2)) bcarray2 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2)) result = bcarray1.dot(bcarray2) expected = matrix.dot(matrix.T) assert_array_equal(expected, result)
def test_dot_matrix_float32(): matrix = np.random.random_sample(size=(1000, 100)).astype('float32') bcarray1 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2)) bcarray2 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2)) result = bcarray1.dot(bcarray2) expected = matrix.dot(matrix.T) assert_array_almost_equal(expected, result, decimal=4)
def test_dot_matrix_chunklen_greater_than_length(): matrix = np.random.random_sample(size=(1000, 100)) bcarray1 = bdot.carray(matrix, chunklen=2**11, cparams=bdot.cparams(clevel=2)) bcarray2 = bdot.carray(matrix, chunklen=2**11, cparams=bdot.cparams(clevel=2)) result = bcarray1.dot(bcarray2) expected = matrix.dot(matrix.T) assert_array_almost_equal(expected, result, decimal=5)
def test_dot_matrix_chunklen_greater_than_length_numpy_out(): matrix = np.random.random_sample(size=(1000, 100)) bcarray1 = bdot.carray(matrix, chunklen=2**11, cparams=bdot.cparams(clevel=2)) bcarray2 = bdot.carray(matrix, chunklen=2**11, cparams=bdot.cparams(clevel=2)) result = np.empty((1000, 1000), dtype=np.float64) bcarray1.dot(bcarray2, out=result) expected = matrix.dot(matrix.T) assert_array_almost_equal(expected, result, decimal=5)
def test_dot_incompatible_dtype(): matrix = np.random.random_integers(0, 12000, size=(10000, 100)) bcarray = bdot.carray(matrix, chunklen=2**13, cparams=bdot.cparams(clevel=2)) v = bcarray[0].astype('int32') result = bcarray.dot(v)
def time_matrix_2_18_vector_32(self): matrix = np.random.random_integers(0, 120, size=(2 ** 18, 32)) bcarray = bdot.carray(matrix, chunklen=2**14, cparams=bdot.cparams(clevel=2)) v = bcarray[0] output = bcarray.empty_like_dot(v) result = bcarray.dot(v, out=output)
def test_dot_int64(): matrix = np.random.random_integers(0, 12000, size=(10000, 100)) bcarray = bdot.carray(matrix, chunklen=2**13, cparams=bdot.cparams(clevel=2)) v = bcarray[0] result = bcarray.dot(v) expected = matrix.dot(v) assert_array_equal(expected, result)
def test_dot_float32(): matrix = np.random.random_sample(size=(10000, 100)).astype('float32') bcarray = bdot.carray(matrix, chunklen=2**13, cparams=bdot.cparams(clevel=2)) v = bcarray[0] result = bcarray.dot(v) expected = matrix.dot(v) assert_array_almost_equal(expected, result, decimal=5)
def test_dot_chunklen_greater_than_length(): matrix = np.random.random_sample(size=(100, 100)) bcarray = bdot.carray(matrix, chunklen=2**10, cparams=bdot.cparams(clevel=2)) v = bcarray[0] result = bcarray.dot(v) expected = matrix.dot(v) assert_array_almost_equal(expected, result, decimal=5)
def time_matrix_2_18_vector_32(self): matrix = np.random.random_integers(0, 120, size=(2**18, 32)) bcarray = bdot.carray(matrix, chunklen=2**14, cparams=bdot.cparams(clevel=2)) v = bcarray[0] output = bcarray.empty_like_dot(v) result = bcarray.dot(v, out=output)
def empty_like(self, shape=None, chunklen=None, cparams=None, rootdir=None): ''' Create an empty bdot.carray container matching this one, with optional modifications. ''' p_dtype = self.dtype if shape == None: shape = self.shape if cparams == None: cparams = self.cparams if (len(shape) == 1): result_template = np.ndarray(shape=(0), dtype=p_dtype) return bdot.carray(result_template, expectedlen=shape[0], chunklen=chunklen, cparams=cparams, rootdir=rootdir) elif (len(self.shape) == 2): result_template = np.ndarray((0, shape[1]), dtype=p_dtype) return bdot.carray(result_template, expectedlen=shape[0], chunklen=chunklen, cparams=cparams, rootdir=rootdir) else: raise ValueError( "Can't create a carray like that. Only one and two dimensions supported." )