Exemple #1
0
 def test_identity_dimension_when_existing_dim_split_with_wildcard(self):
     arr = ArrayWithUnits(np.zeros((12, )), [ContrivedDimension(10)])
     rs = arr.reshape((2, -1, 3))
     self.assertIsInstance(rs, ArrayWithUnits)
     self.assertIsInstance(rs.dimensions[0], IdentityDimension)
     self.assertIsInstance(rs.dimensions[1], IdentityDimension)
     self.assertIsInstance(rs.dimensions[2], IdentityDimension)
Exemple #2
0
 def test_can_add_dimension_of_size_one_to_1d_array(self):
     arr = ArrayWithUnits(np.zeros((3, )), [ContrivedDimension(10)])
     rs = arr.reshape((1, 1, arr.size))
     self.assertIsInstance(rs, ArrayWithUnits)
     self.assertIsInstance(rs.dimensions[0], IdentityDimension)
     self.assertIsInstance(rs.dimensions[1], IdentityDimension)
     self.assertIsInstance(rs.dimensions[2], ContrivedDimension)
Exemple #3
0
 def test_can_maintain_array_with_units_when_reshaping_2d(self):
     arr = ArrayWithUnits(np.zeros((1, 10)),
                          [ContrivedDimension(10),
                           ContrivedDimension2(10)])
     squeezed = arr.reshape((10, ))
     self.assertEqual((10, ), squeezed.shape)
     self.assertIsInstance(squeezed, ArrayWithUnits)
     self.assertIsInstance(squeezed.dimensions[0], ContrivedDimension2)
Exemple #4
0
 def test_can_reshape_and_downgrade_to_identity_dimension(self):
     arr = ArrayWithUnits(np.zeros((100, 10)),
                          [ContrivedDimension(10),
                           ContrivedDimension2(10)])
     flattened = arr.reshape((-1, ))
     self.assertEqual((1000, ), flattened.shape)
     self.assertIsInstance(flattened, ArrayWithUnits)
     self.assertIsInstance(flattened.dimensions[0], IdentityDimension)