forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copying.pyx
852 lines (661 loc) · 24.3 KB
/
copying.pyx
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
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
import pickle
from libc.stdint cimport int32_t, uint8_t, uintptr_t
from libcpp cimport bool
from libcpp.memory cimport make_shared, shared_ptr, unique_ptr
from libcpp.utility cimport move
from libcpp.vector cimport vector
from rmm._lib.device_buffer cimport DeviceBuffer
import cudf
from cudf.core.buffer import Buffer, acquire_spill_lock, as_buffer
from cudf._lib cimport pylibcudf
from cudf._lib.column cimport Column
from cudf._lib.scalar import as_device_scalar
from cudf._lib.scalar cimport DeviceScalar
from cudf._lib.utils cimport table_view_from_columns, table_view_from_table
from cudf._lib.reduce import minmax
from cudf.core.abc import Serializable
cimport cudf._lib.cpp.contiguous_split as cpp_contiguous_split
cimport cudf._lib.cpp.copying as cpp_copying
from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view, mutable_column_view
from cudf._lib.cpp.libcpp.functional cimport reference_wrapper
from cudf._lib.cpp.libcpp.memory cimport make_unique
from cudf._lib.cpp.lists.gather cimport (
segmented_gather as cpp_segmented_gather,
)
from cudf._lib.cpp.lists.lists_column_view cimport lists_column_view
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.cpp.types cimport size_type
from cudf._lib.utils cimport (
columns_from_pylibcudf_table,
columns_from_table_view,
columns_from_unique_ptr,
data_from_table_view,
table_view_from_columns,
)
# workaround for https://github.com/cython/cython/issues/3885
ctypedef const scalar constscalar
def _gather_map_is_valid(
gather_map: "cudf.core.column.ColumnBase",
nrows: int,
check_bounds: bool,
nullify: bool,
) -> bool:
"""Returns true if gather map is valid.
A gather map is valid if empty or all indices are within the range
``[-nrows, nrows)``, except when ``nullify`` is specified.
"""
if not check_bounds or nullify or len(gather_map) == 0:
return True
gm_min, gm_max = minmax(gather_map)
return gm_min >= -nrows and gm_max < nrows
@acquire_spill_lock()
def copy_column(Column input_column):
"""
Deep copies a column
Parameters
----------
input_columns : column to be copied
Returns
-------
Deep copied column
"""
cdef unique_ptr[column] c_result
cdef column_view input_column_view = input_column.view()
with nogil:
c_result = move(make_unique[column](input_column_view))
return Column.from_unique_ptr(move(c_result))
@acquire_spill_lock()
def _copy_range_in_place(Column input_column,
Column target_column,
size_type input_begin,
size_type input_end,
size_type target_begin):
cdef column_view input_column_view = input_column.view()
cdef mutable_column_view target_column_view = target_column.mutable_view()
cdef size_type c_input_begin = input_begin
cdef size_type c_input_end = input_end
cdef size_type c_target_begin = target_begin
with nogil:
cpp_copying.copy_range_in_place(
input_column_view,
target_column_view,
c_input_begin,
c_input_end,
c_target_begin)
def _copy_range(Column input_column,
Column target_column,
size_type input_begin,
size_type input_end,
size_type target_begin):
cdef column_view input_column_view = input_column.view()
cdef column_view target_column_view = target_column.view()
cdef size_type c_input_begin = input_begin
cdef size_type c_input_end = input_end
cdef size_type c_target_begin = target_begin
cdef unique_ptr[column] c_result
with nogil:
c_result = move(cpp_copying.copy_range(
input_column_view,
target_column_view,
c_input_begin,
c_input_end,
c_target_begin)
)
return Column.from_unique_ptr(move(c_result))
@acquire_spill_lock()
def copy_range(Column source_column,
Column target_column,
size_type source_begin,
size_type source_end,
size_type target_begin,
size_type target_end,
bool inplace):
"""
Copy a contiguous range from a source to a target column
Notes
-----
Expects the source and target ranges to have been sanitised to be
in-range for the source and target column respectively. For
example via ``slice.indices``.
"""
msg = "Source and target ranges must be same length"
assert source_end - source_begin == target_end - target_begin, msg
if target_end >= target_begin and inplace:
# FIXME: Are we allowed to do this when inplace=False?
return target_column
if inplace:
_copy_range_in_place(source_column, target_column,
source_begin, source_end, target_begin)
else:
return _copy_range(source_column, target_column,
source_begin, source_end, target_begin)
@acquire_spill_lock()
def gather(
list columns,
Column gather_map,
bool nullify=False
):
cdef pylibcudf.Table tbl = pylibcudf.copying.gather(
pylibcudf.Table([col.to_pylibcudf(mode="read") for col in columns]),
gather_map.to_pylibcudf(mode="read"),
pylibcudf.copying.OutOfBoundsPolicy.NULLIFY if nullify
else pylibcudf.copying.OutOfBoundsPolicy.DONT_CHECK
)
return columns_from_pylibcudf_table(tbl)
cdef scatter_scalar(list source_device_slrs,
column_view scatter_map,
table_view target_table):
cdef vector[reference_wrapper[constscalar]] c_source
cdef DeviceScalar d_slr
cdef unique_ptr[table] c_result
c_source.reserve(len(source_device_slrs))
for d_slr in source_device_slrs:
c_source.push_back(
reference_wrapper[constscalar](d_slr.get_raw_ptr()[0])
)
with nogil:
c_result = move(
cpp_copying.scatter(
c_source,
scatter_map,
target_table,
)
)
return columns_from_unique_ptr(move(c_result))
cdef scatter_column(list source_columns,
column_view scatter_map,
table_view target_table):
cdef table_view c_source = table_view_from_columns(source_columns)
cdef unique_ptr[table] c_result
with nogil:
c_result = move(
cpp_copying.scatter(
c_source,
scatter_map,
target_table,
)
)
return columns_from_unique_ptr(move(c_result))
@acquire_spill_lock()
def scatter(list sources, Column scatter_map, list target_columns,
bool bounds_check=True):
"""
Scattering source into target as per the scatter map.
`source` can be a list of scalars, or a list of columns. The number of
items in `sources` must equal the number of `target_columns` to scatter.
"""
# TODO: Only single column scatter is used, we should explore multi-column
# scatter for frames for performance increase.
if len(sources) != len(target_columns):
raise ValueError("Mismatched number of source and target columns.")
if len(sources) == 0:
return []
cdef column_view scatter_map_view = scatter_map.view()
cdef table_view target_table_view = table_view_from_columns(target_columns)
if bounds_check:
n_rows = len(target_columns[0])
if not (
(scatter_map >= -n_rows).all()
and (scatter_map < n_rows).all()
):
raise IndexError(
f"index out of bounds for column of size {n_rows}"
)
if isinstance(sources[0], Column):
return scatter_column(
sources, scatter_map_view, target_table_view
)
else:
source_scalars = [as_device_scalar(slr) for slr in sources]
return scatter_scalar(
source_scalars, scatter_map_view, target_table_view
)
@acquire_spill_lock()
def column_empty_like(Column input_column):
cdef column_view input_column_view = input_column.view()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(cpp_copying.empty_like(input_column_view))
return Column.from_unique_ptr(move(c_result))
@acquire_spill_lock()
def column_allocate_like(Column input_column, size=None):
cdef size_type c_size = 0
cdef column_view input_column_view = input_column.view()
cdef unique_ptr[column] c_result
if size is None:
with nogil:
c_result = move(cpp_copying.allocate_like(
input_column_view,
cpp_copying.mask_allocation_policy.RETAIN)
)
else:
c_size = size
with nogil:
c_result = move(cpp_copying.allocate_like(
input_column_view,
c_size,
cpp_copying.mask_allocation_policy.RETAIN)
)
return Column.from_unique_ptr(move(c_result))
@acquire_spill_lock()
def columns_empty_like(list input_columns):
cdef table_view input_table_view = table_view_from_columns(input_columns)
cdef unique_ptr[table] c_result
with nogil:
c_result = move(cpp_copying.empty_like(input_table_view))
return columns_from_unique_ptr(move(c_result))
@acquire_spill_lock()
def column_slice(Column input_column, object indices):
cdef column_view input_column_view = input_column.view()
cdef vector[size_type] c_indices
c_indices.reserve(len(indices))
cdef vector[column_view] c_result
cdef int index
for index in indices:
c_indices.push_back(index)
with nogil:
c_result = move(
cpp_copying.slice(
input_column_view,
c_indices)
)
num_of_result_cols = c_result.size()
result = [
Column.from_column_view(
c_result[i],
input_column) for i in range(num_of_result_cols)]
return result
@acquire_spill_lock()
def columns_slice(list input_columns, list indices):
"""
Given a list of input columns, return columns sliced by ``indices``.
Returns a list of list of columns. The length of return is
`len(indices) / 2`. The `i`th item in return is a list of columns sliced
from ``input_columns`` with `slice(indices[i*2], indices[i*2 + 1])`.
"""
cdef table_view input_table_view = table_view_from_columns(input_columns)
cdef vector[size_type] c_indices = indices
cdef vector[table_view] c_result
with nogil:
c_result = move(
cpp_copying.slice(
input_table_view,
c_indices)
)
return [
columns_from_table_view(
c_result[i], input_columns
) for i in range(c_result.size())
]
@acquire_spill_lock()
def column_split(Column input_column, object splits):
cdef column_view input_column_view = input_column.view()
cdef vector[size_type] c_splits
c_splits.reserve(len(splits))
cdef vector[column_view] c_result
cdef int split
for split in splits:
c_splits.push_back(split)
with nogil:
c_result = move(
cpp_copying.split(
input_column_view,
c_splits)
)
num_of_result_cols = c_result.size()
result = [
Column.from_column_view(
c_result[i],
input_column
) for i in range(num_of_result_cols)
]
return result
@acquire_spill_lock()
def columns_split(list input_columns, object splits):
cdef table_view input_table_view = table_view_from_columns(input_columns)
cdef vector[size_type] c_splits = splits
cdef vector[table_view] c_result
with nogil:
c_result = move(
cpp_copying.split(
input_table_view,
c_splits)
)
return [
columns_from_table_view(
c_result[i], input_columns
) for i in range(c_result.size())
]
def _copy_if_else_column_column(Column lhs, Column rhs, Column boolean_mask):
cdef column_view lhs_view = lhs.view()
cdef column_view rhs_view = rhs.view()
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
cpp_copying.copy_if_else(
lhs_view,
rhs_view,
boolean_mask_view
)
)
return Column.from_unique_ptr(move(c_result))
def _copy_if_else_scalar_column(DeviceScalar lhs,
Column rhs,
Column boolean_mask):
cdef const scalar* lhs_scalar = lhs.get_raw_ptr()
cdef column_view rhs_view = rhs.view()
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
cpp_copying.copy_if_else(
lhs_scalar[0],
rhs_view,
boolean_mask_view
)
)
return Column.from_unique_ptr(move(c_result))
def _copy_if_else_column_scalar(Column lhs,
DeviceScalar rhs,
Column boolean_mask):
cdef column_view lhs_view = lhs.view()
cdef const scalar* rhs_scalar = rhs.get_raw_ptr()
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
cpp_copying.copy_if_else(
lhs_view,
rhs_scalar[0],
boolean_mask_view
)
)
return Column.from_unique_ptr(move(c_result))
def _copy_if_else_scalar_scalar(DeviceScalar lhs,
DeviceScalar rhs,
Column boolean_mask):
cdef const scalar* lhs_scalar = lhs.get_raw_ptr()
cdef const scalar* rhs_scalar = rhs.get_raw_ptr()
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
cpp_copying.copy_if_else(
lhs_scalar[0],
rhs_scalar[0],
boolean_mask_view
)
)
return Column.from_unique_ptr(move(c_result))
@acquire_spill_lock()
def copy_if_else(object lhs, object rhs, Column boolean_mask):
if isinstance(lhs, Column):
if isinstance(rhs, Column):
return _copy_if_else_column_column(lhs, rhs, boolean_mask)
else:
return _copy_if_else_column_scalar(
lhs, as_device_scalar(rhs), boolean_mask)
else:
if isinstance(rhs, Column):
return _copy_if_else_scalar_column(
as_device_scalar(lhs), rhs, boolean_mask)
else:
if lhs is None and rhs is None:
return lhs
return _copy_if_else_scalar_scalar(
as_device_scalar(lhs), as_device_scalar(rhs), boolean_mask)
def _boolean_mask_scatter_columns(list input_columns, list target_columns,
Column boolean_mask):
cdef table_view input_table_view = table_view_from_columns(input_columns)
cdef table_view target_table_view = table_view_from_columns(target_columns)
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[table] c_result
with nogil:
c_result = move(
cpp_copying.boolean_mask_scatter(
input_table_view,
target_table_view,
boolean_mask_view
)
)
return columns_from_unique_ptr(move(c_result))
def _boolean_mask_scatter_scalar(list input_scalars, list target_columns,
Column boolean_mask):
cdef vector[reference_wrapper[constscalar]] input_scalar_vector
input_scalar_vector.reserve(len(input_scalars))
cdef DeviceScalar scl
for scl in input_scalars:
input_scalar_vector.push_back(reference_wrapper[constscalar](
scl.get_raw_ptr()[0]))
cdef table_view target_table_view = table_view_from_columns(target_columns)
cdef column_view boolean_mask_view = boolean_mask.view()
cdef unique_ptr[table] c_result
with nogil:
c_result = move(
cpp_copying.boolean_mask_scatter(
input_scalar_vector,
target_table_view,
boolean_mask_view
)
)
return columns_from_unique_ptr(move(c_result))
@acquire_spill_lock()
def boolean_mask_scatter(list input_, list target_columns,
Column boolean_mask):
"""Copy the target columns, replacing masked rows with input data.
The ``input_`` data can be a list of columns or as a list of scalars.
A list of input columns will be used to replace corresponding rows in the
target columns for which the boolean mask is ``True``. For the nth ``True``
in the boolean mask, the nth row in ``input_`` is used to replace. A list
of input scalars will replace all rows in the target columns for which the
boolean mask is ``True``.
"""
if len(input_) != len(target_columns):
raise ValueError("Mismatched number of input and target columns.")
if len(input_) == 0:
return []
if isinstance(input_[0], Column):
return _boolean_mask_scatter_columns(
input_,
target_columns,
boolean_mask
)
else:
scalar_list = [as_device_scalar(i) for i in input_]
return _boolean_mask_scatter_scalar(
scalar_list,
target_columns,
boolean_mask
)
@acquire_spill_lock()
def shift(Column input, int offset, object fill_value=None):
cdef DeviceScalar fill
if isinstance(fill_value, DeviceScalar):
fill = fill_value
else:
fill = as_device_scalar(fill_value, input.dtype)
cdef column_view c_input = input.view()
cdef int32_t c_offset = offset
cdef const scalar* c_fill_value = fill.get_raw_ptr()
cdef unique_ptr[column] c_output
with nogil:
c_output = move(
cpp_copying.shift(
c_input,
c_offset,
c_fill_value[0]
)
)
return Column.from_unique_ptr(move(c_output))
@acquire_spill_lock()
def get_element(Column input_column, size_type index):
cdef column_view col_view = input_column.view()
cdef unique_ptr[scalar] c_output
with nogil:
c_output = move(
cpp_copying.get_element(col_view, index)
)
return DeviceScalar.from_unique_ptr(
move(c_output), dtype=input_column.dtype
)
@acquire_spill_lock()
def segmented_gather(Column source_column, Column gather_map):
cdef shared_ptr[lists_column_view] source_LCV = (
make_shared[lists_column_view](source_column.view())
)
cdef shared_ptr[lists_column_view] gather_map_LCV = (
make_shared[lists_column_view](gather_map.view())
)
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
cpp_segmented_gather(
source_LCV.get()[0], gather_map_LCV.get()[0])
)
result = Column.from_unique_ptr(move(c_result))
return result
cdef class _CPackedColumns:
@staticmethod
def from_py_table(input_table, keep_index=True):
"""
Construct a ``PackedColumns`` object from a ``cudf.DataFrame``.
"""
import cudf.core.dtypes
cdef _CPackedColumns p = _CPackedColumns.__new__(_CPackedColumns)
if keep_index and (
not isinstance(input_table.index, cudf.RangeIndex)
or input_table.index.start != 0
or input_table.index.stop != len(input_table)
or input_table.index.step != 1
):
input_table_view = table_view_from_table(input_table)
p.index_names = input_table._index_names
else:
input_table_view = table_view_from_table(
input_table, ignore_index=True)
p.column_names = input_table._column_names
p.column_dtypes = {}
for name, col in input_table._data.items():
if isinstance(col.dtype, cudf.core.dtypes._BaseDtype):
p.column_dtypes[name] = col.dtype
p.c_obj = move(cpp_contiguous_split.pack(input_table_view))
return p
@property
def gpu_data_ptr(self):
return int(<uintptr_t>self.c_obj.gpu_data.get()[0].data())
@property
def gpu_data_size(self):
return int(<size_t>self.c_obj.gpu_data.get()[0].size())
def serialize(self):
header = {}
frames = []
gpu_data = as_buffer(
data=self.gpu_data_ptr,
size=self.gpu_data_size,
owner=self,
exposed=True
)
data_header, data_frames = gpu_data.serialize()
header["data"] = data_header
frames.extend(data_frames)
header["column-names"] = self.column_names
header["index-names"] = self.index_names
if self.c_obj.metadata.get()[0].data() != NULL:
header["metadata"] = list(
<uint8_t[:self.c_obj.metadata.get()[0].size()]>
self.c_obj.metadata.get()[0].data()
)
column_dtypes = {}
for name, dtype in self.column_dtypes.items():
dtype_header, dtype_frames = dtype.serialize()
column_dtypes[name] = (
dtype_header,
(len(frames), len(frames) + len(dtype_frames)),
)
frames.extend(dtype_frames)
header["column-dtypes"] = column_dtypes
return header, frames
@staticmethod
def deserialize(header, frames):
cdef _CPackedColumns p = _CPackedColumns.__new__(_CPackedColumns)
gpu_data = Buffer.deserialize(header["data"], frames)
dbuf = DeviceBuffer(
ptr=gpu_data.get_ptr(mode="write"),
size=gpu_data.nbytes
)
cdef cpp_contiguous_split.packed_columns data
data.metadata = move(
make_unique[vector[uint8_t]](
move(<vector[uint8_t]>header.get("metadata", []))
)
)
data.gpu_data = move(dbuf.c_obj)
p.c_obj = move(data)
p.column_names = header["column-names"]
p.index_names = header["index-names"]
column_dtypes = {}
for name, dtype in header["column-dtypes"].items():
dtype_header, (start, stop) = dtype
column_dtypes[name] = pickle.loads(
dtype_header["type-serialized"]
).deserialize(dtype_header, frames[start:stop])
p.column_dtypes = column_dtypes
return p
def unpack(self):
output_table = cudf.DataFrame._from_data(*data_from_table_view(
cpp_contiguous_split.unpack(self.c_obj),
self,
self.column_names,
self.index_names
))
for name, dtype in self.column_dtypes.items():
output_table._data[name] = (
output_table._data[name]._with_type_metadata(dtype)
)
return output_table
class PackedColumns(Serializable):
"""
A packed representation of a Frame, with all columns residing
in a single GPU memory buffer.
"""
def __init__(self, data):
self._data = data
def __reduce__(self):
return self.deserialize, self.serialize()
@property
def __cuda_array_interface__(self):
return {
"data": (self._data.gpu_data_ptr, False),
"shape": (self._data.gpu_data_size,),
"strides": None,
"typestr": "|u1",
"version": 0
}
def serialize(self):
header, frames = self._data.serialize()
header["type-serialized"] = pickle.dumps(type(self))
return header, frames
@classmethod
def deserialize(cls, header, frames):
return cls(_CPackedColumns.deserialize(header, frames))
@classmethod
def from_py_table(cls, input_table, keep_index=True):
return cls(_CPackedColumns.from_py_table(input_table, keep_index))
def unpack(self):
return self._data.unpack()
def pack(input_table, keep_index=True):
"""
Pack the columns of a cudf Frame into a single GPU memory buffer.
"""
return PackedColumns.from_py_table(input_table, keep_index)
def unpack(packed):
"""
Unpack the results of packing a cudf Frame returning a new
cudf Frame in the process.
"""
return packed.unpack()