guruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/guruby/expr.rb +19 -1
  3. data/lib/guruby/var.rb +2 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90abe0f8288b62ebbd12eabbac3fbfbc5a24eb50
4
- data.tar.gz: 39f00000b36f43bdc997ecb6a685d3f7c1878523
3
+ metadata.gz: ce1569b34b64f28b94bf6fee645dee1558048082
4
+ data.tar.gz: b60a693f6504a11594ea9c81309bc89893104f40
5
5
  SHA512:
6
- metadata.gz: 25c749b6eafece828bf27940b7678477230b1f237316e5a331e253b053723db1c8462ce67ecbeafd06842ac4ed96e098e3bfd6dfedde1cf23fa74abf8c6059ac
7
- data.tar.gz: e09329ac7900cfbb8dca7447b486e01ff6840d18863971bdaa54f0a05f8a296820ce9847388ca9d995a89a2199203db6b16fff167d1dc42c7bc6cfddd57369c9
6
+ metadata.gz: a9603e3ecf122e06f510bccb6adbcac0481eb056d668bc3e3b8d57c5fdea2dd96c1a1cf7c04244607edfa8c6244c24d3f9e52f115696d272d5d08a96c45e2b7b
7
+ data.tar.gz: 9b8650d311a06606f717bb33be0b569123f143c52603641e35f1b454966dc3bccd4fec1d74b1656a5f13eda037a6572da28849190ceb1c4722d937f7fce86c80
data/lib/guruby/expr.rb CHANGED
@@ -17,10 +17,28 @@ module Guruby
17
17
  # Add the variable to the expression
18
18
  self + other * 1.0
19
19
  else
20
- fail TypeError unless other.is_a? LinExpr
20
+ fail TypeError
21
21
  end
22
22
  end
23
23
 
24
+ # Add terms from the other expression to this one
25
+ def add(other)
26
+ case other
27
+ when LinExpr
28
+ @terms.merge!(other.terms) { |_, c1, c2| c1 + c2 }
29
+ when Variable
30
+ if @terms.key? other
31
+ @terms[other] += 1.0
32
+ else
33
+ @terms[other] = 1.0
34
+ end
35
+ else
36
+ fail TypeError
37
+ end
38
+
39
+ self
40
+ end
41
+
24
42
  # Produce a string representing the expression
25
43
  def inspect
26
44
  @terms.map do |var, coeff|
data/lib/guruby/var.rb CHANGED
@@ -57,9 +57,9 @@ module Guruby
57
57
  def +(other)
58
58
  case other
59
59
  when LinExpr
60
- other + self * 1
60
+ other + self * 1.0
61
61
  when Variable
62
- self * 1 + other * 1
62
+ LinExpr.new({self => 1.0, other => 1.0})
63
63
  else
64
64
  fail TypeError
65
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Mior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi