Skip to content

load_csv<uint8_t> loads ASCII values #2453

@Kevinpgalligan

Description

@Kevinpgalligan

This code to load a binary matrix and prints its values results in the ASCII values of the elements being loaded, i.e. 48 and 49 instead of 0 and 1. Is this an unsupported use case of the API?

#include <iostream>
#include <fstream>
#include <xtensor/xarray.hpp>
#include <xtensor/xcsv.hpp>
#include <xtensor/xio.hpp>
#include <stdint.h>

int main() {
    std::ifstream f;
    f.open("/tmp/mymatrix.csv");
    if (!f.is_open()) {
        throw std::runtime_error("failed to open file");
    }
    xt::xarray<uint8_t> m = xt::load_csv<uint8_t>(f);
    f.close();
    std::cout << m << std::endl;
    return 0;
}

Sample matrix file mymatrix.csv:

1,0,1
0,1,1

The output is:

{{49,48,49},
 {48,49,49}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions