kaldi.base¶
Functions
get_verbose_level |
Returns the verbose level. |
set_abort_on_assert_failure |
Enables/disables the call to abort in case of assertion failure. |
set_print_stack_trace_on_error |
Enables/disables the printing of stack trace in case of an error. |
set_verbose_level |
Sets the verbose level. |
Classes
Timer |
Kaldi timer. |
-
class
kaldi.base.Timer¶ Kaldi timer.
-
elapsed() → float¶ Returns elapsed time since timer was reset.
-
new(set_timer:bool) → Timer¶ Creates and optionally resets the timer to current time.
-
reset()¶ Resets the timer to current time.
-
-
kaldi.base.get_verbose_level() → int¶ Returns the verbose level.
-
kaldi.base.set_abort_on_assert_failure(a:bool)¶ Enables/disables the call to abort in case of assertion failure.
-
kaldi.base.set_print_stack_trace_on_error(p:bool)¶ Enables/disables the printing of stack trace in case of an error.
-
kaldi.base.set_verbose_level(i:int)¶ Sets the verbose level.
kaldi.base.io¶
Functions
expect_token |
Tries to read the given token and throws exception on failure. |
flush |
Flushes output stream. |
get_stderr |
Returns standard error stream. |
get_stdin |
Returns standard input stream. |
get_stdout |
Returns standard output stream. |
init_kaldi_input_stream |
Initializes an input stream by detecting the binary header. |
init_kaldi_output_stream |
Initializes an output stream by writing an optional binary header. |
peek |
Consumes whitespace (if binary == True) and returns the peek value. |
peek_token |
Returns the first character of the next token or -1 if EOF. |
read |
Reads and returns the contents of the stream as a bytes object. |
read_bool |
Reads a Boolean. |
read_double |
Reads a double precision float. |
read_float |
Reads a single precision float. |
read_int |
Reads an integer. |
read_int_pair_vector |
Reads a sequence of integer pairs. |
read_int_vector |
Reads a sequence of integers. |
read_text |
Reads and returns the contents of the stream as a unicode string. |
read_token |
Reads and returns the next token (throws exception on failure) |
readline |
Reads and returns a line from the input stream. |
readline_text |
Reads and returns a line from the input stream. |
write |
Writes bytes object to output stream. |
write_bool |
Writes a Boolean. |
write_double |
Writes a double precision float. |
write_float |
Writes a single precision float. |
write_int |
Writes an integer. |
write_int_pair_vector |
Writes a sequence of integer pairs. |
write_int_vector |
Writes a sequence of integers. |
write_text |
Writes unicode string to output stream. |
write_token |
Writes non-empty string of non-space characters. |
Classes
ifstream |
Input file stream. |
iostream |
Input/output stream. |
istream |
Input stream. |
istringstream |
Input string stream. |
ofstream |
Output file stream. |
ostream |
Output stream. |
ostringstream |
Output string stream. |
stringstream |
Input/output string stream. |
-
kaldi.base.io.expect_token(is:istream, binary:bool, token:str)¶ Tries to read the given token and throws exception on failure.
-
kaldi.base.io.flush(os:ostream)¶ Flushes output stream.
-
kaldi.base.io.get_stderr() → ostream¶ Returns standard error stream.
-
kaldi.base.io.get_stdin() → istream¶ Returns standard input stream.
-
kaldi.base.io.get_stdout() → ostream¶ Returns standard output stream.
-
class
kaldi.base.io.ifstream¶ Input file stream.
-
from_file(filename:str) → ifstream¶ Creates a new input file stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
-
kaldi.base.io.init_kaldi_input_stream(is:istream) -> (success:bool, binary:bool)¶ Initializes an input stream by detecting the binary header.
-
kaldi.base.io.init_kaldi_output_stream(os:ostream, binary:bool)¶ Initializes an output stream by writing an optional binary header.
-
class
kaldi.base.io.iostream¶ Input/output stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
-
class
kaldi.base.io.istream¶ Input stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
-
class
kaldi.base.io.istringstream¶ Input string stream.
-
from_str(str:str) → istringstream¶ Creates a new input string stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
to_bytes() → bytes¶ Returns stream contents as a bytes object.
-
to_str() → str¶ Returns stream contents as a unicode string.
-
-
class
kaldi.base.io.ofstream¶ Output file stream.
-
from_file(filename:str) → ofstream¶ Creates a new output file stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
-
class
kaldi.base.io.ostream¶ Output stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
-
class
kaldi.base.io.ostringstream¶ Output string stream.
-
from_str(str:str) → ostringstream¶ Creates a new output string stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
to_bytes() → bytes¶ Returns stream contents as a bytes object.
-
to_str() → str¶ Returns stream contents as a unicode string.
-
-
kaldi.base.io.peek(is:istream, binary:bool) → int¶ Consumes whitespace (if binary == True) and returns the peek value.
-
kaldi.base.io.peek_token(is:istream, binary:bool) → int¶ Returns the first character of the next token or -1 if EOF.
-
kaldi.base.io.read(is:istream) → bytes¶ Reads and returns the contents of the stream as a bytes object.
-
kaldi.base.io.read_bool(is:istream, binary:bool) → bool¶ Reads a Boolean.
-
kaldi.base.io.read_double(is:istream, binary:bool) → float¶ Reads a double precision float.
-
kaldi.base.io.read_float(is:istream, binary:bool) → float¶ Reads a single precision float.
-
kaldi.base.io.read_int(is:istream, binary:bool) → int¶ Reads an integer.
-
kaldi.base.io.read_int_pair_vector(is:istream, binary:bool) → list<tuple<int, int>>¶ Reads a sequence of integer pairs.
-
kaldi.base.io.read_int_vector(is:istream, binary:bool) → list<int>¶ Reads a sequence of integers.
-
kaldi.base.io.read_text(is:istream) → str¶ Reads and returns the contents of the stream as a unicode string.
-
kaldi.base.io.read_token(is:istream, binary:bool) → str¶ Reads and returns the next token (throws exception on failure)
-
kaldi.base.io.readline(is:istream) → bytes¶ Reads and returns a line from the input stream.
If the stream is already at EOF, an empty bytes object is returned.
-
kaldi.base.io.readline_text(is:istream) → str¶ Reads and returns a line from the input stream.
If the stream is already at EOF, an empty unicode string is returned.
-
class
kaldi.base.io.stringstream¶ Input/output string stream.
-
from_str(str:str) → stringstream¶ Creates a new input/output string stream.
-
good() → bool¶ Checks whether the state of the stream is good.
-
to_bytes() → bytes¶ Returns stream contents as a bytes object.
-
to_str() → str¶ Returns stream contents as a unicode string.
-
-
kaldi.base.io.write(os:ostream, b:bytes)¶ Writes bytes object to output stream.
-
kaldi.base.io.write_bool(os:ostream, binary:bool, t:bool)¶ Writes a Boolean.
-
kaldi.base.io.write_double(os:ostream, binary:bool, t:float)¶ Writes a double precision float.
-
kaldi.base.io.write_float(os:ostream, binary:bool, t:float)¶ Writes a single precision float.
-
kaldi.base.io.write_int(os:ostream, binary:bool, t:int)¶ Writes an integer.
-
kaldi.base.io.write_int_pair_vector(os:ostream, binary:bool, v:list<tuple<int, int>>)¶ Writes a sequence of integer pairs.
-
kaldi.base.io.write_int_vector(os:ostream, binary:bool, v:list<int>)¶ Writes a sequence of integers.
-
kaldi.base.io.write_text(os:ostream, s:str)¶ Writes unicode string to output stream.
-
kaldi.base.io.write_token(os:ostream, binary:bool, token:str)¶ Writes non-empty string of non-space characters.
kaldi.base.math¶
-
kaldi.base.math.DBL_EPSILON= 2.220446049250313e-16¶
-
kaldi.base.math.FLT_EPSILON= 1.1920929e-07¶
-
kaldi.base.math.M_PI= 3.141592653589793¶
-
kaldi.base.math.M_SQRT2= 1.4142135623730951¶
-
kaldi.base.math.M_2PI= 6.283185307179586¶
-
kaldi.base.math.M_SQRT1_2= 0.7071067811865476¶
-
kaldi.base.math.M_LOG_2PI= 1.8378770664093456¶
-
kaldi.base.math.M_LN2= 0.6931471805599453¶
-
kaldi.base.math.M_LN10= 2.302585092994046¶
-
kaldi.base.math.LOG_ZERO_FLOAT= -inf¶
-
kaldi.base.math.LOG_ZERO_DOUBLE= -inf¶
-
kaldi.base.math.MIN_LOG_DIFF_DOUBLE= -36.04365158081055¶
-
kaldi.base.math.MIN_LOG_DIFF_FLOAT= -15.942384719848633¶
Functions
approx_equal |
Returns abs(a - b) <= relative_tolerance * (abs(a) + abs(b)) |
divide_rounding_down |
Returns a / b, rounding towards negative infinity in all cases. |
double_exp |
Computes e raised to the given power. |
double_hypot |
Computes square root of the sum of the squares of two given numbers. |
double_isfinite |
Determines if the given floating point number has finite value. |
double_isinf |
Determines if the given floating point number is a positive or negative infinity. |
double_isnan |
Determines if the given floating point number is a not-a-number (NaN) value. |
double_log |
Computes the natural (base e) logarithm. |
double_log1p |
Computes natural logarithm of 1 plus the given number (ln(1+x)) |
double_log_add |
Computes log(exp(x) + exp(y)) without losing precision. |
double_log_sub |
Computes log(exp(x) + exp(y)) without losing precision. |
double_rand_gauss2 |
Returns a pair of gaussian random numbers using Box-Muller transform |
double_sqr |
Squares the given floating point number. |
exp |
Computes e raised to the given power. |
factorize |
Splits a positive integer into its prime factors. |
gcd |
Returns the greatest common divisor of two integers. |
hypot |
Computes square root of the sum of the squares of two given numbers. |
isfinite |
Determines if the given floating point number has finite value. |
isinf |
Determines if the given floating point number is a positive or negative infinity. |
isnan |
Determines if the given floating point number is a not-a-number (NaN) value. |
lcm |
Returns the least common multiple for x and y. |
log |
Computes the natural (base e) logarithm. |
log1p |
Computes natural logarithm of 1 plus the given number (ln(1+x)) |
log_add |
Computes log(exp(x) + exp(y)) without losing precision. |
log_sub |
Computes log(exp(x) - exp(y)) without losing precision. |
rand |
Returns a random integer between 0 and RAND_MAX, inclusive. |
rand_gauss |
Returns a random number from standard normal distribution. |
rand_gauss2 |
Returns a pair of gaussian random numbers using Box-Muller transform |
rand_int |
Returns a random integer in the given interval. |
rand_poisson |
Returns a random number from poisson distribution. |
rand_prune |
Prunes by preserving expectations. |
rand_uniform |
Returns a random number from uniform distribution (strictly between 0 and 1). |
round_up_to_nearest_power_of_two |
Rounds input integer up to the nearest power of 2. |
sqr |
Squares the given floating point number. |
with_prob |
Returns True with probability prob. |
Classes
RandomState |
Thread-safe random number generator state. |
-
class
kaldi.base.math.RandomState¶ Thread-safe random number generator state.
-
seed¶ Seed for generating random numbers
-
-
kaldi.base.math.approx_equal(a:float, b:float, relative_tolerance:float=default) → bool¶ Returns abs(a - b) <= relative_tolerance * (abs(a) + abs(b))
-
kaldi.base.math.divide_rounding_down(a:int, b:int) → int¶ Returns a / b, rounding towards negative infinity in all cases.
-
kaldi.base.math.double_exp(x:float) → float¶ Computes e raised to the given power.
-
kaldi.base.math.double_hypot(x:float, y:float) → float¶ Computes square root of the sum of the squares of two given numbers.
-
kaldi.base.math.double_isfinite(arg:float) → bool¶ Determines if the given floating point number has finite value.
-
kaldi.base.math.double_isinf(arg:float) → bool¶ Determines if the given floating point number is a positive or negative infinity.
-
kaldi.base.math.double_isnan(arg:float) → bool¶ Determines if the given floating point number is a not-a-number (NaN) value.
-
kaldi.base.math.double_log(x:float) → float¶ Computes the natural (base e) logarithm.
-
kaldi.base.math.double_log1p(x:float) → float¶ Computes natural logarithm of 1 plus the given number (ln(1+x))
-
kaldi.base.math.double_log_add(x:float, y:float) → float¶ Computes log(exp(x) + exp(y)) without losing precision.
-
kaldi.base.math.double_log_sub(x:float, y:float) → float¶ Computes log(exp(x) + exp(y)) without losing precision.
-
kaldi.base.math.double_rand_gauss2(state:RandomState=default) -> (a:float, b:float)¶ Returns a pair of gaussian random numbers using Box-Muller transform
-
kaldi.base.math.double_sqr(x:float) → float¶ Squares the given floating point number.
-
kaldi.base.math.exp(x:float) → float¶ Computes e raised to the given power.
-
kaldi.base.math.factorize(x)[source]¶ Splits a positive integer into its prime factors.
Parameters: x (int) – positive integer Returns: Prime factors in increasing order, with duplication. Return type: List[int] Raises: ValueError if x <= 0
-
kaldi.base.math.gcd(m:int, n:int) → int¶ Returns the greatest common divisor of two integers.
-
kaldi.base.math.hypot(x:float, y:float) → float¶ Computes square root of the sum of the squares of two given numbers.
-
kaldi.base.math.isfinite(arg:float) → bool¶ Determines if the given floating point number has finite value.
-
kaldi.base.math.isinf(arg:float) → bool¶ Determines if the given floating point number is a positive or negative infinity.
-
kaldi.base.math.isnan(arg:float) → bool¶ Determines if the given floating point number is a not-a-number (NaN) value.
-
kaldi.base.math.lcm(x, y)[source]¶ Returns the least common multiple for x and y.
Parameters: Raises: ValueError if x <= 0 or y <= 0
-
kaldi.base.math.log(x:float) → float¶ Computes the natural (base e) logarithm.
-
kaldi.base.math.log1p(x:float) → float¶ Computes natural logarithm of 1 plus the given number (ln(1+x))
-
kaldi.base.math.log_add(x:float, y:float) → float¶ Computes log(exp(x) + exp(y)) without losing precision.
-
kaldi.base.math.log_sub(x:float, y:float) → float¶ Computes log(exp(x) - exp(y)) without losing precision.
-
kaldi.base.math.rand(state:RandomState=default) → int¶ Returns a random integer between 0 and RAND_MAX, inclusive.
-
kaldi.base.math.rand_gauss(state:RandomState=default) → float¶ Returns a random number from standard normal distribution.
-
kaldi.base.math.rand_gauss2(state:RandomState=default) -> (a:float, b:float)¶ Returns a pair of gaussian random numbers using Box-Muller transform
-
kaldi.base.math.rand_int(first, last, state=None)[source]¶ Returns a random integer in the given interval.
Parameters: - first (int) – Lower bound
- last (int) – Upper bound (inclusive)
- state (RandomState or None) – RNG state
Raises: ValueError if first >= last
-
kaldi.base.math.rand_poisson(lambda:float, state:RandomState=default) → int¶ Returns a random number from poisson distribution.
-
kaldi.base.math.rand_prune(post:float, prune_tresh:float, state:RandomState=default) → float¶ Prunes by preserving expectations.
This is typically used to prune posteriors.
-
kaldi.base.math.rand_uniform(state:RandomState=default) → float¶ Returns a random number from uniform distribution (strictly between 0 and 1).
-
kaldi.base.math.round_up_to_nearest_power_of_two(n)[source]¶ Rounds input integer up to the nearest power of 2.
Parameters: n (int) – Positive integer Raises: ValueError if n <= 0
-
kaldi.base.math.sqr(x:float) → float¶ Squares the given floating point number.
-
kaldi.base.math.with_prob(prob)[source]¶ Returns
Truewith probabilityprob.Parameters: prob (float) – probability of True, 0 <= prob <= 1 Raises: ValueError– Ifprobis negative or greater than 1.0.