def test_vector_norm(exponent): rn = odl.CudaRn(5) xarr, x = _vectors(rn) weight = _pos_vector(odl.CudaRn(5)) weighting = CudaFnVectorWeighting(weight, exponent=exponent) if exponent in (1.0, float('inf')): true_norm = np.linalg.norm(weight.asarray() * xarr, ord=exponent) else: true_norm = np.linalg.norm(weight.asarray() ** (1 / exponent) * xarr, ord=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): weighting.norm(x) else: assert almost_equal(weighting.norm(x), true_norm) # Same with free function pnorm = odl.cu_weighted_norm(weight, exponent=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): pnorm(x) else: assert almost_equal(pnorm(x), true_norm)
def test_const_norm(exponent): rn = odl.CudaRn(5) xarr, x = _vectors(rn) constant = 1.5 weighting = CudaFnConstWeighting(constant, exponent=exponent) factor = 1 if exponent == float('inf') else constant ** (1 / exponent) true_norm = factor * np.linalg.norm(xarr, ord=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): weighting.norm(x) else: assert almost_equal(weighting.norm(x), true_norm) # Same with free function pnorm = odl.cu_weighted_norm(constant, exponent=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): pnorm(x) else: assert almost_equal(pnorm(x), true_norm)
def test_const_norm(exponent): rn = CudaRn(5) xarr, x = example_vectors(rn) constant = 1.5 weighting = CudaFnConstWeighting(constant, exponent=exponent) factor = 1 if exponent == float('inf') else constant ** (1 / exponent) true_norm = factor * np.linalg.norm(xarr, ord=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): weighting.norm(x) else: assert almost_equal(weighting.norm(x), true_norm) # Same with free function pnorm = odl.cu_weighted_norm(constant, exponent=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): pnorm(x) else: assert almost_equal(pnorm(x), true_norm)
def test_vector_norm(exponent): rn = CudaRn(5) xarr, x = example_vectors(rn) weight = _pos_vector(CudaRn(5)) weighting = CudaFnVectorWeighting(weight, exponent=exponent) if exponent in (1.0, float('inf')): true_norm = np.linalg.norm(weight.asarray() * xarr, ord=exponent) else: true_norm = np.linalg.norm(weight.asarray() ** (1 / exponent) * xarr, ord=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): weighting.norm(x) else: assert almost_equal(weighting.norm(x), true_norm) # Same with free function pnorm = odl.cu_weighted_norm(weight, exponent=exponent) if exponent == float('inf'): # Not yet implemented, should raise with pytest.raises(NotImplementedError): pnorm(x) else: assert almost_equal(pnorm(x), true_norm)
def test_vector_norm(exponent): rn = odl.CudaRn(5) xarr, x = _vectors(rn) weight_vec = _pos_array(odl.Rn(5)) weight_elem = rn.element(weight_vec) weighting_vec = CudaFnVectorWeighting(weight_vec, exponent=exponent) weighting_elem = CudaFnVectorWeighting(weight_elem, exponent=exponent) if exponent in (1.0, float('inf')): true_norm = np.linalg.norm(weight_vec * xarr, ord=exponent) else: true_norm = np.linalg.norm(weight_vec ** (1 / exponent) * xarr, ord=exponent) if exponent == float('inf') or int(exponent) != exponent: # Not yet implemented, should raise with pytest.raises(NotImplementedError): weighting_vec.norm(x) with pytest.raises(NotImplementedError): weighting_elem.norm(x) else: assert almost_equal(weighting_vec.norm(x), true_norm) assert almost_equal(weighting_elem.norm(x), true_norm) # Same with free function pnorm_vec = odl.cu_weighted_norm(weight_vec, exponent=exponent) pnorm_elem = odl.cu_weighted_norm(weight_elem, exponent=exponent) if exponent == float('inf') or int(exponent) != exponent: # Not yet implemented, should raise with pytest.raises(NotImplementedError): pnorm_vec(x) with pytest.raises(NotImplementedError): pnorm_elem(x) else: assert almost_equal(pnorm_vec(x), true_norm) assert almost_equal(pnorm_elem(x), true_norm)