umappp 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/ext/umappp/umappp.cpp +10 -6
- data/lib/umappp/version.rb +1 -1
- data/lib/umappp.rb +1 -0
- data/vendor/umappp/NeighborList.hpp +3 -0
- data/vendor/umappp/Umap.hpp +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4268767d4aa68fb7795e72e48a9822b629390091cd5214d460e1d99a3127a3c3
|
4
|
+
data.tar.gz: 684fdcf60aa7dc40a061927103692dda85fc2e40bb1680b0c61f014980197292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9d5181ec290f40b5b22079c36d90a2fe07e1072b35b933ee30da253fc0f734431081334b6fc7510317df330e7c321386bc46da742d4515a646437e70602835
|
7
|
+
data.tar.gz: 05d42582e0d559591bd22b767a6d7df7b821288fa8b44da86d8255822b49e629c15dd33e719d383a08d933ff1dfdd3fdf839e3eed7f2131dc0bf868c3ad467b4
|
data/README.md
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
19
|
-
|
20
19
|
```
|
21
20
|
gem install umappp
|
22
21
|
```
|
@@ -28,10 +27,12 @@ gem install umappp
|
|
28
27
|
This Gem provides the module `Umappp` and its singular method `Umappp.run()`. The first argument of `Umappp.run()` is a two-dimensional Ruby array or a two-dimensional Numo array. [Numo](https://github.com/ruby-numo/numo-narray) is a library for performing N-dimensional array computing like NumPy. The argument is converted to `Numo::SFloat`. SFloat is a single precision floating point number type of Numo::NArray.
|
29
28
|
|
30
29
|
```ruby
|
31
|
-
|
30
|
+
# The embedding is two-dimensional Ruby array or Numo array
|
31
|
+
# Returns Numo::SFloat
|
32
|
+
r = Umappp.run(embedding)
|
32
33
|
|
33
|
-
# with parameters
|
34
|
-
Umappp.run(pixels, num_threads: 8, a: 1.8956, b: 0.8006)
|
34
|
+
# Run with parameters
|
35
|
+
r = Umappp.run(pixels, num_threads: 8, a: 1.8956, b: 0.8006)
|
35
36
|
```
|
36
37
|
|
37
38
|
Available parameters and their default values
|
data/ext/umappp/umappp.cpp
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
// Uniform Manifold Approximation and Projection for Ruby
|
2
2
|
// https://github.com/kojix2/ruby-umappp
|
3
3
|
|
4
|
-
|
5
4
|
#include <rice/rice.hpp>
|
6
5
|
#include <rice/stl.hpp>
|
7
6
|
#include "numo.hpp"
|
@@ -52,7 +51,7 @@ Object umappp_run(
|
|
52
51
|
{
|
53
52
|
// Parameters are taken from a Ruby Hash object.
|
54
53
|
// If there is key, set the value.
|
55
|
-
|
54
|
+
|
56
55
|
auto umap_ptr = new Umap;
|
57
56
|
|
58
57
|
double local_connectivity = Umap::Defaults::local_connectivity;
|
@@ -159,7 +158,7 @@ Object umappp_run(
|
|
159
158
|
num_threads = params.get<int>(Symbol("num_threads"));
|
160
159
|
umap_ptr->set_num_threads(num_threads);
|
161
160
|
}
|
162
|
-
|
161
|
+
|
163
162
|
// initialize_from_matrix
|
164
163
|
|
165
164
|
const float *y = data.read_ptr();
|
@@ -181,12 +180,16 @@ Object umappp_run(
|
|
181
180
|
std::vector<Float> embedding(ndim * nobs);
|
182
181
|
|
183
182
|
auto status = umap_ptr->initialize(knncolle_ptr.get(), ndim, embedding.data());
|
184
|
-
|
183
|
+
if (nobs < 0 || ndim < 0)
|
184
|
+
{
|
185
|
+
throw std::runtime_error("nobs or ndim is negative");
|
186
|
+
}
|
185
187
|
if (tick == 0)
|
186
188
|
{
|
187
189
|
status.run(ndim, embedding.data(), 0);
|
188
190
|
|
189
|
-
|
191
|
+
// it is safe to cast to unsigned int
|
192
|
+
auto na = numo::SFloat({(unsigned int)nobs, (unsigned int)ndim});
|
190
193
|
std::copy(embedding.begin(), embedding.end(), na.write_ptr());
|
191
194
|
|
192
195
|
return na;
|
@@ -201,7 +204,8 @@ Object umappp_run(
|
|
201
204
|
|
202
205
|
status.run(ndim, embedding.data(), epoch_limit);
|
203
206
|
|
204
|
-
|
207
|
+
//it is safe to cast to unsigned int
|
208
|
+
auto na = numo::SFloat({(unsigned int)nobs, (unsigned int)ndim});
|
205
209
|
std::copy(embedding.begin(), embedding.end(), na.write_ptr());
|
206
210
|
|
207
211
|
rb_ary_push(ret, na.value());
|
data/lib/umappp/version.rb
CHANGED
data/lib/umappp.rb
CHANGED
@@ -37,6 +37,7 @@ module Umappp
|
|
37
37
|
# @param seed [Integer]
|
38
38
|
# @param batch [Boolean]
|
39
39
|
# @param num_threads [Integer]
|
40
|
+
# @return [Numo::SFloat] the final embedding
|
40
41
|
|
41
42
|
def self.run(embedding, method: :annoy, ndim: 2, tick: 0, **params)
|
42
43
|
unless (u = (params.keys - default_parameters.keys)).empty?
|
data/vendor/umappp/Umap.hpp
CHANGED
@@ -38,7 +38,7 @@ enum InitMethod { SPECTRAL, SPECTRAL_ONLY, RANDOM, NONE };
|
|
38
38
|
/**
|
39
39
|
* @cond
|
40
40
|
*/
|
41
|
-
int choose_num_epochs(int num_epochs, size_t size) {
|
41
|
+
inline int choose_num_epochs(int num_epochs, size_t size) {
|
42
42
|
if (num_epochs < 0) {
|
43
43
|
// Choosing the number of epochs. We use a simple formula to decrease
|
44
44
|
// the number of epochs with increasing size, with the aim being that
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umappp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|