Skip to content

Commit 7ec268f

Browse files
committed
Merge branch 'main' into fix/bool_json_encoder
2 parents 6775c82 + 35f719b commit 7ec268f

File tree

18 files changed

+58
-84
lines changed

18 files changed

+58
-84
lines changed

.github/workflows/black.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- uses: psf/black@stable
10+
- uses: psf/black@26.1.0

examples/ex_unionref_method.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,26 @@ class Triangle(xo.Struct):
1010
b = xo.Float64
1111
h = xo.Float64
1212

13-
_extra_c_sources = [
14-
"""
13+
_extra_c_sources = ["""
1514
/*gpufun*/
1615
double Triangle_compute_area(Triangle tr, double scale){
1716
double b = Triangle_get_b(tr);
1817
double h = Triangle_get_h(tr);
1918
return 0.5*b*h*scale;
2019
}
21-
"""
22-
]
20+
"""]
2321

2422

2523
class Square(xo.Struct):
2624
a = xo.Float64
2725

28-
_extra_c_sources = [
29-
"""
26+
_extra_c_sources = ["""
3027
/*gpufun*/
3128
double Square_compute_area(Square sq, double scale){
3229
double a = Square_get_a(sq);
3330
return a*a*scale;
3431
}
35-
"""
36-
]
32+
"""]
3733

3834

3935
class Base(xo.UnionRef):
@@ -52,17 +48,15 @@ class Prism(xo.Struct):
5248
height = xo.Float64
5349
volume = xo.Float64
5450

55-
_extra_c_sources = [
56-
"""
51+
_extra_c_sources = ["""
5752
/*gpukern*/
5853
void Prism_compute_volume(Prism pr){
5954
Base base = Prism_getp_base(pr);
6055
double height = Prism_get_height(pr);
6156
double base_area = Base_compute_area(base, 3.);
6257
Prism_set_volume(pr, base_area*height);
6358
}
64-
"""
65-
]
59+
"""]
6660

6761

6862
context = xo.ContextCpu()

examples/kernel_basics/kernel_cffi.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
}
2424
"""
2525

26-
ffi_interface.cdef(
27-
"""
26+
ffi_interface.cdef("""
2827
void mymul(int n,
2928
double* x1, double* x2,
30-
double* y);"""
31-
)
29+
double* y);""")
3230

3331

3432
ffi_interface.set_source(

examples/sixtracklib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
array Elements Element :
2525
"""
2626

27-
2827
import xobject as xo
2928

3029

tests/notest_capi.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,45 +56,36 @@ def test_gen_get():
5656
path = [Multipole.order]
5757

5858
source, _ = capi.gen_method_get(Multipole, path, default_conf)
59-
assert (
60-
source
61-
== """\
59+
assert source == """\
6260
/*gpufun*/ int8_t Multipole_get_order(const Multipole/*restrict*/ obj){
6361
int64_t offset=0;
6462
offset+=8;
6563
return *((/*gpuglmem*/int8_t*) obj+offset);
6664
}"""
67-
)
6865

6966
path = [Multipole.field, Field_N, Field.skew]
7067
source, _ = capi.gen_method_get(Multipole, path, default_conf)
71-
assert (
72-
source
73-
== """\
68+
assert source == """\
7469
/*gpufun*/ double Multipole_get_field_skew(const Multipole/*restrict*/ obj, int64_t i0){
7570
int64_t offset=0;
7671
offset+=32;
7772
offset+=16+i0*16;
7873
offset+=8;
7974
return *(/*gpuglmem*/double*)((/*gpuglmem*/char*) obj+offset);
8075
}"""
81-
)
8276

8377

8478
def test_gen_set():
8579
_, Multipole = gen_classes()
8680
path = [Multipole.order]
8781

8882
source, _ = capi.gen_method_set(Multipole, path, default_conf)
89-
assert (
90-
source
91-
== """\
83+
assert source == """\
9284
/*gpufun*/ void Multipole_set_order(Multipole/*restrict*/ obj, int8_t value){
9385
int64_t offset=0;
9486
offset+=8;
9587
*((/*gpuglmem*/int8_t*) obj+offset)=value;
9688
}"""
97-
)
9889

9990

10091
def test_gen_c_api():

tests/test_capi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ def test_array_get_shape(test_context, array_type):
179179
*out_nd = ARRAY_TYPE_nd(arr);
180180
ARRAY_TYPE_shape(arr, out_shape);
181181
}
182-
""".replace(
183-
"ARRAY_TYPE", array_type.__name__
184-
)
182+
""".replace("ARRAY_TYPE", array_type.__name__)
185183

186184
kernels = {
187185
"get_nd_and_shape": xo.Kernel(

tests/test_common.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def test_atomic(overload, ctype, test_context):
8787

8888
class TestAtomic(xo.Struct):
8989
val = ctype
90-
_extra_c_sources = [
91-
f"""
90+
_extra_c_sources = [f"""
9291
#include "xobjects/headers/common.h"
9392
#include "xobjects/headers/atomicadd.h"
9493
@@ -101,8 +100,7 @@ class TestAtomic(xo.Struct):
101100
retvals[ii] = ret;
102101
END_VECTORIZE;
103102
}}
104-
"""
105-
]
103+
"""]
106104

107105
kernels = {
108106
"run_atomic_test": xo.Kernel(

tests/test_kernel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,13 @@ class TestClass(xo.HybridClass):
216216
"x": xo.Float64,
217217
"y": xo.Float64,
218218
}
219-
_extra_c_sources = [
220-
"""
219+
_extra_c_sources = ["""
221220
/*gpufun*/ double myfun(TestClassData tc){
222221
double x = TestClassData_get_x(tc);
223222
double y = TestClassData_get_y(tc);
224223
return x * y;
225224
}
226-
"""
227-
]
225+
"""]
228226
_kernels = {
229227
"myfun": xo.Kernel(
230228
args=[

tests/test_ref.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,25 @@ class Triangle(xo.Struct):
220220
b = xo.Float64
221221
h = xo.Float64
222222

223-
_extra_c_sources = [
224-
"""
223+
_extra_c_sources = ["""
225224
/*gpufun*/
226225
double Triangle_compute_area(Triangle tr, double scale){
227226
double b = Triangle_get_b(tr);
228227
double h = Triangle_get_h(tr);
229228
return 0.5*b*h*scale;
230229
}
231-
"""
232-
]
230+
"""]
233231

234232
class Square(xo.Struct):
235233
a = xo.Float64
236234

237-
_extra_c_sources = [
238-
"""
235+
_extra_c_sources = ["""
239236
/*gpufun*/
240237
double Square_compute_area(Square sq, double scale){
241238
double a = Square_get_a(sq);
242239
return a*a*scale;
243240
}
244-
"""
245-
]
241+
"""]
246242

247243
class Base(xo.UnionRef):
248244
_reftypes = (Triangle, Square)
@@ -259,8 +255,7 @@ class Prism(xo.Struct):
259255
height = xo.Float64
260256
volume = xo.Float64
261257

262-
_extra_c_sources = [
263-
"""
258+
_extra_c_sources = ["""
264259
/*gpukern*/
265260
void Prism_compute_volume(Prism pr){
266261
Base base = Prism_getp_base(pr);
@@ -269,8 +264,7 @@ class Prism(xo.Struct):
269264
printf("base_area = %e", base_area);
270265
Prism_set_volume(pr, base_area*height);
271266
}
272-
"""
273-
]
267+
"""]
274268

275269
test_context.add_kernels(
276270
kernels={

tests/test_shared_memory.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def test_shared_memory():
3535

3636
class TestElement(xo.HybridClass):
3737
_xofields = {}
38-
_extra_c_sources = [
39-
"""
38+
_extra_c_sources = ["""
4039
__global__ void test_shared_memory(const double* input_arr, double* result, const int n) {
4140
// simple kernel to test shared memory
4241
// reduction with an array of 4 doubles using 2 blocks each 2 threads
@@ -47,7 +46,7 @@ class TestElement(xo.HybridClass):
4746
unsigned int gid = blockIdx.x*blockDim.x + threadIdx.x; // global thread ID: 0,1,2,3
4847
4948
// init shared memory with chunk of input array
50-
extern __shared__ double sdata[2];
49+
extern __shared__ double sdata[];
5150
sdata[tid] = input_arr[gid];
5251
__syncthreads();
5352
@@ -59,8 +58,7 @@ class TestElement(xo.HybridClass):
5958
atomicAdd(&result[tid], sdata[tid]);
6059
}
6160
}
62-
"""
63-
]
61+
"""]
6462
_kernels = _test_shared_memory_kernels
6563

6664
def __init__(

0 commit comments

Comments
 (0)