1313from .fixes import qr_economic
1414from ._logistic_sigmoid import _log_logistic_sigmoid
1515from ..externals .six .moves import xrange
16- from .validation import array2d , DataConversionWarning
16+ from .validation import array2d , NonBLASDotWarning
1717
1818
1919def norm (v ):
@@ -80,23 +80,35 @@ def _fast_dot(A, B):
8080 Parameters
8181 ----------
8282 A, B: instance of np.ndarray
83- input matrices.
83+ input matrices. Matrices are supposed to be of the same types
84+ and to have exactly 2 dimensions. Currently only floats are supported.
85+ In case these requirements aren't met np.dot(A, B) is returned
86+ instead. To activate the related warning issued in this case
87+ execute the following lines of code:
88+
89+ >> import warnings
90+ >> from sklearn.utils.validation import NonBLASDotWarning
91+ >> warnings.simplefilter('always', NonBLASDotWarning)
8492 """
8593
8694 if B .shape [0 ] != A .shape [A .ndim - 1 ]: # check adopted from '_dotblas.c'
87- raise ValueError ('matrices are not aligned' )
95+ msg = ('Invalid array shapes: A.shape[%d] should be the same as '
96+ 'B.shape[0]. Got A.shape=%r B.shape=%r' % (A .ndim - 1 ,
97+ A .shape , B .shape ))
98+ raise ValueError (msg )
8899
89100 if A .dtype != B .dtype or any (x .dtype not in (np .float32 , np .float64 )
90- for x in [A , B ]):
101+ for x in [A , B ]):
91102 warnings .warn ('Data must be of same type. Supported types '
92103 'are 32 and 64 bit float. '
93- 'Falling back to np.dot.' , DataConversionWarning )
104+ 'Falling back to np.dot.' , NonBLASDotWarning )
94105 return np .dot (A , B )
106+
95107 if ((A .ndim == 1 or B .ndim == 1 ) or
96108 (min (A .shape ) == 1 ) or (min (B .shape ) == 1 ) or
97109 (A .ndim != 2 ) or (B .ndim != 2 )):
98110 warnings .warn ('Data must be 2D with more than one colum / row.'
99- 'Falling back to np.dot' , DataConversionWarning )
111+ 'Falling back to np.dot' , NonBLASDotWarning )
100112 return np .dot (A , B )
101113
102114 dot = linalg .get_blas_funcs ('gemm' , (A , B ))
@@ -110,8 +122,7 @@ def _fast_dot(A, B):
110122 fast_dot = _fast_dot
111123except (ImportError , AttributeError ):
112124 fast_dot = np .dot
113- warnings .warn ('Could not import BLAS, falling back to np.dot' ,
114- DataConversionWarning )
125+ warnings .warn ('Could not import BLAS, falling back to np.dot' )
115126
116127
117128def density (w , ** kwargs ):
0 commit comments