walterddr commented on a change in pull request #8631: [FLINK-12745][ml] add 
sparse and dense vector class, and dense matrix class with basic operations.
URL: https://github.com/apache/flink/pull/8631#discussion_r311194716
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-lib/src/test/java/org/apache/flink/ml/common/matrix/SparseVectorTest.java
 ##########
 @@ -0,0 +1,168 @@
+/*
+ * 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.common.matrix;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test cases for SparseVector.
+ */
+public class SparseVectorTest {
+       private static final double TOL = 1.0e-6;
+       private SparseVector v1 = null;
+       private SparseVector v2 = null;
+
+       @Before
+       public void setUp() throws Exception {
+               {
+                       int n = 8;
+                       int[] indices = new int[]{1, 3, 5, 7};
+                       double[] values = new double[]{2.0, 2.0, 2.0, 2.0};
+                       v1 = new SparseVector(n, indices, values);
+               }
+
+               {
+                       int n = 8;
+                       int[] indices = new int[]{3, 4, 5};
+                       double[] values = new double[]{1.0, 1.0, 1.0};
+                       v2 = new SparseVector(n, indices, values);
+               }
+       }
+
+       @Test
+       public void testSize() throws Exception {
+               Assert.assertEquals(v1.size(), 8);
+       }
+
+       @Test
+       public void testPrefix() throws Exception {
+               SparseVector prefixed = v1.prefix(0.2);
+               Assert.assertArrayEquals(prefixed.getIndices(), new int[]{0, 2, 
4, 6, 8});
+               Assert.assertArrayEquals(prefixed.getValues(), new 
double[]{0.2, 2, 2, 2, 2}, 0);
+       }
+
+       @Test
+       public void testAppend() throws Exception {
+               SparseVector prefixed = v1.append(0.2);
+               Assert.assertArrayEquals(prefixed.getIndices(), new int[]{1, 3, 
5, 7, 8});
+               Assert.assertArrayEquals(prefixed.getValues(), new double[]{2, 
2, 2, 2, 0.2}, 0);
+       }
+
+       @Test
+       public void testSortIndices() throws Exception {
+               int n = 8;
+               int[] indices = new int[]{7, 5, 3, 1};
+               double[] values = new double[]{7, 5, 3, 1};
+               v1 = new SparseVector(n, indices, values);
 
 Review comment:
   this seems to be a naming typo? shouldn't we use a local variable instead of 
the static one?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to