Преглед на файлове

Add NumPy Fortran order support (#182)

Lutz Roeder преди 3 седмици
родител
ревизия
f3a5b4bbf1
променени са 2 файла, в които са добавени 20 реда и са изтрити 11 реда
  1. 13 11
      source/python.js
  2. 7 0
      test/models.json

+ 13 - 11
source/python.js

@@ -2852,12 +2852,9 @@ python.Execution = class {
                     const [size] = unpickler.read(1);
                     unpickler.read(size);
                 }
-                if (this.order === 'F') {
-                    throw new python.Error('Fortran order not implemented.');
-                }
                 const size = this.dtype.itemsize * this.shape.reduce((a, b) => a * b, 1);
                 this.data = unpickler.read(size);
-                return execution.invoke(this.subclass, [this.shape, this.dtype, this.data]);
+                return new this.subclass(this.shape, this.dtype, this.data, undefined, undefined, this.order);
             }
         });
         this.registerType('joblib.numpy_pickle.NDArrayWrapper', class {
@@ -3232,9 +3229,16 @@ python.Execution = class {
                     const shape = this.shape;
                     const strides = new Array(shape.length);
                     let stride = this.itemsize;
-                    for (let i = shape.length - 1; i >= 0; i--) {
-                        strides[i] = stride;
-                        stride *= shape[i];
+                    if (this.order === 'F' || this.flags.fn) {
+                        for (let i = 0; i < shape.length; i++) {
+                            strides[i] = stride;
+                            stride *= shape[i];
+                        }
+                    } else {
+                        for (let i = shape.length - 1; i >= 0; i--) {
+                            strides[i] = stride;
+                            stride *= shape[i];
+                        }
                     }
                     return strides;
                 }
@@ -5146,10 +5150,8 @@ python.Execution = class {
                     throw new python.Error(`Unsupported data type '${dtype.str}'.`);
                 }
             }
-            if (fortran_order) {
-                data = null;
-            }
-            return self.invoke('numpy.ndarray', [shape, dtype, data]);
+            const order = fortran_order ? 'F' : 'C';
+            return new numpy.ndarray(shape, dtype, data, undefined, undefined, order);
         });
         this.registerFunction('numpy.save', (file, arr) => {
             const descr = arr.dtype.str;

+ 7 - 0
test/models.json

@@ -7696,6 +7696,13 @@
     "format":   "scikit-learn v0.19.1",
     "link":     "https://github.com/imeraj/Phoenix_Playground/tree/master/1.4/phoenix_ml/lib/phoenix_ml/model"
   },
+  {
+    "type":     "sklearn",
+    "target":   "pca_model.pkl",
+    "source":   "https://github.com/user-attachments/files/25328579/pca_model.pkl.zip[pca_model.pkl]",
+    "format":   "scikit-learn v1.8.0",
+    "link":     "https://github.com/lutzroeder/netron/issues/182"
+  },
   {
     "type":     "sklearn",
     "target":   "pima.xgboost.joblib.pkl",