-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiarray_ext.pyx
More file actions
1129 lines (842 loc) · 43.5 KB
/
Copy pathiarray_ext.pyx
File metadata and controls
1129 lines (842 loc) · 43.5 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Hey Cython, this is Python 3!
# cython: language_level=3
###########################################################################################
# Copyright INAOS GmbH, Thalwil, 2018.
# Copyright Francesc Alted, 2018.
#
# All rights reserved.
#
# This software is the confidential and proprietary information of INAOS GmbH
# and Francesc Alted ("Confidential Information"). You shall not disclose such Confidential
# Information and shall use it only in accordance with the terms of the license agreement.
###########################################################################################
from . cimport ciarray_ext as ciarray
import numpy as np
cimport numpy as np
import cython
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
from math import ceil
from libc.stdlib cimport malloc, free
import iarray as ia
from collections import namedtuple
class IArrayError(Exception):
pass
def iarray_check(error):
if error != 0:
raise IArrayError(str(ciarray.iarray_err_strerror(error)))
IARRAY_ERR_EVAL_ENGINE_FAILED = ciarray.IARRAY_ERR_EVAL_ENGINE_FAILED
IARRAY_ERR_EVAL_ENGINE_NOT_COMPILED = ciarray.IARRAY_ERR_EVAL_ENGINE_NOT_COMPILED
IARRAY_ERR_EVAL_ENGINE_OUT_OF_RANGE = ciarray.IARRAY_ERR_EVAL_ENGINE_OUT_OF_RANGE
cdef set_storage(storage, ciarray.iarray_storage_t *cstore):
cstore.enforce_frame = storage.enforce_frame
if storage.plainbuffer:
cstore.backend = ciarray.IARRAY_STORAGE_PLAINBUFFER
else:
cstore.backend = ciarray.IARRAY_STORAGE_BLOSC
for i in range(len(storage.chunkshape)):
cstore.chunkshape[i] = storage.chunkshape[i]
cstore.blockshape[i] = storage.blockshape[i]
if storage.urlpath is not None:
urlpath = storage.urlpath.encode("utf-8") if isinstance(storage.urlpath, str) else storage.urlpath
cstore.urlpath = storage.urlpath
else:
cstore.urlpath = NULL
cdef class ReadBlockIter:
cdef ciarray.iarray_iter_read_block_t *ia_read_iter
cdef ciarray.iarray_iter_read_block_value_t ia_block_val
cdef Container container
cdef int dtype
cdef int flag
cdef object Info
def __cinit__(self, container, block):
self.container = container
cdef ciarray.int64_t block_[ciarray.IARRAY_DIMENSION_MAX]
if block is None:
block = container.chunkshape
for i in range(len(block)):
block_[i] = block[i]
iarray_check(ciarray.iarray_iter_read_block_new(self.container.context.ia_ctx, &self.ia_read_iter, self.container.ia_container, block_, &self.ia_block_val, False))
if self.container.dtype == np.float64:
self.dtype = 0
else:
self.dtype = 1
self.Info = namedtuple('Info', 'index elemindex nblock shape size slice')
def __dealloc__(self):
ciarray.iarray_iter_read_block_free(&self.ia_read_iter)
def __iter__(self):
return self
def __next__(self):
if ciarray.iarray_iter_read_block_has_next(self.ia_read_iter) != 0:
raise StopIteration
iarray_check(ciarray.iarray_iter_read_block_next(self.ia_read_iter, NULL, 0))
shape = tuple(self.ia_block_val.block_shape[i] for i in range(self.container.ndim))
size = np.prod(shape)
if self.dtype == 0:
view = <np.float64_t[:size]> self.ia_block_val.block_pointer
else:
view = <np.float32_t[:size]> self.ia_block_val.block_pointer
a = np.asarray(view)
elem_index = tuple(self.ia_block_val.elem_index[i] for i in range(self.container.ndim))
index = tuple(self.ia_block_val.block_index[i] for i in range(self.container.ndim))
nblock = self.ia_block_val.nblock
slice_ = tuple([slice(i, i + s) for i, s in zip(elem_index, shape)])
info = self.Info(index=index, elemindex=elem_index, nblock=nblock, shape=shape,
size=size, slice=slice_)
return info, a.reshape(shape)
cdef class WriteBlockIter:
cdef ciarray.iarray_iter_write_block_t *ia_write_iter
cdef ciarray.iarray_iter_write_block_value_t ia_block_val
cdef Container container
cdef int dtype
cdef int flag
cdef object Info
def __cinit__(self, c, block=None):
self.container = c
cdef ciarray.int64_t block_[ciarray.IARRAY_DIMENSION_MAX]
if block is None:
# The block for iteration has always be provided
block = c.chunkshape
for i in range(len(block)):
block_[i] = block[i]
iarray_check(ciarray.iarray_iter_write_block_new(self.container.context.ia_ctx,
&self.ia_write_iter,
self.container.ia_container,
block_,
&self.ia_block_val,
False))
if self.container.dtype == np.float64:
self.dtype = 0
else:
self.dtype = 1
self.Info = namedtuple('Info', 'index elemindex nblock shape size')
def __dealloc__(self):
ciarray.iarray_iter_write_block_free(&self.ia_write_iter)
def __iter__(self):
return self
def __next__(self):
if ciarray.iarray_iter_write_block_has_next(self.ia_write_iter) != 0:
raise StopIteration
iarray_check(ciarray.iarray_iter_write_block_next(self.ia_write_iter, NULL, 0))
shape = tuple(self.ia_block_val.block_shape[i] for i in range(self.container.ndim))
size = np.prod(shape)
if self.dtype == 0:
view = <np.float64_t[:size]> self.ia_block_val.block_pointer
else:
view = <np.float32_t[:size]> self.ia_block_val.block_pointer
a = np.asarray(view)
elem_index = tuple(self.ia_block_val.elem_index[i] for i in range(self.container.ndim))
index = tuple(self.ia_block_val.block_index[i] for i in range(self.container.ndim))
nblock = self.ia_block_val.nblock
info = self.Info(index=index, elemindex=elem_index, nblock=nblock, shape=shape, size=size)
return info, a.reshape(shape)
cdef class IArrayInit:
def __cinit__(self):
iarray_check(ciarray.iarray_init())
def __dealloc__(self):
ciarray.iarray_destroy()
cdef class Config:
cdef ciarray.iarray_config_t config
def __init__(self, compression_codec, compression_level, compression_favor,
use_dict, filters, max_num_threads, fp_mantissa_bits, eval_method):
self.config.compression_codec = compression_codec.value
self.config.compression_level = compression_level
self.config.compression_favor = compression_favor.value
self.config.use_dict = 1 if use_dict else 0
cdef int filter_flags = 0
# TODO: filters are really a pipeline, and here we are just ORing them, which is tricky.
# This should be fixed (probably at C iArray level and then propagating the change here).
# At any rate, `filters` should be a list for displaying purposes in high level Config().
for f in filters:
filter_flags |= f.value
if fp_mantissa_bits > 0:
filter_flags |= ia.Filters.TRUNC_PREC.value
self.config.filter_flags = filter_flags
if eval_method == ia.Eval.AUTO:
method = ciarray.IARRAY_EVAL_METHOD_AUTO
elif eval_method == ia.Eval.ITERBLOSC:
method = ciarray.IARRAY_EVAL_METHOD_ITERBLOSC
elif eval_method == ia.Eval.ITERCHUNK:
method = ciarray.IARRAY_EVAL_METHOD_ITERCHUNK
else:
raise ValueError("eval_method method not recognized:", eval_method)
self.config.eval_method = method
self.config.max_num_threads = max_num_threads
self.config.fp_mantissa_bits = fp_mantissa_bits
def _to_dict(self):
return <object> self.config
cdef class Context:
cdef ciarray.iarray_context_t *ia_ctx
def __init__(self, cfg):
cdef ciarray.iarray_config_t cfg_ = cfg._to_dict()
iarray_check(ciarray.iarray_context_new(&cfg_, &self.ia_ctx))
def __dealloc__(self):
ciarray.iarray_context_free(&self.ia_ctx)
def to_capsule(self):
return PyCapsule_New(self.ia_ctx, "iarray_context_t*", NULL)
cdef class IaDTShape:
cdef ciarray.iarray_dtshape_t ia_dtshape
def __cinit__(self, dtshape):
self.ia_dtshape.ndim = len(dtshape.shape)
if dtshape.dtype == np.float64:
self.ia_dtshape.dtype = ciarray.IARRAY_DATA_TYPE_DOUBLE
elif dtshape.dtype == np.float32:
self.ia_dtshape.dtype = ciarray.IARRAY_DATA_TYPE_FLOAT
for i in range(len(dtshape.shape)):
self.ia_dtshape.shape[i] = dtshape.shape[i]
cdef to_dict(self):
return <object> self.ia_dtshape
@property
def ndim(self):
return self.ia_dtshape.ndim
@property
def dtype(self):
dtype = [np.float64, np.float32]
return dtype[self.ia_dtshape.dtype]
@property
def shape(self):
shape = []
for i in range(self.ndim):
shape.append(self.ia_dtshape.shape[i])
return tuple(shape)
def __str__(self):
return self.ia_dtshape
cdef class RandomContext:
cdef ciarray.iarray_random_ctx_t *random_ctx
cdef Context context
def __init__(self, ctx, seed, rng):
self.context = ctx
cdef ciarray.iarray_random_ctx_t* r_ctx
if rng == ia.RandomGen.MERSENNE_TWISTER:
iarray_check(ciarray.iarray_random_ctx_new(self.context.ia_ctx, seed, ciarray.IARRAY_RANDOM_RNG_MERSENNE_TWISTER, &r_ctx))
elif rng == ia.RandomGen.SOBOL:
iarray_check(ciarray.iarray_random_ctx_new(self.context.ia_ctx, seed, ciarray.IARRAY_RANDOM_RNG_SOBOL, &r_ctx))
else:
raise ValueError("Random generator unknown")
self.random_ctx = r_ctx
def __dealloc__(self):
if self.context is not None and self.context.ia_ctx != NULL:
ciarray.iarray_random_ctx_free(self.context.ia_ctx, &self.random_ctx)
self.context = None
def to_capsule(self):
return PyCapsule_New(self.random_ctx, "iarray_random_ctx_t*", NULL)
cdef class Container:
cdef ciarray.iarray_container_t *ia_container
cdef Context context
def __init__(self, ctx, c):
if ctx is None:
raise ValueError("You must pass a context to the Container constructor")
if c is None:
raise ValueError("You must pass a Capsule to the C container struct of the Container constructor")
self.context = ctx
cdef ciarray.iarray_container_t* c_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(
c, "iarray_container_t*")
self.ia_container = c_
def __dealloc__(self):
if self.context is not None and self.context.ia_ctx != NULL:
ciarray.iarray_container_free(self.context.ia_ctx, &self.ia_container)
self.context = None
def to_capsule(self):
return PyCapsule_New(self.ia_container, "iarray_container_t*", NULL)
@property
def ndim(self):
"""Number of array dimensions."""
cdef ciarray.iarray_dtshape_t dtshape
iarray_check(ciarray.iarray_get_dtshape(self.context.ia_ctx, self.ia_container, &dtshape))
return dtshape.ndim
@property
def shape(self):
"""Tuple of array dimensions."""
cdef ciarray.iarray_dtshape_t dtshape
iarray_check(ciarray.iarray_get_dtshape(self.context.ia_ctx, self.ia_container, &dtshape))
shape = [dtshape.shape[i] for i in range(self.ndim)]
return tuple(shape)
@property
def is_plainbuffer(self):
"""bool indicating if the container is based on a plainbuffer or not"""
cdef ciarray.iarray_storage_t storage
iarray_check(ciarray.iarray_get_storage(self.context.ia_ctx, self.ia_container, &storage))
if storage.backend == ciarray.IARRAY_STORAGE_PLAINBUFFER:
return True
else:
return False
@property
def chunkshape(self):
"""Tuple of chunk dimensions."""
cdef ciarray.iarray_storage_t storage
iarray_check(ciarray.iarray_get_storage(self.context.ia_ctx, self.ia_container, &storage))
if storage.backend == ciarray.IARRAY_STORAGE_PLAINBUFFER or self.is_view():
return None
chunkshape = [storage.chunkshape[i] for i in range(self.ndim)]
return tuple(chunkshape)
@property
def blockshape(self):
"""Tuple of block dimensions."""
cdef ciarray.iarray_storage_t storage
iarray_check(ciarray.iarray_get_storage(self.context.ia_ctx, self.ia_container, &storage))
if storage.backend == ciarray.IARRAY_STORAGE_PLAINBUFFER or self.is_view():
return None
blockshape = [storage.blockshape[i] for i in range(self.ndim)]
return tuple(blockshape)
@property
def dtype(self):
"""Data-type of the array’s elements."""
dtype = [np.float64, np.float32]
cdef ciarray.iarray_dtshape_t dtshape
iarray_check(ciarray.iarray_get_dtshape(self.context.ia_ctx, self.ia_container, &dtshape))
return dtype[dtshape.dtype]
@property
def dtshape(self):
"""The :py:obj:`DTShape` of the array."""
return ia.DTShape(self.shape, self.dtype)
@property
def cratio(self):
"""Array compression ratio"""
cdef ciarray.int64_t nbytes, cbytes
iarray_check(ciarray.iarray_container_info(self.ia_container, &nbytes, &cbytes))
return <double>nbytes / <double>cbytes
def __getitem__(self, key):
# key has been massaged already
start, stop, squeeze_mask = key
return get_slice(self.context, self, start, stop, squeeze_mask, True, None)
def is_view(self):
cdef ciarray.bool view
iarray_check(ciarray.iarray_is_view(self.context.ia_ctx, self.ia_container, &view))
return view
cdef class Expression:
cdef object expression
cdef ciarray.iarray_expression_t *ia_expr
cdef Context context
def __init__(self, cfg):
self.context = Context(cfg)
cdef ciarray.iarray_expression_t* e
iarray_check(ciarray.iarray_expr_new(self.context.ia_ctx, &e))
self.ia_expr = e
self.expression = None
self.storage = None
self.dtshape = None
def __dealloc__(self):
if self.context is not None and self.context.ia_ctx != NULL:
ciarray.iarray_expr_free(self.context.ia_ctx, &self.ia_expr)
self.context = None
def bind(self, var, c):
var2 = var.encode("utf-8") if isinstance(var, str) else var
cdef ciarray.iarray_container_t *c_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(
c.to_capsule(), "iarray_container_t*")
iarray_check(ciarray.iarray_expr_bind(self.ia_expr, var2, c_))
def bind_out_properties(self, dtshape, storage):
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(storage, &store_)
iarray_check(ciarray.iarray_expr_bind_out_properties(self.ia_expr, &dtshape_, &store_))
self.dtshape = dtshape
self.storage = storage
def compile(self, expr):
# Try to support all the ufuncs in numpy
ufunc_repls = {
"arcsin": "asin",
"arccos": "acos",
"arctan": "atan",
"arctan2": "atan2",
"power": "pow",
}
for ufunc in ufunc_repls.keys():
if ufunc in expr:
expr = expr.replace(ufunc, ufunc_repls[ufunc])
expr = expr.encode("utf-8") if isinstance(expr, str) else expr
iarray_check(ciarray.iarray_expr_compile(self.ia_expr, expr))
self.expression = expr
def compile_bc(self, bc, name):
name = name.encode()
iarray_check(ciarray.iarray_expr_compile_udf(self.ia_expr, len(bc), bc, name))
self.expression = "user_defined_function"
def compile_udf(self, func):
self.compile_bc(func.bc, func.name)
def eval(self):
cdef ciarray.iarray_container_t *c;
with nogil:
error = ciarray.iarray_eval(self.ia_expr, &c)
iarray_check(error)
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(self.context, c_c)
#
# Iarray container constructors
#
def copy(cfg, src, view=False):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
cdef int flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
cdef ciarray.iarray_container_t *src_ = <ciarray.iarray_container_t *> PyCapsule_GetPointer(
src.to_capsule(), "iarray_container_t*")
cdef int view_ = view
with nogil:
error = ciarray.iarray_copy(ctx_, src_, view_, &store_, flags, &c)
iarray_check(error)
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def empty(cfg, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_container_new(ctx_, &dtshape_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def arange(cfg, slice_, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
start, stop, step = slice_.start, slice_.stop, slice_.step
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_arange(ctx_, &dtshape_, start, stop, step, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def linspace(cfg, start, stop, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_linspace(ctx_, &dtshape_, start, stop, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def zeros(cfg, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_zeros(ctx_, &dtshape_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def ones(cfg, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_ones(ctx_, &dtshape_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def full(cfg, fill_value, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
if dtshape["dtype"] == ciarray.IARRAY_DATA_TYPE_DOUBLE:
iarray_check(ciarray.iarray_fill_double(ctx_, &dtshape_, fill_value, &store_, flags, &c))
else:
iarray_check(ciarray.iarray_fill_float(ctx_, &dtshape_, fill_value, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def load(cfg, urlpath):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
urlpath = urlpath.encode("utf-8") if isinstance(urlpath, str) else urlpath
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_container_load(ctx_, urlpath, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def open(cfg, urlpath):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
urlpath = urlpath.encode("utf-8") if isinstance(urlpath, str) else urlpath
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_container_open(ctx_, urlpath, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def get_slice(ctx, data, start, stop, squeeze_mask, view, storage):
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_container_t *data_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(
data.to_capsule(), "iarray_container_t*")
shape = [sp%s - st%s for sp, st, s in zip(stop, start, data.shape)]
dtshape = ia.DTShape(shape, data.dtype)
flags = 0
cdef ciarray.int64_t start_[ciarray.IARRAY_DIMENSION_MAX]
cdef ciarray.int64_t stop_[ciarray.IARRAY_DIMENSION_MAX]
for i in range(len(start)):
start_[i] = start[i]
stop_[i] = stop[i]
cdef ciarray.iarray_storage_t store_
cdef ciarray.iarray_container_t *c
if view:
iarray_check(ciarray.iarray_get_slice(ctx_, data_, start_, stop_, view, NULL, flags, &c))
else:
set_storage(storage, &store_)
iarray_check(ciarray.iarray_get_slice(ctx_, data_, start_, stop_, view, &store_, flags, &c))
cdef ciarray.bool squeeze_mask_[ciarray.IARRAY_DIMENSION_MAX]
for i in range(data.ndim):
squeeze_mask_[i] = squeeze_mask[i]
iarray_check(ciarray.iarray_squeeze_index(ctx_, c, squeeze_mask_))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
b = ia.IArray(ctx, c_c)
if b.ndim == 0:
return float(ia.iarray2numpy(b))
return b
def numpy2iarray(cfg, a, dtshape):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
buffer_size = a.size * np.dtype(a.dtype).itemsize
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_from_buffer(ctx_, &dtshape_, np.PyArray_DATA(a), buffer_size, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def iarray2numpy(cfg, c):
ctx = Context(cfg)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(
ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_container_t *c_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(
c.to_capsule(), "iarray_container_t*")
cdef ciarray.iarray_dtshape_t dtshape
iarray_check(ciarray.iarray_get_dtshape(ctx_, c_, &dtshape))
shape = []
for i in range(dtshape.ndim):
shape.append(dtshape.shape[i])
size = np.prod(shape, dtype=np.int64)
dtype = np.float64 if dtshape.dtype == ciarray.IARRAY_DATA_TYPE_DOUBLE else np.float32
if ciarray.iarray_is_empty(c_):
# Return an empty array. Another possibility would be to raise an exception here? Let's wait for a use case...
return np.empty(size, dtype=dtype).reshape(shape)
a = np.zeros(size, dtype=dtype).reshape(shape)
iarray_check(ciarray.iarray_to_buffer(ctx_, c_, np.PyArray_DATA(a), size * sizeof(dtype)))
return a
#
# Random functions
#
def random_rand(cfg, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_rand(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_randn(cfg, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_randn(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_beta(cfg, alpha, beta, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_ALPHA, alpha)
ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_BETA, beta)
else:
ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_ALPHA, alpha)
ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_BETA, beta)
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_beta(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_lognormal(cfg, mu, sigma, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_MU, mu)
ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_SIGMA, sigma)
else:
ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_MU, mu)
ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_SIGMA, sigma)
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_lognormal(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_exponential(cfg, beta, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_BETA, beta))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_BETA, beta))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_exponential(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_uniform(cfg, a, b, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_A, a))
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_B, b))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_A, a))
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_B, b))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_uniform(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_normal(cfg, mu, sigma, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_MU, mu))
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_SIGMA, sigma))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_MU, mu))
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_SIGMA, sigma))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_normal(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_bernoulli(cfg, p, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_P, p))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_P, p))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_bernoulli(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_binomial(cfg, m, p, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_P, p))
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_M, m))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_P, p))
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_M, m))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_binomial(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_poisson(cfg, l, dtshape):
ctx = Context(cfg)
r_ctx = RandomContext(ctx, cfg.seed, cfg.random_gen)
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_random_ctx_t *r_ctx_ = <ciarray.iarray_random_ctx_t*> PyCapsule_GetPointer(r_ctx.to_capsule(), "iarray_random_ctx_t*")
if dtshape.dtype == np.float64:
iarray_check(ciarray.iarray_random_dist_set_param_double(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_LAMBDA, l))
else:
iarray_check(ciarray.iarray_random_dist_set_param_float(r_ctx_, ciarray.IARRAY_RANDOM_DIST_PARAM_LAMBDA, l))
dtshape = IaDTShape(dtshape).to_dict()
cdef ciarray.iarray_dtshape_t dtshape_ = <ciarray.iarray_dtshape_t> dtshape
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
flags = 0 if cfg.storage.urlpath is None else ciarray.IARRAY_CONTAINER_PERSIST
cdef ciarray.iarray_container_t *c
iarray_check(ciarray.iarray_random_poisson(ctx_, &dtshape_, r_ctx_, &store_, flags, &c))
c_c = PyCapsule_New(c, "iarray_container_t*", NULL)
return ia.IArray(ctx, c_c)
def random_kstest(cfg, a, b):
ctx = Context(cfg)
cdef ciarray.iarray_container_t *a_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(a.to_capsule(), "iarray_container_t*")
cdef ciarray.iarray_container_t *b_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(b.to_capsule(), "iarray_container_t*")
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.bool res;
iarray_check(ciarray.iarray_random_kstest(ctx_, a_, b_, &res))
return res
def matmul(cfg, a, b):
ctx = Context(cfg)
cdef ciarray.iarray_container_t *a_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(a.to_capsule(), "iarray_container_t*")
cdef ciarray.iarray_container_t *b_ = <ciarray.iarray_container_t*> PyCapsule_GetPointer(b.to_capsule(), "iarray_container_t*")
cdef ciarray.iarray_context_t *ctx_ = <ciarray.iarray_context_t*> PyCapsule_GetPointer(ctx.to_capsule(), "iarray_context_t*")
cdef ciarray.iarray_container_t *c
cdef ciarray.iarray_storage_t store_
set_storage(cfg.storage, &store_)
iarray_check(ciarray.iarray_linalg_matmul(ctx_, a_, b_, &store_, &c))