numo-libsvm 2.1.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f21522e68f65ccd9ed42fe54021f4a8cf7327ffaf8912d0a0d81266bc9529818
4
- data.tar.gz: 6e2b184199cebb97def06d38dd148a7f5da7972ecceeff37f42d0fb68ca8ff18
3
+ metadata.gz: b29c8702582263f5465fc49e1d3ba7b7efedaa895d3eb988a7167393b64d98e0
4
+ data.tar.gz: 90906818ef9c3b8120a98961da0a845acdfd4c079d5ed5266c1df7706fa39db1
5
5
  SHA512:
6
- metadata.gz: 3bdf8b9a267b188129675424bcf7cfe3b2e92ec6798237dc610624dabdd9dbbae03a3d188f136b790d32502e5f0e53583ead91c08e66ee2bd194cc4455431e79
7
- data.tar.gz: eae8fb9bcac73b6550a27ea076d8cb15442159d6f2ae53dbcc5bbdf730b2b37aa47bca3244f6fe209c2cd39a551ab13faf05f6436f0bc4893877e3aa79a9e3dd
6
+ metadata.gz: e50f643d7b4b4ff55a61abeb2c297a8caebe60adb214f172da17bd569705edc71883aae780ecb5dbca3999571fffcd9cffb1057efcf23c697cb531c1cad17609
7
+ data.tar.gz: b1e45d76573c025deb93c7a29360320a1fe89172a79738a76f6f7561bd91e4443a49f4a108ab5e2cc99048b6e9132756c592915b92257ac6d7abff6f936ddb35
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.3.0
2
+ - Update bundled LIBSVM to 3.35.
3
+
4
+ # 2.2.0
5
+ - Update bundled LIBSVM to 3.31.
6
+
1
7
  # 2.1.1
2
8
  - Fix build failure with Xcode 14 and Ruby 3.1.x.
3
9
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2022 Atsushi Tatsuma
1
+ Copyright (c) 2019-2024 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2019-2022 Atsushi Tatsuma
2
+ * Copyright (c) 2019-2024 Atsushi Tatsuma
3
3
  * All rights reserved.
4
4
  *
5
5
  * Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2019-2022 Atsushi Tatsuma
2
+ * Copyright (c) 2019-2024 Atsushi Tatsuma
3
3
  * All rights reserved.
4
4
  *
5
5
  * Redistribution and use in source and binary forms, with or without
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2000-2019 Chih-Chung Chang and Chih-Jen Lin
2
+ Copyright (c) 2000-2023 Chih-Chung Chang and Chih-Jen Lin
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -8,6 +8,10 @@
8
8
  #include <limits.h>
9
9
  #include <locale.h>
10
10
  #include "svm.h"
11
+ #ifdef _OPENMP
12
+ #include <omp.h>
13
+ #endif
14
+
11
15
  int libsvm_version = LIBSVM_VERSION;
12
16
  typedef float Qfloat;
13
17
  typedef signed char schar;
@@ -50,7 +54,7 @@ static void info(const char *fmt,...)
50
54
  char buf[BUFSIZ];
51
55
  va_list ap;
52
56
  va_start(ap,fmt);
53
- vsprintf(buf,fmt,ap);
57
+ vsnprintf(buf,BUFSIZ,fmt,ap);
54
58
  va_end(ap);
55
59
  (*svm_print_string)(buf);
56
60
  }
@@ -67,7 +71,7 @@ static void info(const char *fmt,...) {}
67
71
  class Cache
