ruby-fann 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/ruby_fann/fann_augment.h +62 -62
- data/ext/ruby_fann/ruby_fann.c +362 -268
- data/lib/ruby_fann/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d60f815b69ebd06c43817b1804684b72474f9a6d7c02f43a7d057ba631baeba3
|
4
|
+
data.tar.gz: 958d4cac668983cbc533dbbb4cf4fca6001d359ca5b6e011c691070bccec24aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1552c4475c755a926e54dc031a6279837e55246289f22275ca6c2ea44303c58891cdb094bcf082155ea8f683c393f38d82e43be96915aa084b88a3e50572630f
|
7
|
+
data.tar.gz: cd557118462f5ca697d036f9ed8ef40ab35a87bacfe7b870a754dd37527a20c5a6f8d48f8d6da0a5f24a127e019f4030a52205e0f9a772ac04756296b93c065b
|
@@ -1,22 +1,21 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
#include "ruby_compat.h"
|
3
3
|
|
4
|
-
FANN_EXTERNAL struct fann_train_data *
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
FANN_EXTERNAL struct fann_train_data *FANN_API fann_create_train_from_rb_ary2(
|
5
|
+
unsigned int num_data,
|
6
|
+
unsigned int num_input,
|
7
|
+
unsigned long num_output)
|
8
8
|
{
|
9
|
-
|
9
|
+
return 0;
|
10
10
|
}
|
11
11
|
|
12
12
|
/*
|
13
13
|
* Copied from fann_create_train_from_callback/file & modified to ease
|
14
14
|
* allocating from ruby arrays:
|
15
15
|
*/
|
16
|
-
FANN_EXTERNAL struct fann_train_data *
|
17
|
-
|
18
|
-
|
19
|
-
)
|
16
|
+
FANN_EXTERNAL struct fann_train_data *FANN_API fann_create_train_from_rb_ary(
|
17
|
+
VALUE inputs,
|
18
|
+
VALUE outputs)
|
20
19
|
{
|
21
20
|
unsigned int i, j;
|
22
21
|
fann_type *data_input, *data_output;
|
@@ -24,89 +23,90 @@ FANN_EXTERNAL struct fann_train_data * FANN_API fann_create_train_from_rb_ary(
|
|
24
23
|
|
25
24
|
long num_input = RARRAY_LEN(RARRAY_PTR(inputs)[0]);
|
26
25
|
long num_output = RARRAY_LEN(RARRAY_PTR(outputs)[0]);
|
27
|
-
|
26
|
+
long num_data = RARRAY_LEN(inputs);
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
if (data == NULL)
|
29
|
+
{
|
31
30
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
32
31
|
return NULL;
|
33
32
|
}
|
34
33
|
|
35
|
-
fann_init_error_data((struct fann_error *)
|
34
|
+
fann_init_error_data((struct fann_error *)data);
|
36
35
|
|
37
|
-
data->num_data
|
38
|
-
data->num_input
|
36
|
+
data->num_data = num_data;
|
37
|
+
data->num_input = num_input;
|
39
38
|
data->num_output = num_output;
|
40
|
-
data->input = (fann_type **)
|
41
|
-
if(data->input == NULL)
|
39
|
+
data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
|
40
|
+
if (data->input == NULL)
|
42
41
|
{
|
43
42
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
44
43
|
fann_destroy_train(data);
|
45
44
|
return NULL;
|
46
45
|
}
|
47
46
|
|
48
|
-
data->output = (fann_type **)
|
49
|
-
if(data->output == NULL)
|
47
|
+
data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
|
48
|
+
if (data->output == NULL)
|
50
49
|
{
|
51
50
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
52
51
|
fann_destroy_train(data);
|
53
52
|
return NULL;
|
54
53
|
}
|
55
|
-
data_input = (fann_type *)
|
56
|
-
if(data_input == NULL)
|
54
|
+
data_input = (fann_type *)calloc(num_input * num_data, sizeof(fann_type));
|
55
|
+
if (data_input == NULL)
|
57
56
|
{
|
58
57
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
59
58
|
fann_destroy_train(data);
|
60
59
|
return NULL;
|
61
60
|
}
|
62
61
|
|
63
|
-
data_output = (fann_type *)
|
64
|
-
if(data_output == NULL)
|
62
|
+
data_output = (fann_type *)calloc(num_output * num_data, sizeof(fann_type));
|
63
|
+
if (data_output == NULL)
|
65
64
|
{
|
66
65
|
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
|
67
66
|
fann_destroy_train(data);
|
68
67
|
return NULL;
|
69
68
|
}
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
70
|
+
VALUE inputs_i, outputs_i;
|
71
|
+
for (i = 0; i != num_data; i++)
|
72
|
+
{
|
73
|
+
data->input[i] = data_input;
|
74
|
+
data_input += num_input;
|
75
|
+
|
76
|
+
inputs_i = RARRAY_PTR(inputs)[i];
|
77
|
+
outputs_i = RARRAY_PTR(outputs)[i];
|
78
|
+
|
79
|
+
if (RARRAY_LEN(inputs_i) != num_input)
|
80
|
+
{
|
81
|
+
rb_raise(
|
82
|
+
rb_eRuntimeError,
|
83
|
+
"Number of inputs at [%d] is inconsistent: (%du != %d)",
|
84
|
+
i, RARRAY_LEN(inputs_i)),
|
85
|
+
num_input;
|
86
|
+
}
|
87
|
+
|
88
|
+
if (RARRAY_LEN(outputs_i) != num_output)
|
89
|
+
{
|
90
|
+
rb_raise(
|
91
|
+
rb_eRuntimeError,
|
92
|
+
"Number of outputs at [%d] is inconsistent: (%d != %d)",
|
93
|
+
i, RARRAY_LEN(outputs_i)),
|
94
|
+
num_output;
|
95
|
+
}
|
96
|
+
|
97
|
+
for (j = 0; j != num_input; j++)
|
98
|
+
{
|
99
|
+
data->input[i][j] = NUM2DBL(RARRAY_PTR(inputs_i)[j]);
|
100
|
+
}
|
101
|
+
|
102
|
+
data->output[i] = data_output;
|
103
|
+
data_output += num_output;
|
104
|
+
|
105
|
+
for (j = 0; j != num_output; j++)
|
106
|
+
{
|
107
|
+
data->output[i][j] = NUM2DBL(RARRAY_PTR(outputs_i)[j]);
|
108
|
+
}
|
109
|
+
}
|
110
110
|
|
111
111
|
return data;
|
112
112
|
}
|