Skip to content

Commit bdc1ddf

Browse files
committed
Resolve linter complaints, remove unused import
1 parent c43c3f1 commit bdc1ddf

5 files changed

Lines changed: 58 additions & 59 deletions

File tree

deriv/deriv.v

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import math
77
fn central_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
88
/*
99
Compute the derivative using the 5-point rule (x-h, x-h/2, x,
10-
* x+h/2, x+h). Note that the central point is not used.
11-
* Compute the error using the difference between the 5-point and
12-
* the 3-point rule (x-h,x,x+h). Again the central point is not
13-
* used.
10+
* x+h/2, x+h). Note that the central point is not used.
11+
* Compute the error using the difference between the 5-point and
12+
* the 3-point rule (x-h,x,x+h). Again the central point is not
13+
* used.
1414
*/
1515
fm1 := f.eval(x - h)
1616
fp1 := f.eval(x + h)
@@ -23,9 +23,9 @@ fn central_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
2323
dy := math.max(math.abs(r3 / h), math.abs(r5 / h)) * (math.abs(x) / h) * prec.f64_epsilon
2424
/*
2525
The truncation error in the r5 approximation itself is O(h^4).
26-
* However, for safety, we estimate the error from r5-r3, which is
27-
* O(h^2). By scaling h we will minimise this estimated error, not
28-
* the actual truncation error in r5.
26+
* However, for safety, we estimate the error from r5-r3, which is
27+
* O(h^2). By scaling h we will minimise this estimated error, not
28+
* the actual truncation error in r5.
2929
*/
3030
result := r5 / h
3131
abserr_trunc := math.abs((r5 - r3) / h) // Estimated truncation error O(h^2)
@@ -40,15 +40,15 @@ pub fn central(f func.Fn, x f64, h f64) (f64, f64) {
4040
if round < trunc && (round > 0.0 && trunc > 0.0) {
4141
/*
4242
Compute an optimised stepsize to minimize the total error,
43-
* using the scaling of the truncation error (O(h^2)) and
44-
* rounding error (O(1/h)).
43+
* using the scaling of the truncation error (O(h^2)) and
44+
* rounding error (O(1/h)).
4545
*/
4646
h_opt := h * math.pow(round / (2.0 * trunc), 1.0 / 3.0)
4747
r_opt, round_opt, trunc_opt := central_deriv(f, x, h_opt)
4848
error_opt := round_opt + trunc_opt
4949
/*
5050
Check that the new error is smaller, and that the new derivative
51-
* is consistent with the error bounds of the original estimate.
51+
* is consistent with the error bounds of the original estimate.
5252
*/
5353
if error_opt < error && math.abs(r_opt - r_0) < 4.0 * error {
5454
result = r_opt
@@ -61,9 +61,9 @@ pub fn central(f func.Fn, x f64, h f64) (f64, f64) {
6161
fn forward_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
6262
/*
6363
Compute the derivative using the 4-point rule (x+h/4, x+h/2,
64-
* x+3h/4, x+h).
65-
* Compute the error using the difference between the 4-point and
66-
* the 2-point rule (x+h/2,x+h).
64+
* x+3h/4, x+h).
65+
* Compute the error using the difference between the 4-point and
66+
* the 2-point rule (x+h/2,x+h).
6767
*/
6868
f1 := f.eval(x + h / 4.0)
6969
f2 := f.eval(x + h / 2.0)
@@ -75,9 +75,9 @@ fn forward_deriv(f func.Fn, x f64, h f64) (f64, f64, f64) {
7575
dy := math.max(math.abs(r2 / h), math.abs(r4 / h)) * math.abs(x / h) * prec.f64_epsilon
7676
/*
7777
The truncation error in the r4 approximation itself is O(h^3).
78-
* However, for safety, we estimate the error from r4-r2, which is
79-
* O(h). By scaling h we will minimise this estimated error, not
80-
* the actual truncation error in r4.
78+
* However, for safety, we estimate the error from r4-r2, which is
79+
* O(h). By scaling h we will minimise this estimated error, not
80+
* the actual truncation error in r4.
8181
*/
8282
result := r4 / h
8383
abserr_trunc := math.abs((r4 - r2) / h) // Estimated truncation error O(h)
@@ -92,15 +92,15 @@ pub fn forward(f func.Fn, x f64, h f64) (f64, f64) {
9292
if round < trunc && (round > 0.0 && trunc > 0.0) {
9393
/*
9494
Compute an optimised stepsize to minimize the total error,
95-
* using the scaling of the estimated truncation error (O(h)) and
96-
* rounding error (O(1/h)).
95+
* using the scaling of the estimated truncation error (O(h)) and
96+
* rounding error (O(1/h)).
9797
*/
9898
h_opt := h * math.pow(round / trunc, 1.0 / 2.0)
9999
r_opt, round_opt, trunc_opt := forward_deriv(f, x, h_opt)
100100
error_opt := round_opt + trunc_opt
101101
/*
102102
Check that the new error is smaller, and that the new derivative
103-
* is consistent with the error bounds of the original estimate.
103+
* is consistent with the error bounds of the original estimate.
104104
*/
105105
if error_opt < error && math.abs(r_opt - r_0) < 4.0 * error {
106106
result = r_opt

diff/diff.v

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import math
77
pub fn backward(f func.Fn, x f64) (f64, f64) {
88
/*
99
Construct a divided difference table with a fairly large step
10-
* size to get a very rough estimate of f''. Use this to estimate
11-
* the step size which will minimize the error in calculating f'.
10+
* size to get a very rough estimate of f''. Use this to estimate
11+
* the step size which will minimize the error in calculating f'.
1212
*/
1313
mut h := prec.sqrt_f64_epsilon
1414
mut a := []f64{}
@@ -17,7 +17,7 @@ pub fn backward(f func.Fn, x f64) (f64, f64) {
1717
mut i := 0
1818
/*
1919
Algorithm based on description on pg. 204 of Conte and de Boor
20-
* (CdB) - coefficients of Newton form of polynomial of degree 2.
20+
* (CdB) - coefficients of Newton form of polynomial of degree 2.
2121
*/
2222
for i = 0; i < 3; i++ {
2323
a << x + (f64(i) - 2.0) * h
@@ -30,7 +30,7 @@ pub fn backward(f func.Fn, x f64) (f64, f64) {
3030
}
3131
/*
3232
Adapt procedure described on pg. 282 of CdB to find best value of
33-
* step size.
33+
* step size.
3434
*/
3535
mut a2 := math.abs(d[0] + d[1] + d[2])
3636
if a2 < 100.0 * prec.sqrt_f64_epsilon {
@@ -46,8 +46,8 @@ pub fn backward(f func.Fn, x f64) (f64, f64) {
4646
pub fn forward(f func.Fn, x f64) (f64, f64) {
4747
/*
4848
Construct a divided difference table with a fairly large step
49-
* size to get a very rough estimate of f''. Use this to estimate
50-
* the step size which will minimize the error in calculating f'.
49+
* size to get a very rough estimate of f''. Use this to estimate
50+
* the step size which will minimize the error in calculating f'.
5151
*/
5252
mut h := prec.sqrt_f64_epsilon
5353
mut a := []f64{}
@@ -56,7 +56,7 @@ pub fn forward(f func.Fn, x f64) (f64, f64) {
5656
mut i := 0
5757
/*
5858
Algorithm based on description on pg. 204 of Conte and de Boor
59-
* (CdB) - coefficients of Newton form of polynomial of degree 2.
59+
* (CdB) - coefficients of Newton form of polynomial of degree 2.
6060
*/
6161
for i = 0; i < 3; i++ {
6262
a << x + f64(i) * h
@@ -69,7 +69,7 @@ pub fn forward(f func.Fn, x f64) (f64, f64) {
6969
}
7070
/*
7171
Adapt procedure described on pg. 282 of CdB to find best value of
72-
* step size.
72+
* step size.
7373
*/
7474
mut a2 := math.abs(d[0] + d[1] + d[2])
7575
if a2 < 100.0 * prec.sqrt_f64_epsilon {
@@ -85,8 +85,8 @@ pub fn forward(f func.Fn, x f64) (f64, f64) {
8585
pub fn central(f func.Fn, x f64) (f64, f64) {
8686
/*
8787
Construct a divided difference table with a fairly large step
88-
* size to get a very rough estimate of f'''. Use this to estimate
89-
* the step size which will minimize the error in calculating f'.
88+
* size to get a very rough estimate of f'''. Use this to estimate
89+
* the step size which will minimize the error in calculating f'.
9090
*/
9191
mut h := prec.sqrt_f64_epsilon
9292
mut a := []f64{}
@@ -95,7 +95,7 @@ pub fn central(f func.Fn, x f64) (f64, f64) {
9595
mut i := 0
9696
/*
9797
Algorithm based on description on pg. 204 of Conte and de Boor
98-
* (CdB) - coefficients of Newton form of polynomial of degree 3.
98+
* (CdB) - coefficients of Newton form of polynomial of degree 3.
9999
*/
100100
for i = 0; i < 4; i++ {
101101
a << x + (f64(i) - 2.0) * h
@@ -108,7 +108,7 @@ pub fn central(f func.Fn, x f64) (f64, f64) {
108108
}
109109
/*
110110
Adapt procedure described on pg. 282 of CdB to find best value of
111-
* step size.
111+
* step size.
112112
*/
113113
mut a3 := math.abs(d[0] + d[1] + d[2] + d[3])
114114
if a3 < 100.0 * prec.sqrt_f64_epsilon {

inout/h5/hdf5_nix.c.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module h5
22

33
import arrays { flatten }
4-
import math
54

65
type Hdf5HidT = i64
76
type Hdf5HsizeT = u64

plot/show.v

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,28 @@ pub fn (p Plot) get_plotly_script(element_id string, config PlotlyScriptConfig)
6969
content: 'import "https://cdn.plot.ly/plotly-2.26.2.min.js";
7070
7171
function removeEmptyFieldsDeeply(obj) {
72-
if (Array.isArray(obj)) {
73-
return obj.map(removeEmptyFieldsDeeply);
74-
}
75-
if (typeof obj === "object") {
76-
const newObj = Object.fromEntries(
77-
Object.entries(obj)
78-
.map(([key, value]) => [key, removeEmptyFieldsDeeply(value)])
79-
.filter(([_, value]) => !!value)
80-
);
81-
return Object.keys(newObj).length > 0 ? newObj : undefined;
82-
}
83-
return obj;
72+
if (Array.isArray(obj)) {
73+
return obj.map(removeEmptyFieldsDeeply);
74+
}
75+
if (typeof obj === "object") {
76+
const newObj = Object.fromEntries(
77+
Object.entries(obj)
78+
.map(([key, value]) => [key, removeEmptyFieldsDeeply(value)])
79+
.filter(([_, value]) => !!value)
80+
);
81+
return Object.keys(newObj).length > 0 ? newObj : undefined;
82+
}
83+
return obj;
8484
}
8585
8686
const layout = ${layout_json};
8787
const traces_with_type_json = ${traces_with_type_json};
8888
const data = [...traces_with_type_json]
89-
.map(({ type, trace: { CommonTrace, _type, ...trace } }) => ({ type, ...CommonTrace, ...trace }));
89+
.map(({ type, trace: { CommonTrace, _type, ...trace } }) => ({ type, ...CommonTrace, ...trace }));
9090
9191
const payload = {
92-
data: removeEmptyFieldsDeeply(data),
93-
layout: removeEmptyFieldsDeeply(layout),
92+
data: removeEmptyFieldsDeeply(data),
93+
layout: removeEmptyFieldsDeeply(layout),
9494
};
9595
9696
Plotly.newPlot("${element_id}", payload);'
@@ -105,14 +105,14 @@ fn (p Plot) get_html(element_id string, config PlotConfig) string {
105105

106106
return '<!DOCTYPE html>
107107
<html>
108-
<head>
109-
<title>${title}</title>
110-
</head>
111-
<body>
112-
<div id="${element_id}"></div>
113-
114-
${*plot_script}
115-
</body>
108+
<head>
109+
<title>${title}</title>
110+
</head>
111+
<body>
112+
<div id="${element_id}"></div>
113+
114+
${*plot_script}
115+
</body>
116116
</html>'
117117
}
118118

poly/poly.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ pub fn solve_cubic(a f64, b f64, c f64) []f64 {
8888
return [-a / 3.0, -a / 3.0, -a / 3.0]
8989
} else if cr2 == cq3 {
9090
/*
91-
this test is actually r2 == q3, written in a form suitable
92-
for exact computation with integers
91+
This test is actually r2 == q3, written in a form suitable
92+
for exact computation with integers
9393
*/
9494
/*
9595
Due to finite precision some double roots may be missed, and
96-
considered to be a pair of complex roots z = x +/- epsilon i
97-
close to the real axis.
96+
considered to be a pair of complex roots z = x +/- epsilon i
97+
close to the real axis.
9898
*/
9999
sqrt_q := math.sqrt(q)
100100
if r > 0.0 {

0 commit comments

Comments
 (0)