[Beignet] [PATCH 2/2 v2] utests: Refine cases for sinpi.
Zhigang Gong
zhigang.gong at linux.intel.com
Wed Mar 12 18:18:29 PDT 2014
LGTM, pushed with the first patch. Thanks.
On Mon, Mar 10, 2014 at 11:32:12AM +0800, Yi Sun wrote:
> The general algorithm is that reducing the x to area [-0.5,0.5] then calculate results.
>
> v2. Correct the algorithm of sinpi.
> Add some input data temporarily, and we're going to design and implement a input data generator which is similar as what Conformance does.
>
> Signed-off-by: Yi Sun <yi.sun at intel.com>
>
> diff --git a/utests/utest_math_gen.py b/utests/utest_math_gen.py
> index 20ae3f1..5a015ad 100755
> --- a/utests/utest_math_gen.py
> +++ b/utests/utest_math_gen.py
> @@ -466,12 +466,45 @@ static float rsqrt(float x)
> sinhUtests = func('sinh','sinh',[sinh_input_type],sinh_output_type,[sinh_input_values],'4 * FLT_ULP')
>
> ##### gentype sinpi(gentype x)
> - sinpi_input_values = base_input_values
> + sinpi_input_values = [0, 1, 3.14, -0.88, -0.12, -0.5, 0.5, -0.49, 0.49, 0.51, -0.51, -0.1, 0.1]
> sinpi_input_type = ['float','float2','float4','float8','float16']
> sinpi_output_type = ['float','float2','float4','float8','float16']
> sinpi_cpu_func='''
> +static float reduce1( float x )
> +{
> + SF fx, fy;
> + fx.f = fy.f = x;
> + int n;
> +
> + fy.spliter.exponent = fx.spliter.exponent - 1;
> + n = (int)fy.f;
> +
> + fx.f = fx.f - 2.0 * n;
> +
> + return fx.f;
> +}
> +
> static float sinpi(float x){
> - return sin(M_PI*x);
> + float r = x;
> + if ( x > 1 || x < -1) r = reduce1(x);
> +
> + // reduce to [-0.5, 0.5]
> + if(r < -0.5)
> + r = -1 - r;
> + else if (r > 0.5)
> + r = 1 - r;
> +
> + if (r > 0.25 && r <= 0.5)
> + return cos((0.5 - r) * M_PI);
> + else if (r >= 0 && r <= 0.25)
> + return sin(r * M_PI);
> + else if (r >= -0.25 && r < 0)
> + return -sin(r * -M_PI);
> + else if (r >= -0.5 && r < -0.25){
> + return -cos((0.5 + r) * M_PI);}
> +
> + // Error return
> + return 0xffffffff;
> } '''
> sinpiUtests = func('sinpi','sinpi',[sinpi_input_type],sinpi_output_type,[sinpi_input_values],'4 * FLT_ULP',sinpi_cpu_func)
>
> --
> 1.8.5.3
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list