You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/04/01 11:41:26 UTC

[GitHub] [ignite] avplatonov commented on a change in pull request #6378: IGNITE-11647: ML Vectors should work with all Serializable objects besides double

avplatonov commented on a change in pull request #6378: IGNITE-11647: ML Vectors should work with all Serializable objects besides double
URL: https://github.com/apache/ignite/pull/6378#discussion_r270826975
 
 

 ##########
 File path: modules/ml/src/main/java/org/apache/ignite/ml/math/primitives/vector/storage/DenseVectorStorage.java
 ##########
 @@ -56,19 +61,85 @@ public DenseVectorStorage(double[] data) {
         this.data = data;
     }
 
+    /**
+     * @param data Backing data array.
+     */
+    public DenseVectorStorage(Serializable[] data) {
+        assert data != null;
+
+        this.rawData = data;
+    }
+
     /** {@inheritDoc} */
     @Override public int size() {
-        return data == null ? 0 : data.length;
+        if (data == null && rawData == null)
+            return 0;
+        else
+            return data != null ? data.length : rawData.length;
+    }
+
+    /**
+     * Tries to cast internal representation of data to array of doubles if need.
+     */
+    private void toNumericArray() {
+        A.ensure(data == null || rawData == null, "data == null || rawData == null");
+        if (data == null && rawData == null)
+            return;
+
+        if (data == null) {
+            data = new double[rawData.length];
+            for (int i = 0; i < rawData.length; i++)
+                data[i] = rawData[i] == null ? 0.0 : ((Number)rawData[i]).doubleValue();
+            rawData = null;
+        }
+    }
+
+    /**
+     * Tries to cast internal representation of data to array of Serializable objects if need.
+     */
+    private void toGenericArray() {
+        A.ensure(data == null || rawData == null, "data == null || rawData == null");
 
 Review comment:
   This is a standard way for assertions in Ignite.Core

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services