From mdowle at mdowle.plus.com  Mon Sep  3 04:04:56 2012
From: mdowle at mdowle.plus.com (Matthew Dowle)
Date: Mon, 3 Sep 2012 03:04:56 +0100
Subject: [Rd] Possible page inefficiency in do_matrix in array.c
Message-ID: <7b0e4d32a6be42cf33560f51195ee706.squirrel@webmail.plus.net>


In do_matrix in src/array.c there is a type switch containing :

case LGLSXP :
    for (i = 0; i < nr; i++)
    for (j = 0; j < nc; j++)
        LOGICAL(ans)[i + j * NR] = NA_LOGICAL;

That seems page inefficient, iiuc. Think it should be :

case LGLSXP :
    for (j = 0; j < nc; j++)
    for (i = 0; i < nr; i++)
        LOGICAL(ans)[i + j * NR] = NA_LOGICAL;

or more simply :

case LGLSXP :
    for (i = 0; i < nc*nr; i++)
        LOGICAL(ans)[i] = NA_LOGICAL;

( with some fine tuning required since NR is type R_xlen_t whilst i, nc
and nr are type int ).

Same goes for all the other types in that switch.

This came up on Stack Overflow here :
http://stackoverflow.com/questions/12220128/reason-for-faster-matrix-allocation-in-r

Matthew



[Rd] Possible page inefficiency in do_matrix in array.c
Matthew Dowle