Skip to content

Commit 8e4c7a4

Browse files
clatapiegerma89RobPasMue
authored
Aligning documentation with the other PyAnsys repositories (#77)
Co-authored-by: German <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 46388f0 commit 8e4c7a4

File tree

7 files changed

+118
-13
lines changed

7 files changed

+118
-13
lines changed

README.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ For users
4040
The ``ansys.math.core`` package currently supports Python 3.7 through
4141
Python 3.10 on Windows, Mac OS, and Linux.
4242

43+
.. warning::
44+
45+
``ansys.math.core`` will no longer support Python 3.7 by June 2023.
46+
47+
4348
Install the latest package for use with this command:
4449

4550
.. code::
@@ -77,7 +82,7 @@ Verify your installation
7782

7883
Check that you can start PyAnsys Math from Python by running this code:
7984

80-
.. code:: python
85+
.. code:: python3
8186
8287
import ansys.math.core.math as pymath
8388
File renamed without changes.
File renamed without changes.

doc/source/index.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ the NumPy and SciPy linear algebra solvers and the PyAnsys Math solver:
3333
+--------------------------------------------+-----------------------------------+
3434
| NumPy and SciPy | PyAnsys Math |
3535
+============================================+===================================+
36-
| .. code:: python | .. code:: python |
36+
| .. code:: python3 | .. code:: python3 |
3737
| | |
3838
| k_py = k + sparse.triu(k, 1).T | k = mm.matrix(k_py, triu=True) |
3939
| m_py = m + sparse.triu(m, 1).T | m = mm.matrix(m_py, triu=True) |
@@ -63,7 +63,7 @@ Quick code
6363

6464
Here is a brief example of how you use PyAnsys Math:
6565

66-
.. code:: python
66+
.. code:: python3
6767
6868
import ansys.math.core.math as pymath
6969
@@ -75,7 +75,9 @@ Here is a brief example of how you use PyAnsys Math:
7575
7676
print(w)
7777
78-
.. code:: output
78+
.. rst-class:: sphx-glr-script-out
79+
80+
.. code-block:: none
7981
8082
UDWZKD :
8183
Size : 5
@@ -90,6 +92,7 @@ For comprehensive PyAnsys Math examples, see :ref:`ref_pymath_examples`.
9092
:maxdepth: 1
9193

9294
getting_started/index
93-
api_ref/index
95+
user_guide/index
96+
api/index
9497
examples/index
9598
contributing/index

doc/source/user_guide/arrays.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
Handling arrays between PyAnsys Math and Python
3+
===============================================
4+
5+
6+
Sending arrays to PyAnsys Math
7+
------------------------------
8+
9+
.. code:: python3
10+
11+
import numpy as np
12+
import ansys.math.core.math as pymath
13+
14+
# Start PyAnsys Math as a service.
15+
mm = pymath.AnsMath()
16+
17+
a = np.random.random((2, 3))
18+
a_pymath = mm.matrix(a, name="A")
19+
20+
print(a_pymath)
21+
22+
.. rst-class:: sphx-glr-script-out
23+
24+
.. code-block:: none
25+
26+
A:
27+
[1,1]: 4.018e-01 [1,2]: 4.635e-01 [1,3]: 3.682e-01
28+
[2,1]: 9.711e-01 [2,2]: 7.601e-02 [2,3]: 8.833e-01
29+
30+
31+
32+
Transfer a PyAnsys Math matrix to NumPy
33+
---------------------------------------
34+
35+
.. code:: python3
36+
37+
a_python = a_pymath.asarray()
38+
print((a == a_python).all())
39+
40+
41+
.. rst-class:: sphx-glr-script-out
42+
43+
.. code-block:: none
44+
45+
True
46+
47+
48+
49+
50+

doc/source/user_guide/index.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. _ref_user_guide:
2+
3+
User guide
4+
==========
5+
6+
Overview
7+
--------
8+
9+
You can use the ``AnsMath()`` method to launch an instance of PyAnsys Math.
10+
11+
.. code:: python3
12+
13+
import ansys.math.core.math as pymath
14+
15+
# Start PyAnsys Math.
16+
mm = pymath.AnsMath()
17+
print(mm)
18+
19+
.. rst-class:: sphx-glr-script-out
20+
21+
.. code-block:: none
22+
23+
APDLMATH PARAMETER STATUS- ( 0 PARAMETERS DEFINED)
24+
25+
Name Type Mem. (MB) Dims Workspace
26+
27+
.. toctree::
28+
:hidden:
29+
:maxdepth: 1
30+
31+
arrays.rst

src/ansys/math/core/math.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,20 @@ def dot(self, vec) -> float:
14941494
self._mapdl.run(f"*DOT,{self.id},{vec.id},py_val")
14951495
return self._mapdl.scalar_param("py_val")
14961496

1497-
def asarray(self) -> np.ndarray:
1498-
"""Return this vector as a NumPy array.
1497+
def asarray(self, dtype=None) -> np.ndarray:
1498+
"""Return the vector as a NumPy array.
1499+
1500+
Parameters
1501+
----------
1502+
dtype : numpy.dtype, optional
1503+
NumPy data type to upload the array as. The options are `np.double <numpy.double>`_,
1504+
`np.int32 <numpy.int32>`_, and `np.int64 <numpy.int64>`_. The default is the current array
1505+
type.
1506+
1507+
Returns
1508+
-------
1509+
np.ndarray
1510+
NumPy array with the defined data type.
14991511
15001512
Examples
15011513
--------
@@ -1504,8 +1516,12 @@ def asarray(self) -> np.ndarray:
15041516
>>> v = mm.ones(10)
15051517
>>> v.asarray()
15061518
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
1519+
>>> v.asarray(dtype=np.int32)
1520+
[1 1 1 1 1 1 1 1 1 1]
1521+
15071522
"""
1508-
return self._mapdl._vec_data(self.id)
1523+
vec_data = self._mapdl._vec_data(self.id)
1524+
return vec_data.astype(dtype) if dtype else vec_data
15091525

15101526
def __array__(self):
15111527
"""Allow NumPy to access this object as if it was an array."""
@@ -1567,7 +1583,7 @@ def sym(self) -> bool:
15671583
return True
15681584

15691585
def asarray(self, dtype=None) -> np.ndarray:
1570-
"""Return the vector as a NumPy array.
1586+
"""Return the matrix as a NumPy array.
15711587
15721588
Parameters
15731589
----------
@@ -1585,11 +1601,11 @@ def asarray(self, dtype=None) -> np.ndarray:
15851601
--------
15861602
>>> import ansys.math.core.math as pymath
15871603
>>> mm = pymath.AnsMath()
1588-
>>> v = mm.ones(10)
1604+
>>> v = mm.ones(2,2)
15891605
>>> v.asarray()
1590-
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
1591-
>>> v.asarray(dtype=np.int)
1592-
[1 1 1 1 1 1 1 1 1 1]
1606+
array([[1., 1.], [1., 1.]])
1607+
>>> v.asarray(dtype=np.int32)
1608+
array([[1, 1], [1, 1]])
15931609
15941610
"""
15951611
if dtype:

0 commit comments

Comments
 (0)