예제 #1
0
 def __init__(self, default_arg=DefaultArrayFunctionArgTemplate):
     ML_NewArgTemplate.__init__(self, default_arg)
     self.parser.add_argument(
         "--test-index-range",
         dest="test_index_range",
         action="store",
         type=(lambda s: list(int(v) for v in s.split(","))),
         default=default_arg.test_index_range,
         help="interval for test arrays size")
예제 #2
0
        return scheme

    def numeric_emulate(self, io_map):
        """ Meta-Function numeric emulation """
        raise NotImplementedError

    @staticmethod
    def __call__(args):
        # just ignore args here and trust default constructor?
        # seems like a bad idea.
        ut_num_simplification = UT_NumericalSimplification(args)
        ut_num_simplification.gen_implementation()

        return True


run_test = UT_NumericalSimplification.__call__

if __name__ == "__main__":
    # auto-test
    main_arg_template = ML_NewArgTemplate(
        default_arg=UT_NumericalSimplification.get_default_args())

    # argument extraction
    args = main_arg_template.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #3
0
        table_value = index >> 1
        add_xx = sollya.round(x + x, self.precision.get_sollya_object(),
                              sollya.RN)
        mult = sollya.round(add_xx * x, self.precision.get_sollya_object(),
                            sollya.RN)
        cst = sollya.round(1.1, self.precision.get_sollya_object(), sollya.RN)
        return sollya.round(
            table_value * sollya.round(
                sollya.round(cst * mult, self.precision.get_sollya_object(),
                             sollya.RN) - add_xx,
                self.precision.get_sollya_object(), sollya.RN),
            self.precision.get_sollya_object(), sollya.RN)


def run_test(args):
    ml_ut_m128_debug = ML_UT_M128_Debug(args)
    ml_ut_m128_debug.gen_implementation()
    return True


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_UT_M128_Debug.get_default_args())
    args = arg_template.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #4
0
                d = specs[i]
                if i == len(specs) - 1:
                    json_str = json.dumps(d, sort_keys=True, indent=4)
                    json_str = "spec: " + json_str.replace("\n", "\nspec: ")
                    print(json_str)
                    break
                nd = specs[i + 1]
                if d["epsilon"] == nd["epsilon"] and d["delta"] == nd["delta"]:
                    continue
                json_str = json.dumps(d, sort_keys=True, indent=4)
                json_str = "spec: " + json_str.replace("\n", "\nspec: ")
                print(json_str)


if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(
        default_arg=ML2_Sinusodial.get_default_args())
    arg_template.parser.add_argument("--slivers", type=int, default=4)
    arg_template.parser.add_argument("--poly-degree", type=int, default=1)
    arg_template.parser.add_argument("--skip-reduction",
                                     default=False,
                                     action="store_const",
                                     const=True)
    arg_template.parser.add_argument("--skip-analysis",
                                     default=False,
                                     action="store_const",
                                     const=True)
    args = arg_template.arg_extraction()
    meta_function = ML2_Sinusodial(args)
    meta_function.gen_implementation()
    if not args.skip_analysis:
        meta_function.determine_error()
예제 #5
0
                                           self.precision, abs_vx)
        medium_approx.set_attributes(tag="medium_approx", debug=debug_multi)

        # approximation for positive values
        scheme = ConditionBlock(
            abs_vx < eps, Return(result),
            ConditionBlock(
                abs_vx < near_indexing.get_max_bound(), Return(near_approx),
                ConditionBlock(abs_vx < medium_indexing.get_max_bound(),
                               Return(medium_approx),
                               Return(Constant(1.0,
                                               precision=self.precision)))))
        return scheme

    def numeric_emulate(self, input_value):
        return bigfloat.gamma(sollya.SollyaObject(input_value).bigfloat())

    standard_test_cases = [
        (1.0, None),
        (sollya.parse("0x1.13b2c6p-2"), None),
    ]


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=ML_Gamma.get_default_args())
    args = arg_template.arg_extraction()

    ml_gamma = ML_Gamma(args)
    ml_gamma.gen_implementation()
        return scheme

    def numeric_emulate(self, x):
        """ numeric emulation """
        # extracting mantissa from x
        # abs_x = abs(x)
        # mantissa = abs_x / S2**sollya.floor(sollya.log2(abs_x))
        # index = sollya.floor((mantissa - 1.0) * 2**8)
        # result = sollya.round(1/sollya.sqrt(1.0 + index * S2**-8), 9, sollya.RN)
        result = sollya.round(1.0 / x, 9, sollya.RN)
        return result


