protected fun generateExtensionProperties ( marker : IsolatedMarker , withNullable : Boolean = true ) : Code

{ <EOL> val markerName = marker . name <EOL> val markerType = "<STR_LIT>" <EOL> val visibility = renderTopLevelDeclarationVisibility ( marker ) <EOL> val shortMarkerName = markerName . substring ( markerName . lastIndexOf ( '<CHAR_LIT:.>' ) + <NUM_LIT:1> ) . removeQuotes ( ) <EOL> val nullableShortMarkerName = "<STR_LIT>" <EOL> fun String . toNullable ( ) = if ( this . last ( ) == '<CHAR_LIT>' || this == "<STR_LIT:*>" ) this else "<STR_LIT>" <EOL> val declarations = mutableListOf < String > ( ) <EOL> val dfTypename = renderColumnsContainerTypeName ( markerType ) <EOL> val nullableDfTypename = renderColumnsContainerTypeName ( markerType . toNullable ( ) ) <EOL> val rowTypename = renderRowTypeName ( markerType ) <EOL> val nullableRowTypename = renderRowTypeName ( markerType . toNullable ( ) ) <EOL> val nullableFields = marker . fields . map { <EOL> it . toNullable ( ) <EOL> } . associateBy { it . columnName } <EOL> marker . fields . sortedBy { it . fieldName . quotedIfNeeded } . forEach { <EOL> val getter = "<STR_LIT>" <EOL> val name = it . fieldName <EOL> val fieldType = it . renderAccessorFieldType ( ) <EOL> val nullableFieldType = nullableFields [ it . columnName ] ! ! . renderAccessorFieldType ( ) <EOL> val columnType = it . renderColumnType ( ) <EOL> val nullableColumnType = nullableFields [ it . columnName ] ! ! . renderColumnType ( ) <EOL> declarations . addAll ( listOf ( generatePropertyCode ( marker = marker , shortMarkerName = shortMarkerName , typeName = dfTypename , name = name . quotedIfNeeded , propertyType = columnType , getter = getter , visibility = visibility , ) , generatePropertyCode ( marker = marker , shortMarkerName = shortMarkerName , typeName = rowTypename , name = name . quotedIfNeeded , propertyType = fieldType , getter = getter , visibility = visibility , ) ) ) <EOL> if ( withNullable ) { <EOL> declarations . addAll ( listOf ( generatePropertyCode ( marker = marker , shortMarkerName = nullableShortMarkerName , typeName = nullableDfTypename , name = name . quotedIfNeeded , propertyType = nullableColumnType , getter = getter , visibility = visibility , ) , generatePropertyCode ( marker = marker , shortMarkerName = nullableShortMarkerName , typeName = nullableRowTypename , name = name . quotedIfNeeded , propertyType = nullableFieldType , getter = getter , visibility = visibility , ) ) ) <EOL> } <EOL> } <EOL> return declarations . joinToString ( "<STR_LIT:\n>" ) <EOL> }

/**
 * nullable properties can be needed when *DECLARED* schema is referenced with nullability:
 * ```
 * @DataSchema
 * data class Schema(val i: Int)
 *
 * @DataSchema
 * data class A(
 * val prop: Schema?
 * )
 * ```
 * When converted `listOf<A>().toDataFrame(maxDepth=2)` actual schema is
 * ```
 * prop:
 * i: Int?
 * ```
 * So this sudden `i: Int?` must be somehow handled.
 * However, REPL code generator will not create such a situation. Nullable properties are not needed then
 */


@ SinceKotlin ( "<STR_LIT:1.5>" ) <EOL> public actual fun Char . isISOControl ( ) : Boolean

{ <EOL> return this <= '<CHAR_LIT>' || this in '<CHAR_LIT>' .. '<CHAR_LIT>' <EOL> }

/**
 * Returns `true` if this character is an ISO control character.
 *
 * A character is considered to be an ISO control character if its [category] is [CharCategory.CONTROL].
 *
 * @sample samples.text.Chars.isISOControl
 */


public actual fun Char . isHighSurrogate ( ) : Boolean

= this in Char . MIN_HIGH_SURROGATE .. Char . MAX_HIGH_SURROGATE

/**
 * Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
 */


public actual fun Char . isLowSurrogate ( ) : Boolean

= this in Char . MIN_LOW_SURROGATE .. Char . MAX_LOW_SURROGATE

/**
 * Returns `true` if this character is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit).
 */


internal fun Char . Companion . toCodePoint ( high : Char , low : Char ) : Int

= <EOL> ( ( ( high - MIN_HIGH_SURROGATE ) shl <NUM_LIT:10> ) or ( low - MIN_LOW_SURROGATE ) ) + <NUM_LIT>

/** Converts a surrogate pair to a unicode code point. Doesn't validate that the characters are a valid surrogate pair. */


internal fun Char . Companion . isSupplementaryCodePoint ( codepoint : Int ) : Boolean

= <EOL> codepoint in MIN_SUPPLEMENTARY_CODE_POINT .. MAX_CODE_POINT

/** Checks if the codepoint specified is a supplementary codepoint or not. */


@ Suppress ( "<STR_LIT:DEPRECATION>" ) <EOL> internal fun Char . Companion . toChars ( codePoint : Int ) : CharArray

= <EOL> when { <EOL> codePoint in <NUM_LIT:0> until MIN_SUPPLEMENTARY_CODE_POINT -> charArrayOf ( codePoint . toChar ( ) ) <EOL> codePoint in MIN_SUPPLEMENTARY_CODE_POINT .. MAX_CODE_POINT -> { <EOL> val low = ( ( codePoint - <NUM_LIT> ) and <NUM_LIT> ) + MIN_LOW_SURROGATE . toInt ( ) <EOL> val high = ( ( ( codePoint - <NUM_LIT> ) ushr <NUM_LIT:10> ) and <NUM_LIT> ) + MIN_HIGH_SURROGATE . toInt ( ) <EOL> charArrayOf ( high . toChar ( ) , low . toChar ( ) ) <EOL> } <EOL> else -> throw IllegalArgumentException ( ) <EOL> }

/**
 * Converts the codepoint specified to a char array. If the codepoint is not supplementary, the method will
 * return an array with one element otherwise it will return an array A with a high surrogate in A[0] and
 * a low surrogate in A[1].
 */


infix fun BuildResult ? . shouldHaveRunTask ( taskPath : String ) : BuildTask

{ <EOL> this should haveTask ( taskPath ) <EOL> return this ? . task ( taskPath ) ! ! <EOL> }


fun BuildResult ? . shouldHaveRunTask ( taskPath : String , expectedOutcome : TaskOutcome ) : BuildTask

{ <EOL> this should haveTask ( taskPath ) <EOL> val task = this ? . task ( taskPath ) ! ! <EOL> task should haveOutcome ( expectedOutcome ) <EOL> return task <EOL> }

/** Assert that a task ran, with an [expected outcome][expectedOutcome]. */


infix fun BuildResult ? . shouldNotHaveRunTask ( taskPath : String )

{ <EOL> this shouldNot haveTask ( taskPath ) <EOL> }

/**
 * Assert that a task did not run.
 *
 * A task might not have run if one of its dependencies failed before it could be run.
 */


public fun put ( key : K , value : @ UnsafeVariance V ) : PersistentMap < K , V >

/**
 * Returns the result of associating the specified [value] with the specified [key] in this map.
 *
 * If this map already contains a mapping for the key, the old value is replaced by the specified value.
 *
 * @return a new persistent map with the specified [value] associated with the specified [key];
 * or this instance if no modifications were made in the result of this operation.
 */


public fun remove ( key : K ) : PersistentMap < K , V >

/**
 * Returns the result of removing the specified [key] and its corresponding value from this map.
 *
 * @return a new persistent map with the specified [key] and its corresponding value removed;
 * or this instance if it contains no mapping for the key.
 */


public fun remove ( key : K , value : @ UnsafeVariance V ) : PersistentMap < K , V >

/**
 * Returns the result of removing the entry that maps the specified [key] to the specified [value].
 *
 * @return a new persistent map with the entry for the specified [key] and [value] removed;
 * or this instance if it contains no entry with the specified key and value.
 */


public fun putAll ( m : Map < out K , @ UnsafeVariance V > ) : PersistentMap < K , V >

/**
 * Returns the result of merging the specified [m] map with this map.
 *
 * The effect of this call is equivalent to that of calling `put(k, v)` once for each
 * mapping from key `k` to value `v` in the specified map.
 *
 * @return a new persistent map with keys and values from the specified map [m] associated;
 * or this instance if no modifications were made in the result of this operation.
 */


public fun clear ( ) : PersistentMap < K , V >

/**
 * Returns an empty persistent map.
 */


public fun build ( ) : PersistentMap < K , V >

/**
 * Returns a persistent map with the same contents as this builder.
 *
 * This method can be called multiple times.
 *
 * If operations applied on this builder have caused no modifications:
 * - on the first call it returns the same persistent map instance this builder was obtained from.
 * - on subsequent calls it returns the same previously returned persistent map instance.
 */


public fun builder ( ) : Builder < K , @ UnsafeVariance V >

/**
 * Returns a new builder with the same contents as this map.
 *
 * The builder can be used to efficiently perform multiple modification operations.
 */


public inline fun < reified T : Number > Multik . rand ( dim0 : Int ) : D1Array < T >

