MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FromProtoField

Function FromProtoField

tensorflow/core/framework/tensor.cc:500–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498// in the compact binary representation.
499template <typename T>
500TensorBuffer* FromProtoField(Allocator* a, const TensorProto& in, int64 n) {
501 CHECK_GT(n, 0);
502 Buffer<T>* buf = new Buffer<T>(a, n);
503 T* data = buf->template base<T>();
504 if (data == nullptr) {
505 buf->Unref();
506 return nullptr;
507 }
508
509 const int64 in_n = ProtoHelper<T>::NumElements(in);
510 if (in_n <= 0) {
511 std::fill_n(data, n, T());
512 } else {
513 auto begin = ProtoHelper<T>::Begin(in);
514 if (n <= in_n) {
515 std::copy_n(begin, n, data);
516 } else {
517 std::copy_n(begin, in_n, data);
518 const T& last = *(data + in_n - 1);
519 std::fill_n(data + in_n, n - in_n, last);
520 }
521 }
522
523 return buf;
524}
525
526// Separate implementation for `ResourceHandle` to handle the case when the
527// proto for the resource is invalid. See `resource_handle.h` constructor and

Callers

nothing calls this directly

Calls 2

NumElementsFunction · 0.50
UnrefMethod · 0.45

Tested by

no test coverage detected