def run_test(args):
    ml_ut_legalize_rcp = ML_UT_LegalizeReciprocalSeed(args)
    ml_ut_legalize_rcp.gen_implementation()
    return True


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_UT_LegalizeReciprocalSeed.get_default_args())
    args = arg_template.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #7
0
            sollya.parse("0x1.7fd01d4fe3196307a4e0008b48p-3")
        ),
        (
            sollya.parse("0x1.4c0ff9a97083c804f4db2002c8p-1"),
            sollya.parse("0x1.7fd01d4fe3196307a4e0008b48p-3")
        ),
        (
            sollya.parse("0x1.4c0ff9a97083c804f4db2002c8p-1"),
            sollya.parse("0x1.7fd01d4fe3196307a4e0008b48p-3")
        ),
        (
            sollya.parse("0x1.4c0ff9a97083c804f4db2002c8p-1"),
            sollya.parse("0x1.7fd01d4fe3196307a4e0008b48p-3")
        ),
    ]

run_test = ML_UT_MultiPrecisionVectorization


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=ML_UT_MultiPrecisionVectorization.get_default_args())
    args = arg_template.arg_extraction()

    if ML_UT_MultiPrecisionVectorization.__call__(args):
        exit(0)
    else:
        exit(1)


예제 #8
0
            S2_u3_cos,
            precision=
            computation_precision  # ML_Custom_FixedPoint_Format(5, 26, signed = True)
        )

        return scheme

    def numeric_emulate(self, input_value):
        if self.cos_output:
            return cos(input_value)
        else:
            return sin(input_value)


if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(
        default_arg=ML_FastSinCos.get_default_args())
    # argument extraction
    arg_template.get_parser().add_argument(
        "--sin",
        dest="cos_output",
        default=True,
        const=False,
        action="store_const",
        help="select sine output (default is cosine)")
    arg_template.get_parser().add_argument(
        "--table-size-log",
        dest="table_size_log",
        default=8,
        type=int,
        action="store",
        help="logarithm of the table size to be used")
예제 #9
0
        n, m, p = random_sizes
        # C is a (n x m) matrix in row-major
        tC_desc = TensorDescriptor([m, n], [1, m], self.precision)
        return [tC_desc]

    def generate_innput_tensor_descriptors(self, random_sizes):
        """ generate list of instance of input tensor descriptors for testing """
        n, m, p = random_sizes
        tA_desc = TensorDescriptor([p, n], [1, p], self.precision)
        # B is a (p x m) matrix in row-major
        tB_desc = TensorDescriptor([m, p], [1, m], self.precision)
        return [tA_desc, tB_desc]


if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(
        default_arg=ShallowConvKernel.get_default_args())
    # extra arguments
    arg_template.get_parser().add_argument(
        "--test-index-range",
        dest="test_index_range",
        default=[[16, 32], [16, 32], [16, 32]],
        type=eval,
        action="store",
        help="random range for matrix sizes")
    arg_template.get_parser().add_argument(
        "--kernel-size",
        dest="kernel_size",
        default=(3, 3),
        type=(lambda s: tuple(map(int, s.split(",")))),
        action="store",
        help="random range for matrix sizes")
