daphne-eu / daphne

DAPHNE: An Open and Extensible System Infrastructure for Integrated Data Analysis Pipelines
Apache License 2.0
67 stars 62 forks source link

Daphne Lib - l1 norm calculation #778

Closed BacchusX1 closed 4 months ago

BacchusX1 commented 4 months ago

I would like to calculate the L1 norm in daphne-lib like that:

test_temp = np.array([0, 1, 2, 3, 4, 5])
support_temp = np.array([1, 2, 3, 4, 5, 6])

a = dc.from_numpy(test_temp)
b = dc.from_numpy(support_temp)

c = a - b

c_numpy = c.abs().sum().compute()

Output:

AttributeError: 'Matrix' object has no attribute 'abs'

For my understanding https://github.com/daphne-eu/daphne/blob/main/doc/DaphneLib/APIRef.md abs() should be available.

So I tried:

test_temp = np.array([0, 1, 2, 3, 4, 5])
support_temp = np.array([0, 1, 2, 3, 4, 5])

a = dc.from_numpy(test_temp)
b = dc.from_numpy(support_temp)

c = a - b

c = c**2
c_numpy = c.sqrt().sum().compute()

Output:

TypeError: unsupported operand type(s) for ** or pow(): 'Matrix' and 'int'

Any suggestions how to do that?

LG Bernhard

pdamme commented 4 months ago

Hi @BacchusX1, your scripts are valid. On the current main branch of DAPHNE they pass successfully, i.e., when doing print(c_numpy), the first script prints 6, the second one 0.0. Support for abs() on DaphneLib matrices was added in 2c1b7013dfea7e7ad839b40a93bbb10cb6edd9b2 in Sep 2023. Could it be that you use an outdated version of DAPHNE, e.g., the v0.2 release? If so, please try using the current state of the main branch, e.g., by following the quickstart guide for developers.

BacchusX1 commented 4 months ago

Yes that was the issue