named_vector 1.0.0 → 1.0.1
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 +8 -8
- data/lib/named_vector.rb +12 -0
- data/specs/initialization.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ZTcxMWZkZWY1MDA4MzhlZDgzNzIwNGRlMWRhNzQ3NDIxZTMzZWYxNA==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MjYxYjUzOWNjOWM0MWY1NWRkYzQzODVlNTFlZjUxYjRkOTJlN2E5Ng==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
ZjdmZTgwYzkyYzVhNjA1ZjdmYzJkNTMzNmU3N2ZhZWJjYjE5NzYxMjA1ZmY0
|
|
10
|
+
MWM5YThiMzkyZWFjY2MyOTJiMTRiMThkZWQ3MzQxMTAwZGJmMWQxMDg5ODVj
|
|
11
|
+
YjJjNDYwOGI0ZGM2MzFjMTU2ODk1ZDU4YzM0OGY1NmUwMjk4ZTA=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ZGE3ZGZmMDU3MzYxNGE1MWZjYTA5OGE3YzE4ZDdjODA2NDQzMDE2NGMzYjNi
|
|
14
|
+
YTY4M2IyYTkwZTdlM2YwNDUwNzUxODAyN2E3NzJlZGJkZjRiNzgxNGYwMTlk
|
|
15
|
+
MWRiZjYxMTA5MzIzNDdmOGVmOTViN2E5YmYzZjJlYTllY2M2ODk=
|
data/lib/named_vector.rb
CHANGED
|
@@ -12,8 +12,20 @@ class NamedVector
|
|
|
12
12
|
def initialize(*dims)
|
|
13
13
|
@vector = Hash.new
|
|
14
14
|
@keys = Set.new
|
|
15
|
+
import_dimensions(dims)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# imports the dimension information in Array form
|
|
19
|
+
# @param dims [Array<Array>,Array<String>, Array<Symbol>, Array<Hash>, Array<Fixnum>, Array<Array>] values to initialize
|
|
20
|
+
def import_dimensions(dims)
|
|
15
21
|
if dims && dims.first
|
|
16
22
|
case dims.first
|
|
23
|
+
when Array
|
|
24
|
+
array = dims.first
|
|
25
|
+
if array.first.class == String
|
|
26
|
+
@keys = Set.new(array.map {|i| i.to_s})
|
|
27
|
+
array.each {|d| self[d]+=1}
|
|
28
|
+
end
|
|
17
29
|
when Hash
|
|
18
30
|
hash = dims.first
|
|
19
31
|
hash.keys.each {|d| modify_dimension(d, hash[d])}
|
data/specs/initialization.rb
CHANGED
|
@@ -53,4 +53,10 @@ describe 'Initialization' do
|
|
|
53
53
|
vector.normalize
|
|
54
54
|
vector.norm.should be_within(0.01).of 1.0
|
|
55
55
|
end
|
|
56
|
+
|
|
57
|
+
it 'should allow sums of vectors to be used for initilization' do
|
|
58
|
+
vector = NamedVector.new(["a","a","a", "b", "b"])
|
|
59
|
+
vector.a.should eq 3
|
|
60
|
+
vector.b.should eq 2
|
|
61
|
+
end
|
|
56
62
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: named_vector
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Raiman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-11-
|
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Vectors with named dimensions.
|
|
14
14
|
email: jraiman@mit.edu
|