Function tract_libcli::tensor::for_data

source ·
pub fn for_data(
    symbol_table: &SymbolTable,
    filename: &str
) -> TractResult<(Option<String>, InferenceFact)>
Expand description

Parses the data command-line argument.

Examples found in repository?
src/tensor.rs (line 237)
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
pub fn for_string(
    symbol_table: &SymbolTable,
    value: &str,
) -> TractResult<(Option<String>, InferenceFact)> {
    if let Some(stripped) = value.strip_prefix('@') {
        for_data(symbol_table, stripped)
    } else {
        let (name, value) = if value.contains(':') {
            let mut splits = value.split(':');
            (Some(splits.next().unwrap().to_string()), splits.next().unwrap())
        } else {
            (None, value)
        };
        if value.contains('=') {
            let mut split = value.split('=');
            let spec = parse_spec(symbol_table, split.next().unwrap())?;
            let value = split.next().unwrap().split(',');
            let dt = spec
                .datum_type
                .concretize()
                .context("Must specify type when giving tensor value")?;
            let shape = spec
                .shape
                .as_concrete_finite()?
                .context("Must specify concrete shape when giving tensor value")?;
            let tensor = dispatch_numbers!(parse_values(dt)(&*shape, value.collect()))?;
            Ok((name, tensor.into()))
        } else {
            Ok((name, parse_spec(symbol_table, value)?))
        }
    }
}