digitalmars.D.learn - Templates args
- Andrey (33/33) Jul 14 2016 Hi guys!
- Andrey (2/35) Jul 14 2016 to something like - Neurons_layer!(float,5,Sigmoid) nf;
- Lodovico Giaretta (4/47) Jul 14 2016 You don't need Sigmoid!float at all. This will work:
- Andrey (3/6) Jul 14 2016 Yes, default init is present, but double, real types are desirable
- ag0aep6g (19/41) Jul 14 2016 [...]
- Andrey (3/18) Jul 14 2016 WOW! It's works. Thanks.
- Steven Schveighoffer (9/32) Jul 14 2016 You can't pass an uninstantiated template type as a type, but you can
Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Function(T value) { ... } const T DerivateFunction(const T value) { ... } } struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { private: static if(neurons_num > 0) T[neurons_num] _neurons_arr; else T[] _neurons_arr; private: alias Function = F.Function; } unittest { Neurons_layer!(float,5,Sigmoid!float) nf; } The question is - How to make in pretty way this line: Neurons_layer!(float,5,Sigmoid!float) nf;
Jul 14 2016
On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote:Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Function(T value) { ... } const T DerivateFunction(const T value) { ... } } struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { private: static if(neurons_num > 0) T[neurons_num] _neurons_arr; else T[] _neurons_arr; private: alias Function = F.Function; } unittest { Neurons_layer!(float,5,Sigmoid!float) nf; } The question is - How to make in pretty way this line: Neurons_layer!(float,5,Sigmoid!float) nf;to something like - Neurons_layer!(float,5,Sigmoid) nf;
Jul 14 2016
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote:On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote:You don't need Sigmoid!float at all. This will work: Neurons_layer!(float, 5) nf; as you provided a default value for the third argument.Hi guys! Help a newbie please. Playing with D and trying to understand some features. Here is my try to carry out my code from C++ project to D struct Sigmoid(T) { const T Function(T value) { ... } const T DerivateFunction(const T value) { ... } } struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { private: static if(neurons_num > 0) T[neurons_num] _neurons_arr; else T[] _neurons_arr; private: alias Function = F.Function; } unittest { Neurons_layer!(float,5,Sigmoid!float) nf; } The question is - How to make in pretty way this line: Neurons_layer!(float,5,Sigmoid!float) nf;to something like - Neurons_layer!(float,5,Sigmoid) nf;
Jul 14 2016
On Thursday, 14 July 2016 at 19:48:20 UTC, Lodovico Giaretta wrote:You don't need Sigmoid!float at all. This will work: Neurons_layer!(float, 5) nf; as you provided a default value for the third argument.Yes, default init is present, but double, real types are desirable
Jul 14 2016
On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote:On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote:[...][...]struct Sigmoid(T) {[...]} struct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) {Make F an alias parameter: ---- struct Neurons_layer(T = float, size_t neurons_num = 0, alias F = Sigmoid) if(isFloatingPoint!T && is(typeof(F!T.Function))) { ... private: alias Function = F!T.Function; } unittest { Neurons_layer!(float,5,Sigmoid) nf; } ----private: alias Function = F.Function; } unittest { Neurons_layer!(float,5,Sigmoid!float) nf; } The question is - How to make in pretty way this line: Neurons_layer!(float,5,Sigmoid!float) nf;to something like - Neurons_layer!(float,5,Sigmoid) nf;
Jul 14 2016
On Thursday, 14 July 2016 at 19:48:38 UTC, ag0aep6g wrote:Make F an alias parameter: ---- struct Neurons_layer(T = float, size_t neurons_num = 0, alias F = Sigmoid) if(isFloatingPoint!T && is(typeof(F!T.Function))) { ... private: alias Function = F!T.Function; } unittest { Neurons_layer!(float,5,Sigmoid) nf; } ----WOW! It's works. Thanks. I like D more and more )))
Jul 14 2016
On 7/14/16 3:28 PM, Andrey wrote:On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote:You can't pass an uninstantiated template type as a type, but you can pass as an alias: struct Neurons_layer(T = float, size_t neurons_num = 0, alias FTemp = Sigmoid) { alias F = FTemp!T; ... -Stevestruct Neurons_layer(T = float, size_t neurons_num = 0, F = Sigmoid!T) if(isFloatingPoint!T && is(typeof(F.Function))) { private: static if(neurons_num > 0) T[neurons_num] _neurons_arr; else T[] _neurons_arr; private: alias Function = F.Function; } unittest { Neurons_layer!(float,5,Sigmoid!float) nf; } The question is - How to make in pretty way this line: Neurons_layer!(float,5,Sigmoid!float) nf;to something like - Neurons_layer!(float,5,Sigmoid) nf;
Jul 14 2016