Skip to content

Commit

Permalink
Merge pull request #83 from jonnor/no-double
Browse files Browse the repository at this point in the history
Avoid double precision operations
  • Loading branch information
Zepan authored Jan 29, 2025
2 parents 4e7aadd + 7bcb087 commit 943b4df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tm_layers.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ tm_err_t TM_WEAK tml_softmax(tm_mat_t* in, tm_mat_t* out, sctype_t in_s, zptype_
dout[c] -= dmax;
dout[c] = (float)tm_exp(dout[c]);
sum += dout[c];
dout[c] -= 0.000001; //prevent 1.0 value (cause 256 overflow)
dout[c] -= 0.000001f; //prevent 1.0 value (cause 256 overflow)
}
for(int c=0; c <in->c; c++){ //int8/int16 <= fp32, so it is ok
#if TM_MDL_TYPE == TM_MDL_INT8 || TM_MDL_TYPE == TM_MDL_INT16
Expand Down
4 changes: 2 additions & 2 deletions src/tm_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ tm_err_t TM_WEAK tm_preprocess(tm_mdl_t* mdl, tm_pp_t pp_type, tm_mat_t* in, tm_
#else
case TMPP_UINT2FP01:
for(int i=0; i<in_size; i++)
out->data[i] = (((uint8_t*)(in->data))[i])/255.0;
out->data[i] = (((uint8_t*)(in->data))[i])/255.0f;
break;
case TMPP_UINT2FPN11:
for(int i=0; i<in_size; i++)
out->data[i] = ((((uint8_t*)(in->data))[i])-128)/128.0;
out->data[i] = ((((uint8_t*)(in->data))[i])-128)/128.0f;
break;
#endif
default: //don't do anything
Expand Down

0 comments on commit 943b4df

Please sign in to comment.