Coverage for picos/tools.py: 87.50%

16 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-03-26 07:46 +0000

1# ------------------------------------------------------------------------------ 

2# Copyright (C) 2020 Maximilian Stahlberg 

3# 

4# This file is part of PICOS. 

5# 

6# PICOS is free software: you can redistribute it and/or modify it under the 

7# terms of the GNU General Public License as published by the Free Software 

8# Foundation, either version 3 of the License, or (at your option) any later 

9# version. 

10# 

11# PICOS is distributed in the hope that it will be useful, but WITHOUT ANY 

12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 

13# A PARTICULAR PURPOSE. See the GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License along with 

16# this program. If not, see <http://www.gnu.org/licenses/>. 

17# ------------------------------------------------------------------------------ 

18 

19"""Backwards compatibility version of an older module.""" 

20 

21from .apidoc import api_end, api_start 

22from .expressions.data import load_data 

23from .legacy import deprecated, throw_deprecation_warning 

24 

25# Deprecated as of 2.0. 

26throw_deprecation_warning("The 'picos.tools' module is deprecated and will be " 

27 "removed in a future release. Try importing from 'picos' or 'picos.algebra'" 

28 "instead.") 

29 

30_API_START = api_start(globals()) 

31# ------------------------------- 

32 

33 

34from builtins import sum as builtin_sum # noqa 

35 

36from . import ( # noqa 

37 sum, geomean, norm, tracepow, trace, sum_k_largest, sum_k_largest_lambda, 

38 lambda_max, sum_k_smallest, sum_k_smallest_lambda, lambda_min, 

39 partial_transpose, partial_trace, detrootn, ball, simplex, 

40 truncated_simplex, expcone, exp, log, sumexp, kullback_leibler, logsumexp, 

41 lse, diag, diag_vect, new_param, import_cbf, kron, flow_Constraint 

42) 

43 

44from .formatting import ( # noqa 

45 detect_range, parameterized_string 

46) 

47 

48 

49@deprecated("2.0", reason="Write '{k: v.value for k, v in x.items()}' instead.") 

50def eval_dict(dict_of_variables): 

51 """Evaluate all values of a dictionary. 

52 

53 :param dict dict_of_variables: 

54 A dictionary mapping arbitrary keys to PICOS objects that have a 

55 ``value`` attribute, such as variables. 

56 

57 :returns: 

58 Another dictionary with the original dicitonary's values replaced by the 

59 value of their ``value`` attribute. 

60 """ 

61 return {k: v.value for k, v in dict_of_variables.items()} 

62 

63 

64@deprecated("2.0", useInstead="picos.expressions.data.load_data") 

65def retrieve_matrix(mat, exSize=None): 

66 """Legacy wrapper around :func:`~.expressions.data.load_data`.""" 

67 return load_data(value=mat, shape=exSize, sparse=True, legacy=True) 

68 

69 

70# -------------------------------------- 

71__all__ = api_end(_API_START, globals())