def test_tensor_vector_mtable_input_output(self): input_schema_str = "col0 TENSOR, col1 DENSE_VECTOR, col2 MTABLE" t = Tensor.fromNdarray(np.array([[1, 2], [3, 4]], dtype=np.int32)) v = DenseVector.ones(10) m = MTable.fromDataframe( pd.DataFrame([[1.0, "A", 0, 0, 0], [2.0, "B", 1, 1, 0], [3.0, "C", 2, 2, 1], [4.0, "D", 3, 3, 1]]), 'f0 double, f1 string, f2 int, f3 int, label int') values = [t, v, m] # input j_csv_util_cls = get_java_class( "com.alibaba.alink.common.utils.TableUtil") j_input_col_types: List[JavaObject] = j_csv_util_cls.getColTypes( input_schema_str) j_row = LocalPredictor._create_input_j_row(values, j_input_col_types) j_row_type_adapter = get_java_class( "com.alibaba.alink.python.utils.RowTypeAdapter") j_row_type_adapter.checkRowType(j_row, j_input_col_types) # output arr = LocalPredictor._j_row_to_arr(j_row) self.assertEqual(3, len(arr)) self.assertTrue(isinstance(arr[0], (Tensor, ))) self.assertTrue(isinstance(arr[0], (IntTensor, ))) self.assertTrue(isinstance(arr[1], (DenseVector, ))) self.assertTrue(isinstance(arr[1], (Vector, ))) self.assertTrue(isinstance(arr[2], (MTable, )))
def test_create_input_j_row(self): j_csv_util_cls = get_java_class( "com.alibaba.alink.common.utils.TableUtil") input_schema_str = "col0 boolean, col1 byte, col2 short, col3 int, col4 long, col5 float, col6 double, col7 varchar" values = [True, 1, 1, 1, 1, 2., 4., "123"] j_input_col_types: List[JavaObject] = j_csv_util_cls.getColTypes( input_schema_str) j_row = LocalPredictor._create_input_j_row(values, j_input_col_types) j_row_type_adapter = get_java_class( "com.alibaba.alink.python.utils.RowTypeAdapter") j_row_type_adapter.checkRowType(j_row, j_input_col_types)
def test_existence_of_java_class_method(self): AlinkGlobalConfiguration.setPrintProcessInfo(True) j_check_wrapper_util_cls = get_java_class( "com.alibaba.alink.python.utils.CheckWrapperUtil") py_classes = get_all_subclasses( JavaObjectWrapperWithAutoTypeConversion) inconsistency = [] for py_class in py_classes: j_cls_name = py_class._j_cls_name py_func_set = set( filter( lambda d: not d.startswith("_") and d != "get_j_obj" and d != "j_cls_name", dir(py_class))) if hasattr(py_class, '_unsupported_j_methods'): py_func_set = py_func_set.union( set(py_class._unsupported_j_methods)) j_func_set = set( j_check_wrapper_util_cls.getJMethodNames(j_cls_name)) if py_func_set != j_func_set: inconsistency.append((j_cls_name, py_func_set - j_func_set, j_func_set - py_func_set)) self.assertTrue( len(inconsistency) == 0, "Inconsistency: {}".format(inconsistency))
def test_tensor_methods_coverage(self): py_class = Tensor j_cls_name = py_class._j_cls_name py_func_set = set(filter( lambda d: not d.startswith("_") and d != "get_j_obj" and d != "j_cls_name", dir(py_class))) py_func_set -= {'toNdarray', 'fromNdarray'} if hasattr(py_class, '_unsupported_j_methods'): py_func_set = py_func_set.union(set(py_class._unsupported_j_methods)) j_check_wrapper_util_cls = get_java_class("com.alibaba.alink.python.utils.CheckWrapperUtil") j_func_set = set(j_check_wrapper_util_cls.getJMethodNames(j_cls_name)) self.assertSetEqual(py_func_set, j_func_set)