-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConvergenceWarning.ts
126 lines (97 loc) · 3.2 KB
/
ConvergenceWarning.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* eslint-disable */
/* NOTE: This file is auto-generated. Do not edit it directly. */
import crypto from 'node:crypto'
import { PythonBridge, NDArray, ArrayLike, SparseMatrix } from '@/sklearn/types'
/**
Custom warning to capture convergence problems
[Python Reference](https://scikit-learn.org/stable/modules/generated/sklearn.exceptions.ConvergenceWarning.html)
*/
export class ConvergenceWarning {
id: string
opts: any
_py: PythonBridge
_isInitialized: boolean = false
_isDisposed: boolean = false
constructor(opts?: { args?: any }) {
this.id = `ConvergenceWarning${crypto.randomUUID().split('-')[0]}`
this.opts = opts || {}
}
get py(): PythonBridge {
return this._py
}
set py(pythonBridge: PythonBridge) {
this._py = pythonBridge
}
/**
Initializes the underlying Python resources.
This instance is not usable until the `Promise` returned by `init()` resolves.
*/
async init(py: PythonBridge): Promise<void> {
if (this._isDisposed) {
throw new Error(
'This ConvergenceWarning instance has already been disposed'
)
}
if (this._isInitialized) {
return
}
if (!py) {
throw new Error(
'ConvergenceWarning.init requires a PythonBridge instance'
)
}
this._py = py
await this._py.ex`
import numpy as np
from sklearn.exceptions import ConvergenceWarning
try: bridgeConvergenceWarning
except NameError: bridgeConvergenceWarning = {}
`
// set up constructor params
await this._py.ex`ctor_ConvergenceWarning = {'args': ${
this.opts['args'] ?? undefined
}}
ctor_ConvergenceWarning = {k: v for k, v in ctor_ConvergenceWarning.items() if v is not None}`
await this._py
.ex`bridgeConvergenceWarning[${this.id}] = ConvergenceWarning(**ctor_ConvergenceWarning)`
this._isInitialized = true
}
/**
Disposes of the underlying Python resources.
Once `dispose()` is called, the instance is no longer usable.
*/
async dispose() {
if (this._isDisposed) {
return
}
if (!this._isInitialized) {
return
}
await this._py.ex`del bridgeConvergenceWarning[${this.id}]`
this._isDisposed = true
}
/**
Exception.with\_traceback(tb) – set self.\_\_traceback\_\_ to tb and return self.
*/
async with_traceback(opts: {}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This ConvergenceWarning instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'ConvergenceWarning must call init() before with_traceback()'
)
}
// set up method params
await this._py.ex`pms_ConvergenceWarning_with_traceback = {}
pms_ConvergenceWarning_with_traceback = {k: v for k, v in pms_ConvergenceWarning_with_traceback.items() if v is not None}`
// invoke method
await this._py
.ex`res_ConvergenceWarning_with_traceback = bridgeConvergenceWarning[${this.id}].with_traceback(**pms_ConvergenceWarning_with_traceback)`
// convert the result from python to node.js
return this
._py`res_ConvergenceWarning_with_traceback.tolist() if hasattr(res_ConvergenceWarning_with_traceback, 'tolist') else res_ConvergenceWarning_with_traceback`
}
}