midas-edge 0.2.3 → 0.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: 71b32a1851488ba989ccc792af8922d1148f0c0f4585574821ea1759c908ad41
4
- data.tar.gz: a4b9105e96a3407708d8e64a31c33e93dbbb8c9127c1f99f802044cdd4aa6818
3
+ metadata.gz: 5d4056b117cffbbbf0e5f9f97988789f9b2d53fc78753122ce7a03a45f532eff
4
+ data.tar.gz: f218bd317db9c4b3a792924e4312e35d84233bcb81198ea0a8f2a2551ef83452
5
5
  SHA512:
6
- metadata.gz: 28149251ec92a2b24e07c7745ad0b759c23ff4d957fa56298d6c6a92384f798e0651086a524b3b95e7911ed5500405929ef6627059429d41f3126381b73e479e
7
- data.tar.gz: 2146d83339cd7c466d053f82f937a44ceb16d609d31034cd740b90425601ea12861e9bd1377a8696c5655af929a8dc1201fae6e79bed3addfd96125931e2f674
6
+ metadata.gz: eede2417d3bce099af436eee2fb97497675c7056ae7adf5b496cfaf7e170533242a32f0dcda017c58847eb279af48f2dc1b61bff0bab81e0397250f8200518ed
7
+ data.tar.gz: 5b2bf24281919ae2f80f460bb7566bdf9d25b8bec145f2b43e59c8abb24a4f30e62c0d5ac2a8b6ecb8561d76e993a0facd6b0b2f177c3cee476daf2809bc4f7c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.0 (2021-05-17)
2
+
3
+ - Updated to Rice 4
4
+ - Dropped support for Ruby < 2.6
5
+
1
6
  ## 0.2.3 (2020-11-17)
2
7
 
3
8
  - Updated MIDAS to 1.1.2
