spnet 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,4 +22,18 @@ In Block, contain all InPort objects in @in_ports, and all OutPort objects in @o
22
22
 
23
23
  === 0.1.4 / 2013-02-06
24
24
 
25
- CommandInPort only requires :command_map instead of :list_commands_handler and :exec_command_handler. The command map is just a hash that maps command names to their execution handlers.
25
+ CommandInPort only requires :command_map instead of :list_commands_handler and :exec_command_handler. The command map is just a hash that maps command names to their execution handlers.
26
+
27
+ === 0.1.5 / 2013-02-18
28
+
29
+ Update for use with hashmake-0.1.5 gem.
30
+ Add storage classes: NetworkState, BlockState, LinkState, and PortLocater. These are for persisting a network without relying on non-SPNet objects, which may not be serializable.
31
+ Add limiter classes: RangeLimiter, UpperLimiter, LowerLimiter, EnumLimiter, and NoLimiter. A given limiter object will be used in a ParamInPort to limit an incoming value. The default NoLimiter object does nothing.
32
+ Remove @sample_rate_port from Block class. This means blocks can't change sample rate after initialization.
33
+ Every block is given just one parameter: a Hash containing the :sample_rate key. Block instances expect to recieve this key in #initialize.
34
+
35
+ === 0.1.6 / 2013-02-18
36
+
37
+ Change port_params to params.
38
+ Only export params that have changed from initialization.
39
+ Remove @name from Network class.
@@ -22,6 +22,7 @@ class Block
22
22
  # for details of which keys are required.
23
23
  def initialize args = {}
24
24
  hash_make Block::ARG_SPECS, args
25
+ @initial_params = collect_params
25
26
  end
26
27
 
27
28
  # Execute the block algorithm.
@@ -33,14 +34,30 @@ class Block
33
34
  # Produces a BlockState object based on this Block object.
34
35
  # @return [BlockState]
35
36
  def export_state
36
- port_params = {}
37
+ params = collect_params
38
+
39
+ # discard the params that are the same as the initial port params
40
+ params.keys.each do |key|
41
+ if params[key] == @initial_params[key]
42
+ params.delete key
43
+ end
44
+ end
45
+
46
+ BlockState.new(:class_sym => self.class.to_s.to_sym, :params => params)
47
+ end
48
+
49
+ private
50
+
51
+ def collect_params
52
+ params = {}
53
+
37
54
  @in_ports.each do |name, port|
38
55
  if port.is_a?(ParamInPort)
39
- port_params[name] = port.get_value
56
+ params[name] = port.get_value
40
57
  end
41
58
  end
42
59
 
43
- BlockState.new(:class_sym => self.class.to_s.to_sym, :port_params => port_params)
60
+ return params
44
61
  end
45
62
  end
46
63
  end
@@ -9,12 +9,11 @@ class Network
9
9
  # Define arg specs to use in processing hashed arguments during #initialize.
10
10
  ARG_SPECS = {
11
11
  :sample_rate => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){a > 0.0}),
12
- :name => arg_spec(:reqd => false, :type => String, :default => ""),
13
12
  :blocks => arg_spec_hash(:reqd => false, :type => Block),
14
13
  :links => arg_spec_array(:reqd => false, :type => Link),
15
14
  }
16
15
 
17
- attr_reader :sample_rate, :name, :blocks, :links
16
+ attr_reader :sample_rate, :blocks, :links
18
17
 
19
18
  # A new instance of Network. Changes all block sample rates (if necessary) to
20
19
  # match the given sample rate. Activates links.
@@ -47,7 +46,7 @@ class Network
47
46
  link_states.push link.export_state(@blocks)
48
47
  end
49
48
 
50
- return NetworkState.new(:name => @name, :block_states => block_states, :link_states => link_states)
49
+ return NetworkState.new(:block_states => block_states, :link_states => link_states)
51
50
  end
52
51
 
53
52
  end
@@ -9,10 +9,10 @@ class BlockState
9
9
  # Define arg specs to use in processing hashed arguments during #initialize.
10
10
  ARG_SPECS = {
11
11
  :class_sym => arg_spec(:reqd => true, :type => Symbol),
12
- :port_params => arg_spec_hash(:reqd => false, :type => Object)
12
+ :params => arg_spec_hash(:reqd => false, :type => Object)
13
13
  }
14
14
 
15
- attr_reader :class_sym, :hashed_args, :port_params
15
+ attr_reader :class_sym, :hashed_args, :params
16
16
 
17
17
  # A new instance of NetworkState.
18
18
  # @param [Hash] args Hashed arguments for initialization. See Network::ARG_SPECS
@@ -28,7 +28,7 @@ class BlockState
28
28
  klass = Kernel.const_get(@class_sym)
29
29
  block = klass.new :sample_rate => args[:sample_rate]
30
30
 
31
- @port_params.each do |port_name,value|
31
+ @params.each do |port_name,value|
32
32
  if block.in_ports.has_key?(port_name)
33
33
  port = block.in_ports[port_name]
34
34
  port.set_value value
@@ -8,12 +8,11 @@ class NetworkState
8
8
 
9
9
  # Define arg specs to use in processing hashed arguments during #initialize.
10
10
  ARG_SPECS = {
11
- :name => arg_spec(:reqd => false, :type => String, :default => ""),
12
11
  :block_states => arg_spec_hash(:reqd => false, :type => BlockState),
13
12
  :link_states => arg_spec_array(:reqd => false, :type => LinkState),
14
13
  }
15
14
 
16
- attr_reader :sample_rate, :name, :block_models, :link_models
15
+ attr_reader :sample_rate, :block_models, :link_models
17
16
 
