multiarray 0.15.0 → 0.15.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.
- data/Rakefile +1 -1
- data/lib/multiarray/operations.rb +34 -0
- data/test/tc_multiarray.rb +12 -0
- data/test/tc_sequence.rb +8 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -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.
|
data/test/tc_multiarray.rb
CHANGED
@@ -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
|