{ <EOL> require ( dim0 > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val frand : ( ) -> T = fRand ( dtype ) <EOL> val data = initMemoryView ( dim0 , dtype ) { frand ( ) } <EOL> return D1Array ( data , shape = intArrayOf ( dim0 ) , dim = D1 ) <EOL> }

/**
 * Returns a vector of the specified size filled with random numbers uniformly distributed for:
 * Int - [Int.MIN_VALUE, Int.MAX_VALUE)
 * Long - [Long.MIN_VALUE, Long.MAX_VALUE)
 * Float - [0f, 1f)
 * Double - [0.0, 1.0)
 */


public inline fun < reified T : Number > Multik . rand ( dim0 : Int , dim1 : Int ) : D2Array < T >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val shape = intArrayOf ( dim0 , dim1 ) <EOL> for ( i in shape . indices ) { <EOL> require ( shape [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val frand : ( ) -> T = fRand ( dtype ) <EOL> val data = initMemoryView ( dim0 * dim1 , dtype ) { frand ( ) } <EOL> return D2Array ( data , shape = shape , dim = D2 ) <EOL> }

/**
 * Returns a matrix of the specified shape filled with random numbers uniformly distributed for:
 * Int - [Int.MIN_VALUE, Int.MAX_VALUE)
 * Long - [Long.MIN_VALUE, Long.MAX_VALUE)
 * Float - [0f, 1f)
 * Double - [0.0, 1.0)
 */


public inline fun < reified T : Number > Multik . rand ( dim0 : Int , dim1 : Int , dim2 : Int ) : D3Array < T >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val shape = intArrayOf ( dim0 , dim1 , dim2 ) <EOL> for ( i in shape . indices ) { <EOL> require ( shape [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val frand : ( ) -> T = fRand ( dtype ) <EOL> val data = initMemoryView ( dim0 * dim1 * dim2 , dtype ) { frand ( ) } <EOL> return D3Array ( data , shape = shape , dim = D3 ) <EOL> }

/**
 * Returns an NDArray of the specified shape filled with random numbers uniformly distributed for:
 * Int - [Int.MIN_VALUE, Int.MAX_VALUE)
 * Long - [Long.MIN_VALUE, Long.MAX_VALUE)
 * Float - [0f, 1f)
 * Double - [0.0, 1.0)
 */


public inline fun < reified T : Number > Multik . rand ( dim0 : Int , dim1 : Int , dim2 : Int , dim3 : Int ) : D4Array < T >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val shape = intArrayOf ( dim0 , dim1 , dim2 , dim3 ) <EOL> for ( i in shape . indices ) { <EOL> require ( shape [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val frand : ( ) -> T = fRand ( dtype ) <EOL> val data = initMemoryView ( dim0 * dim1 * dim2 * dim3 , dtype ) { frand ( ) } <EOL> return D4Array ( data , shape = shape , dim = D4 ) <EOL> }


public inline fun < reified T : Number > Multik . rand ( dim0 : Int , dim1 : Int , dim2 : Int , dim3 : Int , vararg dims : Int ) : NDArray < T , DN >

{ <EOL> return rand ( intArrayOf ( dim0 , dim1 , dim2 , dim3 , * dims ) ) <EOL> }


public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( shape : IntArray ) : NDArray < T , D >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val dim = dimensionClassOf < D > ( shape . size ) <EOL> requireDimension ( dim , shape . size ) <EOL> for ( i in shape . indices ) { <EOL> require ( shape [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val size = shape . fold ( <NUM_LIT:1> , Int :: times ) <EOL> val frand : ( ) -> T = fRand ( dtype ) <EOL> val data = initMemoryView ( size , dtype ) { frand ( ) } <EOL> return NDArray ( data , shape = shape , dim = dim ) <EOL> }


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( from : T , until : T , vararg dims : Int ) : NDArray < T , D >

= <EOL> Multik . rand ( from , until , dims )

/**
 * Returns an NDArray of the specified shape filled with number uniformly distributed between [[from], [until])
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( from : T , until : T , dims : IntArray ) : NDArray < T , D >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val dim = dimensionClassOf < D > ( dims . size ) <EOL> requireDimension ( dim , dims . size ) <EOL> for ( i in dims . indices ) { <EOL> require ( dims [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val size = dims . fold ( <NUM_LIT:1> , Int :: times ) <EOL> val data = randData ( from , until , size , dtype ) <EOL> return NDArray ( data , shape = dims , dim = dim ) <EOL> }

/**
 * Returns an NDArray of the specified shape filled with number uniformly distributed between [[from], [until])
 *
 * Note: Float generation is inefficient.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( seed : Int , from : T , until : T , vararg dims : Int ) : NDArray < T , D >

= Multik . rand ( Random ( seed ) , from , until , dims )

/**
 * Returns an NDArray of the specified shape filled with number uniformly distributed between [[from], [until])
 * with the specified [seed].
 *
 * Note: Float generation is inefficient.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( seed : Int , from : T , until : T , dims : IntArray ) : NDArray < T , D >


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( gen : Random , from : T , until : T , vararg dims : Int ) : NDArray < T , D >

= Multik . rand ( gen , from , until , dims )

/**
 * Returns an NDArray of the specified shape filled with number uniformly distributed between [[from], [until])
 * with the specified [gen].
 *
 * Note: Float generation is inefficient.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < reified T : Number , reified D : Dimension > Multik . rand ( gen : Random , from : T , until : T , dims : IntArray ) : NDArray < T , D >

{ <EOL> val dtype = DataType . ofKClass ( T :: class ) <EOL> val dim = dimensionClassOf < D > ( dims . size ) <EOL> requireDimension ( dim , dims . size ) <EOL> for ( i in dims . indices ) { <EOL> require ( dims [ i ] > <NUM_LIT:0> ) { "<STR_LIT>" } <EOL> } <EOL> val size = dims . fold ( <NUM_LIT:1> , Int :: times ) <EOL> val data = randData ( from , until , size , dtype , gen ) <EOL> return NDArray ( data , shape = dims , dim = dim ) <EOL> }


fun declaredSchemaOf ( type : Type ) : Scheme

/**
 * Given a type, return the declared scheme for the type.
 */


fun currentInferredSchemeOf ( type : Type ) : Scheme ?

/**
 * Given a type, return the last updated scheme. This is used to reduce the number of times
 * that [updatedInferredScheme] is called. Returning `null` will prevent
 * [updatedInferredScheme] from being called at all (for example, from the front-end which
 * ignores updates). If not caching to prevent [updatedInferredScheme] from being called too
 * often, return [declaredSchemaOf] instead. This will then call [updatedInferredScheme]
 * whenever it is different from what was declared.
 */


fun updatedInferredScheme ( type : Type , scheme : Scheme )

/**
 * Called when the inferencer determines
 */


fun containerOf ( node : Node ) : Node

/**
 * Return the container of the node. A container is the function or lambda the node is part of.
 */


fun kindOf ( node : Node ) : NodeKind

/**
 * Return the kind of the node that allows the node to be treated correctly by the inferencer.
 */


fun schemeParameterIndexOf ( node : Node , container : Node ) : Int

/**
 * Return which parameter index this parameter references. The [node] passed in will only be
 * one for [kindOf] returns [NodeKind.ParameterReference].
 *
 * For parameter nodes the inferencer needs to determine which parameter of the scheme of the
 * node is being referenced to allow the scheme determined for the usage of the parameter to
 * infer the scheme of the parameter.
 */


fun typeOf ( node : Node ) : Type ?

/**
 * Return an instance of type where [Type] is the type passed to the [TypeAdapter] of the
 * inferencer.
 */


fun referencedContainerOf ( node : Node ) : Node ?

/**
 * When [node] is the target of a call this should return the container (e.g. the function or
 * lambda) being called. Otherwise, return `null`.
 */


fun getLazyScheme ( node : Node ) : LazyScheme ?

/**
 * Retrieve a lazy scheme from the store (such as a mutableMapOf<Node, LazyScheme>().
 */


fun storeLazyScheme ( node : Node , value : LazyScheme )

/**
 * Store the lazy scheme [value] for [node].
 */


fun reportCallError ( node : Node , expected : String , received : String )

/**
 * Report a call node applier is not correct.
 */


fun reportParameterError ( node : Node , index : Int , expected : String , received : String )

/**
 * Report that the value or lambda passed to a parameter to a call was not correct.
 */


fun log ( node : Node ? , message : String )

/**
 * Log internal errors detected that indicate problems in the inference algorithm or when the
 * adapters violate an internal constraint such as the schemes are not the same shape for the
 * target of a call.
 */


private fun Bindings . unify ( call : Node ? , a : CallBindings , b : CallBindings ) : Boolean

{ <EOL> if ( ! unify ( a . target , b . target ) ) { <EOL> if ( call != null ) { <EOL> val aName = a . target . safeToken <EOL> val bName = b . target . safeToken <EOL> errorReporter . reportCallError ( call , aName , bName ) <EOL> } <EOL> return false <EOL> } <EOL> val count = if ( a . parameters . size != b . parameters . size ) { <EOL> if ( call != null ) <EOL> errorReporter . log ( call , "<STR_LIT>" ) <EOL> if ( a . parameters . size > b . parameters . size ) b . parameters . size else a . parameters . size <EOL> } else a . parameters . size <EOL> for ( i in <NUM_LIT:0> until count ) { <EOL> val ap = a . parameters [ i ] <EOL> val bp = b . parameters [ i ] <EOL> if ( ! unify ( null , ap , bp ) ) { <EOL> if ( call != null ) { <EOL> val aToken = ap . target . token <EOL> val bToken = bp . target . token <EOL> if ( aToken != null && bToken != null ) { <EOL> errorReporter . reportParameterError ( call , i , bp . target . token ! ! , ap . target . token ! ! <EOL> ) <EOL> } else unify ( call , ap , bp ) <EOL> } <EOL> } <EOL> } <EOL> val aResult = a . result <EOL> val bResult = b . result <EOL> if ( aResult != null && bResult != null ) { <EOL> return unify ( null , aResult , bResult ) <EOL> } <EOL> return true <EOL> }

/**
 * Perform structural unification of two call bindings. All bindings that are in the same
 * structural place must unify or there is an error in the source. That is the targets are
 * unified and the parameter call bindings are unified recursively as well as the call
 * binding of the result. If [call] is `null` then the error is reported by the caller
 * instead. For example, failing to unify the parameters of a call binding should be
 * considered a failure to unify the entire binding not just the parameter.
 */


private fun restartable ( node : Node , block : ( Bindings , Binding , ( Node ) -> CallBindings ? <EOL> ) -> Unit ) : Boolean

{ <EOL> if ( node in inProgress ) return false <EOL> inProgress . add ( node ) <EOL> try { <EOL> val container = nodeAdapter . containerOf ( node ) <EOL> val containerLazyScheme = container . toLazyScheme ( ) <EOL> val bindings = containerLazyScheme . bindings <EOL> fun observed ( lazyScheme : LazyScheme ) : LazyScheme { <EOL> if ( lazyScheme . bindings != bindings && ! lazyScheme . closed ) { <EOL> var remove = { } <EOL> val result : ( ) -> Unit = { <EOL> if ( node !in inProgress ) { <EOL> remove ( ) <EOL> pending . add { restartable ( node , block ) } <EOL> } <EOL> } <EOL> remove = lazyScheme . onChange ( result ) <EOL> } <EOL> return lazyScheme <EOL> } <EOL> fun schemeOf ( node : Node ) : Scheme = <EOL> observed ( node . toLazyScheme ( ) ) . toScheme ( ) <EOL> fun callBindingsOf ( node : Node ) : CallBindings ? { <EOL> return when ( nodeAdapter . kindOf ( node ) ) { <EOL> NodeKind . ParameterReference -> { <EOL> val parameterContainer = nodeAdapter . containerOf ( node ) <EOL> val parameterContainerLazyScheme = parameterContainer . toLazyScheme ( ) <EOL> val parameterContainerScheme = <EOL> nodeAdapter . schemeParameterIndexOf ( node , parameterContainer ) <EOL> if ( parameterContainerScheme !in <EOL> parameterContainerLazyScheme . parameters . indices ) { <EOL> return null <EOL> } <EOL> parameterContainerLazyScheme <EOL> . parameters [ parameterContainerScheme ] <EOL> . toCallBindings ( ) <EOL> } <EOL> NodeKind . Lambda , NodeKind . Variable , NodeKind . Expression -> <EOL> observed ( node . toLazyScheme ( bindings ) ) . toCallBindings ( ) <EOL> NodeKind . Function -> { <EOL> schemeOf ( node ) . toCallBindings ( bindings ) <EOL> } <EOL> } <EOL> } <EOL> block ( bindings , containerLazyScheme . target , :: callBindingsOf ) <EOL> if ( pending . isNotEmpty ( ) ) { <EOL> val skipped = mutableListOf < ( ) -> Boolean > ( ) <EOL> while ( pending . isNotEmpty ( ) ) { <EOL> val pendingCall = pending . removeAt ( pending . lastIndex ) <EOL> if ( ! pendingCall ( ) ) skipped . add ( pendingCall ) <EOL> } <EOL> skipped . forEach { pending . add ( it ) } <EOL> } <EOL> } finally { <EOL> inProgress . remove ( node ) <EOL> } <EOL> return true <EOL> }

/**
 * Restart [block] if a [LazyScheme] used to produce a [CallBindings] changes. This also
 * informs the [TypeAdapter] when the inferencer infers a refinement of the scheme for the type
 * of the container of [node].
 */


fun visitVariable ( variable : Node , initializer : Node )

= <EOL> restartable ( variable ) { bindings , _ , callBindingsOf -> <EOL> val initializerBinding = callBindingsOf ( initializer ) ? : return@restartable <EOL> val variableBindings = callBindingsOf ( variable ) ? : return@restartable <EOL> bindings . unify ( variable , variableBindings , initializerBinding ) <EOL> }

/**
 * Infer the scheme of the variable from the scheme of the initializer.
 */


fun visitCall ( call : Node , target : Node , arguments : List < Node > )

= <EOL> restartable ( call ) { bindings , currentApplier , callBindingsOf -> <EOL> val targetCallBindings = callBindingsOf ( target ) ? : run { <EOL> errorReporter . log ( call , "<STR_LIT>" ) <EOL> return@restartable <EOL> } <EOL> val parameters = arguments . map { callBindingsOf ( it ) } <EOL> if ( parameters . any { it == null } ) { <EOL> errorReporter . log ( call , "<STR_LIT>" ) <EOL> return@restartable <EOL> } <EOL> val result = if ( targetCallBindings . result != null ) { <EOL> callBindingsOf ( call ) <EOL> } else null <EOL> val callBinding = CallBindings ( currentApplier , parameters = parameters . filterNotNull ( ) , result , anyParameters = false ) <EOL> bindings . unify ( call , callBinding , targetCallBindings ) <EOL> if ( callBinding . parameters . size == arguments . size ) { <EOL> arguments . forEachIndexed { index , argument -> <EOL> if ( nodeAdapter . kindOf ( argument ) == NodeKind . Lambda ) { <EOL> val parameter = callBinding . parameters [ index ] <EOL> val lambdaTarget = parameter . target <EOL> if ( lambdaTarget . token == null ) { <EOL> bindings . unify ( lambdaTarget , currentApplier ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> for ( ( parameterBinding , argument ) in callBinding . parameters . zip ( arguments ) ) { <EOL> if ( nodeAdapter . kindOf ( argument ) == NodeKind . Lambda && parameterBinding . target . token != null ) { <EOL> val lambdaScheme = argument . toLazyScheme ( ) <EOL> if ( lambdaScheme . target . token == null ) { <EOL> lambdaScheme . bindings . unify ( lambdaScheme . target , parameterBinding . target ) <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Infer the scheme of the container the target and the arguments of the call. This also infers
 * a scheme for the call when it is used as an argument or variable initializer.
 */


= node . toLazyScheme ( ) . toScheme ( )

/**
 * For testing, produce the scheme inferred or the scheme from the declaration.
 */


protected open fun isTargetDeclaration ( declaration : IrDeclaration ) : Boolean

= declaration . isExpect

/**
 * [isTargetDeclaration] can be overridden to customize if an element referring to [declaration] should be transformed. This check
 * precedes [getActualClass], [getActualProperty], and so on.
 */


@ Test <EOL> fun testAwaitCancellation ( )

= runTest { <EOL> expect ( <NUM_LIT:1> ) <EOL> val completable = CompletableSource { s -> <EOL> s . onSubscribe ( object : Disposable { <EOL> override fun dispose ( ) { expect ( <NUM_LIT:4> ) } <EOL> override fun isDisposed ( ) : Boolean { expectUnreached ( ) ; return false } <EOL> } ) <EOL> } <EOL> val job = launch ( start = CoroutineStart . UNDISPATCHED ) { <EOL> try { <EOL> expect ( <NUM_LIT:2> ) <EOL> completable . await ( ) <EOL> } catch ( e : CancellationException ) { <EOL> expect ( <NUM_LIT:5> ) <EOL> throw e <EOL> } <EOL> } <EOL> expect ( <NUM_LIT:3> ) <EOL> job . cancelAndJoin ( ) <EOL> finish ( <NUM_LIT:6> ) <EOL> }

/** Tests that calls to [await] throw [CancellationException] and dispose of the subscription when their [Job] is
 * cancelled. */


private fun batchNorm ( tf : Ops , x : Operand < Float > , gamma : Variable < Float > ? , beta : Operand < Float > ? , movingMean : Operand < Float > , movingVar : Operand < Float > , eps : Operand < Float > , ) : Operand < Float >

{ <EOL> var inv : Operand < Float > = tf . math . rsqrt ( tf . math . add ( movingVar , eps ) ) <EOL> if ( scale ) inv = tf . math . mul ( inv , gamma ) <EOL> val xNorm = tf . math . mul ( tf . math . sub ( x , movingMean ) , inv ) <EOL> return if ( center ) tf . math . add ( xNorm , beta ) <EOL> else xNorm <EOL> }

/**
 * ```
 * def batch_norm(X, gamma, beta, moving_mean, moving_var, eps):
 * # Compute reciprocal of square root of the moving variance element-wise
 * inv = tf.cast(tf.math.rsqrt(moving_var + eps), X.dtype)
 * # Scale and shift
 * inv *= gamma
 * Y = X * inv + (beta - moving_mean * inv)
 * return Y
 * ```
 */


public actual fun < T > MutableList < T > . reverse ( ) : Unit

{ <EOL> val midPoint = ( size / <NUM_LIT:2> ) - <NUM_LIT:1> <EOL> if ( midPoint < <NUM_LIT:0> ) return <EOL> var reverseIndex = lastIndex <EOL> for ( index in <NUM_LIT:0> .. midPoint ) { <EOL> val tmp = this [ index ] <EOL> this [ index ] = this [ reverseIndex ] <EOL> this [ reverseIndex ] = tmp <EOL> reverseIndex -- <EOL> } <EOL> }

/**
 * Reverses elements in the list in-place.
 */


@ ParameterizedTest ( name = "<STR_LIT>" ) <EOL> @ ArgumentsSource ( LatestTestedVersionsArgumentsProvider :: class ) <EOL> fun `should fail with DokkaException and readable message if failOnWarning is triggered` ( buildVersions : BuildVersions )

{ <EOL> val result = createGradleRunner ( buildVersions , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . buildAndFail ( ) <EOL> assertEquals ( TaskOutcome . FAILED , assertNotNull ( result . task ( "<STR_LIT>" ) ) . outcome ) <EOL> result . output . contains ( "<STR_LIT>" ) <EOL> result . output . contains ( """<STR_LIT>""" . trimIndent ( ) . toRegex ( ) ) <EOL> result . output . contains ( "<STR_LIT>" . toRegex ( ) ) <EOL> }

/**
 * The test project contains some undocumented declarations, so if both `reportUndocumented`
 * and `failOnWarning` are enabled - it should fail
 */


internal fun < S : Segment < S > > S . findSegmentInternal ( id : Long , createNewSegment : ( id : Long , prev : S ) -> S ) : SegmentOrClosed < S >

{ <EOL> var cur : S = this <EOL> while ( cur . id < id || cur . isRemoved ) { <EOL> val next = cur . nextOrIfClosed { return SegmentOrClosed ( CLOSED ) } <EOL> if ( next != null ) { <EOL> cur = next <EOL> continue <EOL> } <EOL> val newTail = createNewSegment ( cur . id + <NUM_LIT:1> , cur ) <EOL> if ( cur . trySetNext ( newTail ) ) { <EOL> if ( cur . isRemoved ) cur . remove ( ) <EOL> cur = newTail <EOL> } <EOL> } <EOL> return SegmentOrClosed ( cur ) <EOL> }

/**
 * Returns the first segment `s` with `s.id >= id` or `CLOSED`
 * if all the segments in this linked list have lower `id`, and the list is closed for further segment additions.
 */


@ Suppress ( "<STR_LIT:NOTHING_TO_INLINE>" , "<STR_LIT>" ) <EOL> internal inline fun < S : Segment < S > > AtomicRef < S > . moveForward ( to : S ) : Boolean

= loop { cur -> <EOL> if ( cur . id >= to . id ) return true <EOL> if ( ! to . tryIncPointers ( ) ) return false <EOL> if ( compareAndSet ( cur , to ) ) { <EOL> if ( cur . decPointers ( ) ) cur . remove ( ) <EOL> return true <EOL> } <EOL> if ( to . decPointers ( ) ) to . remove ( ) <EOL> }

/**
 * Returns `false` if the segment `to` is logically removed, `true` on a successful update.
 */


@ Suppress ( "<STR_LIT:NOTHING_TO_INLINE>" ) <EOL> internal inline fun < S : Segment < S > > AtomicRef < S > . findSegmentAndMoveForward ( id : Long , startFrom : S , noinline createNewSegment : ( id : Long , prev : S ) -> S ) : SegmentOrClosed < S >

{ <EOL> while ( true ) { <EOL> val s = startFrom . findSegmentInternal ( id , createNewSegment ) <EOL> if ( s . isClosed || moveForward ( s . segment ) ) return s <EOL> } <EOL> }

/**
 * Tries to find a segment with the specified [id] following by next references from the
 * [startFrom] segment and creating new ones if needed. The typical use-case is reading this `AtomicRef` values,
 * doing some synchronization, and invoking this function to find the required segment and update the pointer.
 * At the same time, [Segment.cleanPrev] should also be invoked if the previous segments are no longer needed
 * (e.g., queues should use it in dequeue operations).
 *
 * Since segments can be removed from the list, or it can be closed for further segment additions.
 * Returns the segment `s` with `s.id >= id` or `CLOSED` if all the segments in this linked list have lower `id`,
 * and the list is closed.
 */


internal fun < N : ConcurrentLinkedListNode < N > > N . close ( ) : N

{ <EOL> var cur : N = this <EOL> while ( true ) { <EOL> val next = cur . nextOrIfClosed { return cur } <EOL> if ( next === null ) { <EOL> if ( cur . markAsClosed ( ) ) return cur <EOL> } else { <EOL> cur = next <EOL> } <EOL> } <EOL> }

/**
 * Closes this linked list of nodes by forbidding adding new ones,
 * returns the last node in the list.
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> inline fun nextOrIfClosed ( onClosedAction : ( ) -> Nothing ) : N ?

= nextOrClosed . let { <EOL> if ( it === CLOSED ) { <EOL> onClosedAction ( ) <EOL> } else { <EOL> it as N ? <EOL> } <EOL> }

/**
 * Returns the next segment or `null` of the one does not exist,
 * and invokes [onClosedAction] if this segment is marked as closed.
 */


= _next . compareAndSet ( null , value )

/**
 * Tries to set the next segment if it is not specified and this segment is not marked as closed.
 */


{ _prev . lazySet ( null ) }

/**
 * Cleans the pointer to the previous node.
 */


= _next . compareAndSet ( null , CLOSED )

/**
 * Tries to mark the linked list as closed by forbidding adding new nodes after this one.
 */


{ <EOL> assert { isRemoved || isTail } <EOL> if ( isTail ) return <EOL> while ( true ) { <EOL> val prev = aliveSegmentLeft <EOL> val next = aliveSegmentRight <EOL> next . _prev . update { if ( it === null ) null else prev } <EOL> if ( prev !== null ) prev . _next . value = next <EOL> if ( next . isRemoved && ! next . isTail ) continue <EOL> if ( prev !== null && prev . isRemoved ) continue <EOL> return <EOL> } <EOL> }

/**
 * Removes this node physically from this linked list. The node should be
 * logically removed (so [isRemoved] returns `true`) at the point of invocation.
 */


abstract fun onCancellation ( index : Int , cause : Throwable ? , context : CoroutineContext )

/**
 * This function is invoked on continuation cancellation when this segment
 * with the specified [index] are installed as cancellation handler via
 * `SegmentDisposable.disposeOnCancellation(Segment, Int)`.
 *
 * @param index the index under which the sement registered itself in the continuation.
 * Indicies are opaque and arithmetics or numeric intepretation is not allowed on them,
 * as they may encode additional metadata.
 * @param cause the cause of the cancellation, with the same semantics as [CancellableContinuation.invokeOnCancellation]
 * @param context the context of the cancellable continuation the segment was registered in
 */


{ <EOL> if ( cleanedAndPointers . incrementAndGet ( ) == numberOfSlots ) remove ( ) <EOL> }

/**
 * Invoked on each slot clean-up; should not be invoked twice for the same slot.
 */


fun loadCache ( )

/** Push the cache object onto the stack. */


fun initCache ( )


fun clearCache ( )

/** Clear cache. The cache storage should be on the stack. */


fun getViewFromCache ( )

/** Push the cached view onto the stack, or push `null` if the view is not cached. `Int` id should be on the stack. */


fun putViewToCache ( getView : ( ) -> Unit )

/** Cache the view. `Int` id should be on the stack. */


fun dependencies ( configure : KotlinDependencyHandler . ( ) -> Unit )

/**
 * Configures all dependencies for this entity.
 */


fun dependencies ( configure : Action < KotlinDependencyHandler > )


@ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . ERROR ) <EOL> fun warnNpmGenerateExternals ( logger : Logger )

{ <EOL> logger . warn ( """<STR_LIT>""" . trimMargin ( ) ) <EOL> }


{ <EOL> }

/**
 * This is an example <!-- not visible --> of html
 */


{ <EOL> }

/**
 * This is an <b> documentation </b>
 */


private fun checkImpl ( candidate : Candidate , sink : CheckerSink , context : ResolutionContext , dslMarkersProvider : ( ) -> Set < ClassId > , isImplicitReceiverMatching : ( ImplicitReceiverValue < * > ) -> Boolean , )

{ <EOL> val resolvedReceiverIndex = context . bodyResolveContext . implicitReceiverStack . indexOfFirst { isImplicitReceiverMatching ( it ) } <EOL> if ( resolvedReceiverIndex == - <NUM_LIT:1> ) return <EOL> val closerReceivers = context . bodyResolveContext . implicitReceiverStack . drop ( resolvedReceiverIndex + <NUM_LIT:1> ) <EOL> if ( closerReceivers . isEmpty ( ) ) return <EOL> val dslMarkers = dslMarkersProvider ( ) <EOL> if ( dslMarkers . isEmpty ( ) ) return <EOL> if ( closerReceivers . any { receiver -> receiver . getDslMarkersOfImplicitReceiver ( context ) . any { it in dslMarkers } } ) { <EOL> sink . reportDiagnostic ( DslScopeViolation ( candidate . symbol ) ) <EOL> } <EOL> }

/**
 * Checks whether the implicit receiver (represented as an object of type `T`) violates DSL scope rules.
 */


internal fun AbstractNativeSimpleTest . generateTestCaseWithSingleModule ( sourcesRoot : File ? , freeCompilerArgs : TestCompilerArgs = TestCompilerArgs . EMPTY , extras : TestCase . Extras = TestCase . WithTestRunnerExtras ( TestRunnerType . DEFAULT ) , ) : TestCase

{ <EOL> val moduleName : String = sourcesRoot ? . name ? . removeSuffix ( "<STR_LIT>" ) ? : LAUNCHER_MODULE_NAME <EOL> val module = TestModule . Exclusive ( moduleName , emptySet ( ) , emptySet ( ) , emptySet ( ) ) <EOL> sourcesRoot ? . walkTopDown ( ) <EOL> ? . filter { it . isFile && it . extension == "<STR_LIT:kt>" } <EOL> ? . forEach { file -> module . files += TestFile . createCommitted ( file , module ) } <EOL> return TestCase ( id = TestCaseId . Named ( moduleName ) , kind = TestKind . STANDALONE , modules = setOf ( module ) , freeCompilerArgs = freeCompilerArgs , nominalPackageName = PackageName . EMPTY , checks = TestRunChecks . Default ( testRunSettings . get < Timeouts > ( ) . executionTimeout ) , extras = extras ) . apply { <EOL> initialize ( null , null ) <EOL> } <EOL> }

/**
 * [sourcesRoot] points either to a .kt-file, or a folder.
 *
 * If it's present, then it's name (without .kt-extension, if it's a file) will be used as 'moduleName' for generated module.
 */


private fun makePropertiesFilesReproducible ( )

{ <EOL> workDirectory . get ( ) . asFile . walk ( ) <EOL> . filter { it . isFile && it . extension == "<STR_LIT>" } <EOL> . forEach { file -> <EOL> logger . info ( "<STR_LIT>" ) <EOL> val comments = file . readLines ( ) <EOL> . takeWhile { it . startsWith ( '<CHAR_LIT>' ) } <EOL> . dropLast ( <NUM_LIT:1> ) <EOL> val properties = file . readLines ( ) . dropWhile { it . startsWith ( '<CHAR_LIT>' ) } <EOL> val updatedProperties = ( comments + properties ) . joinToString ( "<STR_LIT:\n>" ) <EOL> file . writeText ( updatedProperties ) <EOL> } <EOL> }

/**
 * Remove non-reproducible timestamps from any generated [Properties] files.
 */


fun process ( host : KotlinKernelHost ) : FieldValue ?

/**
 * Processes local variables and generates code snippets that perform type conversions
 */


public operator fun get ( index : Int ) : T

/**
 * Gets the row at given [index].
 *
 * NOTE: This doesn't work in the [ColumnsSelectionDsl], use [ColumnsSelectionDsl.col] to select a column by index.
 */


public operator fun get ( firstIndex : Int , vararg otherIndices : Int ) : BaseColumn < T >

= get ( headPlusIterable ( firstIndex , otherIndices . asIterable ( ) ) )

/**
 * Gets the rows at given indices.
 *
 * NOTE: This doesn't work in the [ColumnsSelectionDsl], use [ColumnsSelectionDsl.cols] to select columns by index.
 */


public operator fun get ( range : IntRange ) : BaseColumn < T >

/**
 * Gets the rows at given range of indices.
 *
 * NOTE: This doesn't work in the [ColumnsSelectionDsl], use [ColumnsSelectionDsl.cols] to select columns by range.
 */


public operator fun get ( indices : Iterable < Int > ) : BaseColumn < T >


public fun customFormat ( layerNameColumnName : String = "<STR_LIT>" , outputShapeColumnName : String = "<STR_LIT>" , paramsCountColumnName : String = "<STR_LIT>" , connectedToColumnName : String = "<STR_LIT>" , columnSeparator : String = "<STR_LIT:U+0020>" , lineSeparatorSymbol : Char = '<CHAR_LIT:_>' , thickLineSeparatorSymbol : Char = '<CHAR_LIT>' , withConnectionsColumn : Boolean = layersSummaries . any { it . inboundLayers . size > <NUM_LIT:1> } ) : List < String >

{ <EOL> val headerRows = mutableListOf ( "<STR_LIT>" ) <EOL> name ? . let { headerRows . add ( "<STR_LIT>" ) } <EOL> val header = SimpleSection ( headerRows ) <EOL> val rows = layersSummaries . map { layer -> <EOL> val cells = mutableListOf ( Cell ( "<STR_LIT>" ) , Cell ( layer . outputShape . toString ( ) ) , Cell ( layer . paramsCount . toString ( ) ) ) <EOL> if ( withConnectionsColumn ) { <EOL> cells . add ( Cell ( layer . inboundLayers ) ) <EOL> } <EOL> TableRow ( cells ) <EOL> } <EOL> val columnNames = if ( withConnectionsColumn ) { <EOL> listOf ( layerNameColumnName , outputShapeColumnName , paramsCountColumnName , connectedToColumnName ) <EOL> } else { <EOL> listOf ( layerNameColumnName , outputShapeColumnName , paramsCountColumnName ) <EOL> } <EOL> val mainSection = <EOL> SectionWithColumns ( rows , columnNames ) <EOL> val footer = SimpleSection ( listOf ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> return formatTable ( listOf ( header , mainSection , footer ) , columnSeparator , lineSeparatorSymbol , thickLineSeparatorSymbol ) <EOL> }

/**
 * Formats model summary
 * @param [layerNameColumnName] title of the column with layer names
 * @param [outputShapeColumnName] title of the column with layer output shapes
 * @param [paramsCountColumnName] title of the column with layer parameter counts
 * @param [connectedToColumnName] title of the column with layers that are inputs for a layer
 * @param [columnSeparator] text chunk that will be used as column separator for the layer description table
 * @param [lineSeparatorSymbol] character that will be used to produce a string to separate rows of the layer description table
 * @param [thickLineSeparatorSymbol] character that will be used to produce a string to separate general model description,
 * header and body of the table with layers description, and description footer
 * @param [withConnectionsColumn] flag that turns on/off displaying of the column with names of inbound layers
 * @return description of model summary as list of strings, which are suitable for printing or logging
 */


fun jvmToolchain ( action : Action < JavaToolchainSpec > )

{ <EOL> toolchainSupport . applyToolchain ( action ) <EOL> }

/**
 * Configures [Java toolchain](https://docs.gradle.org/current/userguide/toolchains.html) both for Kotlin JVM and Java tasks.
 *
 * @param action - action to configure [JavaToolchainSpec]
 */


{ <EOL> jvmToolchain { <EOL> it . languageVersion . set ( JavaLanguageVersion . of ( jdkVersion ) ) <EOL> } <EOL> }

/**
 * Configures [Java toolchain](https://docs.gradle.org/current/userguide/toolchains.html) both for Kotlin JVM and Java tasks.
 *
 * @param jdkVersion - jdk version as number. For example, 17 for Java 17.
 */


@ ExperimentalKotlinGradlePluginApi <EOL> fun < T : Named > NamedDomainObjectContainer < T > . invokeWhenCreated ( name : String , configure : T . ( ) -> Unit )

{ <EOL> configureEach { if ( it . name == name ) it . configure ( ) } <EOL> project . launchInStage ( KotlinPluginLifecycle . Stage . ReadyForExecution ) { <EOL> if ( name !in names ) { <EOL> named ( name ) . configure ( configure ) <EOL> } <EOL> } <EOL> }

/**
 * Can be used to configure objects that are not yet created, or will be created in
 * 'afterEvaluate' (e.g. typically Android source sets containing flavors and buildTypes)
 *
 * Will fail project evaluation if the domain object is not created before 'afterEvaluate' listeners in the buildscript.
 *
 * @param configure: Called inline, if the value is already present. Called once the domain object is created.
 */


public fun < T > encodeToByteArray ( serializer : SerializationStrategy < T > , value : T ) : ByteArray

/**
 * Serializes and encodes the given [value] to byte array using the given [serializer].
 *
 * @throws SerializationException in case of any encoding-specific error
 * @throws IllegalArgumentException if the encoded input does not comply format's specification
 */


public fun < T > decodeFromByteArray ( deserializer : DeserializationStrategy < T > , bytes : ByteArray ) : T

/**
 * Decodes and deserializes the given [byte array][bytes] to the value of type [T] using the given [deserializer].
 *
 * @throws SerializationException in case of any decoding-specific error
 * @throws IllegalArgumentException if the decoded input is not a valid instance of [T]
 */


public fun < T > encodeToString ( serializer : SerializationStrategy < T > , value : T ) : String

/**
 * Serializes and encodes the given [value] to string using the given [serializer].
 *
 * @throws SerializationException in case of any encoding-specific error
 * @throws IllegalArgumentException if the encoded input does not comply format's specification
 */


public fun < T > decodeFromString ( deserializer : DeserializationStrategy < T > , string : String ) : T

/**
 * Decodes and deserializes the given [string] to the value of type [T] using the given [deserializer].
 *
 * @throws SerializationException in case of any decoding-specific error
 * @throws IllegalArgumentException if the decoded input is not a valid instance of [T]
 */


public inline fun < reified T > StringFormat . encodeToString ( value : T ) : String

= <EOL> encodeToString ( serializersModule . serializer ( ) , value )

/**
 * Serializes and encodes the given [value] to string using serializer retrieved from the reified type parameter.
 *
 * @throws SerializationException in case of any encoding-specific error
 * @throws IllegalArgumentException if the encoded input does not comply format's specification
 */


public inline fun < reified T > StringFormat . decodeFromString ( string : String ) : T

= <EOL> decodeFromString ( serializersModule . serializer ( ) , string )

/**
 * Decodes and deserializes the given [string] to the value of type [T] using deserializer
 * retrieved from the reified type parameter.
 *
 * @throws SerializationException in case of any decoding-specific error
 * @throws IllegalArgumentException if the decoded input is not a valid instance of [T]
 */


public fun < T > BinaryFormat . encodeToHexString ( serializer : SerializationStrategy < T > , value : T ) : String

= <EOL> InternalHexConverter . printHexBinary ( encodeToByteArray ( serializer , value ) , lowerCase = true )

/**
 * Serializes and encodes the given [value] to byte array, delegating it to the [BinaryFormat],
 * and then encodes resulting bytes to hex string.
 *
 * Hex representation does not interfere with serialization and encoding process of the format and
 * only applies transformation to the resulting array. It is recommended to use for debugging and
 * testing purposes.
 *
 * @throws SerializationException in case of any encoding-specific error
 * @throws IllegalArgumentException if the encoded input does not comply format's specification
 */


public fun < T > BinaryFormat . decodeFromHexString ( deserializer : DeserializationStrategy < T > , hex : String ) : T

= <EOL> decodeFromByteArray ( deserializer , InternalHexConverter . parseHexBinary ( hex ) )

/**
 * Decodes byte array from the given [hex] string and the decodes and deserializes it
 * to the value of type [T], delegating it to the [BinaryFormat].
 *
 * This method is a counterpart to [encodeToHexString].
 *
 * @throws SerializationException in case of any decoding-specific error
 * @throws IllegalArgumentException if the decoded input is not a valid instance of [T]
 */


public inline fun < reified T > BinaryFormat . encodeToHexString ( value : T ) : String

= <EOL> encodeToHexString ( serializersModule . serializer ( ) , value )


public inline fun < reified T > BinaryFormat . decodeFromHexString ( hex : String ) : T

= <EOL> decodeFromHexString ( serializersModule . serializer ( ) , hex )


public inline fun < reified T > BinaryFormat . encodeToByteArray ( value : T ) : ByteArray

= <EOL> encodeToByteArray ( serializersModule . serializer ( ) , value )

/**
 * Serializes and encodes the given [value] to byte array using serializer
 * retrieved from the reified type parameter.
 *
 * @throws SerializationException in case of any encoding-specific error
 * @throws IllegalArgumentException if the encoded input does not comply format's specification
 */


public inline fun < reified T > BinaryFormat . decodeFromByteArray ( bytes : ByteArray ) : T

= <EOL> decodeFromByteArray ( serializersModule . serializer ( ) , bytes )

/**
 * Decodes and deserializes the given [byte array][bytes] to the value of type [T] using deserializer
 * retrieved from the reified type parameter.
 *
 * @throws SerializationException in case of any decoding-specific error
 * @throws IllegalArgumentException if the decoded input is not a valid instance of [T]
 */


fun isEnabled ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if the given [phase] should be executed during compilation.
 */


fun isVerbose ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if the compiler should print additional information
 * during [phase] execution.
 */


fun disable ( phase : AnyNamedPhase )

/**
 * Prevent compiler from executing the given [phase].
 */


fun shouldDumpStateBefore ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if compiler should dump its state right before
 * the execution of the given [phase].
 */


fun shouldDumpStateAfter ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if compiler should dump its state right after
 * the execution of the given [phase].
 */


fun shouldValidateStateBefore ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if compiler should validate its state right before
 * the execution of the given [phase].
 */


fun shouldValidateStateAfter ( phase : AnyNamedPhase ) : Boolean

/**
 * Check if compiler should validate its state right after
 * the execution of the given [phase].
 */


abstract fun add ( other : @ UnsafeVariance T ? ) : T ?

/**
 * This function is used to decide how multiple attributes should be united in presence of typealiases:
 * typealias B = @SomeAttribute(1) A
 * typealias C = @SomeAttribute(2) B
 *
 * For determining attribute value of expanded type of C we should add @SomeAttribute(2) to @SomeAttribute(1)
 *
 * This function must be symmetrical: a.add(b) == b.add(a)
 */


infix fun definitelyDifferFrom ( other : ConeAttributes ) : Boolean

{ <EOL> if ( this === other ) return false <EOL> if ( this . isEmpty ( ) && other . isEmpty ( ) ) return false <EOL> for ( index in indices ) { <EOL> val a = arrayMap [ index ] <EOL> val b = other . arrayMap [ index ] <EOL> if ( a == null && b == null ) continue <EOL> if ( ( a == null ) != ( b == null ) ) return true <EOL> if ( a ! ! . implementsEquality && a != b ) return true <EOL> } <EOL> return false <EOL> }

/**
 * Returns `true` if this instance is definitely not equal to the [other] instance.
 * This is `true` when one instance contains an attribute **type** that the other doesn't contain or both instances contain
 * an attribute of a type where [ConeAttribute.implementsEquality]` == true` and the attribute's [equals] method returns `false`.
 *
 * A return value of `false` doesn't guarantee that the instances are equal because [ConeAttribute.implementsEquality] is optional,
 * i.e., not all attributes can be compared structurally.
 *
 * @see org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl.equals
 */


inline fun transformTypesWith ( transform : ( ConeKotlinType ) -> ConeKotlinType ? ) : ConeAttributes ?

{ <EOL> if ( isEmpty ( ) ) return null <EOL> var newList : MutableList < ConeAttribute < * > > ? = null <EOL> var hasDifference = false <EOL> for ( ( i , attr ) in this . withIndex ( ) ) { <EOL> if ( attr !is ConeAttributeWithConeType ) continue <EOL> val substitutedAttribute = attr . transformOrNull ( transform ) ? : continue <EOL> if ( newList == null ) { <EOL> newList = this . toMutableList ( ) <EOL> } <EOL> newList [ i ] = substitutedAttribute <EOL> hasDifference = hasDifference || substitutedAttribute != attr <EOL> } <EOL> if ( newList != null && ! hasDifference ) { <EOL> return this <EOL> } <EOL> return newList ? . let ( Companion :: create ) <EOL> }

/**
 * Applies the [transform] to all attributes that are subtypes of [ConeAttributeWithConeType] and returns a [ConeAttributes]
 * with the results of transforms that were not-`null` or `null` if no attributes were transformed.
 */


fun isKotlinInternalCompiledFile ( file : VirtualFile , fileContent : ByteArray ? = null ) : Boolean

{ <EOL> if ( ! file . isValidAndExists ( fileContent ) ) { <EOL> return false <EOL> } <EOL> val clsKotlinBinaryClassCache = ClsKotlinBinaryClassCache . getInstance ( ) <EOL> if ( ! clsKotlinBinaryClassCache . isKotlinJvmCompiledFile ( file , fileContent ) ) { <EOL> return false <EOL> } <EOL> val innerClass = <EOL> try { <EOL> if ( fileContent == null ) { <EOL> ClassFileViewProvider . isInnerClass ( file ) <EOL> } else { <EOL> ClassFileViewProvider . isInnerClass ( file , fileContent ) <EOL> } <EOL> } catch ( exception : Exception ) { <EOL> Logger <EOL> . getInstance ( "<STR_LIT>" ) <EOL> . debug ( file . path , exception ) <EOL> return false <EOL> } <EOL> if ( innerClass ) { <EOL> return true <EOL> } <EOL> val header = clsKotlinBinaryClassCache . getKotlinBinaryClassHeaderData ( file , fileContent ) ? : return false <EOL> if ( header . classId . isLocal ) return true <EOL> return header . kind == KotlinClassHeader . Kind . SYNTHETIC_CLASS || <EOL> header . kind == KotlinClassHeader . Kind . MULTIFILE_CLASS_PART <EOL> }

/**
 * Checks if this file is a compiled "internal" Kotlin class, i.e. a Kotlin class (not necessarily ABI-compatible with the current plugin)
 * which should NOT be decompiled (and, as a result, shown under the library in the Project view, be searchable via Find class, etc.)
 */


@ Test <EOL> fun createZeroFilledByteArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Byte > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:0> . toByte ( ) } } <EOL> }

/**
 * This method checks if a byte array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createByteArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Byte > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:1> . toByte ( ) } } <EOL> }

/**
 * Creates a byte array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityByteMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Byte > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT:1> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT:0> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Byte>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromByteList ( )

{ <EOL> val list = listOf ( listOf < Byte > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf < Byte > ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:2> ) ) <EOL> val a : D2Array < Byte > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of byte lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromByteSet ( )

{ <EOL> val set = setOf < Byte > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Byte > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of bytes
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveByteArray ( )

{ <EOL> val array = byteArrayOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getByteArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive ByteArray
 * and checks if the array's ByteArray representation matches the input ByteArray.
 */


@ Test <EOL> fun createByte2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Byte > ( <NUM_LIT:2> , <NUM_LIT:3> ) { ( it + <NUM_LIT:3> ) . toByte ( ) } <EOL> val expected = byteArrayOf ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getByteArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's ByteArray representation matches the expected output.
 */


@ Test <EOL> fun createByte2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> ( i * j + <NUM_LIT:7> ) . toByte ( ) } <EOL> val expected = byteArrayOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getByteArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's ByteArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedByte2DArray ( )

{ <EOL> val list = listOf ( listOf < Byte > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf < Byte > ( <NUM_LIT:4> , <NUM_LIT:7> ) , listOf < Byte > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val expected = listOf ( listOf < Byte > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:0> ) , listOf < Byte > ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ) , listOf < Byte > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val a : D2Array < Byte > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }

/**
 * Tests the function 'createAlignedNDArray' that creates a two-dimensional array from a list of number lists.
 * The test asserts that:
 * - The output array's size matches the size of the longest list in the input
 * and all lists are filled to match this length.
 * - The lists shorter than the longest one are filled with the specified filling value.
 */


@ Test <EOL> fun createZeroFilledShortArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Short > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:0> . toShort ( ) } } <EOL> }

/**
 * This method checks if a short array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createShortArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Short > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:1> . toShort ( ) } } <EOL> }

/**
 * Creates a short array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityShortMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Short > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT:1> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT:0> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Short>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromShortList ( )

{ <EOL> val list = listOf ( listOf < Short > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf < Short > ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:2> ) ) <EOL> val a : D2Array < Short > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of short lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> @ Ignore <EOL> fun createTwoDimensionalArrayFromShortSet ( )

{ <EOL> val set = setOf < Short > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Short > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of shorts
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveShortArray ( )

{ <EOL> val array = shortArrayOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getShortArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive ShortArray
 * and checks if the array's ShortArray representation matches the input ShortArray.
 */


@ Test <EOL> fun createShort2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Short > ( <NUM_LIT:2> , <NUM_LIT:3> ) { ( it + <NUM_LIT:3> ) . toShort ( ) } <EOL> val expected = shortArrayOf ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getShortArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's ShortArray representation matches the expected output.
 */


@ Test <EOL> fun createShort2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> ( i * j + <NUM_LIT:7> ) . toShort ( ) } <EOL> val expected = shortArrayOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getShortArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's ShortArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedShort2DArray ( )

{ <EOL> val list = listOf ( listOf < Short > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf < Short > ( <NUM_LIT:4> , <NUM_LIT:7> ) , listOf < Short > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val expected = listOf ( listOf < Short > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:0> ) , listOf < Short > ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ) , listOf < Short > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val a : D2Array < Short > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }


@ Test <EOL> fun createZeroFilledIntArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Int > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:0> } } <EOL> }

/**
 * This method checks if an integer array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createIntArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Int > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:1> } } <EOL> }

/**
 * Creates an integer array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityIntMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Int > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT:1> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT:0> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Int>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromIntList ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:2> ) ) <EOL> val a : D2Array < Int > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of integer lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromIntSet ( )

{ <EOL> val set = setOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Int > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of integers
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveIntArray ( )

{ <EOL> val array = intArrayOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getIntArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive IntArray
 * and checks if the array's IntArray representation matches the input IntArray.
 */


@ Test <EOL> fun createInt2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Int > ( <NUM_LIT:2> , <NUM_LIT:3> ) { ( it + <NUM_LIT:3> ) } <EOL> val expected = intArrayOf ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getIntArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's IntArray representation matches the expected output.
 */


@ Test <EOL> fun createInt2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + <NUM_LIT:7> } <EOL> val expected = intArrayOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getIntArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's IntArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedInt2DArray ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf ( <NUM_LIT:4> , <NUM_LIT:7> ) , listOf ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val expected = listOf ( listOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:0> ) , listOf ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ) , listOf ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val a : D2Array < Int > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }

/**
 * Tests the function 'createAlignedNDArray' that creates a two-dimensional array from a list of number lists.
 * The test asserts that:
 * - The output array's size matches the size of the longest list in the input
 * and all lists are filled to match this length.
 * - The lists shorter than the longest one are filled with the specified filling value.
 */


@ Test <EOL> fun createZeroFilledLongArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Long > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:0L> } } <EOL> }

/**
 * This method checks if a long array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createLongArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Long > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:1L> } } <EOL> }

/**
 * Creates a long array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityLongMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Long > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT:1L> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT:0L> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Long>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromLongList ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1L> , <NUM_LIT:3L> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val a : D2Array < Long > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of long lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromLongSet ( )

{ <EOL> val set = setOf ( <NUM_LIT:1L> , <NUM_LIT:3L> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Long > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of longs
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveLongArray ( )

{ <EOL> val array = longArrayOf ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:2> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getLongArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive LongArray
 * and checks if the array's LongArray representation matches the input LongArray.
 */


@ Test <EOL> fun createLong2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Long > ( <NUM_LIT:2> , <NUM_LIT:3> ) { it + <NUM_LIT:3L> } <EOL> val expected = longArrayOf ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getLongArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's LongArray representation matches the expected output.
 */


@ Test <EOL> fun createLong2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices < Long > ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + <NUM_LIT> } <EOL> val expected = longArrayOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getLongArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's LongArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedLong2DArray ( )

{ <EOL> val list = listOf ( listOf < Long > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , listOf < Long > ( <NUM_LIT:4> , <NUM_LIT:7> ) , listOf < Long > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val expected = listOf ( listOf < Long > ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT:0> ) , listOf < Long > ( <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:0> ) , listOf < Long > ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:10> ) ) <EOL> val a : D2Array < Long > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }


@ Test <EOL> fun createZeroFilledFloatArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Float > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT> } } <EOL> }

