(filename: str, tensor_length: int)
| 568 | return meta |
| 569 | |
| 570 | def from_bin_stream(filename: str, tensor_length: int) -> torch.Tensor: |
| 571 | # read binary file |
| 572 | with open(filename, 'rb') as f: |
| 573 | byte_data = f.read() |
| 574 | |
| 575 | # set up tensor to be saved |
| 576 | unsigned_sym = torch.zeros(tensor_length, dtype=torch.int) |
| 577 | |
| 578 | # unpack byte array |
| 579 | for i in range(tensor_length): |
| 580 | byte_index = i // 8 |
| 581 | bit_position = i % 8 |
| 582 | |
| 583 | # Check if specific bit is 1 |
| 584 | if byte_index < len(byte_data) and (byte_data[byte_index] & (1 << bit_position)): |
| 585 | unsigned_sym[i] = 1 |
| 586 | |
| 587 | # Convert 0/1 to -1/+1 |
| 588 | signed_sym = unsigned_sym * 2 - 1 |
| 589 | signed_sym = signed_sym.to(dtype=torch.float32) |
| 590 | |
| 591 | return signed_sym |
| 592 | |
| 593 | def _decompress_gaussian_ans( |
| 594 | compress_dir: str, param_name: str, meta: Dict[str, Any], decoded_means: Tensor, |
no outgoing calls
no test coverage detected