Example #1
0
	def testSparseReduce(self):
		ref_env = CPUEnvironment()

		tests = (
			(128, 16),
			(128, 1024 * 8),
			(50, 531),
			(40, 24),
			(457, 389),
			(457, 5)
		)

		for final_length, multiplier in tests:
			for dtype in (numpy.float32, numpy.complex64):
				data = getTestArray((final_length * multiplier,), dtype, 1)
				d_data = self.env.toDevice(data)
				ref_data = ref_env.toDevice(data)

				reduce = createReduce(self.env, dtype)
				ref_reduce = createReduce(ref_env, dtype)

				d_result = reduce.sparse(d_data, final_length=final_length)
				ref_result = ref_reduce.sparse(ref_data, final_length=final_length)

				self.assert_(diff(self.env.fromDevice(d_result),
					ref_env.fromDevice(ref_result)) < 1e-3)
Example #2
0
	def testPermute(self):
		ref_env = CPUEnvironment()

		testcases = itertools.product(
			(
				(3, 4, 5), (10, 16, 20), (10, 11, 16), (16, 21, 25), (29, 35, 46), (20, 30, 100),
			),
			(numpy.float32, numpy.complex64),
			(1, 3))

		for shape, dtype, batch in testcases:

			shape = (batch,) + shape
			new_shape = shape[:-3] + (shape[-2], shape[-1], shape[-3])

			data = getTestArray(shape, dtype, batch)

			tr = createPermute(self.env, dtype)
			ref_tr = createPermute(ref_env, dtype)

			d_data = self.env.toDevice(data)
			d_temp = self.env.allocate(new_shape, dtype)

			ref_data = ref_env.toDevice(data)
			ref_temp = ref_env.allocate(new_shape, dtype)

			tr(d_data, d_temp, shape, batch=batch)
			ref_tr(ref_data, ref_temp, shape, batch=batch)

			result = self.env.fromDevice(d_temp)
			ref_result = ref_env.fromDevice(ref_temp)

			self.assert_(diff(result, ref_result) < 1e-6)
Example #3
0
    def testCompare(self):

        ref_env = CPUEnvironment()
        for shape, dtype, batch in self.testcases:
            data = getTestArray(shape, dtype, batch)
            plan = createFFTPlan(self.env, shape, dtype)
            ref_plan = createFFTPlan(ref_env, shape, dtype)

            d_data = self.env.toDevice(data)
            d_temp = self.env.allocate(data.shape, dtype)

            ref_data = ref_env.toDevice(data)
            ref_temp = ref_env.allocate(data.shape, dtype)

            plan.execute(d_data, d_temp, batch=batch)
            ref_plan.execute(ref_data, ref_temp, batch=batch)

            self.assert_(diff(self.env.fromDevice(d_temp), ref_env.fromDevice(ref_temp)) < 1e-6)
Example #4
0
	def testCompare(self):
		ref_env = CPUEnvironment()

		for shape, dtype, batch in self.testcases:

			data = getTestArray(shape, dtype, batch)

			tr = createTranspose(self.env, dtype)
			ref_tr = createTranspose(ref_env, dtype)

			d_data = self.env.toDevice(data)
			d_temp = self.env.allocate(data.shape, dtype)

			ref_data = ref_env.toDevice(data)
			ref_temp = ref_env.allocate(data.shape, dtype)

			tr(d_data, d_temp, shape[1], shape[0], batch=batch)
			ref_tr(ref_data, ref_temp, shape[1], shape[0], batch=batch)

			result = self.env.fromDevice(d_temp)
			ref_result = ref_env.fromDevice(ref_temp)

			self.assert_(diff(result, ref_result) < 1e-6)