You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2017/12/26 19:06:34 UTC

madlib git commit: Multiple: Hard-wire values for construct_array calls

Repository: madlib
Updated Branches:
  refs/heads/master d0ad93d26 -> 44f89c9a1


Multiple: Hard-wire values for construct_array calls

JIRA: MADLIB-1185

Original investigation and RCA performed by
  Nikhil Kak <nk...@pivotal.io> and
  Orhan Kislal <ok...@pivotal.io>

Multiple modules called get_typlenbyvalalign in the constructor of a
struct, which led to querying the catalog during dlopen. This is frowned
down upon [1] and the problem got exposed in PG10. This commit provides
a temporary solution by hard-wiring the necessary values. This is OK in
these scenarios, since the types used are INT4, INT8 and FLOAT8, all
with fixed, stable storage and alignment patterns. Ideal solution to the
problem is to use MADlib's Allocator::allocateArray instead of the
construct_array functions.

[1] https://www.postgresql.org/message-id/96420364a3d055172776752a1de80714%40smtp.hushmail.com

Closes #219


Project: http://git-wip-us.apache.org/repos/asf/madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/madlib/commit/44f89c9a
Tree: http://git-wip-us.apache.org/repos/asf/madlib/tree/44f89c9a
Diff: http://git-wip-us.apache.org/repos/asf/madlib/diff/44f89c9a

Branch: refs/heads/master
Commit: 44f89c9a1f161c884215b48a99780f01b69bed0d
Parents: d0ad93d
Author: Rahul Iyer <ri...@apache.org>
Authored: Thu Dec 21 14:19:44 2017 -0800
Committer: Rahul Iyer <ri...@apache.org>
Committed: Thu Dec 21 15:31:09 2017 -0800

----------------------------------------------------------------------
 src/modules/crf/viterbi.cpp       | 20 ++-------
 src/modules/lda/lda.cpp           | 60 +++++++++++--------------
 src/modules/linalg/matrix_ops.cpp | 63 ++++++++++++--------------
 src/modules/linalg/svd.cpp        | 43 +++++++-----------
 src/modules/tsa/arima.cpp         | 80 +++++++++++++++-------------------
 5 files changed, 109 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/madlib/blob/44f89c9a/src/modules/crf/viterbi.cpp