/**
 * This method checks if a float array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createFloatArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Float > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT> } } <EOL> }

/**
 * Creates a float array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityFloatMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Float > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Float>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromFloatList ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val a : D2Array < Float > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of float lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromFloatSet ( )

{ <EOL> val set = setOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Float > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of floats
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveFloatArray ( )

{ <EOL> val array = floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getFloatArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive FloatArray
 * and checks if the array's FloatArray representation matches the input FloatArray.
 */


@ Test <EOL> fun createFloat2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Float > ( <NUM_LIT:2> , <NUM_LIT:3> ) { it + <NUM_LIT> } <EOL> val expected = floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getFloatArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's FloatArray representation matches the expected output.
 */


@ Test <EOL> fun createFloat2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices < Float > ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + <NUM_LIT> } <EOL> val expected = floatArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getFloatArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's FloatArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedFloat2DArray ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val expected = listOf ( listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val a : D2Array < Float > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }

/**
 * Tests the function 'createAlignedNDArray' that creates a two-dimensional array from a list of number lists.
 * The test asserts that:
 * - The output array's size matches the size of the longest list in the input
 * and all lists are filled to match this length.
 * - The lists shorter than the longest one are filled with the specified filling value.
 */


@ Test <EOL> fun createZeroFilledDoubleArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < Double > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:0.0> } } <EOL> }

/**
 * This method checks if a double array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createDoubleArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < Double > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == <NUM_LIT:1.0> } } <EOL> }

/**
 * Creates a double array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityDoubleMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < Double > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( <NUM_LIT:1.0> , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( <NUM_LIT:0.0> , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<Double>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromDoubleList ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1.0> , <NUM_LIT:3.0> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2.0> ) ) <EOL> val a : D2Array < Double > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of double lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromDoubleSet ( )

{ <EOL> val set = setOf ( <NUM_LIT:1.0> , <NUM_LIT:3.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2.0> ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < Double > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of doubles
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveDoubleArray ( )

{ <EOL> val array = doubleArrayOf ( <NUM_LIT:1.0> , <NUM_LIT:3.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2.0> ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getDoubleArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive DoubleArray
 * and checks if the array's DoubleArray representation matches the input DoubleArray.
 */


@ Test <EOL> fun createDouble2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < Double > ( <NUM_LIT:2> , <NUM_LIT:3> ) { it + <NUM_LIT:3.0> } <EOL> val expected = doubleArrayOf ( <NUM_LIT:3.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getDoubleArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's DoubleArray representation matches the expected output.
 */


@ Test <EOL> fun createDouble2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices < Double > ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + <NUM_LIT> } <EOL> val expected = doubleArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getDoubleArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's DoubleArray representation matches the expected output.
 */


@ OptIn ( ExperimentalMultikApi :: class ) <EOL> @ Test <EOL> fun createAlignedDouble2DArray ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1.0> , <NUM_LIT:3.0> , <NUM_LIT> ) , listOf ( <NUM_LIT> , <NUM_LIT> ) , listOf ( <NUM_LIT:2.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val expected = listOf ( listOf ( <NUM_LIT:1.0> , <NUM_LIT:3.0> , <NUM_LIT> , <NUM_LIT:0.0> ) , listOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , listOf ( <NUM_LIT:2.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> val a : D2Array < Double > = mk . createAlignedNDArray ( list , filling = <NUM_LIT:0.0> ) <EOL> assertEquals ( expected , a . toListD2 ( ) ) <EOL> }


@ Test <EOL> fun createZeroFilledComplexFloatArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < ComplexFloat > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == ComplexFloat . zero } } <EOL> }

/**
 * This method checks if a ComplexFloat array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createComplexFloatArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < ComplexFloat > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == ComplexFloat . one } } <EOL> }

/**
 * Creates a ComplexFloat array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityComplexFloatMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < ComplexFloat > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( ComplexFloat . one , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( ComplexFloat . zero , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<ComplexFloat>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromComplexFloatList ( )

{ <EOL> val list = listOf ( listOf ( ComplexFloat . one , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) , listOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) ) <EOL> val a : D2Array < ComplexFloat > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of complex float lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromComplexFloatSet ( )

{ <EOL> val set = setOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < ComplexFloat > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of complex floats
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveComplexFloatArray ( )

{ <EOL> val array = complexFloatArrayOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getComplexFloatArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive ComplexFloatArray
 * and checks if the array's ComplexFloatArray representation matches the input ComplexFloatArray.
 */


@ Test <EOL> fun createComplexFloat2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < ComplexFloat > ( <NUM_LIT:2> , <NUM_LIT:3> ) { ComplexFloat ( it + <NUM_LIT> , round ( ( it - <NUM_LIT> ) * <NUM_LIT> ) / <NUM_LIT> ) } <EOL> val expected = complexFloatArrayOf ( <NUM_LIT> - <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getComplexFloatArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's ComplexFloatArray representation matches the expected output.
 */


@ Test <EOL> fun createComplexFloat2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices < ComplexFloat > ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + ComplexFloat ( <NUM_LIT:7> ) } <EOL> val expected = complexFloatArrayOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getComplexFloatArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's ComplexFloatArray representation matches the expected output.
 */


@ Test <EOL> fun createZeroFilledComplexDoubleArray ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . zeros < ComplexDouble > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == ComplexDouble . zero } } <EOL> }

/**
 * This method checks if a ComplexDouble array of a given size is correctly created with all elements set to zero.
 */


@ Test <EOL> fun createComplexDoubleArrayFilledWithOnes ( )

{ <EOL> val dim1 = <NUM_LIT:5> <EOL> val dim2 = <NUM_LIT:7> <EOL> val a = mk . ones < ComplexDouble > ( dim1 , dim2 ) <EOL> assertEquals ( dim1 * dim2 , a . size ) <EOL> assertEquals ( dim1 * dim2 , a . data . size ) <EOL> assertTrue { a . all { it == ComplexDouble . one } } <EOL> }