예제 #10
0
파일: remquo.py 프로젝트: metalibm/metalibm
            (sollya.parse("-0x1.86c83abe0854ep+268"), FP_MinusInfty(self.precision)),
            # bad sign of remainder
            (sollya.parse("0x1.d3fb9968850a5p-960"), sollya.parse("-0x0.23c1ed19c45fp-1022")),
            # bad sign of zero
            (FP_MinusZero(self.precision), sollya.parse("0x1.85200a9235193p-450")),
            # bad remainder
            (sollya.parse("0x1.fffffffffffffp+1023"), sollya.parse("0x1.1f31bcd002a7ap-803")),
            # bad sign
            (sollya.parse("-0x1.4607d0c9fc1a7p-878"), sollya.parse("-0x1.9b666b840b1bp-1023")),
        ]
        return fp64_list if self.precision.get_bit_size() >= 64 else []



if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=MetaRemQuo.get_default_args()
    )
    arg_template.get_parser().add_argument(
         "--quotient-size", dest="quotient_size", default=3, type=int,
        action="store", help="number of bit to return for the quotient")
    arg_template.get_parser().add_argument(
         "--mode", dest="mode", default="quotient", choices=['quotient', 'remainder', 'full'],
        action="store", help="number of bit to return for the quotient")

    ARGS = arg_template.arg_extraction()

    ml_remquo = MetaRemQuo(ARGS)
    ml_remquo.gen_implementation()
예제 #11
0
        scheme = Statement(
            Return(
                external_function(*tuple(inputs)),
                precision=self.precision,
            ))

        return scheme

    def numeric_emulate(self, *args):
        return self.emulate(*args)


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_ExternalBench.get_default_args())

    def precision_list_parser(s):
        return [precision_parser(p) for p in s.split(",")]

    # argument extraction
    arg_template.get_parser().add_argument(
        "--function",
        dest="bench_function_name",
        default="expf",
        action="store",
        type=str,
        help="name of the function to be benched")
    arg_template.get_parser().add_argument(
        "--headers",
        dest="headers",
예제 #12
0
    def __init__(self,arg_template = DefaultArgTemplate):
        # initializing I/O precision
        precision = ArgDefault.select_value([arg_template.precision, precision])
        io_precisions = [precision] * 2

        # initializing base class
        ML_FunctionBasis.__init__(self,
          arg_template=arg_template
        )

        self.precision = precision


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate()

    arg_template.get_parser().add_argument(
        "--test-gappa", dest="test_gappa", action="store_const", const=True,
        default=False, help="test gappa install")
    arg_template.get_parser().add_argument(
        "--test-cgpe", dest="test_cgpe", action="store_const", const=True,
        default=False, help="test cgpe install")
    arg_template.get_parser().add_argument(
        "--full-status", dest="full_status", action="store_const", const=True,
        default=False, help="test full Metalibm status")
    # argument extraction
    args = arg_template.arg_extraction()

    if args.test_cgpe or args.full_status:
        print("CPGE available:  {}".format(polynomials.is_cgpe_available()))
예제 #13
0
                                           arg_map={
                                               0: FO_Arg(0),
                                               1: FO_Arg(1),
                                               2: FO_Arg(2)
                                           },
                                           require_header=["mpfr.h"])
        emulate_func = FunctionObject(emulate_func_name,
                                      [ML_Mpfr_t, ML_Mpfr_t, ML_Int32],
                                      ML_Int32, emulate_func_op)
        mpfr_call = Statement(
            ReferenceAssign(result_ternary,
                            emulate_func(result, mpfr_x, mpfr_rnd)))

        return mpfr_call

    def numeric_emulate(self, input_value):
        """ Numeric emaluation of exponential """
        return sollya.exp(input_value)


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_Exponential.get_default_args())
    # argument extraction
    args = parse_arg_index_list = arg_template.arg_extraction()

    ml_exp = ML_Exponential(args)

    ml_exp.gen_implementation()