----------------------------------------------------------------------
diff --git a/src/modules/crf/viterbi.cpp b/src/modules/crf/viterbi.cpp
index 25aeb62..4fa0a0b 100644
--- a/src/modules/crf/viterbi.cpp
+++ b/src/modules/crf/viterbi.cpp
@@ -18,22 +18,8 @@ namespace modules {
 namespace crf {
 
 using namespace dbal::eigen_integration;
-using madlib::dbconnector::postgres::madlib_get_typlenbyvalalign;
 using madlib::dbconnector::postgres::madlib_construct_array;
 
-typedef struct __type_info{
-    Oid oid;
-    int16_t len;
-    bool    byval;
-    char    align;
-
-    __type_info(Oid oid):oid(oid)
-    {
-        madlib_get_typlenbyvalalign(oid, &len, &byval, &align);
-    }
-} type_info;
-
-static type_info INT4TI(INT4OID);
 
 AnyType vcrf_top1_label::run(AnyType& args) {
 
@@ -124,10 +110,12 @@ AnyType vcrf_top1_label::run(AnyType& args) {
      * elements are used to store the best labels and the last element is used
      * to store the conditional probability of the sequence.
      */
+
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<int> result(
         madlib_construct_array(
-            NULL, doc_len+1, INT4TI.oid,
-               INT4TI.len, INT4TI.byval, INT4TI.align));
+            NULL, doc_len + 1, INT4OID, sizeof(int32_t), true, 'i'));
 
     /* trace back to get the labels for the rest tokens in a sentence */
     result[doc_len - 1] = top1_label;

http://git-wip-us.apache.org/repos/asf/madlib/blob/44f89c9a/src/modules/lda/lda.cpp
----------------------------------------------------------------------
diff --git a/src/modules/lda/lda.cpp b/src/modules/lda/lda.cpp
index 93194e8..6d61b43 100644
--- a/src/modules/lda/lda.cpp
+++ b/src/modules/lda/lda.cpp
@@ -22,24 +22,9 @@ namespace modules {
 namespace lda {
 
 using namespace dbal::eigen_integration;
-using madlib::dbconnector::postgres::madlib_get_typlenbyvalalign;
 using madlib::dbconnector::postgres::madlib_construct_array;
 using madlib::dbconnector::postgres::madlib_construct_md_array;
 
-typedef struct __type_info{
-    Oid oid;
-    int16_t len;
-    bool    byval;
-    char    align;
-
-    __type_info(Oid oid):oid(oid)
-    {
-        madlib_get_typlenbyvalalign(oid, &len, &byval, &align);
-    }
-} type_info;
-static type_info INT4TI(INT4OID);
-static type_info INT8TI(INT8OID);
-
 /**
  * @brief This function samples a new topic for a word in a document based on
  * the topic counts computed on the rest of the corpus. This is the core
@@ -311,10 +296,11 @@ AnyType lda_random_assign::run(AnyType & args)
     if(topic_num < 1)
         throw std::invalid_argument( "invalid argument - topic_num");
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<int32_t> doc_topic(
         madlib_construct_array(
-            NULL, topic_num + word_count, INT4TI.oid, INT4TI.len, INT4TI.byval,
-            INT4TI.align));
+            NULL, topic_num + word_count, INT4OID, sizeof(int32_t), true, 'i'));
 
     for(int32_t i = 0; i < word_count; i++){
         int32_t topic = static_cast<int32_t>(random() % topic_num);
@@ -373,6 +359,8 @@ AnyType lda_count_topic_sfunc::run(AnyType & args)
         throw std::invalid_argument(
             "dimension mismatch - sum(counts) != topic_assignment.size()");
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<int64_t> state(NULL);
     int32_t *model;
     if(args[0].isNull()) {
@@ -384,8 +372,7 @@ AnyType lda_count_topic_sfunc::run(AnyType & args)
         int dims[1] = {static_cast<int>( (voc_size * (topic_num + 1) + 1) * sizeof(int32_t) / sizeof(int64_t) )};
         int lbs[1] = {1};
         state = madlib_construct_md_array(
-            NULL, NULL, 1, dims, lbs, INT8TI.oid, INT8TI.len, INT8TI.byval,
-            INT8TI.align);
+            NULL, NULL, 1, dims, lbs, INT8OID, sizeof(int64_t), true, 'd');
         // the reason we use bigint[] because integer[] has limit on number of
         // elements and thus cannot be larger than 500MB
         model = reinterpret_cast<int32_t *>(state.ptr());
@@ -449,12 +436,13 @@ AnyType lda_transpose::run(AnyType & args)
     int32_t row_num = static_cast<int32_t>(matrix.sizeOfDim(0));
     int32_t col_num = static_cast<int32_t>(matrix.sizeOfDim(1));
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     int dims[2] = {col_num, row_num};
     int lbs[2] = {1, 1};
     MutableArrayHandle<int64_t> transposed(
         madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, INT8TI.oid, INT8TI.len, INT8TI.byval,
-            INT8TI.align));
+            NULL, NULL, 2, dims, lbs, INT8OID, sizeof(int64_t), true, 'd'));
 
     for(int32_t i = 0; i < row_num; i++){
         int32_t index = i * col_num;
@@ -501,10 +489,12 @@ AnyType lda_unnest_transpose::SRF_next(void *user_fctx, bool *is_last_call)
         return Null();
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<int32_t> outarray(
         madlib_construct_array(
-            NULL, ctx->dim, INT4TI.oid, INT4TI.len, INT4TI.byval,
-            INT4TI.align));
+            NULL, ctx->dim, INT4OID, sizeof(int32_t), true, 'i'));
+
     for (int i = 0; i < ctx->dim; i ++) {
         outarray[i] = ctx->inarray[(ctx->maxcall + 1) * i + ctx->curcall];
     }
@@ -540,10 +530,12 @@ AnyType lda_unnest::SRF_next(void *user_fctx, bool *is_last_call)
         return Null();
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<int32_t> outarray(
         madlib_construct_array(
-            NULL, ctx->dim, INT4TI.oid, INT4TI.len, INT4TI.byval,
-            INT4TI.align));
+            NULL, ctx->dim, INT4OID, sizeof(int32_t), true, 'i'));
+
     for (int i = 0; i < ctx->dim; i ++) {
         outarray[i] = ctx->inarray[ctx->curcall * (ctx->dim + 1) + i];
     }
@@ -621,14 +613,13 @@ AnyType lda_perplexity_sfunc::run(AnyType & args){
             throw std::invalid_argument("invalid topic counts in model");
         }
 
+        // FIXME: construct_array functions circumvent the abstraction layer. These
+        // should be replaced with appropriate Allocator:: calls.
         state =  madlib_construct_array(NULL,
                                         static_cast<int>(model64.size()) +
                                             topic_num +
                                             static_cast<int>(sizeof(double) / sizeof(int64_t)),
-                                        INT8TI.oid,
-                                        INT8TI.len,
-                                        INT8TI.byval,
-                                        INT8TI.align);
+                                        INT8OID, sizeof(int64_t), true, 'd');
 
         memcpy(state.ptr(), model64.ptr(), model64.size() * sizeof(int64_t));
         int32_t *_model = reinterpret_cast<int32_t *>(state.ptr());
@@ -747,12 +738,13 @@ AnyType lda_parse_model::run(AnyType & args){
 
     const int32_t *model = reinterpret_cast<const int32_t *>(state.ptr());
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     int dims[2] = {voc_size/2, topic_num};
     int lbs[2] = {1, 1};
     MutableArrayHandle<int32_t> model_part1(
         madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, INT4TI.oid, INT4TI.len, INT4TI.byval,
-            INT4TI.align));
+            NULL, NULL, 2, dims, lbs, INT4OID, sizeof(int32_t), true, 'i'));
 
     for(int32_t i = 0; i < voc_size/2; i++){
         for(int32_t j = 0; j < topic_num; j++){
@@ -760,12 +752,12 @@ AnyType lda_parse_model::run(AnyType & args){
         }
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     int dims2[2] = {voc_size - voc_size/2, topic_num};
-
     MutableArrayHandle<int32_t> model_part2(
         madlib_construct_md_array(
-            NULL, NULL, 2, dims2, lbs, INT4TI.oid, INT4TI.len, INT4TI.byval,
-            INT4TI.align));
+            NULL, NULL, 2, dims2, lbs, INT4OID, sizeof(int32_t), true, 'i'));
 
     for(int32_t i = voc_size/2; i < voc_size; i++){
         for(int32_t j = 0; j < topic_num; j++){

http://git-wip-us.apache.org/repos/asf/madlib/blob/44f89c9a/src/modules/linalg/matrix_ops.cpp
----------------------------------------------------------------------
diff --git a/src/modules/linalg/matrix_ops.cpp b/src/modules/linalg/matrix_ops.cpp
index c671416..02908ad 100644
--- a/src/modules/linalg/matrix_ops.cpp
+++ b/src/modules/linalg/matrix_ops.cpp
@@ -24,26 +24,12 @@ namespace madlib {
 namespace modules {
 namespace linalg {
 
-using madlib::dbconnector::postgres::madlib_get_typlenbyvalalign;
 using madlib::dbconnector::postgres::madlib_construct_array;
 using madlib::dbconnector::postgres::madlib_construct_md_array;
 
 // Use Eigen
 using namespace dbal::eigen_integration;
 
-typedef struct __type_info{
-    Oid oid;
-    int16_t len;
-    bool    byval;
-    char    align;
-
-    __type_info(Oid oid):oid(oid)
-    {
-        madlib_get_typlenbyvalalign(oid, &len, &byval, &align);
-    }
-} type_info;
-static type_info FLOAT8TI(FLOAT8OID);
-static type_info INT4TI(INT4OID);
 
 AnyType matrix_densify_sfunc::run(AnyType & args)
 {
@@ -68,8 +54,7 @@ AnyType matrix_densify_sfunc::run(AnyType & args)
     MutableArrayHandle<double> state(NULL);
     if (args[0].isNull()){
         state =  madlib_construct_array(
-            NULL, col_dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-            FLOAT8TI.align);
+            NULL, col_dim, FLOAT8OID, sizeof(double), true, 'd');
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -93,13 +78,14 @@ AnyType matrix_mem_sum_sfunc::run(AnyType & args)
     int row_m = static_cast<int>(m.sizeOfDim(0));
     int col_m = static_cast<int>(m.sizeOfDim(1));
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if (args[0].isNull()){
         int dims[2] = {row_m, col_m};
         int lbs[2] = {1, 1};
         state =  madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
-            FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+            NULL, NULL, 2, dims, lbs, FLOAT8OID, sizeof(double), true, 'd');
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -128,13 +114,14 @@ AnyType matrix_blockize_sfunc::run(AnyType & args)
             "invalid argument - block size should be positive");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if (args[0].isNull()){
         int32_t dims[2] = {rsize, csize};
         int lbs[2] = {1, 1};
         state = madlib_construct_md_array(
-                NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
-                FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+                NULL, NULL, 2, dims, lbs, FLOAT8OID, sizeof(double), true, 'd');
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -172,9 +159,10 @@ AnyType matrix_mem_mult::run(AnyType & args)
     if (trans_b)
         dims[1] = row_b;
     int lbs[2] = {1, 1};
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> r = madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
-            FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+            NULL, NULL, 2, dims, lbs, FLOAT8OID, sizeof(double), true, 'd');
 
     for (int i = 0; i < row_a; i++){
         for(int j = 0; j < col_a; j++){
@@ -200,11 +188,12 @@ AnyType matrix_mem_trans::run(AnyType & args)
     int row_m = static_cast<int>(m.sizeOfDim(0));
     int col_m = static_cast<int>(m.sizeOfDim(1));
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     int dims[2] = {col_m, row_m};
     int lbs[2] = {1, 1};
     MutableArrayHandle<double> r = madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
-            FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+            NULL, NULL, 2, dims, lbs, FLOAT8OID, sizeof(double), true, 'd');
 
     for (int i = 0; i < row_m; i++){
         for(int j = 0; j < col_m; j++){
@@ -221,7 +210,7 @@ AnyType rand_vector::run(AnyType & args)
         throw std::invalid_argument("invalid argument - dim should be positive");
     }
     MutableArrayHandle<int> r =  madlib_construct_array(
-            NULL, dim, INT4TI.oid, INT4TI.len, INT4TI.byval, INT4TI.align);
+            NULL, dim, INT4OID, sizeof(int32_t), true, 'i');
 
     for (int i = 0; i < dim; i++){
         *(r.ptr() + i) = (int)(drand48() * 1000);
@@ -356,15 +345,16 @@ AnyType rand_block::run(AnyType & args)
         should be positive");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     int dims[2] = {row_dim, col_dim};
     int lbs[2] = {1, 1};
-    MutableArrayHandle<int> r = madlib_construct_md_array(
-            NULL, NULL, 2, dims, lbs, INT4TI.oid,
-            INT4TI.len, INT4TI.byval, INT4TI.align);
+    MutableArrayHandle<int32_t> r = madlib_construct_md_array(
+            NULL, NULL, 2, dims, lbs, INT4OID, sizeof(int32_t), true, 'i');
 
     for (int i = 0; i < row_dim; i++){
         for(int j = 0; j < col_dim; j++){
-                *(r.ptr() + i * col_dim + j) = (int)(drand48() * 1000);
+                *(r.ptr() + i * col_dim + j) = (int32_t)(drand48() * 1000);
         }
     }
     return r;
@@ -423,10 +413,11 @@ AnyType row_split::SRF_next(void *user_fctx, bool *is_last_call)
         size = ctx->dim % ctx->size;
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> outarray(
         madlib_construct_array(
-            NULL, size, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align));
+            NULL, size, FLOAT8OID, sizeof(double), true, 'd'));
     memcpy(outarray.ptr(), ctx->inarray + ctx->curcall * ctx->size,
            size * sizeof(double));
 
@@ -462,11 +453,12 @@ AnyType matrix_unblockize_sfunc::run(AnyType & args)
             "invalid argument - col_id should be in the range of [1, total_col_dim]");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if (args[0].isNull()){
         state =  madlib_construct_array(
-            NULL, total_col_dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-            FLOAT8TI.align);
+            NULL, total_col_dim, FLOAT8OID, sizeof(double), true, 'd');
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -506,10 +498,11 @@ AnyType unnest_block::SRF_next(void *user_fctx, bool *is_last_call)
         return Null();
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> outarray(
         madlib_construct_array(
-            NULL, ctx->dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-            FLOAT8TI.align));
+            NULL, ctx->dim, FLOAT8OID, sizeof(double), true, 'd'));
     memcpy(
         outarray.ptr(), ctx->inarray + ctx->curcall * ctx->dim, ctx->dim *
         sizeof(double));

http://git-wip-us.apache.org/repos/asf/madlib/blob/44f89c9a/src/modules/linalg/svd.cpp
----------------------------------------------------------------------
diff --git a/src/modules/linalg/svd.cpp b/src/modules/linalg/svd.cpp
index ccdf6a9..0c120d6 100644
--- a/src/modules/linalg/svd.cpp
+++ b/src/modules/linalg/svd.cpp
@@ -24,9 +24,7 @@ using namespace dbal::eigen_integration;// Use Eigen
 namespace modules {
 namespace linalg {
 
-using madlib::dbconnector::postgres::madlib_get_typlenbyvalalign;
 using madlib::dbconnector::postgres::madlib_construct_array;
-using madlib::dbconnector::postgres::madlib_construct_md_array;
 
 // To get a rank-k approximation of the original matrix if we perform k + s Lanczos
 // bidiagonalization steps followed by the SVD of a small matrix B(k+s) then the
@@ -44,20 +42,6 @@ const size_t MAX_LANCZOS_STEPS = 5000;
 // that are "zero", rather than use the exact value of 0.
 const double ZERO_THRESHOLD = 1e-8;
 
-
-typedef struct __type_info{
-    Oid oid;
-    int16_t len;
-    bool    byval;
-    char    align;
-
-    __type_info(Oid oid):oid(oid)
-    {
-        madlib_get_typlenbyvalalign(oid, &len, &byval, &align);
-    }
-} type_info;
-static type_info FLOAT8TI(FLOAT8OID);
-
 /* Project the vector v into the vector u (in-place) */
 static void __project(MappedColumnVector& u, MutableNativeColumnVector& v){
     double uu = u.dot(u);
@@ -129,12 +113,13 @@ AnyType svd_lanczos_sfunc::run(AnyType & args){
             "Data contains different sized arrays");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if(args[0].isNull()){
         state = MutableArrayHandle<double>(
             madlib_construct_array(
-                NULL, dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align));
+                NULL, dim, FLOAT8OID, sizeof(double), true, 'd'));
         for (int i = 0; i < dim; i++)
             state[i] = 0;
     }else{
@@ -234,15 +219,14 @@ AnyType svd_gram_schmidt_orthogonalize_sfunc::run(AnyType & args){
             "dimensions mismatch: u.size() != v.size()");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if(args[0].isNull()){
         state = MutableArrayHandle<double>(
             madlib_construct_array(NULL,
                                    static_cast<int>(u.size()) * 2,
-                                   FLOAT8TI.oid,
-                                   FLOAT8TI.len,
-                                   FLOAT8TI.byval,
-                                   FLOAT8TI.align));
+                                   FLOAT8OID, sizeof(double), true, 'd'));
 
         // Save v into the state variable
         memcpy(state.ptr() + u.size(), v.data(), v.size() * sizeof(double));
@@ -341,11 +325,12 @@ AnyType svd_decompose_bidiagonal_sfunc::run(AnyType & args){
             "invalid parameter: col_id should be in the range of [1, k]");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if(args[0].isNull()){
         state = MutableArrayHandle<double>(
-            madlib_construct_array(NULL, k * k, FLOAT8TI.oid,
-                FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            madlib_construct_array(NULL, k * k, FLOAT8OID, sizeof(double), true, 'd'));
     } else {
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -457,12 +442,13 @@ AnyType svd_block_lanczos_sfunc::run(AnyType & args){
             "invalid parameter: col_id should be in the range of [1, dim]");
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if(args[0].isNull()){
         state = MutableArrayHandle<double>(
             madlib_construct_array(
-                NULL, dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align));
+                NULL, dim, FLOAT8OID, sizeof(double), true, 'd'));
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }
@@ -495,12 +481,13 @@ AnyType svd_sparse_lanczos_sfunc::run(AnyType & args){
     MappedColumnVector vec = args[4].getAs<MappedColumnVector >();
     int32_t dim = args[5].getAs<int32_t>();
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> state(NULL);
     if(args[0].isNull()){
         state = MutableArrayHandle<double>(
             madlib_construct_array(
-                NULL, dim, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align));
+                NULL, dim, FLOAT8OID, sizeof(double), true, 'd'));
     }else{
         state = args[0].getAs<MutableArrayHandle<double> >();
     }

http://git-wip-us.apache.org/repos/asf/madlib/blob/44f89c9a/src/modules/tsa/arima.cpp
----------------------------------------------------------------------
diff --git a/src/modules/tsa/arima.cpp b/src/modules/tsa/arima.cpp
index 1845213..e6f2e73 100644
--- a/src/modules/tsa/arima.cpp
+++ b/src/modules/tsa/arima.cpp
@@ -22,28 +22,10 @@ namespace modules {
 namespace tsa {
 
 using namespace dbal::eigen_integration;
-using madlib::dbconnector::postgres::madlib_get_typlenbyvalalign;
 using madlib::dbconnector::postgres::madlib_construct_array;
 using madlib::dbconnector::postgres::madlib_construct_md_array;
 using namespace std;
 
-// ----------------------------------------------------------------------
-
-typedef struct __type_info{
-    Oid oid;
-    int16_t len;
-    bool    byval;
-    char    align;
-
-    __type_info(Oid oid):oid(oid)
-    {
-        madlib_get_typlenbyvalalign(oid, &len, &byval, &align);
-    }
-} type_info;
-
-static type_info FLOAT8TI(FLOAT8OID);
-
-// ----------------------------------------------------------------------
 
 AnyType arima_residual::run (AnyType & args)
 {
@@ -67,10 +49,11 @@ AnyType arima_residual::run (AnyType & args)
 
     int ret_size = static_cast<int>((distid == 1) ? \
             (tvals.size()+d) : (tvals.size()-p));
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> res(
         madlib_construct_array(
-            NULL, ret_size, FLOAT8TI.oid,
-               FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, ret_size, FLOAT8OID, sizeof(double), true, 'd'));
 
     if (q < 1) {
         // compute the errors
@@ -137,10 +120,11 @@ AnyType arima_diff::run (AnyType & args)
     ArrayHandle<double> tvals = args[0].getAs<ArrayHandle<double> >();
     uint32_t d  = args[1].getAs<uint32_t>();
     int sz = static_cast<int>(tvals.size() - d);
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> diffs(
         madlib_construct_array(
-            NULL, sz, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
-
+            NULL, sz, FLOAT8OID, sizeof(double), true, 'd'));
     // get diff coef
     int* coef = diff_coef(d);
 
@@ -172,14 +156,13 @@ AnyType arima_adjust::run (AnyType & args)
     ArrayHandle<double> pre_tvals = args[2].getAs<ArrayHandle<double> >();
     int32_t p  = args[3].getAs<int32_t>();
 
-    // note that curr_tvals.size() could be different with prez_tvals.size()
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
+    // note that curr_tvals.size() could be different from prez_tvals.size()
     MutableArrayHandle<double> res(
         madlib_construct_array(NULL,
                                static_cast<int>(cur_tvals.size() + p),
-                               FLOAT8TI.oid,
-                               FLOAT8TI.len,
-                               FLOAT8TI.byval,
-                               FLOAT8TI.align));
+                               FLOAT8OID, sizeof(double), true, 'd'));
 
     // fill in the last p values from the previous tvals
     for(int i = 0; i < p; i++)
@@ -235,18 +218,20 @@ AnyType arima_lm::run (AnyType & args)
     int l = p + q;
     if (include_mean) l++;
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> prez(
         madlib_construct_array(
-            NULL, 0, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, 0, FLOAT8OID, sizeof(double), true, 'd'));
     MutableArrayHandle<double> prej(
         madlib_construct_array(
-            NULL, 0, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, 0, FLOAT8OID, sizeof(double), true, 'd'));
     if (q > 0) {
         if (distid == 1) {
             prez = madlib_construct_array(
-                NULL, q, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+                NULL, q, FLOAT8OID, sizeof(double), true, 'd');
             prej = madlib_construct_array(
-                NULL, q * l,  FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+                NULL, q * l,  FLOAT8OID, sizeof(double), true, 'd');
         } else {
             prez = args[7].getAs<MutableArrayHandle<double> >();
             prej = args[8].getAs<MutableArrayHandle<double> >();
@@ -259,14 +244,14 @@ AnyType arima_lm::run (AnyType & args)
             tvals[i] -= mean;
 
     double z2 = 0;
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> jj(
         madlib_construct_array(
-            NULL, l * l, FLOAT8TI.oid,
-            FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, l * l, FLOAT8OID, sizeof(double), true, 'd'));
     MutableArrayHandle<double> jz(
         madlib_construct_array(
-            NULL, l, FLOAT8TI.oid,
-            FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, l, FLOAT8OID, sizeof(double), true, 'd'));
 
     for (size_t t = p; t < tvals.size(); t++) {
         // compute the error and Jacob
@@ -353,13 +338,15 @@ AnyType arima_lm_result_sfunc::run (AnyType& args)
 
     MutableArrayHandle<double> state(NULL);
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     if (args[0].isNull()) {
         // state[0:(l*l-1)]         - jj
         // state[(l*l):(l*l+l-1)]   - jz
         // state[l*l+l]             - z2
         // state[l*l+l+1]           - l
-        state = madlib_construct_array(NULL, l2+l+2, FLOAT8TI.oid,
-                                       FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
+        state = madlib_construct_array(NULL, l2 + l + 2,
+                                       FLOAT8OID, sizeof(double), true, 'd');
 
         for (int i = 0; i < l2; i++) state[i] = jj[i];
         for (int i = 0; i < l; i++) state[l2 + i] = jz[i];
@@ -409,12 +396,14 @@ AnyType arima_lm_result_ffunc::run (AnyType& args)
             mx = jj[ll];
     }
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> arr_jj(
         madlib_construct_array(
-            NULL, l*l, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, l*l, FLOAT8OID, sizeof(double), true, 'd'));
     MutableArrayHandle<double> arr_jz(
         madlib_construct_array(
-            NULL, l, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
+            NULL, l, FLOAT8OID, sizeof(double), true, 'd'));
 
     memcpy(arr_jj.ptr(), jj, l*l*sizeof(double));
     memcpy(arr_jz.ptr(), jz, l*sizeof(double));
@@ -542,6 +531,8 @@ AnyType arima_lm_stat_sfunc::run (AnyType& args)
 
     MutableArrayHandle<double> state(NULL);
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     if (args[0].isNull()) {
         // Eqs. (1.2.21, 1.2.22) tells how many Z^2 are needed
         // Also Hessian is symmetric
@@ -553,8 +544,7 @@ AnyType arima_lm_stat_sfunc::run (AnyType& args)
         // state[(2*l*l+4):((2*l*l+1)*q+(2*l*l+3))]  -- all the PreZ
         // last one   --- p
         state = madlib_construct_array(
-            NULL, sz, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align);
+            NULL, sz, FLOAT8OID, sizeof(double), true, 'd');
         for (size_t i = 0; i < state.size(); i++) state[i] = 0.;
         state[0] = l;
         state[1] = delta;
@@ -655,11 +645,13 @@ AnyType arima_lm_stat_ffunc::run (AnyType& args)
          m.transpose(), EigenvaluesOnly, ComputePseudoInverse);
     ColumnVector diag = decomposition.pseudoInverse().diagonal();
 
+    // FIXME: construct_array functions circumvent the abstraction layer. These
+    // should be replaced with appropriate Allocator:: calls.
     MutableArrayHandle<double> std_err(
         madlib_construct_array(
-            NULL, l, FLOAT8TI.oid, FLOAT8TI.len, FLOAT8TI.byval,
-                FLOAT8TI.align));
-    for (int i = 0; i < l; i++) std_err[i] = sqrt(diag[i]);
+            NULL, l, FLOAT8OID, sizeof(double), true, 'd'));
+    for (int i = 0; i < l; i++)
+        std_err[i] = sqrt(diag[i]);
 
     delete [] hessian;