#NEWLINE# def test_inplace_swap_row( ) : #NEWLINE# #INDENT# X = np . array ( [ [ 0 , 3 , 0 ] , [ 2 , 4 , 0 ] , [ 0 , 0 , 0 ] , [ 9 , 8 , 7 ] , [ 4 , 0 , 5 ] ] , dtype = np . float64 ) #NEWLINE# X_csr = sp . csr_matrix ( X ) #NEWLINE# X_csc = sp . csc_matrix ( X ) #NEWLINE# swap = linalg . get_blas_funcs ( ( 'swap' , ) , ( X , ) ) #NEWLINE# swap = swap [ 0 ] #NEWLINE# ( X [ 0 ] , X [ ( - 1 ) ] ) = swap ( X [ 0 ] , X [ ( - 1 ) ] ) #NEWLINE# inplace_swap_row ( X_csr , 0 , ( - 1 ) ) #NEWLINE# inplace_swap_row ( X_csc , 0 , ( - 1 ) ) #NEWLINE# assert_array_equal ( X_csr . toarray ( ) , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csr . toarray ( ) ) #NEWLINE# ( X [ 2 ] , X [ 3 ] ) = swap ( X [ 2 ] , X [ 3 ] ) #NEWLINE# inplace_swap_row ( X_csr , 2 , 3 ) #NEWLINE# inplace_swap_row ( X_csc , 2 , 3 ) #NEWLINE# assert_array_equal ( X_csr . toarray ( ) , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csr . toarray ( ) ) #NEWLINE# assert_raises ( TypeError , inplace_swap_row , X_csr . tolil ( ) ) #NEWLINE# X = np . array ( [ [ 0 , 3 , 0 ] , [ 2 , 4 , 0 ] , [ 0 , 0 , 0 ] , [ 9 , 8 , 7 ] , [ 4 , 0 , 5 ] ] , dtype = np . float32 ) #NEWLINE# X_csr = sp . csr_matrix ( X ) #NEWLINE# X_csc = sp . csc_matrix ( X ) #NEWLINE# swap = linalg . get_blas_funcs ( ( 'swap' , ) , ( X , ) ) #NEWLINE# swap = swap [ 0 ] #NEWLINE# ( X [ 0 ] , X [ ( - 1 ) ] ) = swap ( X [ 0 ] , X [ ( - 1 ) ] ) #NEWLINE# inplace_swap_row ( X_csr , 0 , ( - 1 ) ) #NEWLINE# inplace_swap_row ( X_csc , 0 , ( - 1 ) ) #NEWLINE# assert_array_equal ( X_csr . toarray ( ) , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csr . toarray ( ) ) #NEWLINE# ( X [ 2 ] , X [ 3 ] ) = swap ( X [ 2 ] , X [ 3 ] ) #NEWLINE# inplace_swap_row ( X_csr , 2 , 3 ) #NEWLINE# inplace_swap_row ( X_csc , 2 , 3 ) #NEWLINE# assert_array_equal ( X_csr . toarray ( ) , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csc . toarray ( ) ) #NEWLINE# assert_array_equal ( X , X_csr . toarray ( ) ) #NEWLINE# assert_raises ( TypeError , inplace_swap_row , X_csr . tolil ( ) )