zaleslaw 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_r270822331
########## 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: What is A.ensure? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services