data/NOTICE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright 2020 Rui Liu (liurui39660) and Siddharth Bhatia (bhatiasiddharth)
2
- Copyright 2020 Andrew Kane
2
+ Copyright 2020-2021 Andrew Kane
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [MIDAS](https://github.com/bhatiasiddharth/MIDAS) - edge stream anomaly detection - for Ruby
4
4
 
5
- [![Build Status](https://travis-ci.org/ankane/midas.svg?branch=master)](https://travis-ci.org/ankane/midas)
5
+ [![Build Status](https://github.com/ankane/midas/workflows/build/badge.svg?branch=master)](https://github.com/ankane/midas/actions)
6
6
 
7
7
  ## Installation
8
8
 
9
- Add these lines to your application’s Gemfile:
9
+ Add this line to your application’s Gemfile:
10
10
 
11
11
  ```ruby
12
12
  gem 'midas-edge'
data/ext/midas/ext.cpp CHANGED
@@ -8,15 +8,10 @@
8
8
  #include <RelationalCore.hpp>
9
9
 
10
10
  // rice
11
- #include <rice/Module.hpp>
12
- #include <rice/String.hpp>
11
+ #include <rice/rice.hpp>
12
+ #include <rice/stl.hpp>
13
13
 
14
- using Rice::Module;
15
- using Rice::String;
16
- using Rice::define_module;
17
- using Rice::define_class_under;
18
-
19
- void load_str(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& times, std::string input, bool directed) {
14
+ void load_str(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& times, const std::string& input, bool directed) {
20
15
  int* input_ptr = (int*) input.data();
21
16
  size_t n = input.size() / sizeof(int);
22
17
 
@@ -41,8 +36,7 @@ void load_str(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& ti
41
36
  // load_data from main.cpp
42
37
  // modified to throw std::runtime_error when cannot find file
43
38
  // instead of exiting
44
- void load_file(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& times, std::string input_file, bool undirected)
45
- {
39
+ void load_file(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& times, const std::string& input_file, bool undirected) {
46
40
  FILE* infile = fopen(input_file.c_str(), "r");
47
41
  if (infile == NULL) {
48
42
  throw std::runtime_error("Could not read file: " + input_file);
@@ -56,8 +50,7 @@ void load_file(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& t
56
50
  dst.push_back(d);
57
51
  times.push_back(t);
58
52
  }
59
- }
60
- else {
53
+ } else {
61
54
  while (fscanf(infile, "%d,%d,%d", &s, &d, &t) == 3) {
62
55
  src.push_back(s);
63
56
  dst.push_back(d);
@@ -67,12 +60,15 @@ void load_file(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& t
67
60
  times.push_back(t);
68
61
  }
69
62
  }
63
+
64
+ fclose(infile);
70
65
  }
71
66
 
72
67
  std::string fit_predict(std::vector<int>& src, std::vector<int>& dst, std::vector<int>& times, int num_rows, int num_buckets, float factor, float threshold, bool relations, int seed) {
73
68
  srand(seed);
74
69
  size_t n = src.size();
75
- const auto result = new float[n];
70
+ std::vector<float> result;
71
+ result.reserve(n);
76
72
 
77
73
  if (!std::isnan(threshold)) {
78
74
  MIDAS::FilteringCore midas(num_rows, num_buckets, threshold, factor);
@@ -90,25 +86,26 @@ std::string fit_predict(std::vector<int>& src, std::vector<int>& dst, std::vecto
90
86
  result[i] = midas(src[i], dst[i], times[i]);
91
87
  }
92
88
  }
93
- return std::string((char*) result, sizeof(float) / sizeof(char) * n);
89
+
90
+ // std::string copies data
91
+ return std::string((char*) result.data(), sizeof(float) / sizeof(char) * n);
94
92
  }
95
93
 
96
94
  extern "C"
97
- void Init_ext()
98
- {
99
- Module rb_mMidas = define_module("Midas");
95
+ void Init_ext() {
96
+ auto rb_mMidas = Rice::define_module("Midas");
100
97
 
101
- define_class_under(rb_mMidas, "Detector")
102
- .define_method(
98
+ Rice::define_class_under(rb_mMidas, "Detector")
99
+ .define_function(
103
100
  "_fit_predict_str",
104
- *[](std::string input, int num_rows, int num_buckets, float factor, float threshold, bool relations, bool directed, int seed) {
101
+ [](const std::string& input, int num_rows, int num_buckets, float factor, float threshold, bool relations, bool directed, int seed) {
105
102
  std::vector<int> src, dst, times;
106
103
  load_str(src, dst, times, input, directed);
107
104
  return fit_predict(src, dst, times, num_rows, num_buckets, factor, threshold, relations, seed);
108
105
  })
109
- .define_method(
106
+ .define_function(
110
107
  "_fit_predict_file",
111
- *[](std::string input, int num_rows, int num_buckets, float factor, float threshold, bool relations, bool directed, int seed) {
108
+ [](const std::string& input, int num_rows, int num_buckets, float factor, float threshold, bool relations, bool directed, int seed) {
112
109
  std::vector<int> src, dst, times;
113
110
  load_file(src, dst, times, input, !directed);
114
111
  return fit_predict(src, dst, times, num_rows, num_buckets, factor, threshold, relations, seed);
data/ext/midas/extconf.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "mkmf-rice"
2
2
 
3
- $CXXFLAGS << " -std=c++11"
3
+ $CXXFLAGS << " -std=c++17"
4
4
 
5
5
  midas = File.expand_path("../../vendor/MIDAS/src", __dir__)
6
6
  $INCFLAGS << " -I#{midas}"
data/lib/midas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Midas
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midas-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: 4.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
26
+ version: 4.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: numo-narray
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,64 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake-compiler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '5'
97
41
  description:
98
- email: andrew@chartkick.com
42
+ email: andrew@ankane.org
99
43
  executables: []
100
44
  extensions:
101
45
  - ext/midas/extconf.rb
@@ -128,14 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
72
  requirements:
129
73
  - - ">="
130
74
  - !ruby/object:Gem::Version
131
- version: '2.4'
75
+ version: '2.6'
132
76
  required_rubygems_version: !ruby/object:Gem::Requirement
133
77
  requirements:
134
78
  - - ">="
135
79
  - !ruby/object:Gem::Version
136
80
  version: '0'
137
81
  requirements: []
138
- rubygems_version: 3.1.4
82
+ rubygems_version: 3.2.3
139
83
  signing_key:
140
84
  specification_version: 4
141
85
  summary: Edge stream anomaly detection for Ruby