Skip to content

Type conversion in inits is not working as intended #264

@MartinuzziFrancesco

Description

@MartinuzziFrancesco

Describe the bug

Type conversion in the initializers doesn't work as expected. It is fine for default arguments, but fails when user gives ie a Float64 as scaling while the matrix is supposed to be Float32.

Expected behavior

Matrix type should not be changed by the weight/scaling/other keyword optional changes made by the user.

Minimal Reproducible Example

julia> sr = scaled_rand(5, 5) # all good here, default kwargs 
5×5 Matrix{Float32}:
 -0.0669356   0.0944272  -0.0191563   0.0934286   0.0190222
  0.0159724  -0.0799005   0.0279123  -0.0188943   0.0148647
  0.026355   -0.0970182   0.0567368  -0.0737949  -0.0444782
 -0.0177412  -0.0292692   0.0679244   0.0714962   0.03553
 -0.0184405   0.004071   -0.0891089   0.0892906  -0.0399615

julia> sr = scaled_rand(5, 5; scaling = 0.5) #user gives a Float64 as kwarg, but matrix should still be Float32 (default value)
5×5 Matrix{Float64}:
 -0.334678    0.472136  -0.0957814   0.467143    0.0951111
  0.0798621  -0.399503   0.139562   -0.0944713   0.0743235
  0.131775   -0.485091   0.283684   -0.368974   -0.222391
 -0.0887059  -0.146346   0.339622    0.357481    0.17765
 -0.0922025   0.020355  -0.445545    0.446453   -0.199807

Potential solution

Just change type conversion instead of being here to be directly on the computations (here)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomersinitsinitializers for internal matrices

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions