initializer

When global_variables_initializer() is actually required

我的未来我决定 提交于 2019-11-30 17:16:58
import tensorflow as tf x = tf.constant(35, name='x') y = tf.Variable(x + 5, name='y') # model = tf.global_variables_initializer() with tf.Session() as session: print("x = ", session.run(x)) # session.run(model) print("y = ", session.run(y)) I was not able to understand when global_variables_initializer() is actually required. In the above code, if we uncomment lines 4 & 7, I can execute the code and see the values. If I run as-is, I see a crash. My question is which variables it is initializing. x is a constant which does not need initialization and y is variable which is not being

Assigning let variable in fallible initializer swift 1.2

佐手、 提交于 2019-11-30 14:14:32
I have a struct with a fallible initializer, not an instance method, but an initializer. After updating to 1.2, when I try to assign a let property inside the initializer, I receive the following error Cannot assign to 'aspectRatio' in self . My code below: import Foundation public struct MediaItem { public let url: NSURL! public let aspectRatio: Double public var description: String { return (url.absoluteString ?? "no url") + " (aspect ratio = \(aspectRatio))" } // MARK: - Private Implementation init?(data: NSDictionary?) { var valid = false if let urlString = data?.valueForKeyPath(TwitterKey

Rails how to create an initializer inside a gem

有些话、适合烂在心里 提交于 2019-11-30 13:53:40
I am trying to build a gem in Rails 3 and inside it i am trying to pass an initializer: Credentials.configure do |config| file = File.read("#{Rails.root}/config/twitter.yaml") file_config = YAML.load(file) config.consumer_key = file_config[Rails.env][:consumer_key] config.consumer_secret = file_config[Rails.env][:consumer_secret] config.callback_url = URI.escape(file_config[Rails.env][:callback_url]) config.time_stamp = Time.now.to_i end and then i am trying to call it like this: Credentials.time_stamp but i get this error: uninitialized constant Twitter::Credentials what is the problem?

Is it possible to use a c# object initializer with a factory method?

戏子无情 提交于 2019-11-30 12:33:42
问题 I have a class with a static factory method on it. I want to call the factory to retrieve an instance of the class, and then do additional initialization, preferablly via c# object initializer syntax : MyClass instance = MyClass.FactoryCreate() { someProperty = someValue; } vs MyClass instance = MyClass.FactoryCreate(); instance.someProperty = someValue; 回答1: No. Alternatively you could accept a lambda as an argument, which also gives you full control in which part of the "creation" process

Advanced C question: Please explain C construct *({ foo(&bar); &bar; })

懵懂的女人 提交于 2019-11-30 10:06:06
This is ultimately a C question that arose when studying code in completion.h of the Linux kernel source, where I see a C technique I've never used in C before. Although have a vague sense what it's doing, I'd like to fine tune my understanding with a precise description, and I'm not quite sure how to search for the answer with Google without a potentially a long ordeal. The relevant lines of code from the linux kernel's completion.h : struct completion { unsigned int done; wait_queue_head_t wait; }; #define COMPLETION_INITIALIZER_ONSTACK(work) \ (*({ init_completion(&work); &work; })) #define

Rails 3.1 Deployment to Heroku Error

安稳与你 提交于 2019-11-30 05:14:46
I'm trying to deploy my app to Heroku, I've done this before on my Windows machine, and now I am currently using a mac. I'm trying to use Postgresql for the first time. I have the following in my Gemfile: gem 'pg' EDIT: AndrewDavis-OSX:lunchbox ardavis$ rvm list rvm rubies => ruby-1.9.2-p180 [ x86_64 ] AndrewDavis-OSX:lunchbox ardavis$ heroku rake db:migrate rake aborted! /app/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end App::Application.config.session_store :cookie_store, key: '_app_session' ^ (See full trace by running task with --trace) (in /app) As

Is it possible to use a c# object initializer with a factory method?

一笑奈何 提交于 2019-11-30 02:59:57
I have a class with a static factory method on it. I want to call the factory to retrieve an instance of the class, and then do additional initialization, preferablly via c# object initializer syntax : MyClass instance = MyClass.FactoryCreate() { someProperty = someValue; } vs MyClass instance = MyClass.FactoryCreate(); instance.someProperty = someValue; No. Alternatively you could accept a lambda as an argument, which also gives you full control in which part of the "creation" process will be called. This way you can call it like: MyClass instance = MyClass.FactoryCreate(c=> { c.SomeProperty

C# initialiser conditional assignment

人盡茶涼 提交于 2019-11-30 01:19:05
问题 In a c# initialiser, I want to not set a property if a condition is false. Something like this: ServerConnection serverConnection = new ServerConnection() { ServerInstance = server, LoginSecure = windowsAuthentication, if (!windowsAuthentication) { Login = user, Password = password } }; It can be done? How? 回答1: You can't do this; C# initializers are a list of name = value pairs. See here for details: http://msdn.microsoft.com/en-us/library/ms364047(VS.80).aspx#cs3spec_topic5 You'll need to

Multiple constructors: the Pythonic way? [duplicate]

人盡茶涼 提交于 2019-11-29 20:33:37
This question already has an answer here: How to overload __init__ method based on argument type? 10 answers I have a container class that holds data. When the container is created, there are different methods to pass data. Pass a file which contains the data Pass the data directly via arguments Don't pass data; just create an empty container In Java, I would create three constructors. Here's how it would look like if it were possible in Python: class Container: def __init__(self): self.timestamp = 0 self.data = [] self.metadata = {} def __init__(self, file): f = file.open() self.timestamp = f

Assigning let variable in fallible initializer swift 1.2

早过忘川 提交于 2019-11-29 20:05:47
问题 I have a struct with a fallible initializer, not an instance method, but an initializer. After updating to 1.2, when I try to assign a let property inside the initializer, I receive the following error Cannot assign to 'aspectRatio' in self . My code below: import Foundation public struct MediaItem { public let url: NSURL! public let aspectRatio: Double public var description: String { return (url.absoluteString ?? "no url") + " (aspect ratio = \(aspectRatio))" } // MARK: - Private