Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn

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 )))


Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn
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


Re: Templates args

2016-07-14 Thread ag0aep6g via Digitalmars-d-learn

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)))
{

[...]

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;


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;
}



Re: Templates args

2016-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn

On 7/14/16 3:28 PM, Andrey wrote:

On Thursday, 14 July 2016 at 19:27:14 UTC, Andrey wrote:



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;


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;
   ...

-Steve


Re: Templates args

2016-07-14 Thread Lodovico Giaretta via Digitalmars-d-learn

On Thursday, 14 July 2016 at 19:28:23 UTC, Andrey wrote:

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;


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.


Re: Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn

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;


Templates args

2016-07-14 Thread Andrey via Digitalmars-d-learn

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;