rainwoodman / vast

vala and scientific numerical computation
11 stars 1 forks source link

String #8

Open arteymix opened 7 years ago

arteymix commented 7 years ago

There's two way of handling strings (e.g. typeof (string)) that comes to my mind:

  1. as a scalar and we store a char* pointer (should be the current way)
  2. as a vector of char and we use the last shape dimension to constraint its length plus an optional \0 byte if the string happens to be smaller

This means that we would also provide vectorized string utilities that fits the representation we choose.

rainwoodman commented 7 years ago

Oops. I commented in the PR.

  1. I am against char* pointer, because it does not fit our current memory ownership model. We insist the physical storage shall be handled by Array.data. We do not want to call 'free' function when objects are eliminated from the Array.
  2. Extra dimension may work, but it sounds like special case handling in the API.
  3. I wonder if we can make use of the elsize argument. Currently, when the elsize is bigger than the actual storage, the behavior of unused bytes is undefined.

      new Array.full(typeof(char), 10, ....)

    will define a fixed size string array, where each item is at most 10 bytes?

rainwoodman commented 7 years ago

Looks like everything here just works if we do 3?

arteymix commented 7 years ago

I'll think about all this. The string is a very special case because it has its own type.

In general, I like the idea of handling vector-scalar with mul * sizeof (type):

new Array (typeof (char), 12 * sizeof (char), {10}); // 10 12-sized char arrays

It would be nice to check this particular case when printing arrays.

rainwoodman commented 7 years ago

I wonder if this means we can have basic vector items for other types too.

new Array (typeof (double), 3 * sizeof (double), {10}); // 10 double 3-vectors
arteymix commented 7 years ago

Vector items are bad because we cannot apply cast or transformation consistently on them. I only think we should handle string in this particular way.

2016-11-10 14:00 GMT-05:00 Yu Feng notifications@github.com:

I wonder if this means we can have basic vector items for other types too.

new Array (typeof (double), 3 * sizeof (double), {10}); // 10 double 3-vectors

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rainwoodman/vast/issues/8#issuecomment-259776747, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQeTSiceGRGbtXbCyM2LJq42FExaUxlks5q82negaJpZM4Kt-8f .

Guillaume Poirier-Morency guillaumepoiriermorency@gmail.com

Étudiant au baccalauréat en Informatique à l'Université de Montréal Développeur d'application web

Mon blog: arteymix.github.io Mon projet de coopérative: pittoresque.github.io Clé PGP: B1AD6EA5 https://pgp.mit.edu/pks/lookup?op=vindex&search=0x1CCFC3A2B1AD6EA5

rainwoodman commented 7 years ago

That's a fair point.

rainwoodman commented 7 years ago

We shall strictly handle vectors as dimensions, then.