MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / apply_key

Method apply_key

mlx/data/op/LoadImage.cpp:23–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 format_(format),
22 from_memory_(from_memory) {}
23std::shared_ptr<Array> LoadImage::apply_key(
24 const std::shared_ptr<const Array>& src) const {
25 std::filesystem::path path;
26 std::shared_ptr<Array> dst;
27 if (!from_memory_) {
28 path = prefix_;
29 if (src->type() != ArrayType::Int8) {
30 throw std::runtime_error("LoadImage: char array (int8) expected");
31 }
32 std::string filename(reinterpret_cast<char*>(src->data()), src->size());
33 path /= filename;
34 }
35 if (info_) {
36 auto info = from_memory_ ? core::image::info(src) : core::image::info(path);
37 std::vector<int64_t> info_array({info.width, info.height});
38 dst = std::make_shared<Array>(info_array);
39 } else {
40 dst = from_memory_ ? core::image::load(src) : core::image::load(path);
41 if (!dst) {
42 throw std::runtime_error(
43 "LoadImage: unable to load image <" +
44 (from_memory_ ? "stream" : path.string()) + ">");
45 }
46 }
47 return dst;
48}
49} // namespace op
50} // namespace data
51} // namespace mlx

Callers

nothing calls this directly

Calls 5

typeMethod · 0.80
infoFunction · 0.50
loadFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected