メインコンテンツへスキップ

Python matrix api with non-writable numpy float64 array error: buffer source array is read-only

回答済み

コメント

4件のコメント

  • Riley Clement
    • Gurobi Staff Gurobi Staff

    Hi Sean, 

    I'll ask our dev team to take a look.  Which version of gurobipy are you using?

    Thanks,
    Riley

    0
  • Sean Ma
    • First Comment
    • First Question

    Thanks Riley. Gurobipy version: '12.0.0'. 

    0
  • Riley Clement
    • Gurobi Staff Gurobi Staff

    Hi Sean,

    I can confirm this is unintended behavior and we've added an item to our development backlog to patch it in a future release.

    We don't do the calculation in place, and we don't modify the array, but we haven't promised the compiler that we won't modify it either so we get an error when the float64 array has flags.writeable=False.

    Are you running into this problem in production, or was this just to demonstrate the bug for us?

    If you need to keep flags.writeable=True and consequently need a workaround there's a couple of options.  For this specific example, (c*v).sum() is the dot product and is equivalent to c@v, and this latter form does not produce the error (and is faster to build).

    Otherwise you can use the array's copy function to produce a temporary copy which by default will have flags.writeable=True, i.e.

    model.setObjective((c.copy() * v).sum(), gp.GRB.MINIMIZE)

    Thanks,
    Riley

     

    0
  • Sean Ma
    • First Comment
    • First Question

    Thanks Riley for the quick response. 

    Some data manipulation using pandas / polars DataFrame will lead to flags.writable=False. 

    I am currently using the array's copy as a workaround. 

    0

サインインしてコメントを残してください。