Example #1
0
	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.")
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
    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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
    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)
Example #12
0
    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."
            )