+
Skip to content

early and informative exception when passing a non-scalar func to solver.optimize #753

Open
@joostvanzwieten

Description

@joostvanzwieten

solver.optimize requires a scalar function. If provided with a function that has one dimension or more, than solver.optimize (or actually sparse.take) spits out an error message that is not very helpful to end users. Example:

from nutils import function, solver
solver.optimize('x', function.Argument('x', (1,))**2)

Traceback:

Traceback (most recent call last):
  File "solver.py", line 834, in optimize
    val, res, jac = _integrate_blocks(functional, residual, jacobian, arguments=lhs, mask=mask)
  File "nutils/solver.py", line 981, in _integrate_blocks
    res = [sparse.take(next(data), [m]) for m in mask]
  File "nutils/solver.py", line 981, in <listcomp>
    res = [sparse.take(next(data), [m]) for m in mask]
  File "nutils/sparse.py", line 290, in take
    assert axis == len(shape)
AssertionError

Let's raise an early (don't traverse into _integrate_blocks) and informative exception instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载