Skip to main content

hurray_file_writer_write_tensor

Function hurray_file_writer_write_tensor 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hurray_file_writer_write_tensor( handle: *mut HurrayFileWriter, name: *const u8, name_len: usize, descriptor: *const HurrayDescriptor, payloads: *const HurrayIoSlice, count: usize, ) -> HurrayStatus
Expand description

Writes one tensor under name: its descriptor, its padding, then its data buffers.

payloads MUST have one entry per buffer in the descriptor’s buffer table, in that order, each with the declared byte_size. The whole tensor is validated before a byte reaches the sink. The name is recorded in the footer index, so it is what hurray_file_reader_read_tensor will ask for; it MUST be non-empty, at most 65 535 bytes, and unique within the file.

Returns:

  • HURRAY_OK — the tensor is entirely written and the payload pointers are no longer held.
  • HURRAY_ERR_INVALID_FILE — the name is empty, too long, or already used in this file. Refused before a byte goes out, so the file is still completable and another name may be used.
  • HURRAY_ERR_SINK_CLOSED — the sink stopped accepting bytes, or the write callback failed, once part of this tensor was already out. A torn tensor is in the file and a forward-only writer cannot get back to its start, so the writer is poisoned: every later call fails, including the footer, and the bytes on the sink are not a container.
  • Whatever status the write callback returned, if it failed before any byte of this tensor reached the sink. Nothing was emitted, so the call MAY be retried — under the same name, which the failed attempt did not consume — and the file is still completable (ADR-041 § 6b).

A composite is written with hurray_file_writer_write_composite; a composite head offered here is refused, because a head alone is not a valid tensor.

§Safety

  • handle MUST point to a live HurrayFileWriter and descriptor to a live HurrayDescriptor.
  • name MUST be readable for name_len bytes.
  • If count is non-zero, payloads MUST point to count readable HurrayIoSlice values, each describing memory readable for its own len bytes.
  • All of that memory MUST stay valid and unmodified until this call returns.