18
17
  # A new instance of NetworkState.
19
18
  # @param [Hash] args Hashed arguments for initialization. See Network::ARG_SPECS
@@ -38,7 +37,7 @@ class NetworkState
38
37
  links.push link_state.make_link blocks
39
38
  end
40
39
 
41
- Network.new :name => @name, :blocks => blocks, :links => links, :sample_rate => sample_rate
40
+ Network.new :blocks => blocks, :links => links, :sample_rate => sample_rate
42
41
  end
43
42
  end
44
43
  end
@@ -1,5 +1,5 @@
1
1
  # Provide infrastructure for forming processing networks.
2
2
  module SPNet
3
3
  # spnet version
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -62,19 +62,31 @@ describe SPNet::Block do
62
62
  end
63
63
 
64
64
  context '#export_state' do
65
- before :all do
66
- block = TestBlock.new :sample_rate => @sample_rate
67
- block.in_ports["VALUE1"].set_value(4.4)
68
- block.in_ports["VALUE2"].set_value(5.5)
69
- @state = block.export_state
65
+ it 'should set class_sym to :Block' do
66
+ TestBlock.new(:sample_rate => @sample_rate).export_state.class_sym.should eq(:TestBlock)
70
67
  end
71
68
 
72
- it 'should set class_sym to :Block' do
73
- @state.class_sym.should eq(:TestBlock)
69
+ it 'should have empty port params since no params were modified' do
70
+ TestBlock.new(:sample_rate => @sample_rate).export_state.params.should be_empty
74
71
  end
75
72
 
76
- it 'should set port_params according to ParamInPort settings' do
77
- @state.port_params.should eq("VALUE1" => 4.4, "VALUE2" => 5.5)
73
+ context 'one param modified' do
74
+ it 'should set params according to ParamInPort settings' do
75
+ block = TestBlock.new :sample_rate => @sample_rate
76
+ block.in_ports["VALUE1"].set_value(4.4)
77
+ state = block.export_state
78
+ state.params.should eq("VALUE1" => 4.4)
79
+ end
80
+ end
81
+
82
+ context 'both params modified' do
83
+ it 'should set params according to ParamInPort settings' do
84
+ block = TestBlock.new :sample_rate => @sample_rate
85
+ block.in_ports["VALUE1"].set_value(4.4)
86
+ block.in_ports["VALUE2"].set_value(5.5)
87
+ state = block.export_state
88
+ state.params.should eq("VALUE1" => 4.4, "VALUE2" => 5.5)
89
+ end
78
90
  end
79
91
  end
80
92
  end
@@ -6,15 +6,11 @@ describe SPNet::Network do
6
6
  @sample_rate = 1.0
7
7
  end
8
8
 
9
- context 'no name, blocks, or links given' do
9
+ context 'no blocks, or links given' do
10
10
  before :all do
11
11
  @network = Network.new :sample_rate => @sample_rate
12
12
  end
13
13
 
14
- it 'should have empty name' do
15
- @network.name.should be_empty
16
- end
17
-
18
14
  it 'should have no blocks' do
19
15
  @network.blocks.should be_empty
20
16
  end
@@ -12,8 +12,8 @@ describe SPNet::BlockState do
12
12
  "VALUE1" => 0.0,
13
13
  "VALUE2" => 1.0,
14
14
  }
15
- block_state = BlockState.new :class_sym => :TestBlock, :port_params => params
16
- block_state.port_params.should eq(params)
15
+ block_state = BlockState.new :class_sym => :TestBlock, :params => params
16
+ block_state.params.should eq(params)
17
17
  end
18
18
  end
19
19
 
@@ -24,7 +24,7 @@ describe SPNet::BlockState do
24
24
  "VALUE2" => 0.9,
25
25
  }
26
26
  @class_sym = :TestBlock
27
- block_state = BlockState.new :class_sym => @class_sym, :port_params => @params
27
+ block_state = BlockState.new :class_sym => @class_sym, :params => @params
28
28
  @block = block_state.make_block :sample_rate => 2
29
29
  end
30
30
 
@@ -5,8 +5,8 @@ describe SPNet::NetworkState do
5
5
  before :all do
6
6
  @network_state = NetworkState.new(
7
7
  :block_states => {
8
- "A" => BlockState.new(:class_sym => :TestBlock, :hashed_args => {}, :port_params => { "VALUE1" => 0.2}),
9
- "B" => BlockState.new(:class_sym => :TestBlock, :hashed_args => {}, :port_params => { "VALUE1" => 0.4})
8
+ "A" => BlockState.new(:class_sym => :TestBlock, :hashed_args => {}, :params => { "VALUE1" => 0.2}),
9
+ "B" => BlockState.new(:class_sym => :TestBlock, :hashed_args => {}, :params => { "VALUE1" => 0.4})
10
10
  },
11
11
  :link_states => [
12
12
  LinkState.new(
@@ -25,7 +25,7 @@ describe SPNet::NetworkState do
25
25
  network.blocks["B"].class.should be(TestBlock)
26
26
  end
27
27
 
28
- it 'should assign values found in :port_params' do
28
+ it 'should assign values found in :params' do
29
29
  network = @network_state.make_network :sample_rate => 4
30
30
  network.blocks["A"].value1.should eq(0.2)
31
31
  network.blocks["B"].value1.should eq(0.4)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -699340785
189
+ hash: 654422513
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -699340785
198
+ hash: 654422513
199
199
  requirements: []
200
200
  rubyforge_project:
201
201
  rubygems_version: 1.8.23