@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . encodeToByteArray ( startIndex : Int = <NUM_LIT:0> , endIndex : Int = this . length , throwOnInvalidSequence : Boolean = false ) : ByteArray

{ <EOL> AbstractList . checkBoundsIndexes ( startIndex , endIndex , length ) <EOL> return encodeUtf8 ( this , startIndex , endIndex , throwOnInvalidSequence ) <EOL> }

/**
 * Encodes this string or its substring to an array of bytes in UTF-8 encoding.
 *
 * @param startIndex the beginning (inclusive) of the substring to encode, 0 by default.
 * @param endIndex the end (exclusive) of the substring to encode, length of this string by default.
 * @param throwOnInvalidSequence specifies whether to throw an exception on malformed char sequence or replace.
 *
 * @throws IndexOutOfBoundsException if [startIndex] is less than zero or [endIndex] is greater than the length of this string.
 * @throws IllegalArgumentException if [startIndex] is greater than [endIndex].
 * @throws CharacterCodingException if this string contains malformed char sequence and [throwOnInvalidSequence] is true.
 */


public actual fun String . substring ( startIndex : Int ) : String

= <EOL> subSequence ( startIndex , this . length ) as String

/**
 * Returns a substring of this string that starts at the specified [startIndex] and continues to the end of the string.
 */


public actual fun String . substring ( startIndex : Int , endIndex : Int ) : String

= <EOL> subSequence ( startIndex , endIndex ) as String

/**
 * Returns the substring of this string starting at the [startIndex] and ending right before the [endIndex].
 *
 * @param startIndex the start index (inclusive).
 * @param endIndex the end index (exclusive).
 */


@ Deprecated ( "<STR_LIT>" , ReplaceWith ( "<STR_LIT>" ) ) <EOL> @ DeprecatedSinceKotlin ( warningSince = "<STR_LIT:1.5>" ) <EOL> public actual fun String . toUpperCase ( ) : String

= uppercase ( )

/**
 * Returns a copy of this string converted to upper case using the rules of the default locale.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> public actual fun String . uppercase ( ) : String

= uppercaseImpl ( )

/**
 * Returns a copy of this string converted to upper case using Unicode mapping rules of the invariant locale.
 *
 * This function supports one-to-many and many-to-one character mapping,
 * thus the length of the returned string can be different from the length of the original string.
 *
 * @sample samples.text.Strings.uppercase
 */


@ Deprecated ( "<STR_LIT>" , ReplaceWith ( "<STR_LIT>" ) ) <EOL> @ DeprecatedSinceKotlin ( warningSince = "<STR_LIT:1.5>" ) <EOL> public actual fun String . toLowerCase ( ) : String

= lowercase ( )

/**
 * Returns a copy of this string converted to lower case using the rules of the default locale.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> public actual fun String . lowercase ( ) : String

= lowercaseImpl ( )

/**
 * Returns a copy of this string converted to lower case using Unicode mapping rules of the invariant locale.
 *
 * This function supports one-to-many and many-to-one character mapping,
 * thus the length of the returned string can be different from the length of the original string.
 *
 * @sample samples.text.Strings.lowercase
 */


@ Deprecated ( "<STR_LIT>" , ReplaceWith ( "<STR_LIT>" ) ) <EOL> @ DeprecatedSinceKotlin ( warningSince = "<STR_LIT:1.5>" ) <EOL> public actual fun String . capitalize ( ) : String

= replaceFirstChar ( Char :: uppercaseChar )

/**
 * Returns a copy of this string having its first letter titlecased using the rules of the default locale,
 * or the original string if it's empty or already starts with a title case letter.
 *
 * The title case of a character is usually the same as its upper case with several exceptions.
 * The particular list of characters with the special title case form depends on the underlying platform.
 *
 * @sample samples.text.Strings.capitalize
 */


@ Deprecated ( "<STR_LIT>" , ReplaceWith ( "<STR_LIT>" ) ) <EOL> @ DeprecatedSinceKotlin ( warningSince = "<STR_LIT:1.5>" ) <EOL> public actual fun String . decapitalize ( ) : String

= replaceFirstChar ( Char :: lowercaseChar )

/**
 * Returns a copy of this string having its first letter lowercased using the rules of the default locale,
 * or the original string if it's empty or already starts with a lower case letter.
 *
 * @sample samples.text.Strings.decapitalize
 */


public actual fun CharSequence . repeat ( n : Int ) : String

{ <EOL> require ( n >= <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> if ( isEmpty ( ) ) return "<STR_LIT>" <EOL> return when ( n ) { <EOL> <NUM_LIT:0> -> "<STR_LIT>" <EOL> <NUM_LIT:1> -> this . toString ( ) <EOL> else -> { <EOL> val sequence = this <EOL> buildString ( n * length ) { <EOL> repeat ( n ) { <EOL> append ( sequence ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Returns a string containing this char sequence repeated [n] times.
 * @throws [IllegalArgumentException] when n < 0.
 * @sample samples.text.Strings.repeat
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . replace ( oldChar : Char , newChar : Char , ignoreCase : Boolean = false ) : String

{ <EOL> return buildString ( length ) { <EOL> this@replace . forEach { c -> <EOL> append ( if ( c . equals ( oldChar , ignoreCase ) ) newChar else c ) <EOL> } <EOL> } <EOL> }

/**
 * Returns a new string with all occurrences of [oldChar] replaced with [newChar].
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . replace ( oldValue : String , newValue : String , ignoreCase : Boolean = false ) : String

{ <EOL> run { <EOL> var occurrenceIndex : Int = indexOf ( oldValue , <NUM_LIT:0> , ignoreCase ) <EOL> if ( occurrenceIndex < <NUM_LIT:0> ) return this <EOL> val oldValueLength = oldValue . length <EOL> val searchStep = oldValueLength . coerceAtLeast ( <NUM_LIT:1> ) <EOL> val newLengthHint = length - oldValueLength + newValue . length <EOL> if ( newLengthHint < <NUM_LIT:0> ) throw OutOfMemoryError ( ) <EOL> val stringBuilder = StringBuilder ( newLengthHint ) <EOL> var i = <NUM_LIT:0> <EOL> do { <EOL> stringBuilder . append ( this , i , occurrenceIndex ) . append ( newValue ) <EOL> i = occurrenceIndex + oldValueLength <EOL> if ( occurrenceIndex >= length ) break <EOL> occurrenceIndex = indexOf ( oldValue , occurrenceIndex + searchStep , ignoreCase ) <EOL> } while ( occurrenceIndex > <NUM_LIT:0> ) <EOL> return stringBuilder . append ( this , i , length ) . toString ( ) <EOL> } <EOL> }

/**
 * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string
 * with the specified [newValue] string.
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . replaceFirst ( oldChar : Char , newChar : Char , ignoreCase : Boolean = false ) : String

{ <EOL> val index = indexOf ( oldChar , ignoreCase = ignoreCase ) <EOL> return if ( index < <NUM_LIT:0> ) this else this . replaceRange ( index , index + <NUM_LIT:1> , newChar . toString ( ) ) <EOL> }

/**
 * Returns a new string with the first occurrence of [oldChar] replaced with [newChar].
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . replaceFirst ( oldValue : String , newValue : String , ignoreCase : Boolean = false ) : String

{ <EOL> val index = indexOf ( oldValue , ignoreCase = ignoreCase ) <EOL> return if ( index < <NUM_LIT:0> ) this else this . replaceRange ( index , index + oldValue . length , newValue ) <EOL> }

/**
 * Returns a new string obtained by replacing the first occurrence of the [oldValue] substring in this string
 * with the specified [newValue] string.
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String ? . equals ( other : String ? , ignoreCase : Boolean = false ) : Boolean

{ <EOL> if ( this == null ) return other == null <EOL> if ( other == null ) return false <EOL> if ( ! ignoreCase ) return this == other <EOL> if ( this . length != other . length ) return false <EOL> for ( index in <NUM_LIT:0> until this . length ) { <EOL> val thisChar = this [ index ] <EOL> val otherChar = other [ index ] <EOL> if ( ! thisChar . equals ( otherChar , ignoreCase ) ) { <EOL> return false <EOL> } <EOL> } <EOL> return true <EOL> }

/**
 * Returns `true` if this string is equal to [other], optionally ignoring character case.
 *
 * Two strings are considered to be equal if they have the same length and the same character at the same index.
 * If [ignoreCase] is true, the result of `Char.uppercaseChar().lowercaseChar()` on each character is compared.
 *
 * @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
 */


@ SinceKotlin ( "<STR_LIT:1.2>" ) <EOL> @ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . compareTo ( other : String , ignoreCase : Boolean = false ) : Int

{ <EOL> if ( ignoreCase ) { <EOL> val n1 = this . length <EOL> val n2 = other . length <EOL> val min = minOf ( n1 , n2 ) <EOL> if ( min == <NUM_LIT:0> ) return n1 - n2 <EOL> for ( index in <NUM_LIT:0> until min ) { <EOL> var thisChar = this [ index ] <EOL> var otherChar = other [ index ] <EOL> if ( thisChar != otherChar ) { <EOL> thisChar = thisChar . uppercaseChar ( ) <EOL> otherChar = otherChar . uppercaseChar ( ) <EOL> if ( thisChar != otherChar ) { <EOL> thisChar = thisChar . lowercaseChar ( ) <EOL> otherChar = otherChar . lowercaseChar ( ) <EOL> if ( thisChar != otherChar ) { <EOL> return thisChar . compareTo ( otherChar ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> return n1 - n2 <EOL> } else { <EOL> return compareTo ( other ) <EOL> } <EOL> }

/**
 * Compares two strings lexicographically, optionally ignoring case differences.
 *
 * If [ignoreCase] is true, the result of `Char.uppercaseChar().lowercaseChar()` on each character is compared.
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> public actual infix fun CharSequence ? . contentEquals ( other : CharSequence ? ) : Boolean

= contentEqualsImpl ( other )

/**
 * Returns `true` if the contents of this char sequence are equal to the contents of the specified [other],
 * i.e. both char sequences contain the same number of the same characters in the same order.
 *
 * @sample samples.text.Strings.contentEquals
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> public actual fun CharSequence ? . contentEquals ( other : CharSequence ? , ignoreCase : Boolean ) : Boolean

{ <EOL> return if ( ignoreCase ) <EOL> this . contentEqualsIgnoreCaseImpl ( other ) <EOL> else <EOL> this . contentEqualsImpl ( other ) <EOL> }

/**
 * Returns `true` if the contents of this char sequence are equal to the contents of the specified [other], optionally ignoring case difference.
 *
 * @param ignoreCase `true` to ignore character case when comparing contents.
 *
 * @sample samples.text.Strings.contentEquals
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . startsWith ( prefix : String , ignoreCase : Boolean = false ) : Boolean

= <EOL> regionMatches ( <NUM_LIT:0> , prefix , <NUM_LIT:0> , prefix . length , ignoreCase )

/**
 * Returns `true` if this string starts with the specified prefix.
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . startsWith ( prefix : String , startIndex : Int , ignoreCase : Boolean = false ) : Boolean

= <EOL> regionMatches ( startIndex , prefix , <NUM_LIT:0> , prefix . length , ignoreCase )

/**
 * Returns `true` if a substring of this string starting at the specified offset [startIndex] starts with the specified prefix.
 */


@ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . endsWith ( suffix : String , ignoreCase : Boolean = false ) : Boolean

= <EOL> regionMatches ( length - suffix . length , suffix , <NUM_LIT:0> , suffix . length , ignoreCase )

/**
 * Returns `true` if this string ends with the specified suffix.
 */


public actual fun CharSequence . regionMatches ( thisOffset : Int , other : CharSequence , otherOffset : Int , length : Int , ignoreCase : Boolean ) : Boolean

= regionMatchesImpl ( thisOffset , other , otherOffset , length , ignoreCase )

/**
 * Returns `true` if the specified range in this char sequence is equal to the specified range in another char sequence.
 * @param thisOffset the start offset in this char sequence of the substring to compare.
 * @param other the string against a substring of which the comparison is performed.
 * @param otherOffset the start offset in the other char sequence of the substring to compare.
 * @param length the length of the substring to compare.
 */


@ SinceKotlin ( "<STR_LIT:1.9>" ) <EOL> @ Suppress ( "<STR_LIT:ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS>" ) <EOL> public actual fun String . regionMatches ( thisOffset : Int , other : String , otherOffset : Int , length : Int , ignoreCase : Boolean = false ) : Boolean

/**
 * Returns `true` if the specified range in this string is equal to the specified range in another string.
 * @param thisOffset the start offset in this string of the substring to compare.
 * @param other the string against a substring of which the comparison is performed.
 * @param otherOffset the start offset in the other string of the substring to compare.
 * @param length the length of the substring to compare.
 */


{ <EOL> val ( train , test ) = mnist ( ) <EOL> lenet5Classic . use { <EOL> val earlyStopping = EarlyStopping ( monitor = EpochTrainingEvent :: valLossValue , minDelta = <NUM_LIT:0.0> , patience = <NUM_LIT:2> , verbose = true , mode = EarlyStoppingMode . AUTO , baseline = <NUM_LIT> , restoreBestWeights = false ) <EOL> it . compile ( optimizer = Adam ( clipGradient = ClipGradientByValue ( <NUM_LIT> ) ) , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> it . logSummary ( ) <EOL> it . fit ( dataset = train , epochs = EPOCHS , batchSize = TRAINING_BATCH_SIZE , earlyStopping ) <EOL> val accuracy = it . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This example shows how to do image classification from scratch using [lenet5Classic], without leveraging pre-trained weights or a pre-made model.
 * We demonstrate the workflow on the Mnist classification dataset.
 *
 * It includes:
 * - dataset loading from S3
 * - callback definition
 * - model compilation with [EarlyStopping] callback
 * - model summary
 * - model training
 * - model evaluation
 */


= lenetWithEarlyStoppingCallback ( )


fun append ( charCode : Int , categoryId : String ) : Boolean

/**
 * Appends the [charCode] to this range pattern.
 * Returns true if the [charCode] with the specified [categoryId] could be accommodated within this pattern.
 * Returns false otherwise.
 */


fun prepend ( charCode : Int , categoryId : String ) : Boolean

/**
 * Prepends the [charCode] to this range pattern.
 * Returns true if the [charCode] with the specified [categoryId] could be accommodated within this pattern.
 * Returns false otherwise.
 */


fun rangeStart ( ) : Int

/**
 * Char code of the first char in this range.
 */


fun rangeEnd ( ) : Int

/**
 * Char code of the last char in this range.
 */


fun category ( ) : Int

/**
 * An integer value that contains information about the category of each char in this range.
 */


fun categoryIdOf ( charCode : Int ) : String

/**
 * Returns category id of the char with the specified [charCode].
 * Throws an exception if the [charCode] is not in `rangeStart()..rangeEnd()`.
 */


operator fun Product . contains ( item : Any ? ) : Boolean

= productIterator ( ) . contains ( item )

/** Tests whether this iterator contains a given value as an element.
 * Note: may not terminate for infinite iterators.
 *
 * @param item the element to test.
 * @return `true` if this iterator produces some value that
 * is equal (as determined by `==`) to `elem`, `false` otherwise.
 * @note Reuse: After calling this method, one should discard the iterator it was called on.
 * Using it is undefined and subject to change.
 */


operator fun Product . iterator ( ) : Iterator < Any ? >

= JavaConverters . asJavaIterator ( productIterator ( ) )

/**
 * An iterator over all the elements of this product.
 * @return in the default implementation, an `Iterator<Any?>`
 */


fun Product . asIterable ( ) : Iterable < Any ? >

= object : Iterable < Any ? > { <EOL> override fun iterator ( ) : Iterator < Any ? > = JavaConverters . asJavaIterator ( productIterator ( ) ) <EOL> }

/**
 * Converts this product to an `Any?` iterable.
 */


@ Throws ( IndexOutOfBoundsException :: class ) <EOL> operator fun Product . get ( n : Int ) : Any ?

= productElement ( n )

/** The n'th element of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 *
 * @param n the index of the element to return
 * @throws IndexOutOfBoundsException
 * @return the element `n` elements after the first element
 */


fun Product . getOrNull ( n : Int ) : Any ?

= if ( n in <NUM_LIT:0> until size ) productElement ( n ) else null

/** The n'th element of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 *
 * @param n the index of the element to return
 * @return the element `n` elements after the first element, `null` if out of bounds
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> @ Throws ( IndexOutOfBoundsException :: class , ClassCastException :: class ) <EOL> inline fun < reified T > Product . getAs ( n : Int ) : T

= productElement ( n ) as T

/** The n'th element of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 * The result is cast to the given type [T].
 *
 * @param n the index of the element to return
 * @throws IndexOutOfBoundsException
 * @throws ClassCastException
 * @return the element `n` elements after the first element
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> inline fun < reified T > Product . getAsOrNull ( n : Int ) : T ?

= getOrNull ( n ) as? T

/** The n'th element of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 * The result is cast to the given type [T].
 *
 * @param n the index of the element to return
 * @return the element `n` elements after the first element, `null` if out of bounds or unable to be cast
 */


@ Throws ( IndexOutOfBoundsException :: class ) <EOL> operator fun Product . get ( indexRange : IntRange ) : List < Any ? >

= indexRange . map ( :: get )

/** The range of n'th elements of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 *
 * @param indexRange the indices of the elements to return
 * @throws IndexOutOfBoundsException
 * @return the elements in [indexRange]
 */


fun Product . getOrNull ( indexRange : IntRange ) : List < Any ? >

= indexRange . map ( :: getOrNull )

/** The range of n'th elements of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 *
 * @param indexRange the indices of the elements to return
 * @return the elements in [indexRange], `null` if out of bounds
 */


@ Throws ( IndexOutOfBoundsException :: class , ClassCastException :: class ) <EOL> inline fun < reified T > Product . getAs ( indexRange : IntRange ) : List < T >

= indexRange . map ( :: getAs )

/** The range of n'th elements of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 * The results are cast to the given type [T].
 *
 * @param indexRange the indices of the elements to return
 * @throws IndexOutOfBoundsException
 * @throws ClassCastException
 * @return the elements in [indexRange]
 */


inline fun < reified T > Product . getAsOrNull ( indexRange : IntRange ) : List < T ? >

= indexRange . map ( :: getAsOrNull )

/** The range of n'th elements of this product, 0-based. In other words, for a
 * product `A(x,,1,,, ..., x,,k,,)`, returns `x,,(n+1),,` where `0 <= n < k`.
 * The results are cast to the given type [T].
 *
 * @param indexRange the indices of the elements to return
 * @return the elements in [indexRange], `null` is out of bounds or unable to be cast
 */


fun getConstraintsContainedSpecifiedTypeVariable ( typeVariableConstructor : TypeConstructorMarker ) : Collection < Constraint >

/**
 * Only necessary for incorporation optimization
 */


@ Test <EOL> fun testResumingFromAnotherThread ( )

= runTest { <EOL> suspendCancellableCoroutine < Unit > { cont -> <EOL> thread { <EOL> Thread . sleep ( <NUM_LIT:10> ) <EOL> cont . resume ( Unit ) <EOL> } <EOL> } <EOL> }

/** Tests that resuming the coroutine of [runTest] asynchronously in reasonable time succeeds. */


@ Test <EOL> fun testStandardTestDispatcherIsConfined ( ) : Unit

= runBlocking { <EOL> val scheduler = TestCoroutineScheduler ( ) <EOL> val initialThread = Thread . currentThread ( ) <EOL> val job = launch ( StandardTestDispatcher ( scheduler ) ) { <EOL> assertEquals ( initialThread , Thread . currentThread ( ) ) <EOL> withContext ( Dispatchers . IO ) { <EOL> val ioThread = Thread . currentThread ( ) <EOL> assertNotSame ( initialThread , ioThread ) <EOL> } <EOL> assertEquals ( initialThread , Thread . currentThread ( ) ) <EOL> } <EOL> scheduler . advanceUntilIdle ( ) <EOL> while ( job . isActive ) { <EOL> scheduler . receiveDispatchEvent ( ) <EOL> scheduler . advanceUntilIdle ( ) <EOL> } <EOL> }

/** Tests that [StandardTestDispatcher] is not executed in-place but confined to the thread in which the
 * virtual time control happens. */


public fun thread ( start : Boolean = true , isDaemon : Boolean = false , contextClassLoader : ClassLoader ? = null , name : String ? = null , priority : Int = - <NUM_LIT:1> , block : ( ) -> Unit ) : Thread

{ <EOL> val thread = object : Thread ( ) { <EOL> public override fun run ( ) { <EOL> block ( ) <EOL> } <EOL> } <EOL> if ( isDaemon ) <EOL> thread . isDaemon = true <EOL> if ( priority > <NUM_LIT:0> ) <EOL> thread . priority = priority <EOL> if ( name != null ) <EOL> thread . name = name <EOL> if ( contextClassLoader != null ) <EOL> thread . contextClassLoader = contextClassLoader <EOL> if ( start ) <EOL> thread . start ( ) <EOL> return thread <EOL> }

/**
 * Creates a thread that runs the specified [block] of code.
 *
 * @param start if `true`, the thread is immediately started.
 * @param isDaemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when
 * the only threads running are all daemon threads.
 * @param contextClassLoader the class loader to use for loading classes and resources in this thread.
 * @param name the name of the thread.
 * @param priority the priority of the thread.
 */


@ kotlin . internal . InlineOnly <EOL> public inline fun < T : Any > ThreadLocal < T > . getOrSet ( default : ( ) -> T ) : T

{ <EOL> return get ( ) ? : default ( ) . also ( this :: set ) <EOL> }

/**
 * Gets the value in the current thread's copy of this
 * thread-local variable or replaces the value with the result of calling
 * [default] function in case if that value was `null`.
 *
 * If the variable has no value for the current thread,
 * it is first initialized to the value returned
 * by an invocation of the [ThreadLocal.initialValue] method.
 * Then if it is still `null`, the provided [default] function is called and its result
 * is stored for the current thread and then returned.
 */


/**
 * [LazyThreadSafetyMode.PUB<caret>LICATION]
 */


fun lenetOnMnistInferenceWithTensorNames ( )

{ <EOL> val ( train , test ) = mnist ( ) <EOL> SavedModel . load ( PATH_TO_MODEL ) . use { <EOL> println ( it . graphToString ( ) ) <EOL> val prediction = it . predict ( train . getX ( <NUM_LIT:0> ) , "<STR_LIT>" , "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" + train . getY ( <NUM_LIT:0> ) ) <EOL> val predictions = it . predict ( test ) { data -> predict ( data , "<STR_LIT>" , "<STR_LIT>" ) } <EOL> println ( predictions . toString ( ) ) <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This examples demonstrates running [SavedModel] for prediction on [mnist] dataset.
 *
 * It uses string tensor names to get access to input/output tensors in TensorFlow static graph.
 */


= lenetOnMnistInferenceWithTensorNames ( )


public fun append ( value : Char ) : Appendable

/**
 * Appends the specified character [value] to this Appendable and returns this instance.
 *
 * @param value the character to append.
 */


public fun append ( value : CharSequence ? ) : Appendable

/**
 * Appends the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence to append. If [value] is `null`, then the four characters `"null"` are appended to this Appendable.
 */


public fun append ( value : CharSequence ? , startIndex : Int , endIndex : Int ) : Appendable

/**
 * Appends a subsequence of the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence from which a subsequence is appended. If [value] is `null`,
 * then characters are appended as if [value] contained the four characters `"null"`.
 * @param startIndex the beginning (inclusive) of the subsequence to append.
 * @param endIndex the end (exclusive) of the subsequence to append.
 *
 * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> public fun < T : Appendable > T . appendRange ( value : CharSequence , startIndex : Int , endIndex : Int ) : T

{ <EOL> @ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> return append ( value , startIndex , endIndex ) as T <EOL> }

/**
 * Appends a subsequence of the specified character sequence [value] to this Appendable and returns this instance.
 *
 * @param value the character sequence from which a subsequence is appended.
 * @param startIndex the beginning (inclusive) of the subsequence to append.
 * @param endIndex the end (exclusive) of the subsequence to append.
 *
 * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
 */


public fun < T : Appendable > T . append ( vararg value : CharSequence ? ) : T

{ <EOL> for ( item in value ) <EOL> append ( item ) <EOL> return this <EOL> }

/**
 * Appends all arguments to the given [Appendable].
 */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( ) : Appendable

= append ( '<CHAR_LIT:\n>' )

/** Appends a line feed character (`\n`) to this Appendable. */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( value : CharSequence ? ) : Appendable

= append ( value ) . appendLine ( )

/** Appends value to the given Appendable and a line feed character (`\n`) after it. */


@ SinceKotlin ( "<STR_LIT:1.4>" ) <EOL> @ kotlin . internal . InlineOnly <EOL> public inline fun Appendable . appendLine ( value : Char ) : Appendable

= append ( value ) . appendLine ( )


internal fun decompiledText ( file : FileWithMetadata . Compatible , serializerProtocol : SerializerExtensionProtocol , flexibleTypeDeserializer : FlexibleTypeDeserializer , renderer : DescriptorRenderer , deserializationConfiguration : DeserializationConfiguration = DeserializationConfiguration . Default ) : DecompiledText

{ <EOL> val packageFqName = file . packageFqName <EOL> val resolver = KlibMetadataDeserializerForDecompiler ( packageFqName , file . proto , file . nameResolver , serializerProtocol , flexibleTypeDeserializer , deserializationConfiguration , ) <EOL> val declarations = arrayListOf < DeclarationDescriptor > ( ) <EOL> declarations . addAll ( resolver . resolveDeclarationsInFacade ( packageFqName ) ) <EOL> for ( classProto in file . classesToDecompile ) { <EOL> val classId = file . nameResolver . getClassId ( classProto . fqName ) <EOL> declarations . addIfNotNull ( resolver . resolveTopLevelClass ( classId ) ) <EOL> } <EOL> return buildDecompiledText ( packageFqName , declarations , renderer ) <EOL> }

/**
 * This function is extracted for [Fe10KlibMetadataDecompiler], [Fe10KlibMetadataStubBuilder] and [K2KlibMetadataDecompiler].
 * TODO: K2 shouldn't use descriptor renderer for building decompiled text.
 * Note that decompiled text is not used for building stubs in K2.
 * That's why in K2 it is important to preserve declaration order during deserialization to not get PSI vs. stubs mismatch.
 */


fun getPreviewImageBounds ( sourceImageWidth : Int , sourceImageHeight : Int , viewWidth : Int , viewHeight : Int , scaleType : PreviewView . ScaleType ) : PreviewImageBounds

{ <EOL> val scale = if ( scaleType == PreviewView . ScaleType . FILL_START || scaleType == PreviewView . ScaleType . FILL_END || scaleType == PreviewView . ScaleType . FILL_CENTER ) { <EOL> max ( viewWidth . toFloat ( ) / sourceImageWidth , viewHeight . toFloat ( ) / sourceImageHeight ) <EOL> } else { <EOL> min ( viewWidth . toFloat ( ) / sourceImageWidth , viewHeight . toFloat ( ) / sourceImageHeight ) <EOL> } <EOL> val previewImageWidth = sourceImageWidth * scale <EOL> val previewImageHeight = sourceImageHeight * scale <EOL> return when ( scaleType ) { <EOL> PreviewView . ScaleType . FILL_START , PreviewView . ScaleType . FIT_START -> { <EOL> PreviewImageBounds ( <NUM_LIT> , <NUM_LIT> , previewImageWidth , previewImageHeight ) <EOL> } <EOL> PreviewView . ScaleType . FILL_END , PreviewView . ScaleType . FIT_END -> { <EOL> PreviewImageBounds ( viewWidth - previewImageWidth , viewHeight - previewImageHeight , previewImageWidth , previewImageHeight ) <EOL> } <EOL> else -> { <EOL> PreviewImageBounds ( viewWidth / <NUM_LIT:2> - previewImageWidth / <NUM_LIT:2> , viewHeight / <NUM_LIT:2> - previewImageHeight / <NUM_LIT:2> , previewImageWidth , previewImageHeight ) <EOL> } <EOL> } <EOL> }

/**
 * Calculate the location of the preview image top-left corner (relative to the component top-left corner)
 * and dimensions, to be used for displaying detected objects, for example with the [DetectorViewBase].
 *
 * When camera preview resolution differs from the dimensions of the [PreviewView] used to display camera input,
 * image is scaled and cropped or padded according to the provided [PreviewView.ScaleType]. Because of this,
 * in order to display detected objects on the [PreviewView], their coordinates need to be converted.
 * This method returns [PreviewImageBounds] object containing the necessary information to preform the conversion
 * from the image coordinate system to the view coordinate system.
 *
 * @param [sourceImageWidth] width of the image from the camera
 * @param [sourceImageHeight] height of the image from the camera
 * @param [viewWidth] width of the target [PreviewView]
 * @param [viewHeight] height of the target [PreviewView]
 * @param [scaleType] scaling option used in the target [PreviewView]
 *
 * @see Scale type
 */


internal fun generateKotlinVersion ( apiDir : File , filePrinter : ( targetFile : File , Printer . ( ) -> Unit ) -> Unit )

{ <EOL> val kotlinVersionFqName = FqName ( "<STR_LIT>" ) <EOL> filePrinter ( fileFromFqName ( apiDir , kotlinVersionFqName ) ) { <EOL> generateDeclaration ( "<STR_LIT>" , kotlinVersionFqName , afterType = "<STR_LIT>" ) { <EOL> for ( languageVersion in LanguageVersion . values ( ) ) { <EOL> val prefix = when { <EOL> languageVersion . isUnsupported -> "<STR_LIT>" <EOL> languageVersion . isDeprecated -> "<STR_LIT>" <EOL> else -> "<STR_LIT>" <EOL> } <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> println ( "<STR_LIT:;>" ) <EOL> println ( ) <EOL> println ( "<STR_LIT>" ) <EOL> withIndent { <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( ) <EOL> println ( "<STR_LIT>" ) <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> println ( "<STR_LIT:}>" ) <EOL> } <EOL> } <EOL> }

/**
 * ApiVersion and LanguageVersion are almost the same in the compiler api, so Gradle DSL options
 * exposes KotlinVersion that covers both of them.
 */


public fun chars ( value : String )

/**
 * A literal string.
 *
 * When formatting, the string is appended to the result as is,
 * and when parsing, the string is expected to be present in the input verbatim.
 */


public fun year ( padding : Padding = Padding . ZERO )

/**
 * A year number.
 *
 * By default, for years [-9999..9999], it's formatted as a decimal number, zero-padded to four digits, though
 * this padding can be disabled or changed to space padding by passing [padding].
 * For years outside this range, it's formatted as a decimal number with a leading sign, so the year 12345
 * is formatted as "+12345".
 */


public fun yearTwoDigits ( baseYear : Int )

/**
 * The last two digits of the ISO year.
 *
 * [baseYear] is the base year for the two-digit year.
 * For example, if [baseYear] is 1960, then this format correctly works with years [1960..2059].
 *
 * On formatting, when given a year in the valid range, it returns the last two digits of the year,
 * so 1993 becomes "93". When given a year outside the valid range, it returns the full year number
 * with a leading sign, so 1850 becomes "+1850", and -200 becomes "-200".
 *
 * On parsing, it accepts either a two-digit year or a full year number with a leading sign.
 * When given a two-digit year, it returns a year in the valid range, so "93" becomes 1993,
 * and when given a full year number with a leading sign, it parses the full year number,
 * so "+1850" becomes 1850.
 */


public fun monthNumber ( padding : Padding = Padding . ZERO )

/**
 * A month-of-year number, from 1 to 12.
 *
 * By default, it's padded with zeros to two digits. This can be changed by passing [padding].
 */


public fun monthName ( names : MonthNames )

/**
 * A month name (for example, "January").
 *
 * Example:
 * ```
 * monthName(MonthNames.ENGLISH_FULL)
 * ```
 */


public fun dayOfMonth ( padding : Padding = Padding . ZERO )

/**
 * A day-of-month number, from 1 to 31.
 *
 * By default, it's padded with zeros to two digits. This can be changed by passing [padding].
 */


public fun dayOfWeek ( names : DayOfWeekNames )

/**
 * A day-of-week name (for example, "Thursday").
 *
 * Example:
 * ```
 * dayOfWeek(DayOfWeekNames.ENGLISH_FULL)
 * ```
 */


public fun date ( format : DateTimeFormat < LocalDate > )

/**
 * An existing [DateTimeFormat] for the date part.
 *
 * Example:
 * ```
 * date(LocalDate.Formats.ISO)
 * ```
 */


public fun hour ( padding : Padding = Padding . ZERO )

/**
 * The hour of the day, from 0 to 23.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 */


public fun amPmHour ( padding : Padding = Padding . ZERO )

/**
 * The hour of the day in the 12-hour clock:
 *
 * * Midnight is 12,
 * * Hours 1-11 are 1-11,
 * * Noon is 12,
 * * Hours 13-23 are 1-11.
 *
 * To disambiguate between the first and the second halves of the day, [amPmMarker] should be used.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 *
 * @see [amPmMarker]
 */


public fun amPmMarker ( am : String , pm : String )

/**
 * The AM/PM marker, using the specified strings.
 *
 * [am] is used for the AM marker (0-11 hours), [pm] is used for the PM marker (12-23 hours).
 *
 * @see [amPmHour]
 */


public fun minute ( padding : Padding = Padding . ZERO )

/**
 * The minute of hour.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 */


public fun second ( padding : Padding = Padding . ZERO )

/**
 * The second of minute.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 */


public fun secondFraction ( minLength : Int = <NUM_LIT:1> , maxLength : Int = <NUM_LIT:9> )

/**
 * The fractional part of the second without the leading dot.
 *
 * When formatting, the decimal fraction will be rounded to fit in the specified [maxLength] and will add
 * trailing zeroes to the specified [minLength].
 * Rounding is performed using the round-toward-zero rounding mode.
 *
 * When parsing, the parser will require that the fraction is at least [minLength] and at most [maxLength]
 * digits long.
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 *
 * See also the [secondFraction] overload that accepts just one parameter, the exact length of the fractional
 * part.
 *
 * @throws IllegalArgumentException if [minLength] is greater than [maxLength] or if either is not in the range 1..9.
 */


public fun secondFraction ( fixedLength : Int )

{ <EOL> secondFraction ( fixedLength , fixedLength ) <EOL> }

/**
 * The fractional part of the second without the leading dot.
 *
 * When formatting, the decimal fraction will add trailing zeroes or be rounded as necessary to always output
 * exactly the number of digits specified in [fixedLength].
 * Rounding is performed using the round-toward-zero rounding mode.
 *
 * When parsing, exactly [fixedLength] digits will be consumed.
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 *
 * See also the [secondFraction] overload that accepts two parameters, the minimum and maximum length of the
 * fractional part.
 *
 * @throws IllegalArgumentException if [fixedLength] is not in the range 1..9.
 *
 * @see secondFraction that accepts two parameters.
 */


public fun time ( format : DateTimeFormat < LocalTime > )

/**
 * An existing [DateTimeFormat] for the time part.
 *
 * Example:
 * ```
 * time(LocalTime.Formats.ISO)
 * ```
 */


public fun dateTime ( format : DateTimeFormat < LocalDateTime > )

/**
 * An existing [DateTimeFormat] for the date-time part.
 *
 * Example:
 * ```
 * dateTime(LocalDateTime.Formats.ISO)
 * ```
 */


public fun offsetHours ( padding : Padding = Padding . ZERO )

/**
 * The total number of hours in the UTC offset, including the sign.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 */


public fun offsetMinutesOfHour ( padding : Padding = Padding . ZERO )

/**
 * The minute-of-hour of the UTC offset.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 */


public fun offsetSecondsOfMinute ( padding : Padding = Padding . ZERO )

/**
 * The second-of-minute of the UTC offset.
 *
 * By default, it's zero-padded to two digits, but this can be changed with [padding].
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 */


public fun offset ( format : DateTimeFormat < UtcOffset > )

/**
 * An existing [DateTimeFormat] for the UTC offset part.
 *
 * Example:
 * ```
 * offset(UtcOffset.Formats.FOUR_DIGITS)
 * ```
 */


public fun timeZoneId ( )

/**
 * The IANA time zone identifier, for example, "Europe/Berlin".
 *
 * When formatting, the timezone identifier is supplied as is, without any validation.
 * On parsing, [TimeZone.availableZoneIds] is used to validate the identifier.
 */


public fun dateTimeComponents ( format : DateTimeFormat < DateTimeComponents > )

/**
 * An existing [DateTimeFormat].
 *
 * Example:
 * ```
 * dateTimeComponents(DateTimeComponents.Formats.RFC_1123)
 * ```
 */


internal fun DateTimeFormatBuilder . WithTime . secondFractionInternal ( minLength : Int , maxLength : Int , grouping : List < Int > )

{ <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> when ( this ) { <EOL> is AbstractWithTimeBuilder -> addFormatStructureForTime ( BasicFormatStructure ( FractionalSecondDirective ( minLength , maxLength , grouping ) ) ) <EOL> } <EOL> }

/**
 * The fractional part of the second without the leading dot.
 *
 * When formatting, the decimal fraction will round the number to fit in the specified [maxLength] and will add
 * trailing zeroes to the specified [minLength].
 *
 * Additionally, [grouping] is a list, where the i'th (1-based) element specifies how many trailing zeros to add during
 * formatting when the number would have i digits.
 *
 * When parsing, the parser will require that the fraction is at least [minLength] and at most [maxLength]
 * digits long.
 *
 * This field has the default value of 0. If you want to omit it, use [optional].
 *
 * @throws IllegalArgumentException if [minLength] is greater than [maxLength] or if either is not in the range 1..9.
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> public fun < T : DateTimeFormatBuilder > T . alternativeParsing ( vararg alternativeFormats : T . ( ) -> Unit , primaryFormat : T . ( ) -> Unit ) : Unit

= when ( this ) { <EOL> is AbstractDateTimeFormatBuilder < * , * > -> <EOL> appendAlternativeParsingImpl ( * alternativeFormats as Array < out AbstractDateTimeFormatBuilder < * , * > . ( ) -> Unit > , mainFormat = primaryFormat as ( AbstractDateTimeFormatBuilder < * , * > . ( ) -> Unit ) ) <EOL> else -> throw IllegalStateException ( "<STR_LIT>" ) <EOL> }

/**
 * A format along with other ways to parse the same portion of the value.
 *
 * When parsing, first, [primaryFormat] is used; if parsing the whole string fails using that, the formats
 * from [alternativeFormats] are tried in order.
 *
 * When formatting, the [primaryFormat] is used to format the value, and [alternativeFormats] are ignored.
 *
 * Example:
 * ```
 * alternativeParsing(
 * { dayOfMonth(); char('-'); monthNumber() },
 * { monthNumber(); char(' '); dayOfMonth() },
 * ) { monthNumber(); char('/'); dayOfMonth() }
 * ```
 *
 * This will always format a date as `MM/DD`, but will also accept `DD-MM` and `MM DD`.
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> public fun < T : DateTimeFormatBuilder > T . optional ( ifZero : String = "<STR_LIT>" , format : T . ( ) -> Unit ) : Unit

= when ( this ) { <EOL> is AbstractDateTimeFormatBuilder < * , * > -> appendOptionalImpl ( onZero = ifZero , format as ( AbstractDateTimeFormatBuilder < * , * > . ( ) -> Unit ) ) <EOL> else -> throw IllegalStateException ( "<STR_LIT>" ) <EOL> }

/**
 * An optional section.
 *
 * When formatting, the section is formatted if the value of any field in the block is not equal to the default value.
 * Only [optional] calls where all the fields have default values are permitted.
 *
 * Example:
 * ```
 * offsetHours(); char(':'); offsetMinutesOfHour()
 * optional { char(':'); offsetSecondsOfMinute() }
 * ```
 *
 * Here, because seconds have the default value of zero, they are formatted only if they are not equal to zero, so the
 * UTC offset `+18:30:00` gets formatted as `"+18:30"`, but `+18:30:01` becomes `"+18:30:01"`.
 *
 * When parsing, either [format] or, if that fails, the literal [ifZero] are parsed. If the [ifZero] string is parsed,
 * the values in [format] get assigned their default values.
 *
 * [ifZero] defines the string that is used if values are the default ones.
 *
 * @throws IllegalArgumentException if not all fields used in [format] have a default value.
 */


public fun DateTimeFormatBuilder . char ( value : Char ) : Unit

= chars ( value . toString ( ) )

/**
 * A literal character.
 *
 * This is a shorthand for `chars(value.toString())`.
 */


private fun < T : DoubleColonLHS > tryResolveLHS ( doubleColonExpression : FirCallableReferenceAccess , criterion : ( FirCallableReferenceAccess ) -> Boolean , resolve : ( FirExpression ) -> T ? <EOL> ) : T ?

{ <EOL> val expression = doubleColonExpression . explicitReceiver ? : return null <EOL> if ( ! criterion ( doubleColonExpression ) ) return null <EOL> return resolve ( expression ) <EOL> }

/**
 * Returns null if the LHS is definitely not an expression. Returns a non-null result if a resolution was attempted and led to
 * either a successful result or not.
 */


fun getElement ( element : @ UnsafeVariance E ) : E ?

/**
 * Searches for the specified element in this set.
 *
 * @return the element from the set equal to [element], or `null` if no such element found.
 */


protected abstract fun applyImpl ( data : FloatArray , shape : TensorShape ) : FloatArray

/**
 * Actual implementation of the [Operation] that should be applied to the [data].
 */


@ ExperimentalSerializationApi <EOL> public fun decodeStringChunked ( consumeChunk : ( chunk : String ) -> Unit )

/**
 * Method allows decoding a string value by fixed-size chunks.
 * Usable for handling very large strings that may not fit in memory.
 * Chunk size is guaranteed to not exceed 16384 chars (but it may be smaller than that).
 * Feeds string chunks to the provided consumer.
 *
 * @param consumeChunk - lambda function to handle string chunks
 *
 * Example usage:
 * ```
 * @Serializable(with = LargeStringSerializer::class)
 * data class LargeStringData(val largeString: String)
 *
 * @Serializable
 * data class ClassWithLargeStringDataField(val largeStringField: LargeStringData)
 *
 * object LargeStringSerializer : KSerializer<LargeStringData> {
 * override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("LargeStringContent", PrimitiveKind.STRING)
 *
 * override fun deserialize(decoder: Decoder): LargeStringData {
 * require(decoder is ChunkedDecoder) { "Only chunked decoder supported" }
 *
 * val tmpFile = createTempFile()
 * val writer = FileWriter(tmpFile.toFile()).use {
 * decoder.decodeStringChunked { chunk ->
 * writer.append(chunk)
 * }
 * }
 * return LargeStringData("file://${tmpFile.absolutePathString()}")
 * }
 * }
 * ```
 *
 * In this sample, we need to be able to handle a huge string coming from json. Instead of storing it in memory,
 * we offload it into a file and return the file name instead
 */


internal fun DClass . classlikesInJava ( ) : List < DClasslike >

{ <EOL> val classlikes = classlikes <EOL> . filter { it . name != companion ? . name } <EOL> . map { it . asJava ( ) } <EOL> val companionAsJava = companion ? . companionAsJava ( ) <EOL> return if ( companionAsJava != null ) classlikes . plus ( companionAsJava ) else classlikes <EOL> }

/**
 * Companion objects requires some custom logic for rendering as Java.
 * They are excluded from usual classlikes rendering and added after.
 */


internal fun DObject . asJava ( excludedProps : List < DProperty > = emptyList ( ) , excludedFunctions : List < DFunction > = emptyList ( ) ) : DObject

= copy ( functions = functions . plus ( properties . filterNot { it in excludedProps } . filter { ! it . isJvmField && ! it . isConst && ! it . isLateInit && ! it . hasJvmSynthetic ( ) } . flatMap { listOf ( it . getter , it . setter ) } ) . filterNotNull ( ) . filterNot { it in excludedFunctions } . filterNot { it . hasJvmSynthetic ( ) } . flatMap { it . asJava ( dri . classNames ? : name . orEmpty ( ) ) } , properties = properties . filterNot { it . hasJvmSynthetic ( ) } . filterNot { it in excludedProps } . map { it . asJava ( isFromObjectOrCompanion = true ) } + DProperty ( name = OBJECT_INSTANCE_NAME , modifier = sourceSets . associateWith { JavaModifier . Final } , dri = dri . copy ( callable = Callable ( OBJECT_INSTANCE_NAME , null , emptyList ( ) ) ) , documentation = emptyMap ( ) , sources = emptyMap ( ) , visibility = sourceSets . associateWith { <EOL> JavaVisibility . Public <EOL> } , type = GenericTypeConstructor ( dri , emptyList ( ) ) , setter = null , getter = null , sourceSets = sourceSets , receiver = null , generics = emptyList ( ) , expectPresentInSet = expectPresentInSet , isExpectActual = false , extra = PropertyContainer . withAll ( sourceSets . map { <EOL> mapOf ( it to setOf ( ExtraModifiers . JavaOnlyModifiers . Static ) ) . toAdditionalModifiers ( ) <EOL> } ) ) , classlikes = classlikes . map { it . asJava ( ) } , supertypes = supertypes . mapValues { it . value . map { it . asJava ( ) } } )

/**
 * Parameters [excludedProps] and [excludedFunctions] used for rendering companion objects
 * where some members (that lifted to outer class) are not rendered
 */


public fun recursivePrintGroupInHDF5File ( hdfFile : HdfFile , group : Group )

{ <EOL> for ( node in group ) { <EOL> println ( "<STR_LIT>" + node . name ) <EOL> for ( ( key , value ) in node . attributes ) { <EOL> println ( "<STR_LIT>" ) <EOL> if ( value . isScalar ) { <EOL> println ( "<STR_LIT>" + value . data . toString ( ) ) <EOL> } else if ( value . data is Array < * > ) { <EOL> for ( i in <NUM_LIT:0> until value . size . toInt ( ) ) <EOL> println ( "<STR_LIT>" + ( value . data as Array < * > ) [ i ] . toString ( ) ) <EOL> } <EOL> } <EOL> if ( node is Group ) { <EOL> recursivePrintGroupInHDF5File ( hdfFile , node ) <EOL> } else { <EOL> println ( "<STR_LIT>" + node . path ) <EOL> val dataset = hdfFile . getDatasetByPath ( node . path ) <EOL> val dims = arrayOf ( dataset . dimensions ) <EOL> println ( "<STR_LIT>" + dims . contentDeepToString ( ) ) <EOL> } <EOL> } <EOL> }

/**
 * Helper function to print out file in hdf5 format for debugging purposes.
 */


public fun encodeJsonElement ( element : JsonElement )

/**
 * Appends the given JSON [element] to the current output.
 * This method is allowed to invoke only as the part of the whole serialization process of the class,
 * calling this method after invoking [beginStructure] or any `encode*` method will lead to unspecified behaviour
 * and may produce an invalid JSON result.
 * For example:
 * ```
 * class Holder(val value: Int, val list: List<Int>())
 *
 * // Holder serialize method
 * fun serialize(encoder: Encoder, value: Holder) {
 * // Completely okay, the whole Holder object is read
 * val jsonObject = JsonObject(...) // build a JsonObject from Holder
 * (encoder as JsonEncoder).encodeJsonElement(jsonObject) // Write it
 * }
 *
 * // Incorrect Holder serialize method
 * fun serialize(encoder: Encoder, value: Holder) {
 * val composite = encoder.beginStructure(descriptor)
 * composite.encodeSerializableElement(descriptor, 0, Int.serializer(), value.value)
 * val array = JsonArray(value.list)
 * // Incorrect, encoder is already in an intermediate state after encodeSerializableElement
 * (composite as JsonEncoder).encodeJsonElement(array)
 * composite.endStructure(descriptor)
 * // ...
 * }
 * ```
 */


@ Test <EOL> @ TodoAnalysisApi <EOL> fun `test - stringBuilder` ( )

{ <EOL> doTest ( dependenciesDir . resolve ( "<STR_LIT>" ) ) <EOL> }

/**
 * - Missing implementation of mangling
 */


@ Test <EOL> fun `test - exportedAndNotExportedDependency` ( )

{ <EOL> doTest ( dependenciesDir . resolve ( "<STR_LIT>" ) , configuration = HeaderGenerator . Configuration ( frameworkName = "<STR_LIT>" , withObjCBaseDeclarationStubs = true , dependencies = listOf ( testLibraryAKlibFile , testLibraryBKlibFile ) , exportedDependencies = setOf ( testLibraryAKlibFile ) ) ) <EOL> }

/**
 * https://youtrack.jetbrains.com/issue/KT-65327/Support-reading-klib-contents-in-Analysis-API
 * Requires being able to use AA to iterate over symbols to 'export' the dependency
 */


private fun fullMergeControlFlowEdge ( dest : Int , frame : F , canReuse : Boolean = false )

{ <EOL> val oldFrame = frames [ dest ] <EOL> val changes = when { <EOL> canReuse && ! isMergeNode [ dest ] -> { <EOL> frames [ dest ] = frame <EOL> true <EOL> } <EOL> oldFrame == null -> { <EOL> frames [ dest ] = newFrame ( frame . locals , frame . maxStackSize ) . apply { init ( frame ) } <EOL> true <EOL> } <EOL> ! isMergeNode [ dest ] -> { <EOL> oldFrame . init ( frame ) <EOL> true <EOL> } <EOL> else -> try { <EOL> oldFrame . merge ( frame , interpreter ) <EOL> } catch ( e : AnalyzerException ) { <EOL> throw AnalyzerException ( null , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> updateQueue ( changes , dest ) <EOL> }

/**
 * Updates frame at the index [dest] with its old value if provided and previous control flow node frame [frame].
 * Reuses old frame when possible and when [canReuse] is true.
 * If updated, adds the frame to the queue
 */


private fun FirSimpleFunction . isPlatformOverriddenFunction ( session : FirSession , baseDeclaration : FirSimpleFunction ) : Boolean ?

{ <EOL> if ( this . name != baseDeclaration . name ) { <EOL> return null <EOL> } <EOL> val superInfo = baseDeclaration . symbol . decodeObjCMethodAnnotation ( session ) ? : return null <EOL> val subInfo = symbol . decodeObjCMethodAnnotation ( session ) <EOL> return if ( subInfo != null ) { <EOL> superInfo . selector == subInfo . selector <EOL> } else { <EOL> if ( ! parameterNamesMatch ( this , baseDeclaration ) ) false else null <EOL> } <EOL> }

/**
 * mimics ObjCOverridabilityCondition.isOverridable
 */


private fun parameterNamesMatch ( first : FirSimpleFunction , second : FirSimpleFunction ) : Boolean

{ <EOL> if ( first . valueParameters . size != second . valueParameters . size ) { <EOL> return false <EOL> } <EOL> first . valueParameters . forEachIndexed { index , parameter -> <EOL> if ( index > <NUM_LIT:0> && parameter . name != second . valueParameters [ index ] . name ) { <EOL> return false <EOL> } <EOL> } <EOL> return true <EOL> }

/**
 * mimics ObjCInteropKt.parameterNamesMatch
 */