예제 #14
0
            for e in range(1, reduction_e):
                d = generate_json(errors, sollya.Interval(2**(-e), 2**e))
                specs.append(d)
            for i in range(len(specs)):
                d = specs[i]
                if i == len(specs)-1:
                    json_str = json.dumps(d, sort_keys=True, indent=4)
                    json_str = "spec: " + json_str.replace("\n", "\nspec: ")
                    print(json_str)
                    break
                nd = specs[i+1]
                if d["epsilon"] == nd["epsilon"] and d["delta"] == nd["delta"]:
                    continue
                json_str = json.dumps(d, sort_keys=True, indent=4)
                json_str = "spec: " + json_str.replace("\n", "\nspec: ")
                print(json_str)

if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(default_arg=ML2_Logarithm.get_default_args())
    arg_template.parser.add_argument("--slivers", type=int, default=4)
    arg_template.parser.add_argument("--poly-degree", type=int, default=1)
    arg_template.parser.add_argument("--skip-reduction", default=False,
                                     action="store_const", const=True)
    arg_template.parser.add_argument("--skip-analysis", default=False,
                                     action="store_const", const=True)
    args = arg_template.arg_extraction()
    meta_function = ML2_Logarithm(args)
    meta_function.gen_implementation()
    if not args.skip_analysis:
        meta_function.determine_error()
예제 #15
0
    def numeric_emulate(self, x):
        """ numeric emulation """
        TABLE = [1.1**i for i in range(self.table_size)]
        return TABLE[int(x)]

    @staticmethod
    def __call__(args):
        """ Static method from TestRunner: main test function """
        ut_bfloat16 = ML_UT_BFloat16(args)
        ut_bfloat16.gen_implementation()
        return True

run_test = ML_UT_BFloat16

if __name__ == "__main__":
  # auto-test
  arg_template = ML_NewArgTemplate(default_arg=ML_UT_BFloat16.get_default_args())
  arg_template.get_parser().add_argument(
    "--table-size", dest="table_size", default=10, type=int,
    help="set internal table size")

  args = arg_template.arg_extraction()


  if run_test(args):
    exit(0)
  else:
    exit(1)


예제 #16
0
파일: rootn.py 프로젝트: metalibm/metalibm
             sollya.parse("-0x0.fffffffffffffp-1022 ")),
            # ERROR: rootn: 1125899906842624.000000 ulp error at {-0x1.fffffffffffffp+1023, -1}: *-0x0.4000000000000p-1022 vs. -0x0.0000000000000p+0
            (sollya.parse("-0x1.fffffffffffffp+1023"), -1,
             sollya.parse("-0x0.4000000000000p-1022")),
            (sollya.parse("0x1.fffffffffffffp+1023"), -1,
             sollya.parse("0x0.4000000000000p-1022")),
        ]

        return (fp_64_only if self.precision.get_bit_size() >= 64 else []) \
               + (fp_32_only if self.precision.get_bit_size() == 32 else []) \
               + general_list


if __name__ == "__main__":
    # declaring standard argument structure
    arg_template = ML_NewArgTemplate(default_arg=MetaRootN.get_default_args())

    arg_template.get_parser().add_argument(
        "--expand-div",
        dest="expand_div",
        default=False,
        const=int,
        action="store_const",
        help="expand division to meta-division")

    # filling arg_template structure with command line options
    args = arg_template.arg_extraction()

    # declaring meta-function instance
    meta_function = MetaRootN(args)
예제 #17
0
        return recp_eval_error, div_eval_error

    standard_test_cases = [
        (1.0, sollya.parse("0x1.fffffffffffffp+1023"),
         sollya.parse("0x1p-1024")),
        (sollya.parse("-0x1.34a246p-2"), sollya.parse("-0x1.26e2e2p-1")),
        (sollya.parse("0x1.p0"), sollya.parse("0x1.e0ef5ep-49")),
        (sollya.parse("0x1.7fddbp0"), sollya.parse("0x1.e0ef5ep-49")),
        (sollya.parse("0x1.7fddbp-126"), sollya.parse("0x1.e0ef5ep-49")),
        (1.0, sollya.parse("-0x1.fffffffffffffp+1023"),
         sollya.parse("-0x1p-1024")),
    ]


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_Division.get_default_args())
    arg_template.get_parser().add_argument(
        "--num-iter",
        dest="num_iter",
        default=3,
        type=int,
        action="store",
        help="number of newton-raphson iterations")

    ARGS = arg_template.arg_extraction()

    ml_div = ML_Division(ARGS)
    ml_div.gen_implementation()
