lindong28 commented on a change in pull request #37: URL: https://github.com/apache/flink-ml/pull/37#discussion_r767432991
########## File path: flink-ml-core/src/main/java/org/apache/flink/ml/linalg/typeinfo/SparseVectorSerializer.java ########## @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.flink.ml.linalg.typeinfo; + +import org.apache.flink.api.common.typeutils.SimpleTypeSerializerSnapshot; +import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot; +import org.apache.flink.api.common.typeutils.base.TypeSerializerSingleton; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.ml.linalg.SparseVector; + +import java.io.IOException; +import java.util.Arrays; + +/** Specialized serializer for {@link SparseVector}. */ +public final class SparseVectorSerializer extends TypeSerializerSingleton<SparseVector> { + + private static final long serialVersionUID = 1L; + + private static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; + + private static final int[] EMPTY_INT_ARRAY = new int[0]; + + private static final SparseVectorSerializer INSTANCE = new SparseVectorSerializer(); Review comment: Could you change this variable to public and let `SparseVectorTypeInfo::createSerializer(...)`? This would be consistent with the existing `ValueTypeInfo::createSerializer` in Flink. Could you update `DenseVectorTypeInfo::createSerializer(...)` as well? ########## File path: flink-ml-core/src/main/java/org/apache/flink/ml/linalg/typeinfo/SparseVectorTypeInfo.java ########## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.flink.ml.linalg.typeinfo; + +import org.apache.flink.api.common.ExecutionConfig; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.ml.linalg.SparseVector; + +/** A {@link TypeInformation} for the {@link SparseVector} type. */ +public class SparseVectorTypeInfo extends TypeInformation<SparseVector> { + @Override Review comment: Could you add `public static final SparseVectorTypeInfo INSTANCE = new SparseVectorTypeInfo()` for consistency with other TypeInformation subclasses? ########## File path: flink-ml-core/src/test/java/org/apache/flink/ml/api/StageTest.java ########## @@ -388,5 +388,13 @@ public void testValidators() { ParamValidator<Integer> notNull = ParamValidators.notNull(); Assert.assertTrue(notNull.validate(5)); Assert.assertFalse(notNull.validate(null)); + + ParamValidator<Object[]> nonEmptyArray = ParamValidators.nonEmptyArray(); + Assert.assertTrue(nonEmptyArray.validate(new String[] {"1"})); + Assert.assertFalse(nonEmptyArray.validate(null)); + Assert.assertFalse(nonEmptyArray.validate(new String[0])); + + ParamValidator<Integer> nonEmptyArrayInteger = ParamValidators.nonEmptyArray(); Review comment: hmm.. should its type be `ParamValidator<Integer[]>`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
