コード例 #1
0
// extern void TF_SetAttrFloatList(TF_OperationDescription* desc,
//                                 const char* attr_name, const float* values,
//                                 int num_values);
static PHP_METHOD(TensorFlow_OperationDescription, setAttrFloatList)
{
    zend_string *name;
    zval* values;

    ZEND_PARSE_PARAMETERS_START(2, 2)
        Z_PARAM_STR(name)
        Z_PARAM_ARRAY(values)
    ZEND_PARSE_PARAMETERS_END();


    float* tf_values = NULL;
    int tf_num_values = 0;

    HashTable *values_table = Z_ARRVAL_P(values);
    tf_num_values = zend_hash_num_elements(values_table); // count of array

    if (tf_num_values > 0) {
        tf_values = (float*)emalloc(sizeof(float) * tf_num_values);

        HashPosition pos;
        zval* element;
        int index = 0;

        zend_hash_internal_pointer_reset_ex(values_table, &pos);
        while (zend_hash_has_more_elements_ex(values_table, &pos) == SUCCESS) {
            if (!(element = zend_hash_get_current_data_ex(values_table, &pos))) {
                zend_throw_exception(spl_ce_InvalidArgumentException, "values something wrong", 0);
                return;
            }
            if (zval_get_type(element) != IS_DOUBLE) {
                zend_throw_exception(spl_ce_InvalidArgumentException, "values must be array of float", 0);
                return;
            }
            // insert tf_values
            tf_values[index] = Z_DVAL_P(element);
            // php_printf("%d \n", element->value.lval);
            zend_hash_move_forward_ex(values_table, &pos);

            index++;
        }
    }

    // int i;
    // for (i = 0; i < tf_num_values; i++) {
    //     php_printf("values[%f] ? %d\n", i, tf_values[i]);
    // }
    // php_printf("tf_num_values ? %d\n", tf_num_values);

    // this
    t_tf_operation_description_object* intern = TF_OPERATION_DESCRIPTION_P_ZV(getThis());
    t_tf_operation_description* node = intern->ptr;

    TF_SetAttrFloatList(node->src, name->val, tf_values, tf_num_values);
}
コード例 #2
0
ファイル: tensorflow.c プロジェクト: wedesoft/aiscm
SCM tf_set_attr_float_list(SCM scm_description, SCM scm_name, SCM scm_values)
{
  struct tf_description_t *self = get_tf_description(scm_description);
  int num_values = scm_ilength(scm_values);
  float *values = scm_gc_malloc(sizeof(float) * num_values, "tf-set-attr-float-list");
  for (int i=0; i<num_values; i++) {
    values[i] = (float)scm_to_double(scm_car(scm_values));
    scm_values = scm_cdr(scm_values);
  };
  char *name = scm_to_locale_string(scm_name);
  TF_SetAttrFloatList(self->description, name, values, num_values);
  free(name);
  return SCM_UNDEFINED;
}