b-k / apophenia

A C library for statistical and scientific computing

Home Page:http://apophenia.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inspection functions

heshriti opened this issue · comments

Hi,

I am using Apophonia within CERN-ROOT's interface- which allows you to have active REPL like programming environment.

Are there simple apophonia functions that can help inspect data objects better.

For example in R:

suppose data is a data.frame:

summary(data)
head(data)
tail(data)
str(data)

The above 4 functions are extremely useful. I'd like to get something equivalent in apophenia- which is an excellent library in and of itself.

Can you help implement these functions?

Thank you.

MK

commented
  • There's apop_data_summarize(data). It should be similar to R's summary(), but probably not identical.

  • There are a few macros to slice data sets. Notably,
    apop_data *head = Apop_cs(data, 0, 10)
    produces a view of data with only the first ten rows. Being just a view, it disappears when the given scope is exited. Or try
    apop_data *tail = Apop_cs(data, data->matrix->size1-10, 10)

  • The data set is a plain C struct whose elements are easily available for inspection. Maybe have a look at the apop_data part of the tree figure on http://apophenia.info/gentle.html [Setting aside individual ad hoc settings groups, that diagram covers all the structure types defined by the library.] From there, it's just a question of picking out what you want:

printf("Matrix dims: %zu %zu\n", 
                data->matrix ? data->matrix->size1: 0,
                data->matrix ? data->matrix->size2: 0);
printf("Vector dim: %zu\n", 
                data->vector ? data->vector->size: 0);
printf("text size: %i %i\n", data->textsize[0], data->textsize[1]);

[Didn't test this code; apologies for any typos.]

PS: Would be interested to see how you are using the library in CERN's ROOT.

Thanks Ben.

Using the tips above, I was able to create custom functions to get print out sections of the data.

On Root, I tried experimenting with the console/REPL interface for C code.
simply load the apophenia library using (gSystem -> Load ('lib..')). and this allows you to pass in c code, the main advantage is that you don't have to compile and run. you can just execute.

Unfortunately, only some functions work. The Apop_.. macros don't work. I tried packaging them as functions within the apop library. This creates seg- fault in Root. So I've dropped this route for now..