Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ bytemuck = { version = "1.15", default-features = false, features = ["derive"] }
memmap2 = { version = "0.9", optional = true }

[dev-dependencies]
tempfile = "3.8"
criterion = { version = "0.5", features = ["html_reports"] }
half = "2.6.0"
tempfile = "3.8"

[[example]]
name = "test_real_mrc"
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ fn calculate_statistics(data: &[f32]) -> Statistics {
| `std` | Standard library support | ✅ | File I/O, Error trait |
| `mmap` | Memory-mapped I/O | ✅ | Large file processing |
| `file` | File operations | ✅ | `MrcFile::open()` |
| `f16` | Half-precision support | ❌ | Requires nightly Rust |
| `f16` | Half-precision support | ❌ | |

### no_std Usage

Expand Down Expand Up @@ -492,10 +492,6 @@ We welcome contributions! Here's how to get started:
git clone https://github.com/your-org/mrc.git
cd mrc

# Install nightly Rust (required for f16)
rustup install nightly
rustup override set nightly

# Install dependencies
cargo build --all-features

Expand Down
9 changes: 4 additions & 5 deletions examples/generate_mrc_files.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(f16)]

use half::f16;
use mrc::Header;
use mrc::Mode;
use std::fs::File;
Expand Down Expand Up @@ -90,7 +89,7 @@ fn create_ball_data_2d(mode: Mode, width: usize, height: usize, diameter: f32) -
} else {
0.0f32
};
let f16_value = value as f16;
let f16_value = f16::from_f32(value);
data.extend_from_slice(&f16_value.to_le_bytes());
}
}
Expand Down Expand Up @@ -165,7 +164,7 @@ fn create_ball_data_3d(
} else {
0.0f32
};
let f16_value = value as f16;
let f16_value = f16::from_f32(value);
data.extend_from_slice(&f16_value.to_le_bytes());
}
}
Expand Down Expand Up @@ -275,7 +274,7 @@ fn create_mrc_file(mode: i32, filename: &str) -> std::io::Result<()> {
}
Mode::Float16 => {
for chunk in data.chunks_exact(2) {
let val = f16::from_le_bytes([chunk[0], chunk[1]]) as f32;
let val = f16::from_le_bytes([chunk[0], chunk[1]]).into();
min_val = min_val.min(val);
max_val = max_val.max(val);
sum += val as f64;
Expand Down
4 changes: 0 additions & 4 deletions rust-toolchain.toml

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(feature = "f16", feature(f16))]
#[cfg(feature = "std")]
extern crate alloc;

mod header;
Expand Down
1 change: 1 addition & 0 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl<'a> MrcViewMut<'a> {
}
Some(Mode::Float16) => {
// 2-byte f16 types - use u16 for bytemuck compatibility
// TODO: this should return f16s when the f16 feature is enabled
let data = self.view_mut::<u16>()?;
for val in data.iter_mut() {
let bytes = bytemuck::bytes_of_mut(val);
Expand Down