/**
 * Creates a ComplexDouble array filled with ones of a given size and checks if all elements are set to one.
 */


@ Test <EOL> fun createIdentityMatrix ( )

{ <EOL> val n = <NUM_LIT:7> <EOL> val a = mk . identity < ComplexDouble > ( n ) <EOL> assertEquals ( n * n , a . size ) <EOL> for ( i in <NUM_LIT:0> until n ) { <EOL> for ( j in <NUM_LIT:0> until n ) { <EOL> if ( i == j ) <EOL> assertEquals ( ComplexDouble . one , a [ i , j ] , "<STR_LIT>" ) <EOL> else <EOL> assertEquals ( ComplexDouble . zero , a [ i , j ] , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * Tests the function 'mk.identity<ComplexDouble>(n)' that creates an identity matrix of size n x n.
 * The test asserts that:
 * - The size of the resulting matrix matches n*n.
 * - The diagonal elements of the matrix are 1 and the non-diagonal elements are 0.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromComplexDoubleList ( )

{ <EOL> val list = listOf ( listOf ( <NUM_LIT:1.0> + <NUM_LIT> . i , <NUM_LIT:3.0> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) , listOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT:2.0> + <NUM_LIT> . i ) ) <EOL> val a : D2Array < ComplexDouble > = mk . ndarray ( list ) <EOL> assertEquals ( list , a . toListD2 ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a list of byte lists
 * and checks if the array's list representation matches the input list.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromComplexDoubleSet ( )

{ <EOL> val set = setOf ( <NUM_LIT:1.0> + <NUM_LIT> . i , <NUM_LIT:3.0> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT:2.0> + <NUM_LIT> . i ) <EOL> val shape = intArrayOf ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> val a : D2Array < ComplexDouble > = mk . ndarray ( set , shape = shape ) <EOL> assertEquals ( set . size , a . size ) <EOL> assertEquals ( set , a . toSet ( ) ) <EOL> }

/**
 * Creates a two-dimensional array from a set of complex doubles
 * and checks if the array's set representation matches the input set.
 */


@ Test <EOL> fun createTwoDimensionalArrayFromPrimitiveComplexDoubleArray ( )

{ <EOL> val array = complexDoubleArrayOf ( <NUM_LIT:1.0> + <NUM_LIT> . i , <NUM_LIT:3.0> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT:2.0> + <NUM_LIT> . i ) <EOL> val a = mk . ndarray ( array , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assertEquals ( array . size , a . size ) <EOL> a . data . getComplexDoubleArray ( ) shouldBe array <EOL> }

/**
 * Creates a two-dimensional array from a primitive ComplexDoubleArray
 * and checks if the array's ComplexDoubleArray representation matches the input ComplexDoubleArray.
 */


@ Test <EOL> fun createComplexDouble2DArrayWithInitializationFunction ( )

{ <EOL> val a = mk . d2array < ComplexDouble > ( <NUM_LIT:2> , <NUM_LIT:3> ) { ComplexDouble ( it + <NUM_LIT> , round ( ( it - <NUM_LIT> ) * <NUM_LIT> ) / <NUM_LIT> ) } <EOL> val expected = complexDoubleArrayOf ( <NUM_LIT> - <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getComplexDoubleArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function
 * and checks if the array's ComplexDoubleArray representation matches the expected output.
 */


@ Test <EOL> fun createComplexDouble2DArrayWithInitAndIndices ( )

{ <EOL> val a = mk . d2arrayIndices < ComplexDouble > ( <NUM_LIT:2> , <NUM_LIT:3> ) { i , j -> i * j + ComplexDouble ( <NUM_LIT:7> ) } <EOL> val expected = complexDoubleArrayOf ( <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i , <NUM_LIT> + <NUM_LIT> . i ) <EOL> assertEquals ( expected . size , a . size ) <EOL> a . data . getComplexDoubleArray ( ) shouldBe expected <EOL> }

/**
 * Creates a two-dimensional array with a given size using an initialization function and indices.
 * Checks if the array's ComplexDoubleArray representation matches the expected output.
 */


public inline fun PlotContext . layout ( block : Layout . ( ) -> Unit )

{ <EOL> if ( plotFeatures [ Layout . NAME ] == null ) { <EOL> plotFeatures [ Layout . NAME ] = Layout ( ) . apply ( block ) <EOL> } <EOL> ( plotFeatures [ Layout . NAME ] as Layout ) . apply ( block ) <EOL> }

/**
 * Provides a context for configuring the layout of a plot.
 *
 * Inside this context, you can set various layout properties such as
 * title, subtitle, caption, size, and others.
 *
 * ### Example
 *
 * ```kotlin
 * plot {
 * line { x(listOf(1, 2, 3)); y.constant(5) }
 * layout {
 * title = "Main Title"
 * subtitle = "Subtitle"
 * xAxisLabel = "X-Axis"
 * yAxisLabel = "Y-Axis"
 * style(Style.Grey)
 * }
 * }
 * ```
 */


public inline fun style ( style : Style , block : CustomStyle . ( ) -> Unit = { } )

{ <EOL> this . style = style <EOL> customStyle = CustomStyle ( ) . apply ( block ) <EOL> }

/**
 * Configures the style of the plot.
 *
 * @param style one of the predefined styles.
 * @param block additional customizations to apply on top of the main style.
 */


public inline fun style ( block : CustomStyle . ( ) -> Unit )

{ <EOL> style = CustomStyle ( ) . apply ( block ) <EOL> }

/**
 * Configures a custom style for the plot.
 *
 * @param block a lambda function to define the custom style.
 */


fun registerIntrinsic ( owner : FqName , receiverParameter : FqNameUnsafe ? , name : String , valueParameterCount : Int , impl : IntrinsicMethod )

{ <EOL> intrinsicsMap [ Key ( owner . toUnsafe ( ) , receiverParameter , name , valueParameterCount ) ] = impl <EOL> }

/**
 * @param valueParameterCount -1 for property
 */


private fun setup ( outputDirectory : File , content : String , resolutionTargetInFirstModule : DRI ? = null , resolutionTargetInSecondModule : DRI ? = null ) : File

{ <EOL> val innerModule1 = outputDirectory . resolve ( "<STR_LIT>" ) . also { assertTrue ( it . mkdirs ( ) ) } <EOL> val innerModule2 = outputDirectory . resolve ( "<STR_LIT>" ) . also { assertTrue ( it . mkdirs ( ) ) } <EOL> val packageList2 = innerModule2 . resolve ( "<STR_LIT>" ) <EOL> packageList2 . writeText ( mockedPackageListForPackages ( RecognizedLinkFormat . DokkaHtml , "<STR_LIT>" ) ) <EOL> val packageList1 = innerModule1 . resolve ( "<STR_LIT>" ) <EOL> packageList1 . writeText ( mockedPackageListForPackages ( RecognizedLinkFormat . DokkaHtml , "<STR_LIT>" ) ) <EOL> if ( resolutionTargetInFirstModule != null ) { <EOL> val resolvedFile1 = innerModule1 <EOL> . resolve ( "<STR_LIT>" ) <EOL> resolvedFile1 . parentFile . mkdirs ( ) <EOL> resolvedFile1 . createNewFile ( ) <EOL> } <EOL> if ( resolutionTargetInSecondModule != null ) { <EOL> val resolvedFile2 = innerModule2 <EOL> . resolve ( "<STR_LIT>" ) <EOL> resolvedFile2 . parentFile . mkdirs ( ) <EOL> resolvedFile2 . createNewFile ( ) <EOL> } <EOL> val contentFile = innerModule1 . resolve ( "<STR_LIT>" ) <EOL> contentFile . writeText ( content ) <EOL> return contentFile <EOL> }

/**
 * Create partial output for two modules: `module1` and `module2`.
 * The modules have the same package name `package2` in `package-list`s.
 */


public fun analyseImports ( file : KtFile ) : KtImportOptimizerResult

= withValidityAssertion { <EOL> return analysisSession . importOptimizer . analyseImports ( file ) <EOL> }

/**
 * Takes [file] and inspects its imports and their usages,
 * so they can be optimized based on the resulting [KtImportOptimizerResult].
 *
 * Does **not** change the file.
 */


public fun < T > Flow < T > . distinctUntilChanged ( ) : Flow < T >

= <EOL> when ( this ) { <EOL> is StateFlow < * > -> this <EOL> else -> distinctUntilChangedBy ( keySelector = defaultKeySelector , areEquivalent = defaultAreEquivalent ) <EOL> }

/**
 * Returns flow where all subsequent repetitions of the same value are filtered out.
 *
 * Note that any instance of [StateFlow] already behaves as if `distinctUntilChanged` operator is
 * applied to it, so applying `distinctUntilChanged` to a `StateFlow` has no effect.
 * See [StateFlow] documentation on Operator Fusion.
 * Also, repeated application of `distinctUntilChanged` operator on any flow has no effect.
 */


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> public fun < T > Flow < T > . distinctUntilChanged ( areEquivalent : ( old : T , new : T ) -> Boolean ) : Flow < T >

= <EOL> distinctUntilChangedBy ( keySelector = defaultKeySelector , areEquivalent = areEquivalent as ( Any ? , Any ? ) -> Boolean )

/**
 * Returns flow where all subsequent repetitions of the same value are filtered out, when compared
 * with each other via the provided [areEquivalent] function.
 *
 * Note that repeated application of `distinctUntilChanged` operator with the same parameter has no effect.
 */


public fun < T , K > Flow < T > . distinctUntilChangedBy ( keySelector : ( T ) -> K ) : Flow < T >

= <EOL> distinctUntilChangedBy ( keySelector = keySelector , areEquivalent = defaultAreEquivalent )

/**
 * Returns flow where all subsequent repetitions of the same key are filtered out, where
 * key is extracted with [keySelector] function.
 *
 * Note that repeated application of `distinctUntilChanged` operator with the same parameter has no effect.
 */


private fun < T > Flow < T > . distinctUntilChangedBy ( keySelector : ( T ) -> Any ? , areEquivalent : ( old : Any ? , new : Any ? ) -> Boolean ) : Flow < T >

= when { <EOL> this is DistinctFlowImpl < * > && this . keySelector === keySelector && this . areEquivalent === areEquivalent -> this <EOL> else -> DistinctFlowImpl ( this , keySelector , areEquivalent ) <EOL> }

/**
 * Returns flow where all subsequent repetitions of the same key are filtered out, where
 * keys are extracted with [keySelector] function and compared with each other via the
 * provided [areEquivalent] function.
 *
 * NOTE: It is non-inline to share a single implementing class.
 */


@ Suppress ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> override fun hasOwnName ( name : String ) : Boolean

= <EOL> name in RESERVED_WORDS <EOL> || name == ident <EOL> || name == labelName ? . ident <EOL> || parent ? . hasOwnName ( name ) ? : false

/**
 * Safe call is necessary, because hasOwnName can be called
 * in constructor before labelName is initialized (see KT-4394)
 */


public suspend fun < T > Flow < T > . count ( ) : Int

{ <EOL> var i = <NUM_LIT:0> <EOL> collect { <EOL> ++ i <EOL> } <EOL> return i <EOL> }

/**
 * Returns the number of elements in this flow.
 */


public suspend fun < T > Flow < T > . count ( predicate : suspend ( T ) -> Boolean ) : Int

{ <EOL> var i = <NUM_LIT:0> <EOL> collect { value -> <EOL> if ( predicate ( value ) ) { <EOL> ++ i <EOL> } <EOL> } <EOL> return i <EOL> }

/**
 * Returns the number of elements matching the given predicate.
 */


@ Suppress ( "<STR_LIT>" ) <EOL> @ ExperimentalForeignApi <EOL> public fun < T : Boolean > NativePlacement . alloc ( value : T ) : BooleanVarOf < T >

= <EOL> alloc < BooleanVarOf < T > > { this . value = value }

/**
 * Allocates variable with given value type and initializes it with given value.
 */


@ Suppress ( "<STR_LIT>" ) <EOL> @ ExperimentalForeignApi <EOL> public fun < T : Byte > NativePlacement . alloc ( value : T ) : ByteVarOf < T >

= <EOL> alloc < ByteVarOf < T > > { this . value = value }