elegy/module.py
def apply(
        self,
        parameters: tp.Optional[tp.Dict] = None,
        states: tp.Optional[tp.Dict] = None,
        rng: tp.Optional[tp.Union[np.ndarray, int]] = None,
        get_summaries: bool = False,
        training: bool = True,
    ) -> "ApplyCallable":
        """
        Applies your function injecting some context arguments.

        Arguments:
            parameters:
            states:
            rng:
            get_summaries:

        Returns:
            A function with the same signature as `call` that will
            execute the computation given the context arguments
            passed to `apply`.
        """

        @utils.wraps(self.call)
        def apply_fn(*args, **kwargs):

            current_parameters = self.get_parameters()
            current_states = self.get_states()

            assert current_parameters is not None
            assert current_states is not None

            if parameters is not None:
                self.set_parameters(parameters)

            if states is not None:
                self.set_states(states)

            with context(
                rng=rng,
                building=False,
                training=training,
                get_summaries=get_summaries,
            ) as ctx:
                outputs = self(*args, **kwargs)

            output_parameters = self.get_parameters()
            output_states = self.get_states()

            if parameters is not None:
                self.set_parameters(current_parameters)

            if states is not None:
                self.set_states(current_states)

            return (
                outputs,
                ApplyContext(
                    parameters=output_parameters,
                    states=output_states,
                    losses=ctx.losses,
                    metrics=ctx.metrics,
                    summaries=ctx.summaries,
                ),
            )

        return apply_fn

        Applies your function injecting some context arguments.

        Arguments:
            parameters:
            states:
            rng:
            get_summaries:

        Returns:
            A function with the same signature as `call` that will
            execute the computation given the context arguments
            passed to `apply`.
        
Applies your function injecting some context arguments.
Applies your function injecting some context arguments .
def apply(
        self,
        parameters: tp.Optional[tp.Dict] = None,
        states: tp.Optional[tp.Dict] = None,
        rng: tp.Optional[tp.Union[np.ndarray, int]] = None,
        get_summaries: bool = False,
        training: bool = True,
    ) -> "ApplyCallable":
        @utils.wraps(self.call)
        def apply_fn(*args, **kwargs):
            current_parameters = self.get_parameters()
            current_states = self.get_states()
            assert current_parameters is not None
            assert current_states is not None
            if parameters is not None:
                self.set_parameters(parameters)
            if states is not None:
                self.set_states(states)
            with context(
                rng=rng,
                building=False,
                training=training,
                get_summaries=get_summaries,
            ) as ctx:
                outputs = self(*args, **kwargs)
            output_parameters = self.get_parameters()
            output_states = self.get_states()
            if parameters is not None:
                self.set_parameters(current_parameters)
            if states is not None:
                self.set_states(current_states)
            return (
                outputs,
                ApplyContext(
                    parameters=output_parameters,
                    states=output_states,
                    losses=ctx.losses,
                    metrics=ctx.metrics,
                    summaries=ctx.summaries,
                ),
            )
        return apply_fn
def apply ( self , parameters : tp . Optional [ tp . Dict ] = None , states : tp . Optional [ tp . Dict ] = None , rng : tp . Optional [ tp . Union [ np . ndarray , int ] ] = None , get_summaries : bool = False , training : bool = True , ) -> "ApplyCallable" : @ utils . wraps ( self . call ) def apply_fn ( * args , ** kwargs ) : current_parameters = self . get_parameters ( ) current_states = self . get_states ( ) assert current_parameters is not None assert current_states is not None if parameters is not None : self . set_parameters ( parameters ) if states is not None : self . set_states ( states ) with context ( rng = rng , building = False , training = training , get_summaries = get_summaries , ) as ctx : outputs = self ( * args , ** kwargs ) output_parameters = self . get_parameters ( ) output_states = self . get_states ( ) if parameters is not None : self . set_parameters ( current_parameters ) if states is not None : self . set_states ( current_states ) return ( outputs , ApplyContext ( parameters = output_parameters , states = output_states , losses = ctx . losses , metrics = ctx . metrics , summaries = ctx . summaries , ) , ) return apply_fn
Applies your function injecting some context arguments.
Applies your function injecting some context arguments .
"""
        Applies your function injecting some context arguments.

        Arguments:
            parameters:
            states:
            rng:
            get_summaries:

        Returns:
            A function with the same signature as `call` that will
            execute the computation given the context arguments
            passed to `apply`.
        """
A function with the same signature as `call` that will
execute the computation given the context arguments
passed to `apply`.
A function with the same signature as ` call ` that will execute the computation given the context arguments passed to ` apply ` .
self
parameters
tp.Optional[tp.Dict]
None
states
tp.Optional[tp.Dict]
None
rng
tp.Optional[tp.Union[np.ndarray, int]]
None
get_summaries
bool
None
training
bool