68
72
  {
69
73
  public:
70
- Cache(int l,long int size);
74
+ Cache(int l,size_t size);
71
75
  ~Cache();
72
76
 
73
77
  // request data [0,len)
@@ -77,7 +81,7 @@ public:
77
81
  void swap_index(int i, int j);
78
82
  private:
79
83
  int l;
80
- long int size;
84
+ size_t size;
81
85
  struct head_t
82
86
  {
83
87
  head_t *prev, *next; // a circular list
@@ -91,12 +95,12 @@ private:
91
95
  void lru_insert(head_t *h);
92
96
  };
93
97
 
94
- Cache::Cache(int l_,long int size_):l(l_),size(size_)
98
+ Cache::Cache(int l_,size_t size_):l(l_),size(size_)
95
99
  {
96
100
  head = (head_t *)calloc(l,sizeof(head_t)); // initialized to 0
97
101
  size /= sizeof(Qfloat);
98
- size -= l * sizeof(head_t) / sizeof(Qfloat);
99
- size = max(size, 2 * (long int) l); // cache must be large enough for two columns
102
+ size_t header_size = l * sizeof(head_t) / sizeof(Qfloat);
103
+ size = max(size, 2 * (size_t) l + header_size) - header_size; // cache must be large enough for two columns
100
104
  lru_head.next = lru_head.prev = &lru_head;
101
105
  }
102
106
 
@@ -132,7 +136,7 @@ int Cache::get_data(const int index, Qfloat **data, int len)
132
136
  if(more > 0)
133
137
  {
134
138
  // free old space
135
- while(size < more)
139
+ while(size < (size_t)more)
136
140
  {
137
141
  head_t *old = lru_head.next;
138
142
  lru_delete(old);
@@ -144,7 +148,7 @@ int Cache::get_data(const int index, Qfloat **data, int len)
144
148
 
145
149
  // allocate new space
146
150
  h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
147
- size -= more;
151
+ size -= more; // previous while loop guarantees size >= more and subtraction of size_t variable will not underflow
148
152
  swap(h->len,len);
149
153
  }
150
154
 
@@ -1270,7 +1274,7 @@ public:
1270
1274
  :Kernel(prob.l, prob.x, param)
1271
1275
  {
1272
1276
  clone(y,y_,prob.l);
1273
- cache = new Cache(prob.l,(long int)(param.cache_size*(1<<20)));
1277
+ cache = new Cache(prob.l,(size_t)(param.cache_size*(1<<20)));
1274
1278
  QD = new double[prob.l];
1275
1279
  for(int i=0;i<prob.l;i++)
1276
1280
  QD[i] = (this->*kernel_function)(i,i);
@@ -1282,6 +1286,9 @@ public:
1282
1286
  int start, j;
1283
1287
  if((start = cache->get_data(i,&data,len)) < len)
1284
1288
  {
1289
+ #ifdef _OPENMP
1290
+ #pragma omp parallel for private(j) schedule(guided)
1291
+ #endif
1285
1292
  for(j=start;j<len;j++)
1286
1293
  data[j] = (Qfloat)(y[i]*y[j]*(this->*kernel_function)(i,j));
1287
1294
  }
@@ -1319,7 +1326,7 @@ public:
1319
1326
  ONE_CLASS_Q(const svm_problem& prob, const svm_parameter& param)
1320
1327
  :Kernel(prob.l, prob.x, param)
1321
1328
  {
1322
- cache = new Cache(prob.l,(long int)(param.cache_size*(1<<20)));
1329
+ cache = new Cache(prob.l,(size_t)(param.cache_size*(1<<20)));
1323
1330
  QD = new double[prob.l];
1324
1331
  for(int i=0;i<prob.l;i++)
1325
1332
  QD[i] = (this->*kernel_function)(i,i);
@@ -1366,7 +1373,7 @@ public:
1366
1373
  :Kernel(prob.l, prob.x, param)
1367
1374
  {
1368
1375
  l = prob.l;
1369
- cache = new Cache(l,(long int)(param.cache_size*(1<<20)));
1376
+ cache = new Cache(l,(size_t)(param.cache_size*(1<<20)));
1370
1377
  QD = new double[2*l];
1371
1378
  sign = new schar[2*l];
1372
1379
  index = new int[2*l];
@@ -1397,6 +1404,9 @@ public:
1397
1404
  int j, real_i = index[i];
1398
1405
  if(cache->get_data(real_i,&data,l) < l)
1399
1406
  {
1407
+ #ifdef _OPENMP
1408
+ #pragma omp parallel for private(j) schedule(guided)
1409
+ #endif
1400
1410
  for(j=0;j<l;j++)
1401
1411
  data[j] = (Qfloat)(this->*kernel_function)(real_i,j);
1402
1412
  }
@@ -2219,11 +2229,9 @@ svm_model *svm_train(const svm_problem *prob, const svm_parameter *param)
2219
2229
  double *prob_density_marks = Malloc(double,nr_marks);
2220
2230
 
2221
2231
  if(svm_one_class_probability(prob,model,prob_density_marks) == 0)
2222
- {
2223
- model->prob_density_marks = Malloc(double,nr_marks);
2224
- for(i=0;i<nr_marks;i++)
2225
- model->prob_density_marks[i] = prob_density_marks[i];
2226
- }
2232
+ model->prob_density_marks = prob_density_marks;
2233
+ else
2234
+ free(prob_density_marks);
2227
2235
  }
2228
2236
 
2229
2237
  free(f.alpha);
@@ -2436,8 +2444,8 @@ void svm_cross_validation(const svm_problem *prob, const svm_parameter *param, i
2436
2444
  int nr_class;
2437
2445
  if (nr_fold > l)
2438
2446
  {
2447
+ fprintf(stderr,"WARNING: # folds (%d) > # data (%d). Will use # folds = # data instead (i.e., leave-one-out cross validation)\n", nr_fold, l);
2439
2448
  nr_fold = l;
2440
- fprintf(stderr,"WARNING: # folds > # data. Will use # folds = # data instead (i.e., leave-one-out cross validation)\n");
2441
2449
  }
2442
2450
  fold_start = Malloc(int,nr_fold+1);
2443
2451
  // stratified cv may not give leave-one-out rate
@@ -2598,6 +2606,9 @@ double svm_predict_values(const svm_model *model, const svm_node *x, double* dec
2598
2606
  {
2599
2607
  double *sv_coef = model->sv_coef[0];
2600
2608
  double sum = 0;
2609
+ #ifdef _OPENMP
2610
+ #pragma omp parallel for private(i) reduction(+:sum) schedule(guided)
2611
+ #endif
2601
2612
  for(i=0;i<model->l;i++)
2602
2613
  sum += sv_coef[i] * Kernel::k_function(x,model->SV[i],model->param);
2603
2614
  sum -= model->rho[0];
@@ -2614,6 +2625,9 @@ double svm_predict_values(const svm_model *model, const svm_node *x, double* dec
2614
2625
  int l = model->l;
2615
2626
 
2616
2627
  double *kvalue = Malloc(double,l);
2628
+ #ifdef _OPENMP
2629
+ #pragma omp parallel for private(i) schedule(guided)
2630
+ #endif
2617
2631
  for(i=0;i<l;i++)
2618
2632
  kvalue[i] = Kernel::k_function(x,model->SV[i],model->param);
2619
2633
 
@@ -1,7 +1,7 @@
1
1
  #ifndef _LIBSVM_H
2
2
  #define _LIBSVM_H
3
3
 
4
- #define LIBSVM_VERSION 330
4
+ #define LIBSVM_VERSION 335
5
5
 
6
6
  #ifdef __cplusplus
7
7
  extern "C" {
@@ -3,6 +3,6 @@
3
3
  module Numo
4
4
  module Libsvm
5
5
  # The version of Numo::Libsvm you are using.
6
- VERSION = '2.1.1'
6
+ VERSION = '2.3.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-libsvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
10
+ date: 2024-12-29 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: numo-narray
@@ -56,7 +55,6 @@ metadata:
56
55
  source_code_uri: https://github.com/yoshoku/numo-libsvm
57
56
  documentation_uri: https://yoshoku.github.io/numo-libsvm/doc/
58
57
  rubygems_mfa_required: 'true'
59
- post_install_message:
60
58
  rdoc_options: []
61
59
  require_paths:
62
60
  - lib
@@ -71,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
69
  - !ruby/object:Gem::Version
72
70
  version: '0'
73
71
  requirements: []
74
- rubygems_version: 3.3.26
75
- signing_key:
72
+ rubygems_version: 3.6.2
76
73
  specification_version: 4
77
74
  summary: Numo::Libsvm is a Ruby gem binding to the LIBSVM library. Numo::Libsvm makes
78
75
  to use the LIBSVM functions with dataset represented by Numo::NArray.