Changeset e7779f0 for src


Ignore:
Timestamp:
Dec 29, 2021, 5:52:00 PM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/crepe
Children:
461a89f
Parents:
7f270f8
git-author:
Paul Brossier <piem@piem.org> (01/28/19 22:48:58)
git-committer:
Paul Brossier <piem@piem.org> (12/29/21 17:52:00)
Message:

[tensor] improve shape string for 1d

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ai/tensor.c

    r7f270f8 re7779f0  
    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.