@@ -1277,8 +1277,33 @@ def transform(self, values):
1277
1277
1278
1278
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1279
1279
returns a numpy array of shape (N x :attr:`output_dims`).
1280
- """
1281
- return self .transform_affine (self .transform_non_affine (values ))
1280
+
1281
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1282
+ and returns a numpy array of length :attr:`output_dims`.
1283
+ """
1284
+ # Ensure that values is a 2d array (but remember whether
1285
+ # we started with a 1d or 2d array).
1286
+ values = np .asanyarray (values )
1287
+ ndim = values .ndim
1288
+ values = values .reshape ((- 1 , self .input_dims ))
1289
+
1290
+ # Transform the values
1291
+ res = self .transform_affine (self .transform_non_affine (values ))
1292
+
1293
+ # Convert the result back to the shape of the input values.
1294
+ if ndim == 0 :
1295
+ assert not np .ma .is_masked (res ) # just to be on the safe side
1296
+ return res [0 , 0 ]
1297
+ if ndim == 1 :
1298
+ return res .reshape (- 1 )
1299
+ elif ndim == 2 :
1300
+ return res
1301
+ else :
1302
+ raise ValueError (
1303
+ "Input values must have shape (N x {dims}) "
1304
+ "or ({dims})." .format (dims = self .input_dims ))
1305
+
1306
+ return res
1282
1307
1283
1308
def transform_affine (self , values ):
1284
1309
"""
@@ -1294,6 +1319,9 @@ def transform_affine(self, values):
1294
1319
1295
1320
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1296
1321
returns a numpy array of shape (N x :attr:`output_dims`).
1322
+
1323
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1324
+ and returns a numpy array of length :attr:`output_dims`.
1297
1325
"""
1298
1326
return self .get_affine ().transform (values )
1299
1327
@@ -1310,6 +1338,9 @@ def transform_non_affine(self, values):
1310
1338
1311
1339
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1312
1340
returns a numpy array of shape (N x :attr:`output_dims`).
1341
+
1342
+ Alternatively, accepts a numpy array of length :attr:`input_dims`
1343
+ and returns a numpy array of length :attr:`output_dims`.
1313
1344
"""
1314
1345
return values
1315
1346
@@ -1935,7 +1966,7 @@ def get_matrix(self):
1935
1966
get_matrix .__doc__ = Affine2DBase .get_matrix .__doc__
1936
1967
1937
1968
def transform (self , points ):
1938
- return points
1969
+ return np . asanyarray ( points )
1939
1970
transform .__doc__ = Affine2DBase .transform .__doc__
1940
1971
1941
1972
transform_affine = transform
0 commit comments