16from __future__
import annotations
20from typing
import TYPE_CHECKING, Any, Callable, Tuple
23 from collections.abc
import Iterable
26 import tensorflow
as tf
32 Spec = Tuple[str, str | os.PathLike | Iterable[str | os.PathLike]]
36 """`target` can be a string, list of strings, or None. Normalize to a list of strings
37 to be consistent with `columns`."""
38 if target
is None or target ==
"":
40 if isinstance(target, str):
46 """Drop any target/weights column names that also appear in `columns`."""
47 excluded = set(target_columns) | ({weights_column}
if weights_column
else set())
48 return [str(f)
for f
in columns
if str(f)
not in excluded]
52 """Raise if ImplicitMT is enabled, or was when one of the RDataFrames was created."""
57 "Cannot use RDataLoader with implicit multi-threading enabled, call ROOT.DisableImplicitMT() before creating the data loader and its inputs."
62 """Whether `item` is a `(dataset_name, files)` tuple."""
63 return isinstance(item, tuple)
and len(item) == 2
and isinstance(item[0], str)
67 """Return the inputs as a list of RDataFrames, each `(dataset_name, files)` tuple being read into one RDataFrame."""
70 if _is_spec(inputs)
or not hasattr(inputs,
"__iter__"):
75 if isinstance(item, (str, os.PathLike)):
76 raise TypeError(
"File paths are given together with the dataset to read, as (dataset_name, files) tuples")
78 dataset_name, files = item
79 files = [files]
if isinstance(files, (str, os.PathLike))
else list(files)
81 rdataframes.append(item)
89 columns: list[str] |
None,
90 target_columns: list[str],
92 max_vec_sizes: dict[str, int] |
None =
None,
95 Resolve the columns to load based on the given RDataFrame and columns.
98 x_rdf (RNode): RDataFrame or RNode object.
99 columns (list[str], optional): Feature columns to load.
100 Defaults to all columns in the RDataFrame,
101 except for target_columns and weights_column.
102 target_columns (list[str]): Name(s) of target column(s).
103 weights_column (str): Name of the weight column, or "" for none.
104 max_vec_sizes (dict[str, int], optional):
105 Mapping from vector column name
106 to the maximum size of the vector.
107 Required when using vector based columns.
110 list[int]: List of max vector sizes
112 if max_vec_sizes
is None:
118 rdf_column_names = [str(c)
for c
in x_rdf.GetColumnNames()]
121 ordered_columns = columns + target_columns + ([weights_column]
if weights_column
else [])
126 max_vec_sizes_list = []
127 num_feature_expanded = 0
128 num_target_expanded = 0
130 for i, name
in enumerate(ordered_columns):
133 column_type = x_rdf.GetColumnType(name_str)
135 if "RVec" in column_type:
137 if name_str
in max_vec_sizes:
138 max_vec_sizes_list.append(max_vec_sizes[name_str])
139 for j
in range(max_vec_sizes[name_str]):
141 n_added = max_vec_sizes[name_str]
145 f
"No max size given for feature {name_str}. \
146 Given max sizes: {max_vec_sizes}"
154 num_feature_expanded += n_added
155 elif i <
len(columns) +
len(target_columns):
156 num_target_expanded += n_added
159 self.
target_slice = slice(num_feature_expanded, num_feature_expanded + num_target_expanded)
162 return max_vec_sizes_list
169 batches_in_memory: int = 1,
170 columns: list[str] |
None =
None,
171 max_vec_sizes: dict[str, int] |
None =
None,
172 vec_padding: int = 0,
173 target: str | list[str] |
None =
None,
175 test_size: float = 0.0,
176 shuffle: bool =
True,
177 drop_remainder: bool =
True,
179 load_eager: bool =
False,
180 sampling_type: str =
"",
181 sampling_ratio: float = 1.0,
182 replacement: bool =
False,
184 """Wrapper around the C++ DataLoader
187 inputs (ROOT.RDF.RNode | Spec | Iterable[ROOT.RDF.RNode | Spec]):
188 RDataFrame or ``(dataset_name, files)`` tuple, or a list of them, to load from.
189 A tuple is used to construct a single RDataFrame to read ``dataset_name`` from one or more files.
191 Number of entries per batch returned by the generator.
192 batches_in_memory (int):
193 Approximate number of batches that should be kept in memory at
194 the same time. Higher value results in faster loading, but
195 also higher memory usage. Defaults to 1.
196 columns (list[str] | None):
197 Names of feature columns to load. If not given, all columns are used.
198 max_vec_sizes (dict[str, int] | None):
199 Mapping from vector column name to the maximum size of the vector.
200 Required when using vector based columns.
202 Value used to pad vectors with if the vector is smaller
203 than the given max vector length. Defaults to 0.
204 target (str | list[str] | None):
205 Name or list of names of target column(s).
207 Column used to weight events.
208 Can only be used when a target is given.
210 The ratio of batches being kept for validation.
211 Value has to be between 0 and 1. Defaults to 0.0.
213 Batches consist of random events and are shuffled every epoch.
215 drop_remainder (bool):
216 Drop the remainder of data that is too small to compose full batch.
219 For reproducibility: Set the seed for the random number generator used
220 to split the dataset into training and validation as well as shuffing of the entries.
221 Defaults to 0 which means that the seed is set to the random device.
223 If True, load the full dataset(s) into memory.
224 If False, load data lazily in clusters. Defaults to False.
226 Describes the mode of sampling from the minority and majority dataframes.
227 Supported values are ``"undersampling"`` and ``"oversampling"``. Requires ``load_eager=True``.
229 For 'undersampling' and 'oversampling' it requires a list of exactly two dataframes as input,
230 where the dataframe with the most entries is the majority dataframe
231 and the dataframe with the fewest entries is the minority dataframe.
232 sampling_ratio (float):
233 Ratio of minority and majority entries in the resampled dataset.
234 Requires ``load_eager=True`` and ``sampling_type="undersampling"`` or ``"oversampling"``. Defaults to 1.0.
236 Whether the sampling is with (True) or without (False) replacement.
237 Requires ``load_eager=True`` and ``sampling_type="undersampling"``. Defaults to False.
242 rdataframes = []
if inputs
is None else _open_files(inputs)
244 raise ValueError(
"Detected empty input, at least one valid input is required.")
255 raise ValueError(
"Weights can only be used when a target is provided")
297 return self.
engine.IsActive()
300 return self.
engine.IsTrainingActive()
303 return self.
engine.IsValidationActive()
306 """Initialize the generator to be used for a loop, this spawns the loading thread"""
310 """Deactivate the generator"""
311 self.engine.DeActivate()
313 def ActivateTrainingEpoch(self):
314 """Activate the training epoch of the generato
r"""
315 _raise_if_implicit_mt(self.noded_rdfs)
316 self.engine.ActivateTrainingEpoch()
318 def ActivateValidationEpoch(self):
319 """Activate the validation epoch of the generato
r"""
320 _raise_if_implicit_mt(self.noded_rdfs)
321 self.engine.ActivateValidationEpoch()
323 def DeActivateTrainingEpoch(self):
324 """Deactivate the training epoch of the generato
r"""
325 self.engine.DeActivateTrainingEpoch()
327 def DeActivateValidationEpoch(self):
328 """Deactivate the validation epoch of the generato
r"""
329 self.engine.DeActivateValidationEpoch()
331 def CreateTrainBatches(self):
332 """Create the first training batches from the first cluste
r"""
333 self.engine.CreateTrainBatches()
335 def CreateValidationBatches(self):
336 """Create the first validation batches from the first cluste
r"""
337 self.engine.CreateValidationBatches()
340 def num_training_batches(self) -> int:
341 return self.engine.NumberOfTrainingBatches()
344 def num_validation_batches(self) -> int:
345 return self.engine.NumberOfValidationBatches()
348 def train_remainder_rows(self) -> int:
349 return self.engine.TrainRemainderRows()
352 def val_remainder_rows(self) -> int:
353 return self.engine.ValidationRemainderRows()
357 Return a sample of data that has the same size and types as the actual
358 result. This sample can be used to define the shape and size of the
362 np.ndarray: data sample
367 raise ImportError("Failed to import numpy needed for the ML dataloader")
369 # Split the target and weight
370 if not self.target_given:
371 return np.zeros((self.batch_size, self.num_columns))
373 num_feature_columns = self.train_slice.stop - self.train_slice.start
374 num_target_columns = self.target_slice.stop - self.target_slice.start
376 if not self.weights_given:
377 if num_target_columns == 1:
378 return np.zeros((self.batch_size, num_feature_columns)), np.zeros((self.batch_size)).reshape(-1, 1)
380 return np.zeros((self.batch_size, num_feature_columns)), np.zeros((self.batch_size, num_target_columns))
382 if num_target_columns == 1:
384 np.zeros((self.batch_size, num_feature_columns)),
385 np.zeros((self.batch_size)).reshape(-1, 1),
386 np.zeros((self.batch_size)).reshape(-1, 1),
390 np.zeros((self.batch_size, num_feature_columns)),
391 np.zeros((self.batch_size, num_target_columns)),
392 np.zeros((self.batch_size)).reshape(-1, 1),
395 def _get_raw_array(self, batch) -> np.ndarray:
399 raise ImportError("Failed to import numpy needed for the ML dataloader")
401 batch_size, num_columns = tuple(batch.GetShape())
402 rvec = batch.ReleaseData()
403 return np.asarray(rvec).reshape(batch_size, num_columns)
405 def _split_target_and_weights(
406 self, data: np.ndarray
407 ) -> np.ndarray | Tuple[np.ndarray, np.ndarray] | Tuple[np.ndarray, np.ndarray, np.ndarray]:
408 # Splice target column from the data if target is given
409 if self.target_given:
410 train_data = data[:, self.train_slice]
411 target_data = data[:, self.target_slice]
413 # Splice weight column from the data if weight is given
414 if self.weights_given:
415 weights_data = data[:, self.weights_index]
417 if self.target_slice.stop - self.target_slice.start == 1:
418 return train_data, target_data.reshape(-1, 1), weights_data.reshape(-1, 1)
420 return train_data, target_data, weights_data.reshape(-1, 1)
422 if self.target_slice.stop - self.target_slice.start == 1:
423 return train_data, target_data.reshape(-1, 1)
425 return train_data, target_data
429 def ConvertBatchToNumpy(self, batch) -> np.ndarray:
430 """Convert the batch into a NumPy array
433 batch: Batch returned from the DataLoader
436 np.ndarray: converted batch
438 return self._split_target_and_weights(self._get_raw_array(batch))
440 def ConvertBatchToPyTorch(self, batch: Any, device=None) -> torch.Tensor:
441 """Convert the batch into a PyTorch tensor
444 batch: Batch returned from the DataLoader
447 torch.Tensor: converted batch
451 split = self._split_target_and_weights(self._get_raw_array(batch))
453 tuple(torch.as_tensor(arr, device=device) for arr in split)
454 if isinstance(split, tuple)
455 else torch.as_tensor(split, device=device)
458 def ConvertBatchToTF(self, batch: Any) -> Any:
460 Convert the batch into a TensorFlow tensor
463 batch: Batch returned from the DataLoader
466 tensorflow.Tensor: converted batch
468 import tensorflow as tf
470 arr = self._get_raw_array(batch)
471 batch_size = arr.shape[0]
472 return_data = tf.constant(arr)
474 if batch_size != self.batch_size:
475 return_data = tf.pad(return_data, tf.constant([[0, self.batch_size - batch_size], [0, 0]]))
477 # Splice target column from the data if target is given
478 if self.target_given:
479 train_data = return_data[:, self.train_slice]
480 target_data = return_data[:, self.target_slice]
482 # Splice weight column from the data if weight is given
483 if self.weights_given:
484 weights_data = return_data[:, self.weights_index : self.weights_index + 1]
486 return train_data, target_data, weights_data
488 return train_data, target_data
492 def ConvertBatchToJAX(self, batch: Any, device=None) -> Any:
494 Convert the batch into a JAX array
497 batch: Batch returned from the DataLoader
500 jax.Array: converted batch
503 import jax.numpy as jnp
505 split = self._split_target_and_weights(jnp.asarray(self._get_raw_array(batch)))
507 if isinstance(device, str):
508 device = jax.devices(device)[0]
511 tuple(jax.device_put(arr, device=device) for arr in split)
512 if isinstance(split, tuple)
513 else jax.device_put(split, device=device)
516 # Return a batch when available
517 def GetTrainBatch(self) -> Any:
518 """Return the next training batch of data from the given RDataFrame
521 (np.ndarray): Batch of data of size.
524 batch = self.engine.GetTrainBatch()
525 return batch if (batch and batch.GetSize() > 0) else None
527 def GetValidationBatch(self) -> Any:
528 """Return the next training batch of data from the given RDataFrame
531 (np.ndarray): Batch of data of size.
534 batch = self.engine.GetValidationBatch()
535 return batch if (batch and batch.GetSize() > 0) else None
537 def Save(self, dataset_name: str, filename: str, is_training: bool, output_format: str) -> None:
538 _raise_if_implicit_mt(self.noded_rdfs)
539 self.engine.Save(dataset_name, filename, is_training, output_format)
542# context managers for the loading thread
543class _TrainingEpochContext:
544 def __init__(self, internal: _RDataLoader):
545 self._internal = internal
546 # init loading thread
548 internal.CreateTrainBatches()
551 self._internal.ActivateTrainingEpoch()
554 def __exit__(self, type, value, traceback):
555 self._internal.DeActivateTrainingEpoch()
558class _ValidationEpochContext:
559 def __init__(self, internal: _RDataLoader):
560 self._internal = internal
562 internal.CreateValidationBatches()
565 self._internal.ActivateValidationEpoch()
568 def __exit__(self, type, value, traceback):
569 self._internal.DeActivateValidationEpoch()
572# formatted iterator (returned by as_torch / as_numpy / as_tensorflow)
573class FormattedLoader:
576 Iterable that converts each batch to the requested format.
577 Returned by the as_torch / as_numpy / as_tensorflow methods on RDataLoader.
582 internal: _RDataLoader,
583 conversion_fn: Callable,
586 self._internal = internal
587 self._conversion_fn = conversion_fn
588 self._is_training = is_training
591 ctx_cls = _TrainingEpochContext if self._is_training else _ValidationEpochContext
592 get_batch = self._internal.GetTrainBatch if self._is_training else self._internal.GetValidationBatch
594 with ctx_cls(self._internal):
599 yield self._conversion_fn(batch)
602 return self._make_gen()
608 Entry point for ML batch loading from a ROOT RDataFrame.
610 Usage without a validation split::
612 train = ROOT.Experimental.ML.RDataLoader(df, batch_size=1000, ...)
613 for x, y in train.as_torch():
616 Usage with a validation split::
618 dl = ROOT.Experimental.ML.RDataLoader(df, batch_size=1000, ...)
619 train, val = dl.train_test_split(test_size=0.2)
620 for x, y in train.as_torch():
622 for x, y in val.as_numpy():
628 inputs: ROOT.RDF.RNode | Spec | Iterable[ROOT.RDF.RNode | Spec],
630 batch_size: int = 64,
631 batches_in_memory: int = 10,
632 columns: list[str] | None = None,
633 max_vec_sizes: dict[str, int] | None = None,
634 vec_padding: float = 0.0,
635 target: str | list[str] | None = None,
637 shuffle: bool = True,
638 drop_remainder: bool = True,
640 load_eager: bool = False,
641 sampling_type: str = "",
642 sampling_ratio: float = 1.0,
643 replacement: bool = False,
650 RDataFrame or (dataset_name, files) tuple, or a list of them, to load from.
651 A tuple is used to construct a single RDataFrame to read dataset_name from one or more files.
653 Number of entries per batch.
655 Approximate number of batches held in the shuffle buffer at any
656 time. Larger values improve shuffle quality across cluster
657 boundaries at the cost of higher memory usage. Acts as a soft
658 cap: the buffer may temporarily exceed this. Defaults to 10.
660 Names of feature columns to load. If not given, all columns are used.
662 Maximum size per vector column. Required for RVec columns.
664 Padding value for vectors shorter than their max size. Defaults to 0.
666 Name or list of names of target column(s).
668 Column to use for event weighting. Requires a target.
670 Whether to shuffle data across cluster boundaries every epoch.
673 Drop the last batch if smaller than batch_size. Defaults to True.
675 Seed for the random number generator. 0 means a random seed is
676 drawn from the system. Defaults to 0.
678 If True, load the full dataset into memory before training.
679 If False (default), load lazily in chunks.
681 Resampling strategy: "undersampling" or "oversampling".
682 Requires load_eager=True and exactly two input dataframes.
684 Ratio of minority to majority entries in the resampled dataset.
685 Requires load_eager=True and sampling_type set.
687 Whether undersampling is with replacement. Requires load_eager=True
688 and sampling_type="undersampling".
690 # Store all constructor parameters. The C++ backend (_RDataLoader) is
691 # created lazily on the first call to as_torch/as_numpy/as_tensorflow or
695 batch_size=batch_size,
696 batches_in_memory=batches_in_memory,
698 max_vec_sizes=max_vec_sizes,
699 vec_padding=vec_padding,
703 drop_remainder=drop_remainder,
705 load_eager=load_eager,
706 sampling_type=sampling_type, # TODO(staider) consider turning into an enum
707 sampling_ratio=sampling_ratio,
708 replacement=replacement,
710 self._internal: _RDataLoader | None = None
711 self._test_size: float | None = None
712 self._is_training: bool = True # default: full dataset treated as training
715 def _from_internal(cls, internal: _RDataLoader, is_training: bool) -> RDataLoader:
717 Internal factory that creates a split bound RDataLoader sharing an
718 already-constructed C++ backend, train_test_split uses this to return two
719 RDataLoader instances that both point at the same _RDataLoader object.
721 obj = cls.__new__(cls)
723 obj._internal = internal
724 obj._test_size = None
725 obj._is_training = is_training
728 def _ensure_created(self, test_size: float = 0.0) -> None:
730 Construct the C++ backend if not already done.
732 if self._internal is not None:
733 # Already constructed, guard against accidentally calling with a different split
734 if self._params is not None and test_size != self._test_size:
736 f"RDataLoader was already initialised with test_size="
737 f"{self._test_size}. Create a new RDataLoader to use a different split."
741 self._internal = _RDataLoader(**self._params, test_size=test_size)
742 self._test_size = test_size
744 def train_test_split(self, test_size: float = 0.2) -> Tuple[RDataLoader, RDataLoader]:
747 Partition the dataset into training and validation splits.
748 Returns two RDataLoader instances that share the same underlying C++
749 backend and can each be iterated independently.
751 if not (0.0 < test_size < 1.0):
752 raise ValueError(f"test_size must be in (0.0, 1.0), got {test_size}")
754 self._ensure_created(test_size)
756 RDataLoader._from_internal(self._internal, is_training=True),
757 RDataLoader._from_internal(self._internal, is_training=False),
760 def save(self, dataset_name: str, filename: str | os.PathLike, *, output_format: str = "ttree") -> None:
763 Write this split to disk as it would be loaded for training. This function preserves the
764 input column names when writing the output dataset. Input columns of collection types keep
765 the same type, but their values will be fixed-sized and padded according to the
766 configuration during loading (e.g. via `max_vec_sizes` and `vec_padding`).
769 dataset_name: Name of the output TTree (or RNTuple).
770 filename: Output file path.
771 output_format: `"ttree"` (default) or `"rntuple"`.
773 output_formats = ("ttree", "rntuple")
774 if output_format not in output_formats:
775 raise ValueError(f"output_format must be one of {list(output_formats)}, got {output_format!r}")
777 self._ensure_created()
778 self._internal.Save(dataset_name, str(filename), self._is_training, output_format)
780 def as_numpy(self) -> FormattedLoader:
783 Return an iterable that yields batches as NumPy arrays.
785 self._ensure_created()
786 return FormattedLoader(self._internal, self._internal.ConvertBatchToNumpy, self._is_training)
788 def as_torch(self, device: str | torch.device | None = None) -> FormattedLoader:
791 Return an iterable that yields batches as PyTorch tensors.
794 device: If given, the returned tensors are moved to the specified device.
797 import torch # noqa F401
799 raise ImportError("Failed to import torch needed for the ML dataloader")
801 self._ensure_created()
802 conversion_fn = lambda batch: self._internal.ConvertBatchToPyTorch(batch, device) # noqa: E731
803 return FormattedLoader(self._internal, conversion_fn, self._is_training)
805 def as_tensorflow(self) -> tf.data.Dataset:
808 Return a tf.data.Dataset over batches as TensorFlow tensors.
811 import tensorflow as tf
813 raise ImportError("Failed to import tensorflow needed for the ML dataloader")
815 self._ensure_created()
817 batch_size = self._internal.batch_size
818 num_feature_columns = len(self._internal.feature_columns)
819 num_target_columns = len(self._internal.target_columns)
821 # No target and weights given
822 if not self._internal.target_given:
823 batch_signature = tf.TensorSpec(shape=(batch_size, num_feature_columns), dtype=tf.float32)
825 # Target given, no weights given
826 elif not self._internal.weights_given:
828 tf.TensorSpec(shape=(batch_size, num_feature_columns), dtype=tf.float32),
829 tf.TensorSpec(shape=(batch_size, num_target_columns), dtype=tf.float32),
832 # Target and weights given
835 tf.TensorSpec(shape=(batch_size, num_feature_columns), dtype=tf.float32),
836 tf.TensorSpec(shape=(batch_size, num_target_columns), dtype=tf.float32),
837 tf.TensorSpec(shape=(batch_size, 1), dtype=tf.float32),
840 loader = FormattedLoader(self._internal, self._internal.ConvertBatchToTF, self._is_training)
841 return tf.data.Dataset.from_generator(lambda: loader, output_signature=batch_signature)
843 def as_jax(self, device: str | Any = None) -> FormattedLoader:
846 Return an iterable that yields batches as JAX arrays.
849 device: If given, the returned arrays are moved to the specified device.
850 Can be a string (e.g. "cpu", "gpu", "tpu") or any of JAX's device objects.
853 import jax # noqa F401
855 raise ImportError("Failed to import jax needed for the ML dataloader")
857 self._ensure_created()
858 conversion_fn = lambda batch: self._internal.ConvertBatchToJAX(batch, device) # noqa: E731
859 return FormattedLoader(self._internal, conversion_fn, self._is_training)
862 def columns(self) -> list[str]:
865 All column names as they appear in each batch tensor.
867 if self._internal is None:
868 columns = _exclude_target_and_weights(
869 self._params["columns"] or [], self.target_columns, self.weights_column
871 weights = self.weights_column
872 return columns + self.target_columns + ([weights] if weights else [])
873 return self._internal.all_columns
876 def feature_columns(self) -> list[str]:
879 Feature column names (columns minus target and weights).
881 if self._internal is None:
882 return _exclude_target_and_weights(self._params["columns"] or [], self.target_columns, self.weights_column)
883 return self._internal.feature_columns
886 def target_columns(self) -> list[str]:
891 if self._internal is None:
892 return _normalize_target(self._params["target"])
893 return self._internal.target_columns
896 def weights_column(self) -> str:
899 Weights column name, or empty string if not set.
901 if self._internal is None:
902 return self._params["weights"] if self._params["weights"] is not None else ""
903 return self._internal.weights_column
906 def num_batches(self) -> int:
909 Total number of batches in this split for one epoch.
911 if self._internal is None:
913 "num_batches is available after the first call to "
914 "as_torch / as_numpy / as_tensorflow / train_test_split."
916 if self._is_training:
917 return self._internal.num_training_batches
918 return self._internal.num_validation_batches
921 def last_batch_no_of_rows(self) -> int:
924 Number of rows in the last (remainder) batch, 0 if no remainder.
926 if self._internal is None:
928 "last_batch_no_of_rows is available after the first call to "
929 "as_torch / as_numpy / as_tensorflow / train_test_split."
931 if self._is_training:
932 return self._internal.train_remainder_rows
933 return self._internal.val_remainder_rows
936def _inject_dataloader_api(parentmodule):
938 Inject the public Python API into the ROOT.Experimental.ML namespace.
939 Only RDataLoader is part of the public surface.
941 for cls in [RDataLoader, FormattedLoader]:
942 setattr(parentmodule, cls.__name__, cls)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
In this class, the processes of loading clusters (see RClusterLoader) and creating batches from those...
The public interface to the RDataFrame federation of classes.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
DeActivate(self)
Deactivate the generator.
Activate(self)
Initialize the generator to be used for a loop, this spawns the loading thread.
None __init__(self, ROOT.RDF.RNode|Spec|Iterable[ROOT.RDF.RNode|Spec] inputs, *int batch_size=0, int batches_in_memory=1, list[str]|None columns=None, dict[str, int]|None max_vec_sizes=None, int vec_padding=0, str|list[str]|None target=None, str weights="", float test_size=0.0, bool shuffle=True, bool drop_remainder=True, int set_seed=0, bool load_eager=False, str sampling_type="", float sampling_ratio=1.0, bool replacement=False)
Wrapper around the C++ DataLoader.
list[int] _resolve_columns(self, ROOT.RDF.RNode x_rdf, list[str]|None columns, list[str] target_columns, str weights_column, dict[str, int]|None max_vec_sizes=None)
Resolve the columns to load based on the given RDataFrame and columns.
list _open_files(Any inputs)
Return the inputs as a list of RDataFrames, each (dataset_name, files) tuple being read into one RDat...
list[str] _exclude_target_and_weights(list[str] columns, list[str] target_columns, str weights_column)
Drop any target/weights column names that also appear in columns.
None _raise_if_implicit_mt(list rdfs)
Raise if ImplicitMT is enabled, or was when one of the RDataFrames was created.
list[str] _normalize_target(str|list[str]|None target)
target can be a string, list of strings, or None.
bool _is_spec(Any item)
Whether item is a (dataset_name, files) tuple.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
void EnableThreadSafety()
Enable support for multi-threading within the ROOT code in particular, enables the global mutex to ma...