MCPcopy Create free account
hub / github.com/NVIDIA/DALI / AttachSamples

Method AttachSamples

dali/c_api_2/data_objects.h:542–631  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

540 }
541
542 void AttachSamples(
543 int num_samples,
544 int ndim,
545 daliDataType_t dtype,
546 const char *layout,
547 const daliTensorDesc_t *samples,
548 const daliDeleter_t *sample_deleters) override {
549 ValidateNumSamples(num_samples);
550 if (num_samples > 0 && !samples)
551 throw std::invalid_argument("The pointer to sample descriptors must not be NULL.");
552 if (ndim < 0) {
553 if (num_samples == 0)
554 throw std::invalid_argument(
555 "The number of dimensions must not be negative when num_samples is 0.");
556 else
557 ndim = samples[0].ndim;
558 ValidateNDim(ndim);
559 }
560 if (dtype == DALI_NO_TYPE) {
561 if (num_samples == 0)
562 throw std::invalid_argument(
563 "A valid data type must be provided when there's no sample to take it from.");
564 dtype = samples[0].dtype;
565 }
566 Validate(dtype);
567
568 TensorLayout new_layout = {};
569
570 if (!layout) {
571 if (num_samples > 0) {
572 new_layout = samples[0].layout;
573 Validate(new_layout, ndim);
574 } else if (ndim == tl_->sample_dim()) {
575 new_layout = tl_->GetLayout();
576 }
577 } else {
578 new_layout = layout;
579 Validate(new_layout, ndim);
580 }
581
582 for (int i = 0; i < num_samples; i++) {
583 if (ndim && !samples[i].shape)
584 throw std::invalid_argument(make_string("Got NULL shape in sample ", i, "."));
585 if (samples[i].dtype != dtype)
586 throw std::invalid_argument(make_string("Unexpected data type in sample ", i, ". Got: ",
587 samples[i].dtype, ", expected ", dtype, "."));
588 ValidateSampleShape(i, make_cspan(samples[i].shape, samples[i].ndim), ndim);
589 if (samples[i].layout && new_layout != samples[i].layout)
590 throw std::invalid_argument(make_string("Unexpected layout \"", samples[i].layout,
591 "\" in sample ", i, ". Expected: \"", new_layout, "\"."));
592
593 if (!samples[i].data && volume(make_cspan(samples[i].shape, ndim)))
594 throw std::invalid_argument(make_string(
595 "Got NULL data pointer in a non-empty sample ", i, "."));
596 }
597
598 tl_->Reset();
599 tl_->SetSize(num_samples);

Callers 1

Calls 15

ValidateNumSamplesFunction · 0.85
ValidateNDimFunction · 0.85
ValidateFunction · 0.85
ValidateSampleShapeFunction · 0.85
make_cspanFunction · 0.85
volumeFunction · 0.85
GetTypeInfoFunction · 0.85
SetSizeMethod · 0.80
SetSampleMethod · 0.80
make_stringFunction · 0.50
sample_dimMethod · 0.45
GetLayoutMethod · 0.45

Tested by

no test coverage detected