예제 #18
0
파일: ml_sin.py 프로젝트: metalibm/metalibm
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
# last-modified:    Oct 21st, 2019
#
# wrapper for ML_SinCos to generate sine function
###############################################################################

from metalibm_core.utility.ml_template import ML_NewArgTemplate
from metalibm_functions.ml_sincos import ML_SinCos

if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(default_arg=ML_SinCos.get_default_args(
        output_file="my_sin.c", function_name="my_sin"))
    args = arg_template.arg_extraction()

    # overloading sin_output for force sine function generation
    args.sin_output = True

    ml_sincos = ML_SinCos(args)
    ml_sincos.gen_implementation()
예제 #19
0
                        debug=debug_multi)
        return scheme

    def numeric_emulate(self, input_value):
        return 2**input_value

    @staticmethod
    def get_default_args(**kw):
        """ Return a structure containing the arguments for MetalibmSqrt,
            builtin from a default argument mapping overloaded with @p kw """
        default_args_fast_exp2i = {
            "output_file": "fast_expi.c",
            "function_name": "fast_expi",
            "input_precisions": [ML_Int32],
            "precision": ML_Binary32,
            "accuracy": ML_Faithful,
            "target": GenericProcessor.get_target_instance()
        }
        default_args_fast_exp2i.update(kw)
        return DefaultArgTemplate(**default_args_fast_exp2i)


if __name__ == "__main__":
    # auto-test
    ARG_TEMPLATE = ML_NewArgTemplate(default_arg=FastExp2i.get_default_args())

    ARGS = ARG_TEMPLATE.arg_extraction()

    ML_FAST_EXP_I = FastExp2i(ARGS)
    ML_FAST_EXP_I.gen_implementation()
예제 #20
0
                ConditionBlock(test_zero, return_PosZero, return_NegZero)))
        return_std = Return(result)

        scheme = ConditionBlock(test_std, return_std, return_non_std)
        return scheme

    def numeric_emulate(self, vx):
        """ Numeric emulation for square-root """
        return sollya.sqrt(vx)

    standard_test_cases = [
        (1.651028399744791652636877188342623412609100341796875, )
    ]  # [sollya.parse(x)] for x in  ["+0.0", "-1*0.0", "2.0"]]


if __name__ == "__main__":
    ARG_TEMPLATE = ML_NewArgTemplate(
        default_arg=MetalibmSqrt.get_default_args())
    # TODO: should not be a command line argument but rather determined during generation
    ARG_TEMPLATE.parser.add_argument(
        "--num-iter",
        dest="num_iter",
        action="store",
        default=3,
        help="number of Newton-Raphson iterations")

    ARGS = ARG_TEMPLATE.arg_extraction()

    ML_SQRT = MetalibmSqrt(ARGS)
    ML_SQRT.gen_implementation()
예제 #21
0
                    test_ph_bound, lar_statement,
                    Statement(
                        ReferenceAssign(modk, modk_std),
                        ReferenceAssign(red_vx, red_vx_std),
                    )), result_1))

        return scheme

    def numeric_emulate(self, input_value):
        if self.sin_output:
            return sin(input_value)
        else:
            return cos(input_value)


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=ML_SinCos.get_default_args())
    # argument extraction
    arg_template.get_parser().add_argument(
        "--sin",
        dest="sin_output",
        default=False,
        const=True,
        action="store_const",
        help="select sine output (default is cosine)")

    args = arg_template.arg_extraction()
    ml_sincos = ML_SinCos(args)
    ml_sincos.gen_implementation()
