@@ -1285,8 +1285,33 @@ def transform(self, values):
1285
1285
1286
1286
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1287
1287
returns a numpy array of shape (N x :attr:`output_dims`).
1288
- """
1289
- return self .transform_affine (self .transform_non_affine (values ))
1288
+
1289
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1290
+ and returns a numpy array of length :attr:`output_dims`.
1291
+ """
1292
+ # Ensure that values is a 2d array (but remember whether
1293
+ # we started with a 1d or 2d array).
1294
+ values = np .asanyarray (values )
1295
+ ndim = values .ndim
1296
+ values = values .reshape ((- 1 , self .input_dims ))
1297
+
1298
+ # Transform the values
1299
+ res = self .transform_affine (self .transform_non_affine (values ))
1300
+
1301
+ # Convert the result back to the shape of the input values.
1302
+ if ndim == 0 :
1303
+ assert not np .ma .is_masked (res ) # just to be on the safe side
1304
+ return res [0 , 0 ]
1305
+ if ndim == 1 :
1306
+ return res .reshape (- 1 )
1307
+ elif ndim == 2 :
1308
+ return res
1309
+ else :
1310
+ raise ValueError (
1311
+ "Input values must have shape (N x {dims}) "
1312
+ "or ({dims})." .format (dims = self .input_dims ))
1313
+
1314
+ return res
1290
1315
1291
1316
def transform_affine (self , values ):
1292
1317
"""
@@ -1302,6 +1327,9 @@ def transform_affine(self, values):
1302
1327
1303
1328
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1304
1329
returns a numpy array of shape (N x :attr:`output_dims`).
1330
+
1331
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1332
+ and returns a numpy array of length :attr:`output_dims`.
1305
1333
"""
1306
1334
return self .get_affine ().transform (values )
1307
1335
@@ -1318,6 +1346,9 @@ def transform_non_affine(self, values):
1318
1346
1319
1347
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1320
1348
returns a numpy array of shape (N x :attr:`output_dims`).
1349
+
1350
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1351
+ and returns a numpy array of length :attr:`output_dims`.
1321
1352
"""
1322
1353
return values
1323
1354
@@ -1944,7 +1975,7 @@ def get_matrix(self):
1944
1975
get_matrix .__doc__ = Affine2DBase .get_matrix .__doc__
1945
1976
1946
1977
def transform (self , points ):
1947
- return points
1978
+ return np . asanyarray ( points )
1948
1979
transform .__doc__ = Affine2DBase .transform .__doc__
1949
1980
1950
1981
transform_affine = transform
0 commit comments