@ Deprecated ( level = DeprecationLevel . ERROR , message = "<STR_LIT>" , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> public fun < T > SharedFlow < T > . flowOn ( context : CoroutineContext ) : Flow < T >

= noImpl ( )

/**
 * Applying [flowOn][Flow.flowOn] to [SharedFlow] has no effect.
 * See the [SharedFlow] documentation on Operator Fusion.
 * @suppress
 */


@ Deprecated ( level = DeprecationLevel . ERROR , message = "<STR_LIT>" , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> public fun < T > StateFlow < T > . conflate ( ) : Flow < T >

= noImpl ( )

/**
 * Applying [conflate][Flow.conflate] to [StateFlow] has no effect.
 * See the [StateFlow] documentation on Operator Fusion.
 * @suppress
 */


@ Deprecated ( level = DeprecationLevel . ERROR , message = "<STR_LIT>" , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> public fun < T > StateFlow < T > . distinctUntilChanged ( ) : Flow < T >

= noImpl ( )

/**
 * Applying [distinctUntilChanged][Flow.distinctUntilChanged] to [StateFlow] has no effect.
 * See the [StateFlow] documentation on Operator Fusion.
 * @suppress
 */


@ Deprecated ( message = "<STR_LIT>" + "<STR_LIT>" , level = DeprecationLevel . ERROR , replaceWith = ReplaceWith ( "<STR_LIT>" ) ) <EOL> public fun FlowCollector < * > . cancel ( cause : CancellationException ? = null ) : Unit

= noImpl ( )


@ Deprecated ( message = "<STR_LIT>" + "<STR_LIT>" , level = DeprecationLevel . WARNING , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> @ InlineOnly <EOL> public inline fun < T > SharedFlow < T > . catch ( noinline action : suspend FlowCollector < T > . ( cause : Throwable ) -> Unit ) : Flow < T >

= <EOL> ( this as Flow < T > ) . catch ( action )


@ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . WARNING , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> @ InlineOnly <EOL> public inline fun < T > SharedFlow < T > . retry ( retries : Long = Long . MAX_VALUE , noinline predicate : suspend ( cause : Throwable ) -> Boolean = { true } ) : Flow < T >

= <EOL> ( this as Flow < T > ) . retry ( retries , predicate )


@ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . WARNING , replaceWith = ReplaceWith ( "<STR_LIT:this>" ) ) <EOL> @ InlineOnly <EOL> public inline fun < T > SharedFlow < T > . retryWhen ( noinline predicate : suspend FlowCollector < T > . ( cause : Throwable , attempt : Long ) -> Boolean ) : Flow < T >

= <EOL> ( this as Flow < T > ) . retryWhen ( predicate )


@ Suppress ( "<STR_LIT>" ) <EOL> @ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . WARNING ) <EOL> @ InlineOnly <EOL> public suspend inline fun < T > SharedFlow < T > . toList ( ) : List < T >

= <EOL> ( this as Flow < T > ) . toList ( )


@ InlineOnly <EOL> public suspend inline fun < T > SharedFlow < T > . toList ( destination : MutableList < T > ) : Nothing

{ <EOL> ( this as Flow < T > ) . toList ( destination ) <EOL> throw IllegalStateException ( "<STR_LIT>" ) <EOL> }

/**
 * A specialized version of [Flow.toList] that returns [Nothing]
 * to indicate that [SharedFlow] collection never completes.
 */


@ Suppress ( "<STR_LIT>" ) <EOL> @ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . WARNING ) <EOL> @ InlineOnly <EOL> public suspend inline fun < T > SharedFlow < T > . toSet ( ) : Set < T >

= <EOL> ( this as Flow < T > ) . toSet ( )


@ InlineOnly <EOL> public suspend inline fun < T > SharedFlow < T > . toSet ( destination : MutableSet < T > ) : Nothing

{ <EOL> ( this as Flow < T > ) . toSet ( destination ) <EOL> throw IllegalStateException ( "<STR_LIT>" ) <EOL> }

/**
 * A specialized version of [Flow.toSet] that returns [Nothing]
 * to indicate that [SharedFlow] collection never completes.
 */


@ Suppress ( "<STR_LIT>" ) <EOL> @ Deprecated ( message = "<STR_LIT>" , level = DeprecationLevel . WARNING ) <EOL> @ InlineOnly <EOL> public suspend inline fun < T > SharedFlow < T > . count ( ) : Int

= <EOL> ( this as Flow < T > ) . count ( )


fun generateAnnotationValueAsExpression ( startOffset : Int , endOffset : Int , constantValue : ConstantValue < * > , valueParameter : ValueParameterDescriptor , ) : IrExpression ?

= <EOL> generateConstantOrAnnotationValueAsExpression ( startOffset , endOffset , constantValue , valueParameter . type , valueParameter . varargElementType )

/**
 * @return null if the constant value is an unresolved annotation or an unresolved class literal
 */


protected abstract fun SerialDescriptor . getTag ( index : Int ) : Tag

/**
 * Provides a tag object for given serial descriptor and index.
 * Tag object allows associating given user information with a particular element of composite serializable entity.
 */


protected open fun endEncode ( descriptor : SerialDescriptor )

/**
 * Format-specific replacement for [endStructure], because latter is overridden to manipulate tag stack.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> @ InlineOnly <EOL> public actual inline fun < T > ( suspend ( ) -> T ) . startCoroutineUninterceptedOrReturn ( completion : Continuation < T > ) : Any ?

= <EOL> if ( this !is BaseContinuationImpl ) wrapWithContinuationImpl ( completion ) <EOL> else ( this as Function1 < Continuation < T > , Any ? > ) . invoke ( completion )

/**
 * Starts an unintercepted coroutine without a receiver and with result type [T] and executes it until its first suspension.
 * Returns the result of the coroutine or throws its exception if it does not suspend or [COROUTINE_SUSPENDED] if it suspends.
 * In the latter case, the [completion] continuation is invoked when the coroutine completes with a result or an exception.
 *
 * The coroutine is started directly in the invoker's thread without going through the [ContinuationInterceptor] that might
 * be present in the completion's [CoroutineContext]. It is the invoker's responsibility to ensure that a proper invocation
 * context is established.
 *
 * This function is designed to be used from inside of [suspendCoroutineUninterceptedOrReturn] to resume the execution of the suspended
 * coroutine using a reference to the suspending function.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> @ InlineOnly <EOL> public actual inline fun < R , T > ( suspend R . ( ) -> T ) . startCoroutineUninterceptedOrReturn ( receiver : R , completion : Continuation < T > ) : Any ?

= <EOL> if ( this !is BaseContinuationImpl ) wrapWithContinuationImpl ( receiver , completion ) <EOL> else ( this as Function2 < R , Continuation < T > , Any ? > ) . invoke ( receiver , completion )

/**
 * Starts an unintercepted coroutine with receiver type [R] and result type [T] and executes it until its first suspension.
 * Returns the result of the coroutine or throws its exception if it does not suspend or [COROUTINE_SUSPENDED] if it suspends.
 * In the latter case, the [completion] continuation is invoked when the coroutine completes with a result or an exception.
 *
 * The coroutine is started directly in the invoker's thread without going through the [ContinuationInterceptor] that might
 * be present in the completion's [CoroutineContext]. It is the invoker's responsibility to ensure that a proper invocation
 * context is established.
 *
 * This function is designed to be used from inside of [suspendCoroutineUninterceptedOrReturn] to resume the execution of the suspended
 * coroutine using a reference to the suspending function.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> public actual fun < T > ( suspend ( ) -> T ) . createCoroutineUnintercepted ( completion : Continuation < T > ) : Continuation < Unit >

{ <EOL> val probeCompletion = probeCoroutineCreated ( completion ) <EOL> return if ( this is BaseContinuationImpl ) <EOL> create ( probeCompletion ) <EOL> else <EOL> createCoroutineFromSuspendFunction ( probeCompletion ) { <EOL> ( this as Function1 < Continuation < T > , Any ? > ) . invoke ( it ) <EOL> } <EOL> }

/**
 * Creates unintercepted coroutine without receiver and with result type [T].
 * This function creates a new, fresh instance of suspendable computation every time it is invoked.
 *
 * To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
 * The [completion] continuation is invoked when coroutine completes with result or exception.
 *
 * This function returns unintercepted continuation.
 * Invocation of `resume(Unit)` starts coroutine immediately in the invoker's call stack without going through the
 * [ContinuationInterceptor] that might be present in the completion's [CoroutineContext].
 * It is the invoker's responsibility to ensure that a proper invocation context is established.
 * Note that [completion] of this function may get invoked in an arbitrary context.
 *
 * [Continuation.intercepted] can be used to acquire the intercepted continuation.
 * Invocation of `resume(Unit)` on intercepted continuation guarantees that execution of
 * both the coroutine and [completion] happens in the invocation context established by
 * [ContinuationInterceptor].
 *
 * Repeated invocation of any resume function on the resulting continuation corrupts the
 * state machine of the coroutine and may result in arbitrary behaviour or exception.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> public actual fun < R , T > ( suspend R . ( ) -> T ) . createCoroutineUnintercepted ( receiver : R , completion : Continuation < T > ) : Continuation < Unit >

{ <EOL> val probeCompletion = probeCoroutineCreated ( completion ) <EOL> return if ( this is BaseContinuationImpl ) <EOL> create ( receiver , probeCompletion ) <EOL> else { <EOL> createCoroutineFromSuspendFunction ( probeCompletion ) { <EOL> ( this as Function2 < R , Continuation < T > , Any ? > ) . invoke ( receiver , it ) <EOL> } <EOL> } <EOL> }

/**
 * Creates unintercepted coroutine with receiver type [R] and result type [T].
 * This function creates a new, fresh instance of suspendable computation every time it is invoked.
 *
 * To start executing the created coroutine, invoke `resume(Unit)` on the returned [Continuation] instance.
 * The [completion] continuation is invoked when coroutine completes with result or exception.
 *
 * This function returns unintercepted continuation.
 * Invocation of `resume(Unit)` starts coroutine immediately in the invoker's call stack without going through the
 * [ContinuationInterceptor] that might be present in the completion's [CoroutineContext].
 * It is the invoker's responsibility to ensure that a proper invocation context is established.
 * Note that [completion] of this function may get invoked in an arbitrary context.
 *
 * [Continuation.intercepted] can be used to acquire the intercepted continuation.
 * Invocation of `resume(Unit)` on intercepted continuation guarantees that execution of
 * both the coroutine and [completion] happens in the invocation context established by
 * [ContinuationInterceptor].
 *
 * Repeated invocation of any resume function on the resulting continuation corrupts the
 * state machine of the coroutine and may result in arbitrary behaviour or exception.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> public actual fun < T > Continuation < T > . intercepted ( ) : Continuation < T >

= <EOL> ( this as? ContinuationImpl ) ? . intercepted ( ) ? : this

/**
 * Intercepts this continuation with [ContinuationInterceptor].
 *
 * This function shall be used on the immediate result of [createCoroutineUnintercepted] or [suspendCoroutineUninterceptedOrReturn],
 * in which case it checks for [ContinuationInterceptor] in the continuation's [context][Continuation.context],
 * invokes [ContinuationInterceptor.interceptContinuation], caches and returns the result.
 *
 * If this function is invoked on other [Continuation] instances it returns `this` continuation unchanged.
 */


@ SinceKotlin ( "<STR_LIT:1.3>" ) <EOL> private inline fun < T > createCoroutineFromSuspendFunction ( completion : Continuation < T > , crossinline block : ( Continuation < T > ) -> Any ? <EOL> ) : Continuation < Unit >

{ <EOL> val context = completion . context <EOL> return if ( context === EmptyCoroutineContext ) <EOL> object : RestrictedContinuationImpl ( completion as Continuation < Any ? > ) { <EOL> private var label = <NUM_LIT:0> <EOL> override fun invokeSuspend ( result : Result < Any ? > ) : Any ? = <EOL> when ( label ) { <EOL> <NUM_LIT:0> -> { <EOL> label = <NUM_LIT:1> <EOL> result . getOrThrow ( ) <EOL> block ( this ) <EOL> } <EOL> <NUM_LIT:1> -> { <EOL> label = <NUM_LIT:2> <EOL> result . getOrThrow ( ) <EOL> } <EOL> else -> error ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> else <EOL> object : ContinuationImpl ( completion as Continuation < Any ? > , context ) { <EOL> private var label = <NUM_LIT:0> <EOL> override fun invokeSuspend ( result : Result < Any ? > ) : Any ? = <EOL> when ( label ) { <EOL> <NUM_LIT:0> -> { <EOL> label = <NUM_LIT:1> <EOL> result . getOrThrow ( ) <EOL> block ( this ) <EOL> } <EOL> <NUM_LIT:1> -> { <EOL> label = <NUM_LIT:2> <EOL> result . getOrThrow ( ) <EOL> } <EOL> else -> error ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * This function is used when [createCoroutineUnintercepted] encounters suspending lambda that does not extend BaseContinuationImpl.
 *
 * It happens in two cases:
 * 1. Callable reference to suspending function,
 * 2. Suspending function reference implemented by Java code.
 *
 * We must wrap it into an instance that extends [BaseContinuationImpl], because that is an expectation of all coroutines machinery.
 * As an optimization we use lighter-weight [RestrictedContinuationImpl] base class (it has less fields) if the context is
 * [EmptyCoroutineContext], and a full-blown [ContinuationImpl] class otherwise.
 *
 * The instance of [BaseContinuationImpl] is passed to the [block] so that it can be passed to the corresponding invocation.
 */


private fun < T > createSimpleCoroutineForSuspendFunction ( completion : Continuation < T > ) : Continuation < T >

{ <EOL> val context = completion . context <EOL> return if ( context === EmptyCoroutineContext ) <EOL> object : RestrictedContinuationImpl ( completion as Continuation < Any ? > ) { <EOL> override fun invokeSuspend ( result : Result < Any ? > ) : Any ? { <EOL> return result . getOrThrow ( ) <EOL> } <EOL> } <EOL> else <EOL> object : ContinuationImpl ( completion as Continuation < Any ? > , context ) { <EOL> override fun invokeSuspend ( result : Result < Any ? > ) : Any ? { <EOL> return result . getOrThrow ( ) <EOL> } <EOL> } <EOL> }

/**
 * This function is used when [startCoroutineUninterceptedOrReturn] encounters suspending lambda that does not extend BaseContinuationImpl.
 *
 * It happens in two cases:
 * 1. Callable reference to suspending function or tail-call lambdas,
 * 2. Suspending function reference implemented by Java code.
 *
 * This function is the same as above, but does not run lambda itself - the caller is expected to call [invoke] manually.
 */


internal fun invalidateAfterInBlockModification ( declaration : FirDeclaration ) : Boolean

= when ( declaration ) { <EOL> is FirSimpleFunction -> declaration . inBodyInvalidation ( ) <EOL> is FirPropertyAccessor -> declaration . inBodyInvalidation ( ) <EOL> is FirProperty -> declaration . inBodyInvalidation ( ) <EOL> is FirCodeFragment -> declaration . inBodyInvalidation ( ) <EOL> else -> errorWithFirSpecificEntries ( "<STR_LIT>" , fir = declaration , psi = declaration . psi ) <EOL> }

/**
 * Must be called in a write action.
 * @return **false** if it is not in-block modification
 */


private fun FirSimpleFunction . inBodyInvalidation ( ) : Boolean

{ <EOL> val body = body ? : return false <EOL> invalidateBody ( body ) <EOL> return true <EOL> }

/**
 * Drop body and all related stuff.
 * We should drop:
 * * body
 * * control flow graph reference, because it depends on the body
 * * reduce phase if needed
 *
 * Depends on the body, but we shouldn't drop:
 * * implicit type, because the change mustn't change the resulting type
 * * contract, because a change inside a contract description is OOBM, so this function won't be called in this case
 *
 * Also, we shouldn't update somehow value parameters because they have their own "bodies" (a default value) and
 * changes in them are OOBM, so it is not our case.
 *
 * @return **false** if it is an out-of-block change
 */


private fun FirProperty . inBodyInvalidation ( ) : Boolean

{ <EOL> val initializerState = invalidateInitializer ( ) <EOL> val delegateState = invalidateDelegate ( ) <EOL> when { <EOL> initializerState == PropertyExpressionState . ABSENT && delegateState == PropertyExpressionState . ABSENT -> return false <EOL> initializerState == PropertyExpressionState . LAZY || delegateState == PropertyExpressionState . LAZY -> return true <EOL> } <EOL> decreasePhase ( phaseWithoutBody ) <EOL> replaceControlFlowGraphReference ( null ) <EOL> replaceBodyResolveState ( FirPropertyBodyResolveState . NOTHING_RESOLVED ) <EOL> return true <EOL> }

/**
 * Drop body and all related stuff.
 * We should drop:
 * * initializer or delegate expression
 * * control flow graph reference, because it depends on the initializer or delegate
 * * body resolution state
 * * reduce phase if needed
 *
 * Depends on the body, but we shouldn't drop:
 * * implicit type, because the change mustn't change the resulting type
 *
 * Also, we shouldn't update the property accessors because they don't depend on the initializer or delegate.
 * So it is fine to leave the phase of setter/getter/backing field as it is.
 *
 * @return **false** if it is an out-of-block change
 */


private fun FirPropertyAccessor . inBodyInvalidation ( ) : Boolean

{ <EOL> val body = body ? : return false <EOL> val newPhase = invalidateBody ( body ) ? : return true <EOL> val property = propertySymbol . fir <EOL> property . decreasePhase ( newPhase ) <EOL> val newPropertyResolveState = if ( isGetter ) { <EOL> FirPropertyBodyResolveState . INITIALIZER_RESOLVED <EOL> } else { <EOL> FirPropertyBodyResolveState . INITIALIZER_AND_GETTER_RESOLVED <EOL> } <EOL> property . replaceBodyResolveState ( minOf ( property . bodyResolveState , newPropertyResolveState ) ) <EOL> return true <EOL> }

/**
 * Drop body and all related stuff.
 * We should drop:
 * * body
 * * control flow graph reference, because it depends on the body
 * * property body resolution state
 * * reduce phase if needed
 *
 * Depends on the body, but we shouldn't drop:
 * * implicit type, because the change mustn't change the resulting type
 * * contract, because a change inside a contract description is OOBM, so this function won't be called in this case
 *
 * @return **false** if it is an out-of-block change
 */


@ JvmStatic <EOL> fun newInstance ( param1 : String , param2 : String )

= <EOL> StartFragment ( ) . apply { <EOL> arguments = Bundle ( ) . apply { <EOL> putString ( ARG_PARAM1 , param1 ) <EOL> putString ( ARG_PARAM2 , param2 ) <EOL> } <EOL> }

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 *
 * @param param1 Parameter 1.
 * @param param2 Parameter 2.
 * @return A new instance of fragment StartFragment.
 */


fun createScriptDefinitionFromTemplate ( baseClassType : KotlinType , baseHostConfiguration : ScriptingHostConfiguration , contextClass : KClass < * > = ScriptDefinition :: class , compilation : ScriptCompilationConfiguration . Builder . ( ) -> Unit = { } , evaluation : ScriptEvaluationConfiguration . Builder . ( ) -> Unit = { } ) : ScriptDefinition

{ <EOL> val templateClass : KClass < * > = baseClassType . getTemplateClass ( baseHostConfiguration , contextClass ) <EOL> val mainAnnotation = templateClass . kotlinScriptAnnotation <EOL> val hostConfiguration = constructHostConfiguration ( mainAnnotation . hostConfiguration , baseHostConfiguration ) { } <EOL> val compilationConfiguration = <EOL> constructCompilationConfiguration ( mainAnnotation , hostConfiguration , templateClass , baseClassType , compilation ) <EOL> val evaluationConfiguration = constructEvaluationConfiguration ( mainAnnotation , hostConfiguration , evaluation ) <EOL> return ScriptDefinition ( compilationConfiguration , evaluationConfiguration ) <EOL> }

/**
 * Creates script compilation and evaluation configuration from annotated script base class
 * @param baseClassType the annotated script base class to construct the configuration from
 * @param baseHostConfiguration base scripting host configuration properties
 * @param contextClass optional context class to extract classloading strategy from
 * @param compilation optional configuration function to add more properties to the compilation configuration
 * @param evaluation optional configuration function to add more properties to the evaluation configuration
 */


fun createCompilationConfigurationFromTemplate ( baseClassType : KotlinType , baseHostConfiguration : ScriptingHostConfiguration , contextClass : KClass < * > = ScriptCompilationConfiguration :: class , body : ScriptCompilationConfiguration . Builder . ( ) -> Unit = { } ) : ScriptCompilationConfiguration

{ <EOL> val templateClass : KClass < * > = baseClassType . getTemplateClass ( baseHostConfiguration , contextClass ) <EOL> val mainAnnotation = templateClass . kotlinScriptAnnotation <EOL> val hostConfiguration = constructHostConfiguration ( mainAnnotation . hostConfiguration , baseHostConfiguration ) { } <EOL> return constructCompilationConfiguration ( mainAnnotation , hostConfiguration , templateClass , baseClassType , body ) <EOL> }

/**
 * Creates compilation configuration from annotated script base class
 * NOTE: it is preferable to use createScriptDefinitionFromTemplate for creating all configurations at once
 * @param baseClassType the annotated script base class to construct the configuration from
 * @param baseHostConfiguration scripting host configuration properties
 * @param contextClass optional context class to extract classloading strategy from
 * @param body optional configuration function to add more properties to the compilation configuration
 */


fun createEvaluationConfigurationFromTemplate ( baseClassType : KotlinType , baseHostConfiguration : ScriptingHostConfiguration , contextClass : KClass < * > = ScriptEvaluationConfiguration :: class , body : ScriptEvaluationConfiguration . Builder . ( ) -> Unit = { } ) : ScriptEvaluationConfiguration

{ <EOL> val templateClass : KClass < * > = baseClassType . getTemplateClass ( baseHostConfiguration , contextClass ) <EOL> val mainAnnotation = templateClass . kotlinScriptAnnotation <EOL> val hostConfiguration = constructHostConfiguration ( mainAnnotation . hostConfiguration , baseHostConfiguration ) { } <EOL> return constructEvaluationConfiguration ( mainAnnotation , hostConfiguration , body ) <EOL> }

/**
 * Creates evaluation configuration from annotated script base class
 * NOTE: it is preferable to use createScriptDefinitionFromTemplate for creating all configurations at once
 * @param baseClassType the annotated script base class to construct the configuration from
 * @param baseHostConfiguration scripting host configuration properties
 * @param contextClass optional context class to extract classloading strategy from
 * @param body optional configuration function to add more properties to the evaluation configuration
 */


public inline fun < reified DomainType : Comparable < DomainType > > continuousColorGrey ( paletteRange : ClosedRange < Double > ? = null , domain : ClosedRange < DomainType > , nullValue : Color ? = null , transform : Transformation ? = null ) : ScaleContinuousColorGrey < DomainType >

= ScaleContinuousColorGrey ( paletteRange ? . let { <EOL> it . start to it . endInclusive <EOL> } , domain . let { <EOL> it . start to it . endInclusive <EOL> } , nullValue , transform )

/**
 * Sequential grey continuous color scale for color aesthetic.
 * The palette is computed using an HSV (hue, saturation, value) color model.
 *
 * @param DomainType type of domain
 * @param paletteRange grey values range (between [0, 1]).
 * @param domain [ClosedRange] defining the scale domain.
 * @param nullValue value which null is mapped to.
 * @param transform scale transformation.
 *
 * @return new continuous color scale.
 */


public inline fun < reified DomainType : Comparable < DomainType > > continuousColorGrey ( paletteRange : ClosedRange < Double > ? = null , domainMin : DomainType ? = null , domainMax : DomainType ? = null , nullValue : Color ? = null , transform : Transformation ? = null ) : ScaleContinuousColorGrey < DomainType >

= ScaleContinuousColorGrey ( paletteRange ? . let { <EOL> it . start to it . endInclusive <EOL> } , domainMin to domainMax , nullValue , transform )

/**
 * Sequential grey color continuous scale for color aesthetic.
 * The palette is computed using an HSV (hue, saturation, value) color model.
 *
 * @param DomainType type of domain
 * @param paletteRange grey values range (between [0, 1]).
 * @param domainMin scale domain minimum.
 * @param domainMax scale domain maximum.
 * @param nullValue value which null is mapped to.
 * @param transform scale transformation.
 *
 * @return new continuous color scale.
 */


public inline fun < reified DomainType > categoricalColorGrey ( paletteRange : Pair < Double , Double > ? = null , ) : ScaleCategoricalColorGrey < DomainType >

= ScaleCategoricalColorGrey < DomainType > ( paletteRange , )

/**
 * Sequential grey color categorical scale for color aesthetic.
 * The palette is computed using HSV (hue, saturation, value) color model.
 *
 * @param DomainType type of domain
 * @param paletteRange grey values range (between [0, 1]).
 *
 * @return new categorical color scale.
 */


fun flush ( @ Suppress ( "<STR_LIT:UNUSED_PARAMETER>" ) memoryCachesOnly : Boolean )

{ <EOL> flush ( ) <EOL> }

/**
 * DEPRECATED: This API should be removed because
 * - It's not clear what [memoryCachesOnly] means.
 * - In the past, when `memoryCachesOnly=true` we applied a small optimization: Checking
 * [com.intellij.util.io.PersistentHashMap.isDirty] before calling [com.intellij.util.io.PersistentHashMap.force]. However, if that
 * optimization is useful, it's better to always do it (perhaps inside the [com.intellij.util.io.PersistentHashMap.force] method
 * itself) rather than doing it based on the value of this parameter.
 *
 * Instead, just call [flush] (without a parameter) directly.
 */


{ <EOL> close ( ) <EOL> deleteStorageFiles ( ) <EOL> }

/**
 * DEPRECATED: This API should be removed because:
 * - It's not obvious what "clean" means: It does not exactly describe the current implementation, and it also sounds similar to
 * "clear" which means removing all the map entries, but this method does not do that.
 * - This method currently calls [close] (and [deleteStorageFiles]). However, [close] is often already called separately and
 * automatically, so this API makes it more likely for [close] to be accidentally called twice.
 *
 * Instead, just call [close] and/or [deleteStorageFiles] explicitly.
 */


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.
 */


internal suspend fun Project . createCommonizedCInteropDependencyConfigurationView ( sourceSet : KotlinSourceSet ) : FileCollection

{ <EOL> @ OptIn ( UnsafeApi :: class ) <EOL> val configuration = locateOrCreateCommonizedCInteropDependencyConfiguration ( sourceSet ) ? : return files ( ) <EOL> return configuration . incoming . artifactView { view -> view . isLenient = true } . files <EOL> }

/**
 * Gives access the 'commonized cinterop dependency configuration' of the given [sourceSet].
 * The access is forced through this 'view' because the provided 'artifact view' is forced to be lenient as protective measure.
 *
 * If dependencies do not provide corresponding commonized cinterop element configurations then we should not fail the build!
 */


protected fun < T : FirCallableSymbol < * > > ResultOfIntersection < T > . collectNonOverriddenDeclarations ( explicitlyDeclared : Set < FirCallableSymbol < * > > , destination : MutableList < in T > , )

{ <EOL> when ( this ) { <EOL> is ResultOfIntersection . SingleMember -> { <EOL> val chosenSymbol = chosenSymbol <EOL> if ( chosenSymbol . isInvisible ( ) ) return <EOL> val overriddenBy = chosenSymbol . getOverridden ( explicitlyDeclared ) <EOL> if ( overriddenBy == null ) { <EOL> destination += chosenSymbol <EOL> } <EOL> } <EOL> is ResultOfIntersection . NonTrivial -> { <EOL> val ( visibleNotOverridden , overriddenOrInvisible ) = overriddenMembers <EOL> . partition { ! it . member . isInvisible ( ) && it . member . getOverridden ( explicitlyDeclared ) == null } <EOL> if ( overriddenOrInvisible . isEmpty ( ) ) { <EOL> destination += chosenSymbol <EOL> } else if ( visibleNotOverridden . isNotEmpty ( ) ) { <EOL> destination += supertypeScopeContext <EOL> . convertGroupedCallablesToIntersectionResults ( visibleNotOverridden . map { it . baseScope to listOf ( it . member ) } ) <EOL> . map { it . chosenSymbol } <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * If the receiver [ResultOfIntersection] is not overridden by any symbol in [explicitlyDeclared],
 * adds its [ResultOfIntersection.chosenSymbol] to [destination].
 *
 * If the [ResultOfIntersection] is [ResultOfIntersection.NonTrivial] and only some of the intersected symbols are overridden,
 * constructs a new [ResultOfIntersection] consisting of the non-overridden symbols and adds its [ResultOfIntersection.chosenSymbol]
 * to [destination].
 *
 * It's the opposite operation of [collectDirectOverriddenForDeclared].
 */


protected inline fun < T : FirCallableSymbol < * > > ResultOfIntersection < T > . collectDirectOverriddenForDeclared ( declared : T , result : MutableList < in ResultOfIntersection < T > > , isOverridden : ( T , T ) -> Boolean , )

{ <EOL> when ( this ) { <EOL> is ResultOfIntersection . SingleMember -> { <EOL> val symbolFromSupertype = chosenSymbol <EOL> if ( isOverridden ( declared , symbolFromSupertype ) ) { <EOL> result . add ( this ) <EOL> } <EOL> } <EOL> is ResultOfIntersection . NonTrivial -> { <EOL> val ( overridden , nonOverridden ) = overriddenMembers . partition { <EOL> isOverridden ( declared , it . member ) <EOL> } <EOL> if ( nonOverridden . isEmpty ( ) ) { <EOL> result += this <EOL> } else if ( overridden . isNotEmpty ( ) ) { <EOL> result += supertypeScopeContext . convertGroupedCallablesToIntersectionResults ( overridden . map { it . baseScope to listOf ( it . member ) } ) <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * If [declared] overrides the receiver [ResultOfIntersection], adds it to [result].
 * If the [ResultOfIntersection] is [ResultOfIntersection.NonTrivial] and [declared] only overrides some of the intersected symbols,
 * a new [ResultOfIntersection] is constructed containing only the overridden symbols.
 *
 * Opposite operation to [collectNonOverriddenDeclarations].
 */


protected open fun FirNamedFunctionSymbol . replaceWithWrapperSymbolIfNeeded ( ) : FirNamedFunctionSymbol

{ <EOL> return this <EOL> }

/**
 * This function is currently used only for creating suspend views in Java.
 */


internal fun ConfigurationContainer . configureStdlibVersionAlignment ( )

= all { configuration -> <EOL> configuration . withDependencies { dependencySet -> <EOL> dependencySet <EOL> . withType < ExternalDependency > ( ) <EOL> . configureEach { dependency -> <EOL> if ( dependency . group == KOTLIN_MODULE_GROUP && ( dependency . name == KOTLIN_STDLIB_MODULE_NAME || dependency . name == KOTLIN_STDLIB_JDK7_MODULE_NAME ) && dependency . version != null && SemVer . fromGradleRichVersion ( dependency . version ! ! ) . let { it >= kotlin180Version && it < kotlin1920Version } ) { <EOL> if ( configuration . isCanBeResolved ) configuration . alignStdlibJvmVariantVersions ( dependency ) <EOL> filter { <EOL> it . isCanBeResolved && it . hierarchy . contains ( configuration ) <EOL> } . forEach { <EOL> it . alignStdlibJvmVariantVersions ( dependency ) <EOL> } <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Aligning kotlin-stdlib-jdk8 and kotlin-stdlib-jdk7 dependencies versions with kotlin-stdlib (or kotlin-stdlib-jdk7)
 * when project stdlib version is >= 1.8.0
 */


fun NamedDomainObjectContainer < KotlinSourceSet > . groupSourceSets ( groupName : String , reverseDependencies : List < String > , dependencies : List < String > )

{ <EOL> val sourceSetSuffixes = listOf ( "<STR_LIT>" , "<STR_LIT:Test>" ) <EOL> for ( suffix in sourceSetSuffixes ) { <EOL> register ( groupName + suffix ) { <EOL> for ( dep in dependencies ) { <EOL> dependsOn ( get ( dep + suffix ) ) <EOL> } <EOL> for ( revDep in reverseDependencies ) { <EOL> get ( revDep + suffix ) . dependsOn ( this ) <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Creates shared source sets for a group of source sets.
 *
 * [reverseDependencies] is a list of prefixes of names of source sets that depend on the new source set.
 * [dependencies] is a list of prefixes of names of source sets that the new source set depends on.
 * [groupName] is the prefix of the names of the new source sets.
 *
 * The suffixes of the source sets are "Main" and "Test".
 */


public fun onModification ( module : KtModule , modificationKind : KotlinModuleStateModificationKind )

/**
 * [onModification] is invoked in a write action *before* the [module] is updated or removed (see [modificationKind] for specifics).
 *
 * @see KotlinTopics
 */


public fun createInheritanceTypeSubstitutor ( subClass : KtClassOrObjectSymbol , superClass : KtClassOrObjectSymbol , ) : KtSubstitutor ?

= withValidityAssertion { <EOL> analysisSession . substitutorProvider . createSubstitutor ( subClass , superClass ) <EOL> }

/**
 * Creates a [KtSubstitutor] based on the inheritance relationship between [subClass] and [superClass].
 *
 * The semantic of resulted [KtSubstitutor] is the substitutor that should be applied to a member of [superClass],
 * so it can be called on an instance of [subClass].
 *
 * Basically, it's a composition of inheritance-based substitutions for all the inheritance chain.
 *
 * On the following code:
 * ```
 * class A : B<String>
 * class B<T> : C<T, Int>
 * class C<X, Y>
 * ```
 *
 * * `createInheritanceTypeSubstitutor(A, B)` returns `KtSubstitutor {T -> String}`
 * * `createInheritanceTypeSubstitutor(B, C)` returns `KtSubstitutor {X -> T, Y -> Int}`
 * * `createInheritanceTypeSubstitutor(A, C)` returns `KtSubstitutor {X -> T, Y -> Int} andThen KtSubstitutor {T -> String}`
 *
 * @param subClass the subClass or object symbol.
 * @param superClass the super class symbol.
 * @return [KtSubstitutor] if [subClass] inherits [superClass] and there are no error types in the inheritance path. Returns `null` otherwise.
 */


{ <EOL> val modelHub = TFModelHub ( cacheDirectory = File ( "<STR_LIT>" ) ) <EOL> val modelType = TFModels . CV . VGG19 ( ) <EOL> val model = modelHub . loadModel ( modelType ) <EOL> val layers = model . layers . dropLast ( <NUM_LIT:1> ) . toMutableList ( ) <EOL> layers . forEach ( Layer :: freeze ) <EOL> layers . add ( Dense ( name = "<STR_LIT>" , kernelInitializer = HeNormal ( ) , biasInitializer = HeNormal ( ) , outputSize = <NUM_LIT> , activation = Activations . Relu ) ) <EOL> layers . add ( Dense ( name = "<STR_LIT>" , kernelInitializer = HeNormal ( ) , biasInitializer = HeNormal ( ) , outputSize = <NUM_LIT:2> , activation = Activations . Linear ) ) <EOL> val newModel = Sequential . of ( layers ) <EOL> val dataset = OnFlyImageDataset . create ( File ( dogsCatsSmallDatasetPath ( ) ) , FromFolders ( mapping = mapOf ( "<STR_LIT>" to <NUM_LIT:0> , "<STR_LIT>" to <NUM_LIT:1> ) ) , modelType . createPreprocessing ( newModel ) ) . shuffle ( ) <EOL> val ( train , test ) = dataset . split ( TRAIN_TEST_SPLIT_RATIO ) <EOL> newModel . use { <EOL> it . compile ( optimizer = Adam ( ) , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> val hdfFile = modelHub . loadWeights ( modelType ) <EOL> it . loadWeightsForFrozenLayers ( hdfFile ) <EOL> val accuracyBeforeTraining = it . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> it . fit ( dataset = train , batchSize = TRAINING_BATCH_SIZE , epochs = EPOCHS ) <EOL> val accuracyAfterTraining = it . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> }

/**
 * This example demonstrates the transfer learning concept on VGG'19 model:
 * - Model configuration, model weights and labels are obtained from [TFModelHub].
 * - Weights are loaded from .h5 file, configuration is loaded from .json file.
 * - All layers, excluding the last [Dense], are added to the new Neural Network, its weights are frozen.
 * - New Dense layers are added and initialized via defined initializers.
 * - Model is re-trained on [dogsCatsSmallDatasetPath] dataset.
 *
 * We use the preprocessing DSL to describe the dataset generation pipeline.
 * We demonstrate the workflow on the subset of Kaggle Cats vs Dogs binary classification dataset.
 *
 * @see
 * Very Deep Convolutional Networks for Large-Scale Image Recognition (ICLR 2015).
 * @see
 * Detailed description of VGG'19 model and an approach to build it in Keras.
 */


= vgg19additionalTraining ( )


private fun KTestMessageProto3Oneof . verify ( verificationFunction : ( KTestMessageProto3Oneof , TestMessagesProto3 . TestAllTypesProto3 ) -> Unit , )

{ <EOL> val bytes = ProtoBuf . encodeToByteArray ( this ) <EOL> val restored = TestMessagesProto3 . TestAllTypesProto3 . parseFrom ( bytes ) <EOL> verificationFunction . invoke ( this , restored ) <EOL> val restoredMessage = ProtoBuf . decodeFromByteArray < KTestMessageProto3Oneof > ( restored . toByteArray ( ) ) <EOL> assertEquals ( this , restoredMessage . copy ( oneofBytes = this . oneofBytes ) ) <EOL> assertContentEquals ( this . oneofBytes , restoredMessage . oneofBytes ) <EOL> }

/**
 * Verify that the given [KTestMessageProto3Oneof] is correctly encoded and decoded as
 * [TestMessagesProto3.TestAllTypesProto3] by running the [verificationFunction]. This
 * method also verifies that the encoded and decoded message is equal to the original message.
 *
 * @param verificationFunction a function that verifies the encoded and decoded message. First parameter
 * is the original message and the second parameter is the decoded protobuf library message.
 * @receiver the [KTestMessageProto3Oneof] to verify
 */


{ <EOL> val modelHub = ONNXModelHub ( cacheDirectory = File ( "<STR_LIT>" ) ) <EOL> val modelType = ONNXModels . CVnoTop . ResNet50Custom <EOL> modelHub . loadModel ( modelType ) . use { model -> <EOL> println ( model ) <EOL> val preprocessing = modelType . createPreprocessing ( longArrayOf ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) ) . onnx { onnxModel = model } <EOL> val dogsVsCatsDatasetPath = dogsCatsSmallDatasetPath ( ) <EOL> val dataset = OnFlyImageDataset . create ( File ( dogsVsCatsDatasetPath ) , FromFolders ( mapping = mapOf ( "<STR_LIT>" to <NUM_LIT:0> , "<STR_LIT>" to <NUM_LIT:1> ) ) , preprocessing ) . shuffle ( ) <EOL> val ( train , test ) = dataset . split ( TRAIN_TEST_SPLIT_RATIO ) <EOL> topModel . use { <EOL> topModel . compile ( optimizer = Adam ( ) , loss = Losses . SOFT_MAX_CROSS_ENTROPY_WITH_LOGITS , metric = Metrics . ACCURACY ) <EOL> topModel . fit ( dataset = train , epochs = EPOCHS , batchSize = TRAINING_BATCH_SIZE ) <EOL> val accuracy = topModel . evaluate ( dataset = test , batchSize = TEST_BATCH_SIZE ) . metrics [ Metrics . ACCURACY ] <EOL> println ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }

/**
 * This examples demonstrates the transfer learning concept on ResNet'50 model:
 * - Model configuration, model weights and labels are obtained from [ONNXModelHub].
 * - All layers, excluding the last [Dense], are added to the new Neural Network, its weights are frozen.
 * - ONNX frozen model is used as a preprocessing stage via `onnx` stage of the Image Preprocessing DSL.
 * - New Dense layers are added and initialized via defined initializers.
 * - Model is re-trained on [dogsCatsDatasetPath] dataset.
 *
 *
 * We use the preprocessing DSL to describe the dataset generation pipeline.
 * We demonstrate the workflow on the subset of Kaggle Cats vs Dogs binary classification dataset.
 */


= resnet50additionalTraining ( )


fun reloadScriptConfiguration ( scriptFile : PsiFile , updateEditorWithoutNotification : Boolean = false )

{ <EOL> val extensions = scriptFile . project . extensionArea . getExtensionPoint ( IdeScriptConfigurationControlFacade . EP_NAME ) . extensions <EOL> for ( extension in extensions ) { <EOL> extension . reloadScriptConfiguration ( scriptFile , updateEditorWithoutNotification ) <EOL> } <EOL> }

/**
 * Force reloading the script definition associated with the passed [scriptFile] in the Kotlin plugin
 *
 * [updateEditorWithoutNotification] controls whether the update of the indexes and highlighting of the script files
 * based on the reloaded definition should be reloaded automatically or using notification and explicit reload action
 */


fun reloadScriptConfiguration ( scriptFile : PsiFile , updateEditorWithoutNotification : Boolean = false )


public inline fun < T , D : Dimension > MultiArray < T , D > . all ( predicate : ( T ) -> Boolean ) : Boolean

{ <EOL> if ( isEmpty ( ) ) return true <EOL> for ( element in this ) if ( ! predicate ( element ) ) return false <EOL> return true <EOL> }

/**
 * Returns `true` if all elements match the given [predicate].
 * If an ndarray is empty, then always returns `true`.
 */


public fun < T , D : Dimension > MultiArray < T , D > . any ( ) : Boolean

{ <EOL> return isNotEmpty ( ) <EOL> }

/**
 * Returns `true` if collection has at least one element.
 * @see NDArray.isNotEmpty
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . any ( predicate : ( T ) -> Boolean ) : Boolean

{ <EOL> if ( isEmpty ( ) ) return false <EOL> for ( element in this ) if ( predicate ( element ) ) return true <EOL> return false <EOL> }

/**
 * Returns `true` if at least one element matches the given [predicate].
 * If an ndarray is empty, then always returns `false`.
 */


public fun < T , D : Dimension > MultiArray < T , D > . asSequence ( ) : Sequence < T >

{ <EOL> return Sequence { this . iterator ( ) } <EOL> }

/**
 * Creates a [Sequence] instance that wraps the original collection returning its elements when being iterated.
 */


public inline fun < T , D : Dimension , K , V > MultiArray < T , D > . associate ( transform : ( T ) -> Pair < K , V > ) : Map < K , V >

{ <EOL> val capacity = mapCapacity ( this . size ) . coerceAtLeast ( <NUM_LIT:16> ) <EOL> return associateTo ( LinkedHashMap ( capacity ) , transform ) <EOL> }

/**
 * Returns a [Map] containing key-value pairs provided by [transform] function
 * applied to elements of the given collection.
 *
 * If any of two pairs would have the same key the last one gets added to the map.
 *
 * The returned map preserves the entry iteration order of the original collection.
 */


public inline fun < T , D : Dimension , K > MultiArray < T , D > . associateBy ( keySelector : ( T ) -> K ) : Map < K , T >

{ <EOL> val capacity = mapCapacity ( size ) . coerceAtLeast ( <NUM_LIT:16> ) <EOL> return associateByTo ( LinkedHashMap ( capacity ) , keySelector ) <EOL> }

/**
 * Returns a [Map] containing the elements from the given collection indexed by the key
 * returned from [keySelector] function applied to each element.
 *
 * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
 *
 * The returned map preserves the entry iteration order of the original collection.
 */


public inline fun < T , D : Dimension , K , V > MultiArray < T , D > . associateBy ( keySelector : ( T ) -> K , valueTransform : ( T ) -> V ) : Map < K , V >

{ <EOL> val capacity = mapCapacity ( size ) . coerceAtLeast ( <NUM_LIT:16> ) <EOL> return associateByTo ( LinkedHashMap ( capacity ) , keySelector , valueTransform ) <EOL> }

/**
 * Returns a [Map] containing the values provided by [valueTransform] and indexed by [keySelector] functions applied to elements of the given collection.
 *
 * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
 *
 * The returned map preserves the entry iteration order of the original collection.
 */


public inline fun < T , D : Dimension , K , M : MutableMap < in K , in T > > MultiArray < T , D > . associateByTo ( destination : M , keySelector : ( T ) -> K ) : M

{ <EOL> for ( element in this ) <EOL> destination . put ( keySelector ( element ) , element ) <EOL> return destination <EOL> }

/**
 * Populates and returns the [destination] mutable map with key-value pairs,
 * where key is provided by the [keySelector] function applied to each element of the given collection
 * and value is the element itself.
 *
 * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
 */


public inline fun < T , D : Dimension , K , V , M : MutableMap < in K , in V > > MultiArray < T , D > . associateByTo ( destination : M , keySelector : ( T ) -> K , valueTransform : ( T ) -> V ) : M

{ <EOL> for ( element in this ) <EOL> destination . put ( keySelector ( element ) , valueTransform ( element ) ) <EOL> return destination <EOL> }

/**
 * Populates and returns the [destination] mutable map with key-value pairs,
 * where key is provided by the [keySelector] function and
 * and value is provided by the [valueTransform] function applied to elements of the given collection.
 *
 * If any two elements would have the same key returned by [keySelector] the last one gets added to the map.
 */


public inline fun < T , D : Dimension , K , V , M : MutableMap < in K , in V > > MultiArray < T , D > . associateTo ( destination : M , transform : ( T ) -> Pair < K , V > ) : M

{ <EOL> for ( element in this ) <EOL> destination += transform ( element ) <EOL> return destination <EOL> }

/**
 * Populates and returns the [destination] mutable map with key-value pairs
 * provided by [transform] function applied to each element of the given collection.
 *
 * If any of two pairs would have the same key the last one gets added to the map.
 */


public inline fun < K , D : Dimension , V > MultiArray < K , D > . associateWith ( valueSelector : ( K ) -> V ) : Map < K , V >

{ <EOL> val capacity = mapCapacity ( size ) . coerceAtLeast ( <NUM_LIT:16> ) <EOL> return associateWithTo ( LinkedHashMap ( capacity ) , valueSelector ) <EOL> }

/**
 * Returns a [Map] where keys are elements from the given collection and values are
 * produced by the [valueSelector] function applied to each element.
 *
 * If any two elements are equal, the last one gets added to the map.
 *
 * The returned map preserves the entry iteration order of the original collection.
 */


public inline fun < K , D : Dimension , V , M : MutableMap < in K , in V > > MultiArray < K , D > . associateWithTo ( destination : M , valueSelector : ( K ) -> V ) : M

{ <EOL> for ( element in this ) <EOL> destination . put ( element , valueSelector ( element ) ) <EOL> return destination <EOL> }

/**
 * Populates and returns the [destination] mutable map with key-value pairs for each element of the given collection,
 * where key is the element itself and value is provided by the [valueSelector] function applied to that key.
 *
 * If any two elements are equal, the last one overwrites the former value in the map.
 */


public fun < T : Number , D : Dimension > MultiArray < T , D > . average ( ) : Double

{ <EOL> var sum = <NUM_LIT:0.0> <EOL> var count = <NUM_LIT:0> <EOL> for ( element in this ) { <EOL> sum += element . toDouble ( ) <EOL> if ( ++ count < <NUM_LIT:0> ) throw ArithmeticException ( "<STR_LIT>" ) <EOL> } <EOL> return if ( count == <NUM_LIT:0> ) Double . NaN else sum / count <EOL> }

/**
 * Returns an average value of elements in the ndarray.
 */


public fun < T , D : Dimension > MultiArray < T , D > . chunked ( size : Int ) : NDArray < T , D2 >

{ <EOL> return windowed ( size , size , limit = false ) <EOL> }

/**
 * Splits this ndarray into a 2-D ndarray.
 * The last elements in the resulting ndarray may be zero.
 *
 * @param size number of elements in axis 1.
 */


public operator fun < T , D : Dimension > MultiArray < T , D > . contains ( element : T ) : Boolean

{ <EOL> return indexOf ( element ) >= <NUM_LIT:0> <EOL> }

/**
 * Returns `true` if [element] is found in the collection.
 */


@ Suppress ( "<STR_LIT:NOTHING_TO_INLINE>" ) <EOL> public inline fun < T , D : Dimension > MultiArray < T , D > . count ( ) : Int

= size

/**
 * Returns the number of elements in an ndarray.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . count ( predicate : ( T ) -> Boolean ) : Int

{ <EOL> if ( isEmpty ( ) ) return <NUM_LIT:0> <EOL> var count = <NUM_LIT:0> <EOL> for ( element in this ) if ( predicate ( element ) ) if ( ++ count < <NUM_LIT:0> ) throw ArithmeticException ( "<STR_LIT>" ) <EOL> return count <EOL> }

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


public fun < T , D : Dimension > MultiArray < T , D > . distinct ( ) : NDArray < T , D1 >

= this . toMutableSet ( ) . toCommonNDArray ( this . dtype )

/**
 * Returns a new array containing only distinct elements from the given array.
 */


public inline fun < T , D : Dimension , K > MultiArray < T , D > . distinctBy ( selector : ( T ) -> K ) : NDArray < T , D1 >

{ <EOL> val set = HashSet < K > ( ) <EOL> val list = ArrayList < T > ( ) <EOL> for ( e in this ) { <EOL> val key = selector ( e ) <EOL> if ( set . add ( key ) ) <EOL> list . add ( e ) <EOL> } <EOL> val dtype = DataType . of ( list . first ( ) ) <EOL> return list . toCommonNDArray ( dtype ) <EOL> }

/**
 * Returns a new array containing only elements from the given array
 * having distinct keys returned by the given [selector] function.
 */


public fun < T > MultiArray < T , D1 > . drop ( n : Int ) : D1Array < T >

{ <EOL> if ( n == <NUM_LIT:0> ) return D1Array ( this . data . copyOf ( ) , shape = shape . copyOf ( ) , dim = D1 ) <EOL> val resultSize = size - abs ( n ) <EOL> if ( resultSize < <NUM_LIT:0> ) return D1Array ( initMemoryView ( <NUM_LIT:0> , dtype ) , shape = intArrayOf ( <NUM_LIT:0> ) , dim = D1 ) <EOL> val k = if ( n < <NUM_LIT:0> ) <NUM_LIT:0> else n <EOL> val d = initMemoryView ( resultSize , dtype ) { this [ it + k ] } <EOL> val shape = intArrayOf ( resultSize ) <EOL> return D1Array ( d , shape = shape , dim = D1 ) <EOL> }


public inline fun < T > MultiArray < T , D1 > . dropWhile ( predicate : ( T ) -> Boolean ) : NDArray < T , D1 >

{ <EOL> var yielding = false <EOL> val list = ArrayList < T > ( ) <EOL> for ( item in this ) <EOL> if ( yielding ) <EOL> list . add ( item ) <EOL> else if ( ! predicate ( item ) ) { <EOL> list . add ( item ) <EOL> yielding = true <EOL> } <EOL> return ndarrayCommon ( list , intArrayOf ( list . size ) , D1 ) <EOL> }

/**
 * Drops elements that don't satisfy the [predicate].
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . filter ( predicate : ( T ) -> Boolean ) : D1Array < T >

{ <EOL> val list = ArrayList < T > ( ) <EOL> forEach { if ( predicate ( it ) ) list . add ( it ) } <EOL> val dtype = DataType . of ( list . first ( ) ) <EOL> return list . toCommonNDArray ( dtype ) <EOL> }

/**
 * Return a new array contains elements matching filter.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T > MultiArray < T , D1 > . filterIndexed ( predicate : ( index : Int , T ) -> Boolean ) : D1Array < T >

{ <EOL> val list = ArrayList < T > ( ) <EOL> forEachIndexed { index , element -> if ( predicate ( index , element ) ) list . add ( element ) } <EOL> val dtype = DataType . of ( list . first ( ) ) <EOL> return list . toCommonNDArray ( dtype ) <EOL> }


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , D : Dimension > MultiArray < T , D > . filterMultiIndexed ( predicate : ( index : IntArray , T ) -> Boolean ) : D1Array < T >

{ <EOL> val list = ArrayList < T > ( ) <EOL> forEachMultiIndexed { index , element -> if ( predicate ( index , element ) ) list . add ( element ) } <EOL> val dtype = DataType . of ( list . first ( ) ) <EOL> return list . toCommonNDArray ( dtype ) <EOL> }


public inline fun < T , D : Dimension > MultiArray < T , D > . filterNot ( predicate : ( T ) -> Boolean ) : D1Array < T >

{ <EOL> val list = ArrayList < T > ( ) <EOL> for ( element in this ) if ( ! predicate ( element ) ) list . add ( element ) <EOL> val dtype = DataType . of ( list . first ( ) ) <EOL> return list . toCommonNDArray ( dtype ) <EOL> }


public inline fun < T , D : Dimension > MultiArray < T , D > . find ( predicate : ( T ) -> Boolean ) : T ?

{ <EOL> return firstOrNull ( predicate ) <EOL> }

/**
 * Returns the first element matching the given [predicate], or `null` if no such element was found.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . findLast ( predicate : ( T ) -> Boolean ) : T ?

{ <EOL> return lastOrNull ( predicate ) <EOL> }

/**
 * Returns the last element matching the given [predicate], or `null` if no such element was found.
 */


public fun < T , D : Dimension > MultiArray < T , D > . first ( ) : T

{ <EOL> if ( isEmpty ( ) ) throw NoSuchElementException ( "<STR_LIT>" ) <EOL> return this . data [ this . offset ] <EOL> }

/**
 * Returns first element.
 * @throws [NoSuchElementException] if the collection is empty.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . first ( predicate : ( T ) -> Boolean ) : T

{ <EOL> for ( element in this ) if ( predicate ( element ) ) return element <EOL> throw NoSuchElementException ( "<STR_LIT>" ) <EOL> }

/**
 * Returns the first element matching the given [predicate].
 * @throws [NoSuchElementException] if no such element is found.
 */


public fun < T , D : Dimension > MultiArray < T , D > . firstOrNull ( ) : T ?

{ <EOL> return if ( isEmpty ( ) ) null else return this . first ( ) <EOL> }

/**
 * Returns the first element, or `null` if the collection is empty.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . firstOrNull ( predicate : ( T ) -> Boolean ) : T ?

{ <EOL> for ( element in this ) if ( predicate ( element ) ) return element <EOL> return null <EOL> }

/**
 * Returns the first element matching the given [predicate], or `null` if element was not found.
 */


public inline fun < T , D : Dimension , reified R > MultiArray < T , D > . flatMap ( transform : ( T ) -> Iterable < R > ) : D1Array < R >

{ <EOL> val destination = ArrayList < R > ( ) <EOL> for ( element in this ) { <EOL> val list = transform ( element ) <EOL> destination . addAll ( list ) <EOL> } <EOL> val dtype = DataType . of ( destination . first ( ) ) <EOL> return destination . toCommonNDArray ( dtype ) <EOL> }

/**
 * Returns a flat ndarray of all elements resulting from calling the [transform] function on each element
 * in this ndarray.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , reified R > MultiArray < T , D1 > . flatMapIndexed ( transform : ( index : Int , T ) -> Iterable < R > ) : D1Array < R >

{ <EOL> var index = <NUM_LIT:0> <EOL> val destination = ArrayList < R > ( ) <EOL> for ( element in this ) { <EOL> val list = transform ( checkIndexOverflow ( index ++ ) , element ) <EOL> destination . addAll ( list ) <EOL> } <EOL> val dtype = DataType . of ( destination . first ( ) ) <EOL> return destination . toCommonNDArray ( dtype ) <EOL> }

/**
 * Returns a flat ndarray of all elements resulting from calling the [transform] function on each element and its single
 * index in this d1 ndarray.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , reified R > MultiArray < T , D1 > . flatMapMultiIndexed ( transform : ( index : IntArray , T ) -> Iterable < R > ) : D1Array < R >

{ <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> val destination = ArrayList < R > ( ) <EOL> for ( element in this ) { <EOL> if ( indexIter . hasNext ( ) ) { <EOL> val list = transform ( indexIter . next ( ) , element ) <EOL> destination . addAll ( list ) <EOL> } else { <EOL> throw ArithmeticException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> val dtype = DataType . of ( destination . first ( ) ) <EOL> return destination . toCommonNDArray ( dtype ) <EOL> }

/**
 * Returns a flat ndarray of all elements resulting from calling the [transform] function on each element and its multi
 * index in this dn ndarray.
 */


public inline fun < T , D : Dimension , R > MultiArray < T , D > . fold ( initial : R , operation : ( acc : R , T ) -> R ) : R

{ <EOL> var accumulator = initial <EOL> for ( element in this ) accumulator = operation ( accumulator , element ) <EOL> return accumulator <EOL> }

/**
 * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , R > MultiArray < T , D1 > . foldIndexed ( initial : R , operation : ( index : Int , acc : R , T ) -> R ) : R

{ <EOL> var index = <NUM_LIT:0> <EOL> var accumulator = initial <EOL> for ( element in this ) accumulator = operation ( checkIndexOverflow ( index ++ ) , accumulator , element ) <EOL> return accumulator <EOL> }

/**
 * Accumulates value starting with [initial] value and applying [operation] from left to right
 * to current accumulator value and each element with its index in the original ndarray.
 * @param [operation] function that takes the index of an element, current accumulator value
 * and the element itself, and calculates the next accumulator value.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , D : Dimension , R > MultiArray < T , D > . foldMultiIndexed ( initial : R , operation : ( index : IntArray , acc : R , T ) -> R ) : R

{ <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> var accumulator = initial <EOL> for ( element in this ) { <EOL> if ( indexIter . hasNext ( ) ) <EOL> accumulator = operation ( indexIter . next ( ) , accumulator , element ) <EOL> else <EOL> throw ArithmeticException ( "<STR_LIT>" ) <EOL> } <EOL> return accumulator <EOL> }


public inline fun < T , D : Dimension > MultiArray < T , D > . forEach ( action : ( T ) -> Unit )

{ <EOL> for ( element in this ) action ( element ) <EOL> }

/**
 * Performs the given [action] on each element.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T > MultiArray < T , D1 > . forEachIndexed ( action : ( index : Int , T ) -> Unit )

{ <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) action ( checkIndexOverflow ( index ++ ) , item ) <EOL> }

/**
 * Performs the given [action] on each element, providing sequential index with the element.
 * @param [action] function that takes the index of an element and the element itself
 * and performs the desired action on the element.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , D : Dimension > MultiArray < T , D > . forEachMultiIndexed ( action : ( index : IntArray , T ) -> Unit )

{ <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> for ( item in this ) { <EOL> if ( indexIter . hasNext ( ) ) <EOL> action ( indexIter . next ( ) , item ) <EOL> else <EOL> throw ArithmeticException ( "<STR_LIT>" ) <EOL> } <EOL> }


public inline fun < T , D : Dimension , K > MultiArray < T , D > . groupNDArrayBy ( keySelector : ( T ) -> K ) : Map < K , NDArray < T , D1 > >

{ <EOL> return groupNDArrayByTo ( LinkedHashMap ( ) , keySelector ) <EOL> }

/**
 * Groups elements of a given ndarray by the key returned by [keySelector] for each element,
 * and returns a map where each group key is associated with an ndarray of matching elements.
 */


public inline fun < T , D : Dimension , K , V : Number > MultiArray < T , D > . groupNDArrayBy ( keySelector : ( T ) -> K , valueTransform : ( T ) -> V ) : Map < K , NDArray < V , D1 > >

{ <EOL> return groupNDArrayByTo ( LinkedHashMap ( ) , keySelector , valueTransform ) <EOL> }

/**
 * Groups values returned by [valueTransform] applied to each element of the given ndarray
 * with the key returned by [keySelector] applied to each element,
 * and returns a map where each group key is associated with an ndarray of matching values.
 */


public inline fun < T , D : Dimension , K , M : MutableMap < in K , NDArray < T , D1 > > > MultiArray < T , D > . groupNDArrayByTo ( destination : M , keySelector : ( T ) -> K ) : M

{ <EOL> val map = LinkedHashMap < K , MutableList < T > > ( ) <EOL> for ( element in this ) { <EOL> val key = keySelector ( element ) <EOL> val list = map . getOrPut ( key ) { ArrayList ( ) } <EOL> list . add ( element ) <EOL> } <EOL> for ( item in map ) { <EOL> val dtype = DataType . of ( item . value . first ( ) ) <EOL> destination . put ( item . key , item . value . toCommonNDArray ( dtype = dtype ) ) <EOL> } <EOL> return destination <EOL> }

/**
 * Groups elements of the given array by the key returned by [keySelector] function applied to each
 * element and puts to the [destination] map each group key associated with an ndarray of corresponding elements.
 */


public inline fun < T , D : Dimension , K , V , M : MutableMap < in K , NDArray < V , D1 > > > MultiArray < T , D > . groupNDArrayByTo ( destination : M , keySelector : ( T ) -> K , valueTransform : ( T ) -> V ) : M

{ <EOL> val map = LinkedHashMap < K , MutableList < V > > ( ) <EOL> for ( element in this ) { <EOL> val key = keySelector ( element ) <EOL> val list = map . getOrPut ( key ) { ArrayList ( ) } <EOL> list . add ( valueTransform ( element ) ) <EOL> } <EOL> for ( item in map ) { <EOL> val dtype = DataType . of ( item . value . first ( ) ) <EOL> destination . put ( item . key , item . value . toCommonNDArray ( dtype = dtype ) ) <EOL> } <EOL> return destination <EOL> }

/**
 * Groups values returned by the [valueTransform] function applied to each element of the given ndarray by the key
 * returned by [keySelector] function applied to the element and puts to the destination map each group key
 * associated with an ndarray of corresponding values.
 */


public inline fun < T , D : Dimension , K > MultiArray < T , D > . groupingNDArrayBy ( crossinline keySelector : ( T ) -> K ) : Grouping < T , K >

{ <EOL> return object : Grouping < T , K > { <EOL> override fun sourceIterator ( ) : Iterator < T > = this@groupingNDArrayBy . iterator ( ) <EOL> override fun keyOf ( element : T ) : K = keySelector ( element ) <EOL> } <EOL> }

/**
 * Creates a [Grouping] source from an ndarray to be used later with one of group-and-fold operations using the
 * specified [keySelector] function to extract a key from each element.
 */


public fun < T , D : Dimension > MultiArray < T , D > . indexOf ( element : T ) : Int

{ <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) { <EOL> checkIndexOverflow ( index ) <EOL> if ( element == item ) <EOL> return index <EOL> index ++ <EOL> } <EOL> return - <NUM_LIT:1> <EOL> }

/**
 * Returns first index of [element], or -1 if the collection does not contain element.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . indexOfFirst ( predicate : ( T ) -> Boolean ) : Int

{ <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) { <EOL> checkIndexOverflow ( index ) <EOL> if ( predicate ( item ) ) <EOL> return index <EOL> index ++ <EOL> } <EOL> return - <NUM_LIT:1> <EOL> }

/**
 * Returns index of the first element matching the given [predicate], or -1 if the collection does not contain such element.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . indexOfLast ( predicate : ( T ) -> Boolean ) : Int

{ <EOL> var lastIndex = - <NUM_LIT:1> <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) { <EOL> checkIndexOverflow ( index ) <EOL> if ( predicate ( item ) ) <EOL> lastIndex = index <EOL> index ++ <EOL> } <EOL> return lastIndex <EOL> }

/**
 * Returns index of the last element matching the given [predicate], or -1 if the collection does not contain such element.
 */


public infix fun < T , D : Dimension > MultiArray < T , D > . intersect ( other : Iterable < T > ) : Set < T >

{ <EOL> val set = this . toMutableSet ( ) <EOL> set . retainAll ( other ) <EOL> return set <EOL> }

/**
 * Returns a set containing all elements that are contained by both this collection and the specified collection.
 *
 * The returned set preserves the element iteration order of the original collection.
 *
 * To get a set containing all elements that are contained at least in one of these collections use [union].
 */


public fun < T , D : Dimension , A : Appendable > MultiArray < T , D > . joinTo ( buffer : A , separator : CharSequence = "<STR_LIT:U+002CU+0020>" , prefix : CharSequence = "<STR_LIT>" , postfix : CharSequence = "<STR_LIT>" , limit : Int = - <NUM_LIT:1> , truncated : CharSequence = "<STR_LIT:...>" , transform : ( ( T ) -> CharSequence ) ? = null ) : A

{ <EOL> buffer . append ( prefix ) <EOL> var count = <NUM_LIT:0> <EOL> for ( element in this ) { <EOL> if ( ++ count > <NUM_LIT:1> ) buffer . append ( separator ) <EOL> if ( limit < <NUM_LIT:0> || count <= limit ) { <EOL> when { <EOL> transform != null -> buffer . append ( transform ( element ) ) <EOL> element is CharSequence -> buffer . append ( element ) <EOL> else -> buffer . append ( element . toString ( ) ) <EOL> } <EOL> } else break <EOL> } <EOL> if ( limit in <NUM_LIT:0> until count ) buffer . append ( truncated ) <EOL> buffer . append ( postfix ) <EOL> return buffer <EOL> }

/**
 * Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
 *
 * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
 * elements will be appended, followed by the [truncated] string (which defaults to "...").
 */


public fun < T , D : Dimension > MultiArray < T , D > . joinToString ( separator : CharSequence = "<STR_LIT:U+002CU+0020>" , prefix : CharSequence = "<STR_LIT>" , postfix : CharSequence = "<STR_LIT>" , limit : Int = - <NUM_LIT:1> , truncated : CharSequence = "<STR_LIT:...>" , transform : ( ( T ) -> CharSequence ) ? = null ) : String

{ <EOL> return joinTo ( StringBuilder ( ) , separator , prefix , postfix , limit , truncated , transform ) . toString ( ) <EOL> }

/**
 * Creates a string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
 *
 * If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
 * elements will be appended, followed by the [truncated] string (which defaults to "...").
 */


public fun < T , D : Dimension > MultiArray < T , D > . last ( ) : T

{ <EOL> if ( isEmpty ( ) ) throw NoSuchElementException ( "<STR_LIT>" ) <EOL> val index = IntArray ( dim . d ) { shape [ it ] - <NUM_LIT:1> } <EOL> return this . asDNArray ( ) [ index ] <EOL> }

/**
 * Returns the last element.
 * @throws [NoSuchElementException] if the collection is empty.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . last ( predicate : ( T ) -> Boolean ) : T

{ <EOL> val ndarray = this . asDNArray ( ) <EOL> for ( i in this . multiIndices . reverse ) { <EOL> val element = ndarray [ i ] <EOL> if ( predicate ( element ) ) return element <EOL> } <EOL> throw NoSuchElementException ( "<STR_LIT>" ) <EOL> }

/**
 * Returns the last element matching the given [predicate].
 * @throws [NoSuchElementException] if no such element is found.
 */


public fun < T , D : Dimension > MultiArray < T , D > . lastIndexOf ( element : T ) : Int

{ <EOL> var lastIndex = - <NUM_LIT:1> <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) { <EOL> if ( index < <NUM_LIT:0> ) throw ArithmeticException ( "<STR_LIT>" ) <EOL> if ( element == item ) <EOL> lastIndex = index <EOL> index ++ <EOL> } <EOL> return lastIndex <EOL> }

/**
 * Returns last index of [element], or -1 if the collection does not contain element.
 */


public fun < T , D : Dimension > MultiArray < T , D > . lastOrNull ( ) : T ?

{ <EOL> return if ( isEmpty ( ) ) null else this . asDNArray ( ) [ this . multiIndices . last ] <EOL> }

/**
 * Returns the last element, or `null` if the list is empty.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . lastOrNull ( predicate : ( T ) -> Boolean ) : T ?

{ <EOL> var last : T ? = null <EOL> for ( element in this ) { <EOL> if ( predicate ( element ) ) { <EOL> last = element <EOL> } <EOL> } <EOL> return last <EOL> }

/**
 * Returns the last element matching the given [predicate], or `null` if no such element was found.
 */


public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . map ( transform : ( T ) -> R ) : NDArray < R , D >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> var count = <NUM_LIT:0> <EOL> for ( el in this ) <EOL> data [ count ++ ] = transform ( el ) <EOL> return NDArray ( data , shape = shape , dim = dim ) <EOL> }

/**
 * Return a new array contains elements after applying [transform].
 */


@ Suppress ( "<STR_LIT>" ) <EOL> public fun < T : Number , D : Dimension > MultiArray < T , D > . minimum ( other : MultiArray < T , D > ) : NDArray < T , D >

{ <EOL> requireEqualShape ( this . shape , other . shape ) <EOL> val ret = ( this as NDArray ) . deepCopy ( ) <EOL> when ( dtype ) { <EOL> DataType . DoubleDataType -> ( ret as NDArray < Double , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Double > ) { a , b -> min ( a , b ) } <EOL> DataType . FloatDataType -> ( ret as NDArray < Float , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Float > ) { a , b -> min ( a , b ) } <EOL> DataType . IntDataType -> ( ret as NDArray < Int , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Int > ) { a , b -> min ( a , b ) } <EOL> DataType . LongDataType -> ( ret as NDArray < Long , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Long > ) { a , b -> min ( a , b ) } <EOL> DataType . ShortDataType -> ( ret as NDArray < Short , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Short > ) { a , b -> ( minOf ( a , b ) ) } <EOL> DataType . ByteDataType -> ( ret as NDArray < Byte , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Byte > ) { a , b -> ( minOf ( a , b ) ) } <EOL> else -> throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> } <EOL> return ret <EOL> }

/**
 * Returns the element-wise minimum of array elements for [this] and [other].
 */


public fun < T : Number , D : Dimension > MultiArray < T , D > . maximum ( other : MultiArray < T , D > ) : NDArray < T , D >

{ <EOL> requireEqualShape ( this . shape , other . shape ) <EOL> val ret = ( this as NDArray ) . deepCopy ( ) <EOL> when ( dtype ) { <EOL> DataType . DoubleDataType -> ( ret as NDArray < Double , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Double > ) { a , b -> max ( a , b ) } <EOL> DataType . FloatDataType -> ( ret as NDArray < Float , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Float > ) { a , b -> max ( a , b ) } <EOL> DataType . IntDataType -> ( ret as NDArray < Int , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Int > ) { a , b -> max ( a , b ) } <EOL> DataType . LongDataType -> ( ret as NDArray < Long , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Long > ) { a , b -> max ( a , b ) } <EOL> DataType . ShortDataType -> ( ret as NDArray < Short , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Short > ) { a , b -> ( maxOf ( a , b ) ) } <EOL> DataType . ByteDataType -> ( ret as NDArray < Byte , D > ) . commonAssignOp ( other . iterator ( ) as Iterator < Byte > ) { a , b -> ( maxOf ( a , b ) ) } <EOL> else -> throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> } <EOL> return ret <EOL> }

/**
 * Returns the element-wise maximum of array elements for [this] and [other].
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , reified R : Any > MultiArray < T , D1 > . mapIndexed ( transform : ( index : Int , T ) -> R ) : D1Array < R >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) <EOL> data [ index ] = transform ( index ++ , item ) <EOL> return D1Array ( data , shape = shape , dim = D1 ) <EOL> }


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . mapMultiIndexed ( transform : ( index : IntArray , T ) -> R ) : NDArray < R , D >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> var index = <NUM_LIT:0> <EOL> for ( item in this ) { <EOL> if ( indexIter . hasNext ( ) ) { <EOL> data [ index ++ ] = transform ( indexIter . next ( ) , item ) <EOL> } else { <EOL> throw ArithmeticException ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> return NDArray ( data , shape = shape , dim = dim ) <EOL> }


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , reified R : Any > MultiArray < T , D1 > . mapIndexedNotNull ( transform : ( index : Int , T ) -> R ? ) : D1Array < R >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> var count = <NUM_LIT:0> <EOL> forEachIndexed { index , element -> transform ( index , element ) ? . let { data [ count ++ ] = it } } <EOL> return D1Array ( data , shape = shape , dim = D1 ) <EOL> }


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . mapMultiIndexedNotNull ( transform : ( index : IntArray , T ) -> R ? ) : NDArray < R , D >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> var count = <NUM_LIT:0> <EOL> forEachMultiIndexed { index , element -> transform ( index , element ) ? . let { data [ count ++ ] = it } } <EOL> return NDArray ( data , shape = shape . copyOf ( ) , dim = dim ) <EOL> }


public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . mapNotNull ( transform : ( T ) -> R ? ) : NDArray < R , D >

{ <EOL> val newDtype = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( size , newDtype ) <EOL> var index = <NUM_LIT:0> <EOL> forEach { element -> transform ( element ) ? . let { data [ index ++ ] = it } } <EOL> return NDArray ( data , shape = shape , dim = dim ) <EOL> }


public fun < T : Number , D : Dimension > MultiArray < T , D > . max ( ) : T ?

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var max = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> val e = iterator . next ( ) <EOL> if ( max < e ) max = e <EOL> } <EOL> return max <EOL> }

/**
 * Returns the largest element or `null` if there are no elements.
 */


public inline fun < T , D : Dimension , R : Comparable < R > > MultiArray < T , D > . maxBy ( selector : ( T ) -> R ) : T ?

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var maxElem = iterator . next ( ) <EOL> if ( ! iterator . hasNext ( ) ) return maxElem <EOL> var maxValue = selector ( maxElem ) <EOL> do { <EOL> val e = iterator . next ( ) <EOL> val v = selector ( e ) <EOL> if ( maxValue < v ) { <EOL> maxElem = e <EOL> maxValue = v <EOL> } <EOL> } while ( iterator . hasNext ( ) ) <EOL> return maxElem <EOL> }

/**
 * Returns the first element yielding the largest value of the given function or `null` if there are no elements.
 */


public fun < T , D : Dimension > MultiArray < T , D > . maxWith ( comparator : Comparator < in T > ) : T ?

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var max = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> val e = iterator . next ( ) <EOL> if ( comparator . compare ( max , e ) < <NUM_LIT:0> ) max = e <EOL> } <EOL> return max <EOL> }

/**
 * Returns the first element having the largest value according to the provided [comparator] or `null` if there are no elements.
 */


public fun < T , D : Dimension > MultiArray < T , D > . min ( ) : T ? where T : Number , T : Comparable < T >

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var min = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> val e = iterator . next ( ) <EOL> if ( min > e ) min = e <EOL> } <EOL> return min <EOL> }

/**
 * Returns the smallest element or `null` if there are no elements.
 */


public inline fun < T , D : Dimension , R : Comparable < R > > MultiArray < T , D > . minBy ( selector : ( T ) -> R ) : T ?

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var minElem = iterator . next ( ) <EOL> if ( ! iterator . hasNext ( ) ) return minElem <EOL> var minValue = selector ( minElem ) <EOL> do { <EOL> val e = iterator . next ( ) <EOL> val v = selector ( e ) <EOL> if ( minValue > v ) { <EOL> minElem = e <EOL> minValue = v <EOL> } <EOL> } while ( iterator . hasNext ( ) ) <EOL> return minElem <EOL> }

/**
 * Returns the first element yielding the smallest value of the given function or `null` if there are no elements.
 */


public fun < T , D : Dimension > MultiArray < T , D > . minWith ( comparator : Comparator < in T > ) : T ?

{ <EOL> val iterator = iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var min = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> val e = iterator . next ( ) <EOL> if ( comparator . compare ( min , e ) > <NUM_LIT:0> ) min = e <EOL> } <EOL> return min <EOL> }

/**
 * Returns the first element having the smallest value according to the provided [comparator] or `null` if there are no elements.
 */


public inline fun < T , D : Dimension , C : MultiArray < T , D > > C . onEach ( action : ( T ) -> Unit ) : C

{ <EOL> return apply { for ( element in this ) action ( element ) } <EOL> }

/**
 * Performs the given [action] on each element and returns the collection itself afterwards.
 */


public inline fun < T , D : Dimension > MultiArray < T , D > . partition ( predicate : ( T ) -> Boolean ) : Pair < NDArray < T , D1 > , NDArray < T , D1 > >

{ <EOL> val first = ArrayList < T > ( ) <EOL> val second = ArrayList < T > ( ) <EOL> for ( element in this ) { <EOL> if ( predicate ( element ) ) { <EOL> first . add ( element ) <EOL> } else { <EOL> second . add ( element ) <EOL> } <EOL> } <EOL> val dtype = DataType . of ( first . first ( ) ) <EOL> return Pair ( first . toCommonNDArray ( dtype ) , second . toCommonNDArray ( dtype ) ) <EOL> }

/**
 * Splits the original collection into pair of lists,
 * where *first* list contains elements for which [predicate] yielded `true`,
 * while *second* list contains elements for which [predicate] yielded `false`.
 */


public fun < T , D : Dimension > MultiArray < T , D > . windowed ( size : Int , step : Int = <NUM_LIT:1> , limit : Boolean = true ) : NDArray < T , D2 >

{ <EOL> require ( size > <NUM_LIT:0> && step > <NUM_LIT:0> ) { <EOL> if ( size != step ) <EOL> "<STR_LIT>" <EOL> else <EOL> "<STR_LIT>" <EOL> } <EOL> val thisSize = this . size <EOL> val rSize = min ( thisSize , size ) <EOL> val rStep = min ( thisSize , step ) <EOL> val resultCapacity = when { <EOL> limit -> thisSize / rStep * rSize <EOL> thisSize % rStep == <NUM_LIT:0> -> thisSize / rStep * rSize <EOL> else -> ( thisSize / rStep + <NUM_LIT:1> ) * rSize <EOL> } <EOL> val resData = initMemoryView < T > ( resultCapacity , this . dtype ) <EOL> val thisNDArray = this . flatten ( ) <EOL> var index = <NUM_LIT:0> <EOL> var resIndex = <NUM_LIT:0> <EOL> while ( index in <NUM_LIT:0> until thisSize ) { <EOL> for ( i in <NUM_LIT:0> until rSize ) { <EOL> if ( i + index >= thisSize ) { <EOL> resIndex ++ <EOL> continue <EOL> } <EOL> resData [ resIndex ++ ] = thisNDArray [ i + index ] <EOL> } <EOL> index += rStep <EOL> } <EOL> return D2Array ( resData , <NUM_LIT:0> , intArrayOf ( resultCapacity / rSize , rSize ) , dim = D2 ) <EOL> }

/**
 * Returns a 2-D ndarray of window segments of the specified size, sliding over this ndarray with the specified step.
 *
 * The last few arrays are filled with zeros if limit is false.
 * The [size] and [step] must be positive and can be greater than the number of elements in this ndarray.
 *
 * @param size the size and step must be positive and can be greater than the number of elements in this array
 * @param step the number of elements to move the window forward by on an each step, by default 1
 * @param limit sets a limit on the set of significant elements in the result, otherwise it fills in with zeros
 */


public inline fun < S , D : Dimension , T : S > MultiArray < T , D > . reduce ( operation : ( acc : S , T ) -> S ) : S

{ <EOL> val iterator = this . iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> var accumulator : S = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> accumulator = operation ( accumulator , iterator . next ( ) ) <EOL> } <EOL> return accumulator <EOL> }

/**
 * Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < S , T : S > MultiArray < T , D1 > . reduceIndexed ( operation : ( index : Int , acc : S , T ) -> S ) : S

{ <EOL> val iterator = this . iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> var index = <NUM_LIT:1> <EOL> var accumulator : S = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> accumulator = operation ( checkIndexOverflow ( index ++ ) , accumulator , iterator . next ( ) ) <EOL> } <EOL> return accumulator <EOL> }

/**
 * Accumulates value starting with the first element and applying [operation] from left to right
 * to current accumulator value and each element with its index in the original collection.
 * @param [operation] function that takes the index of an element, current accumulator value
 * and the element itself and calculates the next accumulator value.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> public inline fun < S , D : Dimension , T : S > MultiArray < T , D > . reduceMultiIndexed ( operation : ( index : IntArray , acc : S , T ) -> S ) : S

{ <EOL> val iterator = this . iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) throw UnsupportedOperationException ( "<STR_LIT>" ) <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> var accumulator : S = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) && indexIter . hasNext ( ) ) { <EOL> accumulator = operation ( indexIter . next ( ) , accumulator , iterator . next ( ) ) <EOL> } <EOL> return accumulator <EOL> }


public inline fun < S , D : Dimension , T : S > MultiArray < T , D > . reduceOrNull ( operation : ( acc : S , T ) -> S ) : S ?

{ <EOL> val iterator = this . iterator ( ) <EOL> if ( ! iterator . hasNext ( ) ) return null <EOL> var accumulator : S = iterator . next ( ) <EOL> while ( iterator . hasNext ( ) ) { <EOL> accumulator = operation ( accumulator , iterator . next ( ) ) <EOL> } <EOL> return accumulator <EOL> }

/**
 * Accumulates value starting with the first element and applying [operation] from left to right to current accumulator value and each element. Returns null if the collection is empty.
 */


public fun < T , D : Dimension > MultiArray < T , D > . reversed ( ) : NDArray < T , D >

{ <EOL> if ( size <= <NUM_LIT:1> ) return this . copy ( ) as NDArray < T , D > <EOL> val data = initMemoryView < T > ( this . size , this . dtype ) <EOL> var index = this . size - <NUM_LIT:1> <EOL> for ( element in this ) <EOL> data [ index -- ] = element <EOL> return NDArray ( data , <NUM_LIT:0> , this . shape . copyOf ( ) , dim = this . dim ) <EOL> }


public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . scan ( initial : R , operation : ( acc : R , T ) -> R ) : NDArray < R , D >

{ <EOL> val dataType = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( this . size + <NUM_LIT:1> , dataType ) <EOL> data [ <NUM_LIT:0> ] = initial <EOL> var index = <NUM_LIT:1> <EOL> var accumulator = initial <EOL> for ( element in this ) { <EOL> accumulator = operation ( accumulator , element ) <EOL> data [ index ++ ] = accumulator <EOL> } <EOL> return NDArray ( data , <NUM_LIT:0> , this . shape . copyOf ( ) , dim = this . dim ) <EOL> }

/**
 * Returns a list containing successive accumulation values generated by applying [operation] from left to right
 * to each element and current accumulator value that starts with [initial] value.
 *
 * Note that `acc` value passed to [operation] function should not be mutated;
 * otherwise it would affect the previous value in resulting ndarray.
 *
 * @param [operation] function that takes current accumulator value and an element, and calculates the next accumulator value.
 */


@ JvmName ( "<STR_LIT>" ) <EOL> @ Suppress ( "<STR_LIT:DuplicatedCode>" ) <EOL> public inline fun < T , reified R : Any > MultiArray < T , D1 > . scanIndexed ( initial : R , operation : ( index : Int , acc : R , T ) -> R ) : D1Array < R >

{ <EOL> val dataType = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( this . size + <NUM_LIT:1> , dataType ) <EOL> data [ <NUM_LIT:0> ] = initial <EOL> var count = <NUM_LIT:1> <EOL> var accumulator = initial <EOL> val ndarrayIter = this . iterator ( ) <EOL> while ( ndarrayIter . hasNext ( ) ) { <EOL> accumulator = operation ( count , accumulator , ndarrayIter . next ( ) ) <EOL> data [ count ++ ] = accumulator <EOL> } <EOL> return D1Array ( data , <NUM_LIT:0> , this . shape . copyOf ( ) , dim = D1 ) <EOL> }

/**
 * Return a flat ndarray containing successive accumulation values generated by applying [operation] from left to right to
 * each element, its index in this d1 ndarray and current accumulator value that starts with [initial] value.
 */


@ Suppress ( "<STR_LIT:DuplicatedCode>" ) <EOL> public inline fun < T , D : Dimension , reified R : Any > MultiArray < T , D > . scanMultiIndexed ( initial : R , operation : ( index : IntArray , acc : R , T ) -> R ) : NDArray < R , D >

{ <EOL> val dataType = DataType . ofKClass ( R :: class ) <EOL> val data = initMemoryView < R > ( this . size + <NUM_LIT:1> , dataType ) <EOL> data [ <NUM_LIT:0> ] = initial <EOL> var count = <NUM_LIT:1> <EOL> var accumulator = initial <EOL> val ndarrayIter = this . iterator ( ) <EOL> val indexIter = this . multiIndices . iterator ( ) <EOL> while ( ndarrayIter . hasNext ( ) && indexIter . hasNext ( ) ) { <EOL> accumulator = operation ( indexIter . next ( ) , accumulator , ndarrayIter . next ( ) ) <EOL> data [ count ++ ] = accumulator <EOL> } <EOL> return NDArray ( data , <NUM_LIT:0> , this . shape . copyOf ( ) , dim = this . dim ) <EOL> }

/**
 * Return a flat ndarray containing successive accumulation values generated by applying [operation] from left to right to
 * each element, its multi index in this dn ndarray and current accumulator value that starts with [initial] value.
 */


public fun < T : Number , D : Dimension > MultiArray < T , D > . sorted ( ) : NDArray < T , D >

{ <EOL> val ret = this . deepCopy ( ) as NDArray < T , D > <EOL> when ( this . dtype ) { <EOL> DataType . ByteDataType -> ret . data . getByteArray ( ) . sort ( ) <EOL> DataType . ShortDataType -> ret . data . getShortArray ( ) . sort ( ) <EOL> DataType . IntDataType -> ret . data . getIntArray ( ) . sort ( ) <EOL> DataType . LongDataType -> ret . data . getLongArray ( ) . sort ( ) <EOL> DataType . FloatDataType -> ret . data . getFloatArray ( ) . sort ( ) <EOL> DataType . DoubleDataType -> ret . data . getDoubleArray ( ) . sort ( ) <EOL> DataType . ComplexFloatDataType , DataType . ComplexDoubleDataType -> <EOL> throw Exception ( "<STR_LIT>" ) <EOL> } <EOL> return ret <EOL> }


public fun < T : Number , D : Dimension > MultiArray < T , D > . sum ( ) : T

= mk . math . sum ( this )

/**
 * Returns the sum of all elements in the collection.
 */


public inline fun < T : Number , D : Dimension > MultiArray < T , D > . sumBy ( selector : ( T ) -> Int ) : Int

{ <EOL> var sum = <NUM_LIT:0> <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }

/**
 * Returns the sum of all values produced by [selector] function applied to each element in the collection.
 */


public inline fun < T : Number , D : Dimension > MultiArray < T , D > . sumBy ( selector : ( T ) -> Double ) : Double

{ <EOL> var sum = <NUM_LIT:0.0> <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }


public inline fun < T , D : Dimension > MultiArray < T , D > . sumBy ( selector : ( T ) -> ComplexFloat ) : ComplexFloat

{ <EOL> var sum = ComplexFloat . zero <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }


public inline fun < T , D : Dimension > MultiArray < T , D > . sumBy ( selector : ( T ) -> ComplexDouble ) : ComplexDouble

{ <EOL> var sum = ComplexDouble . zero <EOL> for ( element in this ) { <EOL> sum += selector ( element ) <EOL> } <EOL> return sum <EOL> }


public fun < T , D : Dimension , C : MutableCollection < in T > > MultiArray < T , D > . toCollection ( destination : C ) : C

{ <EOL> for ( item in this ) { <EOL> destination . add ( item ) <EOL> } <EOL> return destination <EOL> }

/**
 * Appends all elements to the given [destination] collection.
 */


public fun < T , D : Dimension > MultiArray < T , D > . toHashSet ( ) : HashSet < T >

{ <EOL> return toCollection ( HashSet ( mapCapacity ( size ) ) ) <EOL> }

/**
 * Returns a [HashSet] of all elements.
 */


public fun < T , D : Dimension > MultiArray < T , D > . toList ( ) : List < T >

{ <EOL> return when ( size ) { <EOL> <NUM_LIT:0> -> emptyList ( ) <EOL> <NUM_LIT:1> -> listOf ( this . first ( ) ) <EOL> else -> this . toMutableList ( ) <EOL> } <EOL> }

/**
 * Returns a [List] containing all elements.
 */


public fun < T > MultiArray < T , D2 > . toListD2 ( ) : List < List < T > >

= <EOL> List ( shape [ <NUM_LIT:0> ] ) { i -> <EOL> List ( shape [ <NUM_LIT:1> ] ) { j -> <EOL> this [ i , j ] <EOL> } <EOL> }

/**
 * Returns a List<List<T>> containing all elements.
 */


public fun < T > MultiArray < T , D3 > . toListD3 ( ) : List < List < List < T > > >

= <EOL> List ( shape [ <NUM_LIT:0> ] ) { i -> <EOL> List ( shape [ <NUM_LIT:1> ] ) { j -> <EOL> List ( shape [ <NUM_LIT:2> ] ) { k -> <EOL> this [ i , j , k ] <EOL> } <EOL> } <EOL> }

/**
 * Returns a List<List<List<T>>> containing all elements.
 */


public fun < T > MultiArray < T , D4 > . toListD4 ( ) : List < List < List < List < T > > > >

= <EOL> List ( shape [ <NUM_LIT:0> ] ) { i -> <EOL> List ( shape [ <NUM_LIT:1> ] ) { j -> <EOL> List ( shape [ <NUM_LIT:2> ] ) { k -> <EOL> List ( shape [ <NUM_LIT:3> ] ) { l -> <EOL> this [ i , j , k , l ] <EOL> } <EOL> } <EOL> } <EOL> }

/**
 * Returns a List<List<List<List<T>>>> containing all elements.
 */


public fun < T , D : Dimension > MultiArray < T , D > . toMutableList ( ) : MutableList < T >

{ <EOL> return toCollection ( ArrayList ( ) ) <EOL> }

/**
 * Returns a [MutableList] filled with all elements of this collection.
 */


public fun < T , D : Dimension > MultiArray < T , D > . toMutableSet ( ) : MutableSet < T >

{ <EOL> return toCollection ( LinkedHashSet ( ) ) <EOL> }

/**
 * Returns a mutable set containing all distinct elements from the given collection.
 *
 * The returned set preserves the element iteration order of the original collection.
 */


public fun < T , D : Dimension > MultiArray < T , D > . toSet ( ) : Set < T >

{ <EOL> return when ( size ) { <EOL> <NUM_LIT:0> -> emptySet ( ) <EOL> <NUM_LIT:1> -> setOf ( this . first ( ) ) <EOL> else -> toCollection ( LinkedHashSet ( mapCapacity ( size ) ) ) <EOL> } <EOL> }

/**
 * Returns a [Set] of all elements.
 *
 * The returned set preserves the element iteration order of the original collection.
 */


public inline fun < T , reified O : Any , D : Dimension > MultiArray < T , D > . toType ( copy : CopyStrategy = CopyStrategy . FULL ) : NDArray < O , D >

{ <EOL> val dtype = DataType . ofKClass ( O :: class ) <EOL> return this . toType ( dtype , copy ) <EOL> }


public fun < T , O : Any , D : Dimension > MultiArray < T , D > . toType ( dtype : DataType , copy : CopyStrategy = CopyStrategy . FULL ) : NDArray < O , D >

{ <EOL> if ( this . dtype == dtype ) { <EOL> return ( if ( copy == CopyStrategy . FULL ) this . copy ( ) else this . deepCopy ( ) ) as NDArray < O , D > <EOL> } <EOL> val size : Int <EOL> val iterData : Iterator < T > <EOL> val offset : Int <EOL> val strides : IntArray <EOL> if ( copy == CopyStrategy . FULL ) { <EOL> size = this . data . size <EOL> iterData = this . data . iterator ( ) <EOL> offset = this . offset <EOL> strides = this . strides . copyOf ( ) <EOL> } else { <EOL> size = this . size <EOL> iterData = this . iterator ( ) <EOL> offset = <NUM_LIT:0> <EOL> strides = computeStrides ( this . shape ) <EOL> } <EOL> val isNumber = this . dtype . isNumber ( ) <EOL> val view = initMemoryView < O > ( size , dtype ) <EOL> when { <EOL> isNumber && dtype == DataType . FloatDataType -> { <EOL> val d = view . getFloatArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toFloat ( ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . DoubleDataType -> { <EOL> val d = view . getDoubleArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toDouble ( ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . IntDataType -> { <EOL> val d = view . getIntArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toInt ( ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . LongDataType -> { <EOL> val d = view . getLongArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toLong ( ) <EOL> } <EOL> } <EOL> } <EOL> ! isNumber && dtype == DataType . ComplexFloatDataType -> { <EOL> val d = view . getComplexFloatArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < ComplexDouble > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> val c = next ( ) <EOL> d [ count ++ ] = ComplexFloat ( c . re , c . im ) <EOL> } <EOL> } <EOL> } <EOL> ! isNumber && dtype == DataType . ComplexDoubleDataType -> { <EOL> val d = view . getComplexDoubleArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < ComplexFloat > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> val c = next ( ) <EOL> d [ count ++ ] = ComplexDouble ( c . re , c . im ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . ComplexFloatDataType -> { <EOL> val d = view . getComplexFloatArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = ComplexFloat ( next ( ) , <NUM_LIT> ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . ComplexDoubleDataType -> { <EOL> val d = view . getComplexDoubleArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = ComplexDouble ( next ( ) , <NUM_LIT:0.0> ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . ShortDataType -> { <EOL> val d = view . getShortArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toShort ( ) <EOL> } <EOL> } <EOL> } <EOL> isNumber && dtype == DataType . ByteDataType -> { <EOL> val d = view . getByteArray ( ) <EOL> var count = <NUM_LIT:0> <EOL> ( iterData as Iterator < Number > ) . apply { <EOL> while ( hasNext ( ) ) { <EOL> d [ count ++ ] = next ( ) . toByte ( ) <EOL> } <EOL> } <EOL> } <EOL> else -> throw Exception ( ) <EOL> } <EOL> return NDArray ( view , offset , this . shape . copyOf ( ) , strides , this . dim ) <EOL> }


@ HtmlTagMarker <EOL> inline fun AUDIO . source ( classes : String ? = null , crossinline block : SOURCE . ( ) -> Unit = { } ) : Unit

= SOURCE ( attributesMapOf ( "<STR_LIT:class>" , classes ) , consumer ) . visit ( block )


private suspend fun processLevel ( towerLevel : TowerScopeLevel , callInfo : CallInfo , group : TowerGroup , explicitReceiverKind : ExplicitReceiverKind ) : Boolean

{ <EOL> val finalGroup = interceptTowerGroup ( group ) <EOL> manager . requestGroup ( finalGroup ) <EOL> val result = handler . handleLevel ( collector , candidateFactory , callInfo , explicitReceiverKind , finalGroup , towerLevel ) <EOL> if ( collector . isSuccess ) onSuccessfulLevel ( finalGroup ) <EOL> return result == ProcessResult . SCOPE_EMPTY <EOL> }

/**
 * @return true if level is empty
 */


public fun String . deserializeJson ( className : String ? = null ) : DeserializeThis

{ <EOL> return DeserializeThis ( jsonString = this , className = className ) <EOL> }

/**
 * Variables with values returned by this function get replaced by deserialized value **in the next cell**.
 * [className] is a simple name of the class to be generated that [jsonString] will be deserialized into.
 *
 * Usage:
 * ```kotlin
 * val user = """{"address":{"street","Baker Street","number":"221B"}}""".deserializeJson()
 * // IN THE NEXT CELL:
 * println(user.address.number + " " + user.address.street)
 * ```
 */


internal suspend fun Project . createCInteropMetadataDependencyClasspath ( sourceSet : DefaultKotlinSourceSet , forIde : Boolean ) : FileCollection

{ <EOL> val dependencyTransformationTask = if ( forIde ) locateOrRegisterCInteropMetadataDependencyTransformationTaskForIde ( sourceSet ) <EOL> else locateOrRegisterCInteropMetadataDependencyTransformationTask ( sourceSet ) <EOL> if ( dependencyTransformationTask == null ) return project . files ( ) <EOL> val dependencyTransformationTaskOutputs = project . files ( dependencyTransformationTask . map { it . outputLibraryFiles } ) <EOL> return dependencyTransformationTaskOutputs + <EOL> createCInteropMetadataDependencyClasspathFromAssociatedCompilations ( sourceSet , forIde ) + <EOL> createCommonizedCInteropDependencyConfigurationView ( sourceSet ) <EOL> }

/**
 * @param forIde: A different task for dependency transformation will be used. This task will not use the regular 'build' directory
 * as transformation output to ensure IDE still being able to resolve the dependencies even when the project is cleaned.
 */


{ <EOL> val size = jsonToCache . size <EOL> if ( size <= <NUM_LIT:10> ) return <EOL> if ( Random . nextInt ( <NUM_LIT:0> , size ) == <NUM_LIT:0> ) { <EOL> val iter = jsonToCache . iterator ( ) <EOL> while ( iter . hasNext ( ) ) { <EOL> if ( iter . next ( ) . key . isDead ) iter . remove ( ) <EOL> } <EOL> } <EOL> }

/**
 * To maintain O(1) access, we cleanup the table from dead references with 1/size probability
 */