multiarray 0.15.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/packagetask'
6
6
  require 'rbconfig'
7
7
 
8
8
  PKG_NAME = 'multiarray'
9
- PKG_VERSION = '0.15.0'
9
+ PKG_VERSION = '0.15.1'
10
10
  RB_FILES = FileList[ 'lib/**/*.rb' ]
11
11
  TC_FILES = FileList[ 'test/tc_*.rb' ]
12
12
  TS_FILES = FileList[ 'test/ts_*.rb' ]
@@ -152,6 +152,40 @@ module Hornetseye
152
152
 
153
153
  alias_method_chain :to_type, :rgb
154
154
 
155
+ # Skip type conversion if it has no effect
156
+ #
157
+ # This operation is a special case handling type conversions to the same type.
158
+ #
159
+ # @param [Class] dest Element type to convert to.
160
+ #
161
+ # @return [Node] Array based on the different element type.
162
+ def to_type_with_identity( dest )
163
+ if dest == typecode
164
+ self
165
+ else
166
+ to_type_without_identity dest
167
+ end
168
+ end
169
+
170
+ alias_method_chain :to_type, :identity
171
+
172
+ # Get array with same elements but different shape
173
+ #
174
+ # The method returns an array with the same elements but with a different shape.
175
+ # The desired shape must have the same number of elements.
176
+ #
177
+ # @param [Array<Integer>] ret_shape Desired shape of return value
178
+ #
179
+ # @return [Node] Array with desired shape.
180
+ def reshape( *ret_shape )
181
+ target = Hornetseye::MultiArray( typecode, *ret_shape )
182
+ if target.size != size
183
+ raise "#{target.size} is of size #{target.size} but should be of size " +
184
+ "#{size}"
185
+ end
186
+ target.new memorise.memory
187
+ end
188
+
155
189
  # Element-wise conditional selection of values
156
190
  #
157
191
  # @param [Node] a First array of values.
@@ -674,6 +674,18 @@ class TC_MultiArray < Test::Unit::TestCase
674
674
  M( I, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].to_intrgb
675
675
  end
676
676
 
677
+ def test_reshape
678
+ [ O, I ].each do |t|
679
+ assert_equal M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
680
+ S( t, 6 )[ 1, 2, 3, 4, 5, 6 ].reshape( 3, 2 )
681
+ assert_equal S( t, 6 )[ 1, 2, 3, 4, 5, 6 ],
682
+ M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].reshape( 6 )
683
+ assert_equal M( t, 2, 3 )[ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ],
684
+ M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].reshape( 2, 3 )
685
+ assert_raise( RuntimeError ) { M( t, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].reshape 3 }
686
+ end
687
+ end
688
+
677
689
  def test_integral
678
690
  assert_equal M( O, 3, 2 )[ [ 1, 3, 6 ], [ 5, 12, 21 ] ],
679
691
  M( O, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].integral
data/test/tc_sequence.rb CHANGED
@@ -867,6 +867,14 @@ class TC_Sequence < Test::Unit::TestCase
867
867
  assert_equal S( C, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_intrgb
868
868
  end
869
869
 
870
+ def test_reshape
871
+ [ O, I ].each do |t|
872
+ assert_equal S( t, 3 )[ 1, 2, 3 ], S( t, 3 )[ 1, 2, 3 ].reshape( 3 )
873
+ assert_raise( RuntimeError ) { S( t, 3 )[ 1, 2, 3 ].reshape 2 }
874
+ assert_raise( RuntimeError ) { S( t, 3 )[ 1, 2, 3 ].reshape 4 }
875
+ end
876
+ end
877
+
870
878
  def test_integral
871
879
  assert_equal S( O, 3 )[ 1, 3, 6 ], S( O, 3 )[ 1, 2, 3 ].integral
872
880
  assert_equal S( I, 3 )[ 1, 3, 6 ], S( I, 3 )[ 1, 2, 3 ].integral
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 15
8
- - 0
9
- version: 0.15.0
8
+ - 1
9
+ version: 0.15.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind