Changeset 21631e9


Ignore:
Timestamp:
Jan 28, 2019, 10:48:58 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/crepe_org
Children:
1df9cd1
Parents:
75662eb
Message:

[tensor] improve shape string for 1d

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    r75662eb r21631e9  
    170170  char_t shape_str_previous[STRN_LENGTH] = "(";
    171171  for (i = 0; i < t->ndim; i++) {
    172     int len = snprintf(shape_str, STRN_LENGTH, "%s%d%s",
    173         shape_str_previous, t->shape[i], (i == t->ndim - 1) ? "" : ", ");
     172    // and space last if not the last one
     173    int add_space = (i < t->ndim - 1);
     174    // add coma first if this not last, or always if 1d
     175    int add_coma = add_space || (t->ndim == 1);
     176    int len = snprintf(shape_str, STRN_LENGTH, "%s%d%s%s",
     177        shape_str_previous, t->shape[i],
     178        add_coma ? "," : "", add_space ? " " : "");
    174179    strncpy(shape_str_previous, shape_str, len);
    175180  }
Note: See TracChangeset for help on using the changeset viewer.