Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters
Questions tagged [initializer]
684 questions
3
votes
3 answers
Char array initialization dilemma
Consider following code:
// hacky, since "123" is 4 chars long (including terminating 0)
char symbols[3] = "123";
// clean, but lot of typing
char symbols[3] = {'1', '2', '3'};
so, the twist is actually described in comment to the code, is there a…

Petr Abdulin
- 33,883
- 9
- 62
- 96
3
votes
1 answer
Building a CNN model but suffer from 'Tensor-typed variable initializers must either be wrapped in an init_scope or callable'
I want to use he_normal as kernel initializer when building CNN model, but suffer this error code and can't find solution. Is there any suggestion?
Searched as much as I can but still can't fix this issue.
Any advice will be…

RayChenPy
- 33
- 3
3
votes
1 answer
Why is array initialization with brackets () marked as error by compilers?
I was researching the initializer syntax in C++, and according to cppreference, there are three possible ways of writing it, 1) brackets, 2) equal sign, 3) braces.
When trying to initialize an array with the 1) brackets syntax, I encounter an…

lpetru
- 117
- 5
3
votes
0 answers
Does an abstract `def __init__` make sense?
I want implementations of my abstract class to accept an integer. For this, I can
from abc import ABC, abstractmethod
class Base(ABC):
@abstractmethod
def __init__(self, i: int):
pass
and then implementations will be like
class…

joel
- 6,359
- 2
- 30
- 55
3
votes
3 answers
"Argument passed to call that takes no arguments" when creating an object
I have an error in using a Swift class. When I am trying to create a new object like so
let prod_obj = Produs(nume: nume_prod, cod_bare: cod_ext)
I get the error "Argument passed to call that takes no arguments" and I don't know why. I've read…

MrEye
- 35
- 1
- 8
3
votes
0 answers
Swift subclassing ObjC Class, initializer gets recognized selector
The problem is simple. I have a Swift class that subclasses an Objective-C class:
class CJGADSearchBannerView: GADSearchBannerView {
...
}
Then I initialize my class as:
let searchBanner = CJGADSearchBannerView(adSize: kGADAdSizeFluid)
The…

ratsimihah
- 1,010
- 1
- 11
- 22
3
votes
1 answer
How can I properly use breakpoints when using an object initializer?
For example, doing something like this:
foreach (DataRow row in data.Rows)
{
Person newPerson = new Person()
{
Id = row.Field("Id"),
Name = row.Field("Name"),
LastName = row.Field("LastName"),
…
delete
3
votes
5 answers
cant initialize var variable more than once
hi i have a var variable and i need initialize it based on if statement this is my code:
var series = new ColumnSeries{};
if(integer == 0)
series = new LineSeries{};
else if (integer == 1)
series = new PieSeries{};
else if (integer == 2)
…
user9641573
3
votes
1 answer
Can you “extend” (i.e. add additional initialization logic to) the auto-generated constructor for a Codable object?
When you implement Codable on an object, the compiler can automatically generate a constructor for you. However it only does this if you haven't written an initializer that accepts a decoder yourself.
That said, we have an object with ~50 let…

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
3
votes
2 answers
Why `xavier_initializer()` and `glorot_uniform_initializer()` are duplicated to some extent?
xavier_initializer(uniform=True, seed=None, dtype=tf.float32) and glorot_uniform_initializer(seed=None, dtype=tf.float32) refer to the same person Xavier Glorot. Why not consolidate them into one function?
xavier_initializer is in tf.contrib.layers.…

user1424739
- 11,937
- 17
- 63
- 152
3
votes
1 answer
Defining Lua methods as initialization
In the Lua language, I am able to define functions in a table with something such as
table = { myfunction = function(x) return x end }
I wondered if I can created methods this way, instead of having to do it like
function table:mymethod() ...…

viktorry
- 167
- 1
- 6
3
votes
1 answer
Using weights initializer with tf.nn.conv2d
When using tf.layers.conv2d, setting the initializer is easy, it can be done through its parameter. But what if I use tf.nn.conv2d? I use this code. Is this equivalent to setting the kernel_initializer parameter in tf.layers.conv2d? Although the…

T.Poe
- 1,949
- 6
- 28
- 59
3
votes
0 answers
void{} vs void() as a void initializer
The void() construction can be used to "create a value of the type void" (strange but true). But the C++11+ initialization syntax with curly braces doesn't work in such case:
int f_int_parenthesis()
{
return int(); // OK
}
int…

Constructor
- 7,273
- 2
- 24
- 66
3
votes
1 answer
Is local_variables_initializer really necessary?
In practice, isn't running global_variables_initializer enough to initialize model variables?
local_variables_initializer seems to be unnecessary and absent even in official and semi-official tensorflow example code. See for…

Giorgos Sfikas
- 707
- 1
- 8
- 19
3
votes
1 answer
How to extend Array for generic type?
I have a class for a linked list declared like this:
class LinkedNode {
let data: T
var next: LinkedNode?
func traverseList(process: (LinkedNode) -> ()) { ... }
}
What I want to do is extend Array to have an initialiser…

MarkAurelius
- 1,203
- 1
- 14
- 27