initializeErrorHandler

Initializes the PyIMSL Math Library error handling system.

Synopsis

initializeErrorHandler ()

Return Value

If the initialization succeeds, zero is returned. If there is an error, a nonzero value is returned.

Description

This function is used to initialize the PyIMSL Math Library error handling system for the current thread. It is not required, but is always allowed.

Use of this function is advised if the possibility of low heap memory exists when calling the PyIMSL Math Library for the first time in the current thread. A successful return from initializeErrorHandler confirms that PyIMSL Math Library error handling system has been initialized and is operational. The effects of calling initializeErrorHandler are limited to the calling thread only.

If initializeErrorHandler is not called and initialization of the error handling system fails, an error message is printed to stderr, and execution is stopped.

Example

In this example, the PyIMSL Math Library error handler is initialized prior to calling multiple other PyIMSL Math Library functions. Often this is not required, but is advised if the possibility of low heap memory exists. Even if not required, the initialization call is always allowed.

The computations performed in this example are based on Example 1 for splineLeastSquares.

from __future__ import print_function
from numpy import *
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.randomUniform import randomUniform
from pyimsl.math.splineValue import splineValue
from pyimsl.math.initializeErrorHandler import initializeErrorHandler
from pyimsl.math.splineLeastSquares import splineLeastSquares

# Define function


def F(x):
    return (1. + sin(x) + 7. * sin(3.0 * x))


# Initialize the IMSL C Stat Library error handler.
status = initializeErrorHandler()

# Verify successful error handler initialization before
# continuing.
if status == 0:
    # Generate random numbers
    ndata = 90
    spline_space_dim = 12
    randomSeedSet(123457)
    random = randomUniform(ndata)

    # Set up data
    xdata = empty(ndata)
    fdata = empty(ndata)
    for i in range(0, ndata):
        xdata[i] = 6. * i / (ndata - 1)
        fdata[i] = F(xdata[i]) + 2. * (random[i] - .5)
    sp = splineLeastSquares(xdata, fdata, spline_space_dim)
    print("       x         error")
    for i in range(0, 10):
        x = 6. * i / 9.
        error = F(x) - splineValue(x, sp)
        print("%10.3f  %10.3f" % (x, error))
else:
    print("Unable to initialize IMSL C Math Library error handler.")