You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@madlib.apache.org by GitBox <gi...@apache.org> on 2019/03/15 17:46:30 UTC

[GitHub] [madlib] njayaram2 commented on a change in pull request #356: Keras model arch table helper functions for keras_fit()

njayaram2 commented on a change in pull request #356: Keras model arch table helper functions for keras_fit()
URL: https://github.com/apache/madlib/pull/356#discussion_r266084992
 
 

 ##########
 File path: src/ports/postgres/modules/convex/test/keras_model_arch_table.sql_in
 ##########
 @@ -0,0 +1,124 @@
+/* -----------------------------------------------------------------------
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * ----------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * Test Keras Model Arch Table helper functions
+ * -------------------------------------------------------------------------- */
+
+
+/* Test successful model creation where no table exists */
+DROP TABLE IF EXISTS test_keras_model_arch_table;
+SELECT keras_create_model('test_keras_model_arch_table', '{"a" : 1, "b" : 2, "c" : [4,5,6] }');
+
+SELECT assert(UPPER(atttypid::regtype::TEXT) = 'INTEGER', 'model_id column should be INTEGER type')
+    FROM pg_attribute WHERE attrelid = 'test_keras_model_arch_table'::regclass
+        AND attname = 'model_id';
+SELECT assert(UPPER(atttypid::regtype::TEXT) = 'JSON', 'model_arch column should be JSON type' ) FROM pg_attribute WHERE attrelid = 'test_keras_model_arch_table'::regclass
+        AND attname = 'model_arch';
+SELECT assert(UPPER(atttypid::regtype::TEXT) =
+    'DOUBLE PRECISION[]', 'model_weights column should be DOUBLE PRECISION[] type')
+    FROM pg_attribute WHERE attrelid = 'test_keras_model_arch_table'::regclass
+        AND attname = 'model_weights';
+
+/*  model id should be 1 */
+SELECT assert(model_id = 1, 'Wrong model_id written by keras_create_model')
+    FROM test_keras_model_arch_table;
+
+/* model arch should be valid json, with all fields accessible with json operators */
+SELECT assert((model_arch->>'a') = '1', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table;
+SELECT assert((model_arch->>'b') = '2', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table;
+SELECT assert((model_arch->'c')->>0 = '4', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table;
+SELECT assert((model_arch->'c')->>1 = '5', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table;
+SELECT assert((model_arch->'c')->>2 = '6', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table;
+/* model_weights should be set to null, since this is not a warm start */
+SELECT assert(model_weights IS NULL, 'model_weights should be NULL after keras_create_model() called.') FROM test_keras_model_arch_table;
+
+
+/* Test model creation where valid table exists */
+SELECT keras_create_model('test_keras_model_arch_table', '{"config" : [1,2,3]}');
+SELECT keras_create_model('test_keras_model_arch_table', '{"config" : [8,4,0]}');
+SELECT assert(model_arch->'config'->>0 = '1', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 2;
+SELECT assert(model_arch->'config'->>1 = '2', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 2;
+SELECT assert(model_arch->'config'->>2 = '3', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 2;
+SELECT assert(model_arch->'config'->>0 = '8', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 3;
+SELECT assert(model_arch->'config'->>1 = '4', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 3;
+SELECT assert(model_arch->'config'->>2 = '0', 'Cannot parse model_arch json in model table.')
+    FROM test_keras_model_arch_table WHERE model_id = 3;
+
+/* Test deletion where valid table exists */
+SELECT keras_delete_model('test_keras_model_arch_table', 2);
 
 Review comment:
   The name of the function created to do this is `delete_keras_model`, but the tests call `keras_delete_model`. This would fail. This is the case in other similar test cases too I guess.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services