| 67 | } |
| 68 | |
| 69 | void Array::init_( |
| 70 | ArrayType type, |
| 71 | const std::vector<int64_t>& shape, |
| 72 | std::shared_ptr<void> data) { |
| 73 | shape_ = shape; |
| 74 | type_ = type; |
| 75 | switch (type_) { |
| 76 | case UInt8: |
| 77 | itemsize_ = sizeof(unsigned char); |
| 78 | break; |
| 79 | case Int32: |
| 80 | itemsize_ = sizeof(int32_t); |
| 81 | break; |
| 82 | case Int64: |
| 83 | itemsize_ = sizeof(int64_t); |
| 84 | break; |
| 85 | case Float: |
| 86 | itemsize_ = sizeof(float); |
| 87 | break; |
| 88 | case Double: |
| 89 | itemsize_ = sizeof(double); |
| 90 | break; |
| 91 | case Int8: |
| 92 | itemsize_ = sizeof(char); |
| 93 | break; |
| 94 | case Any: |
| 95 | itemsize_ = 0; |
| 96 | if (size() != 0) { |
| 97 | throw std::runtime_error( |
| 98 | "Array: cannot create a tensor of undetermined type"); |
| 99 | } |
| 100 | break; |
| 101 | default: |
| 102 | throw std::runtime_error("Array: internal error: unknown type"); |
| 103 | } |
| 104 | if (data) { |
| 105 | data_ = data; |
| 106 | } else { |
| 107 | if (size() > 0) { |
| 108 | data_ = std::shared_ptr<void>(std::malloc(size() * itemsize_), std::free); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | Array::Array(const std::string& str) { |
| 114 | init_(ArrayType::Int8, {static_cast<int64_t>(str.size())}); |
nothing calls this directly
no outgoing calls
no test coverage detected