Module: Tensorflow::Decorator

Included in:
Tensorflow::Datasets::Images::Mnist
Defined in:
lib/tensorflow/decorators.rb

Defined Under Namespace

Classes: Function

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tensorflow/decorators.rb', line 15

def self.extended(klass)
  @waiting_for_method = false
  this = self
  klass.instance_eval do
    @tf = this
  end

  if klass.is_a?(Object) && klass.to_s == 'main'
    klass.class.extend(self)
  end
end

.function(input_signature = []) ⇒ Object



27
28
29
# File 'lib/tensorflow/decorators.rb', line 27

def self.function(input_signature = [])
  @current_function = Function.new(input_signature)
end

.wrap_method(method) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/tensorflow/decorators.rb', line 31

def self.wrap_method(method)
  # We do this little dance because when the method is wrapped it will trigger method_added. So first we need
  # to clear out @current_function before continuing
  if @current_function
    current_function = @current_function
    @current_function = nil
    current_function&.wrap(method)
  end
end

Instance Method Details

#method_added(method_name) ⇒ Object



47
48
49
50
51
# File 'lib/tensorflow/decorators.rb', line 47

def method_added(method_name)
  super(method_name)
  method = self.instance_method(method_name)
  @tf.wrap_method(method)
end

#singleton_method_added(method_name) ⇒ Object



41
42
43
44
45
# File 'lib/tensorflow/decorators.rb', line 41

def singleton_method_added(method_name)
  super(method_name)
  method = self.method(method_name)
  @tf.wrap_method(method)
end