예제 #22
0
        """ generate list of instance of output tensor descriptors for testing """
        n, m, p = random_sizes
        # C is a (n x m) matrix in row-major
        tC_desc = TensorDescriptor([m, n], [1, m], self.precision)
        return [tC_desc]
    def generate_innput_tensor_descriptors(self, random_sizes):
        """ generate list of instance of input tensor descriptors for testing """
        n, m, p = random_sizes
        tA_desc = TensorDescriptor([p, n], [1, p], self.precision)
        # B is a (p x m) matrix in row-major
        tB_desc = TensorDescriptor([m, p], [1, m], self.precision)
        return [tA_desc, tB_desc]


if __name__ == "__main__":
    arg_template = ML_NewArgTemplate(default_arg=MatrixMultiplyKernel.get_default_args())
    # extra arguments
    arg_template.get_parser().add_argument(
        "--test-index-range", dest="test_index_range", default=[[16, 32], [16, 32], [16, 32]],
        type=eval,
        action="store", help="random range for matrix sizes")
    arg_template.get_parser().add_argument(
        "--vectorize", const=True, default=False, action="store_const",
        help="enable matrix-multiply vectorization")
    # argument extraction
    args = arg_template.arg_extraction()

    matrix_multiply_kernel = MatrixMultiplyKernel(args)

    matrix_multiply_kernel.gen_implementation()
예제 #23
0
        ov_value = round(asinh(self.precision.get_max_value()), self.precision.get_sollya_object(), sollya.RD)
        ov_flag = Comparison(Abs(vx), Constant(ov_value, precision = self.precision), specifier = Comparison.Greater)

        # main scheme
        scheme = Statement(
            Return(
                Select(
                    ov_flag,
                    sign*FP_PlusInfty(self.precision),
                    sign*result
                )))

        return scheme

    def numeric_emulate(self, input_value):
        return sinh(input_value)

    standard_test_cases =[[sollya.parse(x)] for x in [
        "0x1.8d3694p-5", "0x1.efc2cp-6", "0x1.f55ddap-5"]
    ]



if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=ML_HyperbolicSine.get_default_args())
    # argument extraction
    args = arg_template.arg_extraction()
    ml_sinh = ML_HyperbolicSine(args)
    ml_sinh.gen_implementation()
예제 #24
0
        else:
            Log.report(
                Log.Warning,
                "gappa was not installed: unable to check execute_gappa_script_extract"
            )

        # dummy scheme to make functionnal code generation
        scheme = Statement(Return(vx))

        return scheme


def run_test(args):
    """ main function for test run """
    ml_ut_gappa_code = ML_UT_GappaCode(args)
    ml_ut_gappa_code.gen_implementation(display_after_gen=False,
                                        display_after_opt=False)
    return True


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_UT_GappaCode.get_default_args())
    args = arg_template.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #25
0
        return scheme

    def numeric_emulate(self, x):
        """ numeric emulation """
        # extracting mantissa from x
        # abs_x = abs(x)
        # mantissa = abs_x / S2**sollya.floor(sollya.log2(abs_x))
        # index = sollya.floor((mantissa - 1.0) * 2**8)
        # result = sollya.round(1/sollya.sqrt(1.0 + index * S2**-8), 9, sollya.RN)
        result = sollya.round(1 / sollya.sqrt(x), 9, sollya.RN)
        return result


def run_test(args):
    ml_ut_legalize_sqrt = ML_UT_LegalizeSqrt(args)
    ml_ut_legalize_sqrt.gen_implementation()
    return True


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_UT_LegalizeSqrt.get_default_args())
    args = arg_template.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #26
0
            raise NotImplementedError

        result = approx

        scheme = Return(result, precision=self.precision, debug=debug_multi)

        return scheme

    def numeric_emulate(self, x):
        """ numeric emulation """
        result = self.precision.round_sollya_object(1 / x)
        return result


