red-datasets-numo-narray 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c231aa43124f2ac9df281f2f8e6527ea00e16a1ffb94c62c2b58087492dfb0b0
4
+ data.tar.gz: 507a4af8a5247210441af2a19b344e721b0eb33e91a00add3b5ebd13e2d5fa2a
5
+ SHA512:
6
+ metadata.gz: 97e2407bb628b420c6b814e5e83734afc66fb5d8c5d3726c6a0886202e917f2abd0863dfaf1aa44faf2da63eb35e81f4c0f7f8f35b934aedd1fd0e80783f123f
7
+ data.tar.gz: 12508c28f2b8a4303a01b8f24a7be18f827d92b1c328dae6f538bc0c14c27f1240ec33900a9a58a9a245effd6ec99798c1b8e0da046f5503f8e515ca672a871c
@@ -0,0 +1,6 @@
1
+ --output-dir doc/reference/en
2
+ --markup markdown
3
+ --markup-provider kramdown
4
+ lib/**/*.rb
5
+ -
6
+ doc/text/**/*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # -*- ruby -*-
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Kouhei Sutou <kou@clear-code.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # README
2
+
3
+ ## Name
4
+
5
+ Red Datasets Numo::NArray
6
+
7
+ ## Description
8
+
9
+ Red Datasets Numo::NArray adds [Numo::NArray](https://github.com/ruby-numo/numo-narray) object export feature to Red Datasets.
10
+
11
+ Red Datasets Numo::NArray adds `#to_narray` method to each dataset in Red Datasets. You can get dataset as Numo::NArray's numeric subclass object.
12
+
13
+ ## Install
14
+
15
+ ```console
16
+ % gem install red-datasets-numo-narray
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Here is an example to access iris dataset by `#to_narray`:
22
+
23
+ ```ruby
24
+ require "datasets"
25
+
26
+ iris = Datasets::Iris.new
27
+ puts iris.to_narray
28
+ ```
29
+
30
+ ## License
31
+
32
+ The MIT license. See `LICENSE.txt` for details.
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "bundler/gem_helper"
5
+
6
+ base_dir = File.join(File.dirname(__FILE__))
7
+
8
+ helper = Bundler::GemHelper.new(base_dir)
9
+ def helper.version_tag
10
+ version
11
+ end
12
+
13
+ helper.install
14
+ spec = helper.gemspec
15
+
16
+ desc "Run tests"
17
+ task :test do
18
+ ruby("test/run-test.rb")
19
+ end
20
+
21
+ task default: :test
@@ -0,0 +1,15 @@
1
+ require "datasets"
2
+
3
+ require "datasets-numo-narray/version"
4
+
5
+ require "datasets-numo-narray/narrayable"
6
+
7
+ module Datasets
8
+ class Dataset
9
+ include DatasetsNumoNArray::DatasetNArrayable
10
+ end
11
+
12
+ class Table
13
+ include DatasetsNumoNArray::TableNArrayable
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require "numo/narray"
2
+
3
+ module DatasetsNumoNArray
4
+ module DatasetNArrayable
5
+ def to_narray(*keys)
6
+ if keys.empty?
7
+ array = collect do |record|
8
+ record.values
9
+ end
10
+ else
11
+ array = collect do |record|
12
+ keys.collect do |key|
13
+ record[key]
14
+ end
15
+ end
16
+ end
17
+ Numo::NArray[*array]
18
+ end
19
+ end
20
+
21
+ module TableNArrayable
22
+ def to_narray(*keys)
23
+ if keys.empty?
24
+ array = collect {|_key, values| values}.transpose
25
+ else
26
+ array = fetch_values(*keys).transpose
27
+ end
28
+ Numo::NArray[*array]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module DatasetsNumoNArray
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ # -*- ruby -*-
2
+
3
+ clean_white_space = lambda do |entry|
4
+ entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
5
+ end
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
8
+ require "datasets-numo-narray/version"
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = "red-datasets-numo-narray"
12
+ spec.version = DatasetsNumoNArray::VERSION
13
+ spec.homepage = "https://github.com/red-data-tools/red-datasets-numo-narray"
14
+ spec.authors = ["Kouhei Sutou"]
15
+ spec.email = ["kou@clear-code.com"]
16
+
17
+ readme = File.read("README.md")
18
+ readme.force_encoding("UTF-8")
19
+ entries = readme.split(/^\#\#\s(.*)$/)
20
+ clean_white_space.call(entries[entries.index("Description") + 1])
21
+ description = clean_white_space.call(entries[entries.index("Description") + 1])
22
+ spec.summary, spec.description, = description.split(/\n\n+/, 3)
23
+ spec.license = "MIT"
24
+ spec.files = [
25
+ "README.md",
26
+ "LICENSE.txt",
27
+ "Rakefile",
28
+ "Gemfile",
29
+ "#{spec.name}.gemspec",
30
+ ]
31
+ spec.files += [".yardopts"]
32
+ spec.files += Dir.glob("lib/**/*.rb")
33
+ spec.files += Dir.glob("doc/text/*")
34
+ spec.test_files += Dir.glob("test/**/*")
35
+
36
+ spec.add_runtime_dependency("numo-narray")
37
+ spec.add_runtime_dependency("red-datasets")
38
+
39
+ spec.add_development_dependency("bundler")
40
+ spec.add_development_dependency("rake")
41
+ spec.add_development_dependency("test-unit")
42
+ spec.add_development_dependency("yard")
43
+ spec.add_development_dependency("kramdown")
44
+ end
@@ -0,0 +1,3 @@
1
+ require "datasets-numo-narray"
2
+
3
+ require "test-unit"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = true
4
+
5
+ require "pathname"
6
+
7
+ base_dir = Pathname.new(__FILE__).dirname.parent.expand_path
8
+
9
+ lib_dir = base_dir + "lib"
10
+ test_dir = base_dir + "test"
11
+
12
+ $LOAD_PATH.unshift(lib_dir.to_s)
13
+
14
+ require_relative "helper"
15
+
16
+ exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
@@ -0,0 +1,64 @@
1
+ class IrisTest < Test::Unit::TestCase
2
+ def setup
3
+ @dataset = Datasets::Iris.new
4
+ @table = @dataset.to_table
5
+ end
6
+
7
+ sub_test_case("Dataset") do
8
+ test("no keys") do
9
+ narray = @dataset.to_narray
10
+ assert_equal([
11
+ [150, 5],
12
+ [5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
13
+ ],
14
+ [
15
+ narray.shape,
16
+ narray[0, nil].to_a,
17
+ ])
18
+ end
19
+
20
+ test("keys") do
21
+ narray = @dataset.to_narray(:sepal_length,
22
+ :sepal_width,
23
+ :petal_length,
24
+ :petal_width)
25
+ assert_equal([
26
+ [150, 4],
27
+ [5.1, 3.5, 1.4, 0.2],
28
+ ],
29
+ [
30
+ narray.shape,
31
+ narray[0, nil].to_a,
32
+ ])
33
+ end
34
+ end
35
+
36
+ sub_test_case("Table") do
37
+ test("no keys") do
38
+ narray = @table.to_narray
39
+ assert_equal([
40
+ [150, 5],
41
+ [5.1, 3.5, 1.4, 0.2, "Iris-setosa"],
42
+ ],
43
+ [
44
+ narray.shape,
45
+ narray[0, nil].to_a,
46
+ ])
47
+ end
48
+
49
+ test("keys") do
50
+ narray = @table.to_narray(:sepal_length,
51
+ :sepal_width,
52
+ :petal_length,
53
+ :petal_width)
54
+ assert_equal([
55
+ [150, 4],
56
+ [5.1, 3.5, 1.4, 0.2],
57
+ ],
58
+ [
59
+ narray.shape,
60
+ narray[0, nil].to_a,
61
+ ])
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red-datasets-numo-narray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kouhei Sutou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: numo-narray
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: red-datasets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
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: test-unit
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: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: kramdown
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: 'Red Datasets Numo::NArray adds `#to_narray` method to each dataset in
112
+ Red Datasets. You can get dataset as Numo::NArray''s numeric subclass object.
113
+
114
+ '
115
+ email:
116
+ - kou@clear-code.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".yardopts"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - lib/datasets-numo-narray.rb
127
+ - lib/datasets-numo-narray/narrayable.rb
128
+ - lib/datasets-numo-narray/version.rb
129
+ - red-datasets-numo-narray.gemspec
130
+ - test/helper.rb
131
+ - test/run-test.rb
132
+ - test/test-iris.rb
133
+ homepage: https://github.com/red-data-tools/red-datasets-numo-narray
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.7.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Red Datasets Numo::NArray adds [Numo::NArray](https://github.com/ruby-numo/numo-narray)
157
+ object export feature to Red Datasets.
158
+ test_files:
159
+ - test/test-iris.rb
160
+ - test/helper.rb
161
+ - test/run-test.rb