Right now, I am attempting to optimize my code by reducing the number of resize.
So, I made this code in the math parser:
change_arr_size(index,count)=(
temp_height=h(##index);
temp_value=da_size(##index);
new_dar_size=da_size(##index)+count;
if(new_dar_size>=temp_height,
while(temp_height<=new_dar_size,
temp_height<<=2;
);
resize(##index,1,temp_height,1,coordinates_and_iterations_array_size,0);
i[##index,h(##index)-1]=temp_value;
);
);
That allows me to reduce the number of resize. Is this proper? Another question, does da_push resize images unnecessarily even though the image that represents the dynamic array is greater than da_size()? Does this mean I have to use copy instead?
Right now, I made a different version of rep_rrd, and I’m so confused as to why my old code is faster.
Like, why is my latest subdivision method is slower than the older one?
array_subdivision(arg_coordinates)=(
arg_coordinates[iteration_index]!=$maximum_iteration?(
starting_coordinate=v(0,decrement_dimensions);
end_coordinate=starting_coordinate+dimensions;
part_coordinates=arg_coordinates[starting_coordinate,2,dimensions];
max_split_possible=int(calculate_distance(part_coordinates)/step_size);
max_split_possible-1?(
arg_coordinates[iteration_index]++;
split_count=v(2,min(max_split_possible,max_split_count));
end_point=1+part_coordinates[1]-(split_count-1)*step_size;
change_arr_size(modifiable_array_ind,split_count);
change_arr_size(unmodifiable_array_ind,split_count);
repeat(split_count-1,
left_coordinate=v(arg_coordinates[starting_coordinate]+step_size,end_point);
arg_coordinates[end_coordinate]=left_coordinate-1;
if(calc_probability()
,da_push(#modifiable_array_ind,arg_coordinates);
,da_push(#unmodifiable_array_ind,arg_coordinates);
);
arg_coordinates[starting_coordinate]=left_coordinate;
end_point+=step_size;
);
arg_coordinates[end_coordinate]=part_coordinates[1];
if(calc_probability()
,da_push(#modifiable_array_ind,arg_coordinates);
,da_push(#unmodifiable_array_ind,arg_coordinates);
);
):(
change_arr_size(unmodifiable_array_ind,1);
da_push(#unmodifiable_array_ind,arg_coordinates);
);
):(
change_arr_size(unmodifiable_array_ind,1);
da_push(#unmodifiable_array_ind,arg_coordinates);
);
);
Old one:
sub_column(info_vector,point)=(
ri=v(1,max_split,1,0)+1;
mri=ri-1;
sx=info_vector[0]+test_boundary;
ex=info_vector[1]-test_boundary;
diff=ex-sx;
bound_check=diff>test_boundary;
skip=0;
da_remove(#-2,point);
if(bound_check,
ds=diff/mri;
if(mri>1&&ds<=test_boundary,
while(mri>1&&ds<=test_boundary,
--ri;
--mri;
ds=diff/mri;
);
);
if(test_boundary||diff?(ds>test_boundary):1,
py=[info_vector[2],info_vector[3]];
iter=info_vector[4]+1;
p=info_vector[0];
repeat(ri,ri_ind,
rb=odd<1?u(0,1)>odd;
ri_ind==mri?(
if(p>info_vector[1],
p=info_vector[1];
if(!(info_vector[3]-info_vector[2]),rb=1;);
);
(rb||(iter==max_iter))?(
da_push(#-1,[p,info_vector[1],py,iter]);
):(
da_push(#-2,[p,info_vector[1],py,iter]);
);
):
!ri_ind?(
mx=sx+ds;
np=min(max(sx,round(u(p,mx))),ex);
vp=[p,np];
(rb||(iter==max_iter))?(
da_push(#-1,[vp,py,iter]);
):(
da_push(#-2,[vp,py,iter]);
);
p=np+1;
if(p>=ex,skip=1;);
):(
if(skip,continue(););
mx+=ds;
np=min(max(p+internal_space,round(u(p,mx))),ex);
vp=[min(p,ex),np];
(rb||(iter==max_iter))?(
da_push(#-1,[vp,py,iter]);
):(
da_push(#-2,[vp,py,iter]);
);
p=np+1;
);
);
,da_push(#-1,info_vector);
);
,da_push(#-1,info_vector);
);
);