def run_test(args):
    ml_ut_accuracies = ML_UT_Accuracies(args)
    ml_ut_accuracies.gen_implementation()
    return True


if __name__ == "__main__":
    # auto-test
    ARG_TEMPLATE = ML_NewArgTemplate(
        default_arg=ML_UT_Accuracies.get_default_args())
    args = ARG_TEMPLATE.arg_extraction()

    if run_test(args):
        exit(0)
    else:
        exit(1)
예제 #27
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################
# created:          Mar 25th, 2020
# last-modified:    Mar 25th, 2020
# Author(s): Nicolas Brunie <*****@*****.**>
###############################################################################

from metalibm_core.utility.ml_template import ML_NewArgTemplate
from metalibm_functions.ml_atan import MetaAtan2


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=MetaAtan2.get_default_args())
    # extra options
    arg_template.get_parser().add_argument(
        "--method", dest="method", default="piecewise", choices=["piecewise", "single"],
        action="store", help="select approximation method")
    arg_template.get_parser().add_argument(
        "--num-sub-intervals", default=8, type=int,
        action="store", help="set the number of sub-intervals in piecewise method")

    args = arg_template.arg_extraction()
    ml_atan2 = MetaAtan2(args)
    ml_atan2.gen_implementation()
예제 #28
0
    for entry in level0_list:
        formats, ops = entry.split(':')
        formats = [precision_parser(f) for f in formats.split(',')]
        ops = [operation_parser(o) for o in ops.split(',')]
        for op in ops:
            if not op in op_map:
                op_map[op] = []
            for f in formats:
                op_map[op].append(f)
    return op_map


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_function_name="main",
                                     default_output_file="bench.c",
                                     default_arg=UnitBench.get_default_args())

    # argument extraction
    arg_template.get_parser().add_argument("--test-num",
                                           dest="test_num",
                                           default=10000,
                                           action="store",
                                           type=int,
                                           help="number of basic iteration")
    arg_template.get_parser().add_argument("--unroll-factor",
                                           dest="unroll_factor",
                                           default=10,
                                           action="store",
                                           type=int,
                                           help="number of basic iteration")
예제 #29
0
                                           arg_map={
                                               0: FO_Arg(0),
                                               1: FO_Arg(1),
                                               2: FO_Arg(2)
                                           },
                                           require_header=["mpfr.h"])
        emulate_func = FunctionObject(emulate_func_name,
                                      [ML_Mpfr_t, ML_Mpfr_t, ML_Int32],
                                      ML_Int32, emulate_func_op)
        mpfr_call = Statement(
            ReferenceAssign(result_ternary,
                            emulate_func(result, mpfr_x, mpfr_rnd)))

        return mpfr_call

    def numeric_emulate(self, input_value):
        """ Numeric emaluation of exponential """
        return sollya.exp(input_value)


if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(
        default_arg=ML_Exponential.get_default_args())
    # argument extraction
    args = arg_template.arg_extraction()

    ml_exp = ML_Exponential(args)

    ml_exp.gen_implementation()
예제 #30
0
        mult = Multiplication(var, var_z, precision=self.precision)
        add = Addition(var_y, mult, precision=self.precision)

        test_program = Statement(
            add,
            Return(add)
        )
        return test_program

    @staticmethod
    def __call__(args):
        # just ignore args here and trust default constructor?
        # seems like a bad idea.
        ut_machine_insn_gen = UT_MachineInsnGeneration(args)
        ut_machine_insn_gen.gen_implementation()
        return True

# main runner for unit tests (called by valid.soft_unit_test)
run_test = UT_MachineInsnGeneration.__call__

if __name__ == "__main__":
    # auto-test
    arg_template = ML_NewArgTemplate(default_arg=UT_MachineInsnGeneration.get_default_args())
    args = arg_template.arg_extraction()

    ut_machine_insn_generation = UT_MachineInsnGeneration(args)
    if run_test(args):
        exit(0)
    else:
        exit(1)