Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit f9aee26

Browse files
Implemented CRubix::map
1 parent e7c9b3c commit f9aee26

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

kernel/interfaces/rubix.c

+32
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,39 @@ PHP_METHOD(CRubix, argmax)
552552
*/
553553
PHP_METHOD(CRubix, map)
554554
{
555+
int i;
556+
zval result;
557+
CArray * target_ca, * ret_ca;
558+
zend_fcall_info fci = empty_fcall_info;
559+
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
560+
zval * obj = getThis();
561+
MemoryPointer ptr, out_ptr;
562+
563+
ZEND_PARSE_PARAMETERS_START(1, 1)
564+
Z_PARAM_FUNC_EX(fci, fci_cache, 1, 0)
565+
ZEND_PARSE_PARAMETERS_END();
566+
567+
ZVAL_TO_MEMORYPOINTER(obj, &ptr, NULL);
568+
target_ca = CArray_FromMemoryPointer(&ptr);
555569

570+
zval *params = emalloc(sizeof(zval));
571+
CArrayDescriptor *newdescr = CArray_DescrFromType(TYPE_DOUBLE_INT);
572+
ret_ca = CArray_NewLikeArray(target_ca, CARRAY_KEEPORDER, newdescr, 0);
573+
574+
for (i = 0; i < CArray_DESCR(target_ca)->numElements; i++) {
575+
ZVAL_DOUBLE(params, DDATA(target_ca)[i]);
576+
fci.param_count = 1;
577+
fci.retval = &result;
578+
fci.params = params;
579+
zend_call_function(&fci, &fci_cache);
580+
DDATA(ret_ca)[i] = zval_get_double(&result);
581+
zval_ptr_dtor(params);
582+
}
583+
584+
add_to_buffer(&out_ptr, ret_ca, sizeof(CArray));
585+
efree(params);
586+
587+
RETURN_MEMORYPOINTER(return_value, &out_ptr);
556588
}
557589

558590
/**

phpsci.c

+1
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,7 @@ static zend_function_entry crubix_class_methods[] =
27252725
PHP_ME(CRubix, solve, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27262726
PHP_ME(CRubix, quantile, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27272727
PHP_ME(CRubix, clip, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
2728+
PHP_ME(CRubix, map, NULL, ZEND_ACC_PUBLIC)
27282729

27292730
PHP_ME(CRubix, log, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27302731
PHP_ME(CRubix, log1p, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)

0 commit comments

Comments
 (0)