or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-operations.mdcuda-integration.mdcustom-kernels.mdfft.mdindex.mdio-operations.mdjit-compilation.mdlinear-algebra.mdmathematical-functions.mdperformance-profiling.mdpolynomial-operations.mdrandom.mdscipy-extensions.md

mathematical-functions.mddocs/

0

# Mathematical Functions

1

2

CuPy provides comprehensive mathematical functions for GPU-accelerated computation, offering NumPy-compatible trigonometric, hyperbolic, exponential, logarithmic, arithmetic, and statistical operations optimized for CUDA and ROCm platforms.

3

4

## Capabilities

5

6

### Trigonometric Functions

7

8

GPU-accelerated trigonometric functions supporting both scalar and array inputs with element-wise operations.

9

10

```python { .api }

11

def sin(x, out=None):

12

"""

13

Trigonometric sine, element-wise.

14

15

Parameters:

16

x: array_like - Input array in radians

17

out: ndarray, optional - Output array of the same shape as x

18

"""

19

20

def cos(x, out=None):

21

"""

22

Cosine element-wise.

23

24

Parameters:

25

x: array_like - Input array in radians

26

out: ndarray, optional - Output array of the same shape as x

27

"""

28

29

def tan(x, out=None):

30

"""

31

Compute tangent element-wise.

32

33

Parameters:

34

x: array_like - Input array in radians

35

out: ndarray, optional - Output array of the same shape as x

36

"""

37

38

def arcsin(x, out=None):

39

"""

40

Inverse sine, element-wise.

41

42

Parameters:

43

x: array_like - y-coordinate on the unit circle

44

out: ndarray, optional - Output array of the same shape as x

45

"""

46

47

def arccos(x, out=None):

48

"""

49

Trigonometric inverse cosine, element-wise.

50

51

Parameters:

52

x: array_like - x-coordinate on the unit circle

53

out: ndarray, optional - Output array of the same shape as x

54

"""

55

56

def arctan(x, out=None):

57

"""

58

Trigonometric inverse tangent, element-wise.

59

60

Parameters:

61

x: array_like - Input values

62

out: ndarray, optional - Output array of the same shape as x

63

"""

64

65

def arctan2(x1, x2, out=None):

66

"""

67

Element-wise arc tangent of x1/x2 choosing the quadrant correctly.

68

69

Parameters:

70

x1: array_like, real-valued - y-coordinates

71

x2: array_like, real-valued - x-coordinates

72

out: ndarray, optional - Output array of same shape as x1 and x2

73

"""

74

75

def hypot(x1, x2, out=None):

76

"""

77

Given the "legs" of a right triangle, return its hypotenuse.

78

79

Parameters:

80

x1, x2: array_like - Leg of the triangle(s)

81

out: ndarray, optional - Output array of same shape as x1 and x2

82

"""

83

84

def degrees(x, out=None):

85

"""

86

Convert angles from radians to degrees.

87

88

Parameters:

89

x: array_like - Input array in radians

90

out: ndarray, optional - Output array of same shape as x

91

"""

92

93

def radians(x, out=None):

94

"""

95

Convert angles from degrees to radians.

96

97

Parameters:

98

x: array_like - Input array in degrees

99

out: ndarray, optional - Output array of same shape as x

100

"""

101

102

def deg2rad(x, out=None):

103

"""

104

Convert angles from degrees to radians.

105

106

Parameters:

107

x: array_like - Angles in degrees

108

out: ndarray, optional - Output array of same shape as x

109

"""

110

111

def rad2deg(x, out=None):

112

"""

113

Convert angles from radians to degrees.

114

115

Parameters:

116

x: array_like - Angles in radians

117

out: ndarray, optional - Output array of same shape as x

118

"""

119

120

def unwrap(p, discont=3.141592653589793, axis=-1):

121

"""

122

Unwrap by changing deltas between values to 2*pi complement.

123

124

Parameters:

125

p: array_like - Input array

126

discont: float, optional - Maximum discontinuity between values (default is pi)

127

axis: int, optional - Axis along which unwrap will operate (default is -1)

128

"""

129

```

130

131

### Hyperbolic Functions

132

133

GPU-accelerated hyperbolic trigonometric functions for mathematical computation.

134

135

```python { .api }

136

def sinh(x, out=None):

137

"""

138

Hyperbolic sine, element-wise.

139

140

Parameters:

141

x: array_like - Input array

142

out: ndarray, optional - Output array of the same shape as x

143

"""

144

145

def cosh(x, out=None):

146

"""

147

Hyperbolic cosine, element-wise.

148

149

Parameters:

150

x: array_like - Input array

151

out: ndarray, optional - Output array of the same shape as x

152

"""

153

154

def tanh(x, out=None):

155

"""

156

Compute hyperbolic tangent element-wise.

157

158

Parameters:

159

x: array_like - Input array

160

out: ndarray, optional - Output array of the same shape as x

161

"""

162

163

def arcsinh(x, out=None):

164

"""

165

Inverse hyperbolic sine element-wise.

166

167

Parameters:

168

x: array_like - Input array

169

out: ndarray, optional - Output array of the same shape as x

170

"""

171

172

def arccosh(x, out=None):

173

"""

174

Inverse hyperbolic cosine, element-wise.

175

176

Parameters:

177

x: array_like - Input array

178

out: ndarray, optional - Output array of the same shape as x

179

"""

180

181

def arctanh(x, out=None):

182

"""

183

Inverse hyperbolic tangent element-wise.

184

185

Parameters:

186

x: array_like - Input array

187

out: ndarray, optional - Output array of the same shape as x

188

"""

189

```

190

191

### Exponential and Logarithmic Functions

192

193

Functions for exponential and logarithmic calculations optimized for GPU computation.

194

195

```python { .api }

196

def exp(x, out=None):

197

"""

198

Calculate the exponential of all elements in the input array.

199

200

Parameters:

201

x: array_like - Input values

202

out: ndarray, optional - Output array of same shape as x

203

"""

204

205

def exp2(x, out=None):

206

"""

207

Calculate 2**p for all p in the input array.

208

209

Parameters:

210

x: array_like - Input values

211

out: ndarray, optional - Output array of same shape as x

212

"""

213

214

def expm1(x, out=None):

215

"""

216

Calculate exp(x) - 1 for all elements in the array.

217

218

Parameters:

219

x: array_like - Input values

220

out: ndarray, optional - Output array of same shape as x

221

"""

222

223

def log(x, out=None):

224

"""

225

Natural logarithm, element-wise.

226

227

Parameters:

228

x: array_like - Input values

229

out: ndarray, optional - Output array of same shape as x

230

"""

231

232

def log10(x, out=None):

233

"""

234

Return the base 10 logarithm of the input array, element-wise.

235

236

Parameters:

237

x: array_like - Input values

238

out: ndarray, optional - Output array of same shape as x

239

"""

240

241

def log2(x, out=None):

242

"""

243

Base-2 logarithm of x.

244

245

Parameters:

246

x: array_like - Input values

247

out: ndarray, optional - Output array of same shape as x

248

"""

249

250

def log1p(x, out=None):

251

"""

252

Return the natural logarithm of one plus the input array, element-wise.

253

254

Parameters:

255

x: array_like - Input values

256

out: ndarray, optional - Output array of same shape as x

257

"""

258

259

def logaddexp(x1, x2, out=None):

260

"""

261

Logarithm of the sum of exponentials of the inputs.

262

263

Parameters:

264

x1, x2: array_like - Input arrays

265

out: ndarray, optional - Output array of same shape as x1 and x2

266

"""

267

268

def logaddexp2(x1, x2, out=None):

269

"""

270

Logarithm of the sum of exponentials of the inputs in base-2.

271

272

Parameters:

273

x1, x2: array_like - Input arrays

274

out: ndarray, optional - Output array of same shape as x1 and x2

275

"""

276

```

277

278

### Arithmetic Functions

279

280

Core arithmetic operations supporting element-wise computation on GPU arrays.

281

282

```python { .api }

283

def add(x1, x2, out=None):

284

"""

285

Add arguments element-wise.

286

287

Parameters:

288

x1, x2: array_like - Input arrays to be added

289

out: ndarray, optional - Output array of same shape as x1 and x2

290

"""

291

292

def subtract(x1, x2, out=None):

293

"""

294

Subtract arguments, element-wise.

295

296

Parameters:

297

x1, x2: array_like - Input arrays to be subtracted

298

out: ndarray, optional - Output array of same shape as x1 and x2

299

"""

300

301

def multiply(x1, x2, out=None):

302

"""

303

Multiply arguments element-wise.

304

305

Parameters:

306

x1, x2: array_like - Input arrays to be multiplied

307

out: ndarray, optional - Output array of same shape as x1 and x2

308

"""

309

310

def divide(x1, x2, out=None):

311

"""

312

Divide arguments element-wise.

313

314

Parameters:

315

x1: array_like - Dividend array

316

x2: array_like - Divisor array

317

out: ndarray, optional - Output array of same shape as x1 and x2

318

"""

319

320

def true_divide(x1, x2, out=None):

321

"""

322

Returns a true division of the inputs, element-wise.

323

324

Parameters:

325

x1: array_like - Dividend array

326

x2: array_like - Divisor array

327

out: ndarray, optional - Output array of same shape as x1 and x2

328

"""

329

330

def floor_divide(x1, x2, out=None):

331

"""

332

Return the largest integer smaller or equal to the division of the inputs.

333

334

Parameters:

335

x1: array_like - Numerator

336

x2: array_like - Denominator

337

out: ndarray, optional - Output array of same shape as x1 and x2

338

"""

339

340

def power(x1, x2, out=None):

341

"""

342

First array elements raised to powers from second array, element-wise.

343

344

Parameters:

345

x1: array_like - Base values

346

x2: array_like - Exponents

347

out: ndarray, optional - Output array of same shape as x1 and x2

348

"""

349

350

def float_power(x1, x2, out=None):

351

"""

352

First array elements raised to powers from second array, element-wise.

353

354

Parameters:

355

x1: array_like - Base values

356

x2: array_like - Exponents

357

out: ndarray, optional - Output array of same shape as x1 and x2

358

"""

359

360

def mod(x1, x2, out=None):

361

"""

362

Return element-wise remainder of division.

363

364

Parameters:

365

x1: array_like - Dividend

366

x2: array_like - Divisor

367

out: ndarray, optional - Output array of same shape as x1 and x2

368

"""

369

370

def remainder(x1, x2, out=None):

371

"""

372

Return element-wise remainder of division.

373

374

Parameters:

375

x1: array_like - Dividend

376

x2: array_like - Divisor

377

out: ndarray, optional - Output array of same shape as x1 and x2

378

"""

379

380

def divmod(x1, x2):

381

"""

382

Return element-wise quotient and remainder simultaneously.

383

384

Parameters:

385

x1: array_like - Dividend

386

x2: array_like - Divisor

387

"""

388

389

def fmod(x1, x2, out=None):

390

"""

391

Return the element-wise remainder of division.

392

393

Parameters:

394

x1: array_like - Dividend

395

x2: array_like - Divisor

396

out: ndarray, optional - Output array of same shape as x1 and x2

397

"""

398

399

def modf(x, out=None):

400

"""

401

Return the fractional and integral parts of an array, element-wise.

402

403

Parameters:

404

x: array_like - Input array

405

out: ndarray, optional - Output array for fractional part, same shape as x

406

"""

407

408

def negative(x, out=None):

409

"""

410

Numerical negative, element-wise.

411

412

Parameters:

413

x: array_like - Input array

414

out: ndarray, optional - Output array of same shape as x

415

"""

416

417

def positive(x, out=None):

418

"""

419

Numerical positive, element-wise.

420

421

Parameters:

422

x: array_like - Input array

423

out: ndarray, optional - Output array of same shape as x

424

"""

425

426

def absolute(x, out=None):

427

"""

428

Calculate the absolute value element-wise.

429

430

Parameters:

431

x: array_like - Input array

432

out: ndarray, optional - Output array of same shape as x

433

"""

434

435

def abs(x, out=None):

436

"""

437

Calculate the absolute value element-wise.

438

439

Parameters:

440

x: array_like - Input array

441

out: ndarray, optional - Output array of same shape as x

442

"""

443

444

def reciprocal(x, out=None):

445

"""

446

Return the reciprocal of the argument, element-wise.

447

448

Parameters:

449

x: array_like - Input array

450

out: ndarray, optional - Output array of same shape as x

451

"""

452

453

def sign(x, out=None):

454

"""

455

Returns an element-wise indication of the sign of a number.

456

457

Parameters:

458

x: array_like - Input values

459

out: ndarray, optional - Output array of same shape as x

460

"""

461

```

462

463

### Rounding Functions

464

465

Functions for rounding floating-point values to integers or specified decimal places.

466

467

```python { .api }

468

def around(a, decimals=0, out=None):

469

"""

470

Round an array to the given number of decimals.

471

472

Parameters:

473

a: array_like - Input data

474

decimals: int, optional - Number of decimal places to round to (default is 0)

475

out: ndarray, optional - Alternative output array

476

"""

477

478

def round(a, decimals=0, out=None):

479

"""

480

Round an array to the given number of decimals.

481

482

Parameters:

483

a: array_like - Input data

484

decimals: int, optional - Number of decimal places to round to (default is 0)

485

out: ndarray, optional - Alternative output array

486

"""

487

488

def rint(x, out=None):

489

"""

490

Round elements of the array to the nearest integer.

491

492

Parameters:

493

x: array_like - Input array

494

out: ndarray, optional - Output array of same shape as x

495

"""

496

497

def fix(x, out=None):

498

"""

499

Round to nearest integer towards zero.

500

501

Parameters:

502

x: array_like - Input values

503

out: ndarray, optional - Output array of same shape as x

504

"""

505

506

def floor(x, out=None):

507

"""

508

Return the floor of the input, element-wise.

509

510

Parameters:

511

x: array_like - Input data

512

out: ndarray, optional - Output array of same shape as x

513

"""

514

515

def ceil(x, out=None):

516

"""

517

Return the ceiling of the input, element-wise.

518

519

Parameters:

520

x: array_like - Input data

521

out: ndarray, optional - Output array of same shape as x

522

"""

523

524

def trunc(x, out=None):

525

"""

526

Return the truncated value of the input, element-wise.

527

528

Parameters:

529

x: array_like - Input data

530

out: ndarray, optional - Output array of same shape as x

531

"""

532

```

533

534

### Sums, Products, and Differences

535

536

Reduction operations and difference calculations for array analysis.

537

538

```python { .api }

539

def sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True):

540

"""

541

Sum of array elements over a given axis.

542

543

Parameters:

544

a: array_like - Elements to sum

545

axis: None or int or tuple of ints, optional - Axis or axes along which a sum is performed

546

dtype: dtype, optional - Type of the returned array and of the accumulator

547

out: ndarray, optional - Alternative output array

548

keepdims: bool, optional - If this is set to True, the axes which are reduced are left in the result as dimensions with size one

549

initial: scalar, optional - Starting value for the sum (default is 0)

550

where: array_like of bool, optional - Elements to include in the sum

551

"""

552

553

def prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=1, where=True):

554

"""

555

Return the product of array elements over a given axis.

556

557

Parameters:

558

a: array_like - Input data

559

axis: None or int or tuple of ints, optional - Axis or axes along which a product is performed

560

dtype: dtype, optional - Type of the returned array

561

out: ndarray, optional - Alternative output array

562

keepdims: bool, optional - If this is set to True, the axes which are reduced are left in the result

563

initial: scalar, optional - Starting value for the product (default is 1)

564

where: array_like of bool, optional - Elements to include in the product

565

"""

566

567

def cumsum(a, axis=None, dtype=None, out=None):

568

"""

569

Return the cumulative sum of the elements along a given axis.

570

571

Parameters:

572

a: array_like - Input array

573

axis: int, optional - Axis along which the cumulative sum is computed (default is None)

574

dtype: dtype, optional - Type of the returned array

575

out: ndarray, optional - Alternative output array

576

"""

577

578

def cumprod(a, axis=None, dtype=None, out=None):

579

"""

580

Return the cumulative product of elements along a given axis.

581

582

Parameters:

583

a: array_like - Input array

584

axis: int, optional - Axis along which the cumulative product is computed (default is None)

585

dtype: dtype, optional - Type of the returned array

586

out: ndarray, optional - Alternative output array

587

"""

588

589

def diff(a, n=1, axis=-1, prepend=None, append=None):

590

"""

591

Calculate the n-th discrete difference along the given axis.

592

593

Parameters:

594

a: array_like - Input array

595

n: int, optional - Number of times values are differenced (default is 1)

596

axis: int, optional - Axis along which the difference is taken (default is -1)

597

prepend, append: array_like, optional - Values to prepend or append to a along axis

598

"""

599

600

def ediff1d(ary, to_end=None, to_begin=None):

601

"""

602

The differences between consecutive elements of an array.

603

604

Parameters:

605

ary: array_like - Input array, will be flattened before the differences are taken

606

to_end: array_like, optional - Number(s) to append at the end of the returned differences

607

to_begin: array_like, optional - Number(s) to prepend at the beginning of the returned differences

608

"""

609

610

def gradient(f, *varargs, axis=None, edge_order=1):

611

"""

612

Return the gradient of an N-dimensional array.

613

614

Parameters:

615

f: array_like - Input array

616

varargs: list of scalar or array, optional - Spacing between f values

617

axis: None or int or tuple of ints, optional - Gradient is calculated only along the given axis or axes

618

edge_order: int, optional - Gradient is calculated using N-th order accurate differences at the boundaries

619

"""

620

621

def trapz(y, x=None, dx=1.0, axis=-1):

622

"""

623

Integrate along the given axis using the composite trapezoidal rule.

624

625

Parameters:

626

y: array_like - Input array to integrate

627

x: array_like, optional - Sample points corresponding to the y values

628

dx: scalar, optional - Spacing between sample points when x is None (default is 1.0)

629

axis: int, optional - Axis along which to integrate (default is -1)

630

"""

631

632

def nansum(a, axis=None, dtype=None, out=None, keepdims=False):

633

"""

634

Return the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

635

636

Parameters:

637

a: array_like - Array containing numbers whose sum is desired

638

axis: None or int or tuple of ints, optional - Axis or axes along which the sum is computed

639

dtype: dtype, optional - Type of the returned array and of the accumulator

640

out: ndarray, optional - Alternative output array

641

keepdims: bool, optional - If this is set to True, the axes which are reduced are left in the result

642

"""

643

644

def nanprod(a, axis=None, dtype=None, out=None, keepdims=False):

645

"""

646

Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.

647

648

Parameters:

649

a: array_like - Array containing numbers whose product is desired

650

axis: None or int or tuple of ints, optional - Axis or axes along which the product is computed

651

dtype: dtype, optional - Type of the returned array and of the accumulator

652

out: ndarray, optional - Alternative output array

653

keepdims: bool, optional - If this is set to True, the axes which are reduced are left in the result

654

"""

655

656

def nancumsum(a, axis=None, dtype=None, out=None):

657

"""

658

Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

659

660

Parameters:

661

a: array_like - Input array

662

axis: int, optional - Axis along which the cumulative sum is computed

663

dtype: dtype, optional - Type of the returned array

664

out: ndarray, optional - Alternative output array

665

"""

666

667

def nancumprod(a, axis=None, dtype=None, out=None):

668

"""

669

Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one.

670

671

Parameters:

672

a: array_like - Input array

673

axis: int, optional - Axis along which the cumulative product is computed

674

dtype: dtype, optional - Type of the returned array

675

out: ndarray, optional - Alternative output array

676

"""

677

```

678

679

### Complex Number Functions

680

681

Functions for working with complex numbers and their components.

682

683

```python { .api }

684

def angle(z, deg=False):

685

"""

686

Return the angle of the complex argument.

687

688

Parameters:

689

z: array_like - Input array

690

deg: bool, optional - Return angle in degrees if True, radians if False (default)

691

"""

692

693

def real(val):

694

"""

695

Return the real part of the complex argument.

696

697

Parameters:

698

val: array_like - Input array

699

"""

700

701

def imag(val):

702

"""

703

Return the imaginary part of the complex argument.

704

705

Parameters:

706

val: array_like - Input array

707

"""

708

709

def conj(x, out=None):

710

"""

711

Return the complex conjugate, element-wise.

712

713

Parameters:

714

x: array_like - Input values

715

out: ndarray, optional - Output array of same shape as x

716

"""

717

718

def conjugate(x, out=None):

719

"""

720

Return the complex conjugate, element-wise.

721

722

Parameters:

723

x: array_like - Input values

724

out: ndarray, optional - Output array of same shape as x

725

"""

726

```

727

728

### Miscellaneous Mathematical Functions

729

730

Additional mathematical utilities and special functions.

731

732

```python { .api }

733

def clip(a, a_min, a_max, out=None):

734

"""

735

Clip (limit) the values in an array.

736

737

Parameters:

738

a: array_like - Array containing elements to clip

739

a_min: scalar or array_like or None - Minimum value

740

a_max: scalar or array_like or None - Maximum value

741

out: ndarray, optional - Results will be placed in this array

742

"""

743

744

def sqrt(x, out=None):

745

"""

746

Return the non-negative square-root of an array, element-wise.

747

748

Parameters:

749

x: array_like - Values whose square-roots are required

750

out: ndarray, optional - Output array of same shape as x

751

"""

752

753

def cbrt(x, out=None):

754

"""

755

Return the cube-root of an array, element-wise.

756

757

Parameters:

758

x: array_like - Input values

759

out: ndarray, optional - Output array of same shape as x

760

"""

761

762

def square(x, out=None):

763

"""

764

Return the element-wise square of the input.

765

766

Parameters:

767

x: array_like - Input data

768

out: ndarray, optional - Output array of same shape as x

769

"""

770

771

def fabs(x, out=None):

772

"""

773

Compute the absolute values element-wise.

774

775

Parameters:

776

x: array_like - Input values

777

out: ndarray, optional - Output array of same shape as x

778

"""

779

780

def maximum(x1, x2, out=None):

781

"""

782

Element-wise maximum of array elements.

783

784

Parameters:

785

x1, x2: array_like - Input arrays holding the elements to be compared

786

out: ndarray, optional - Output array of same shape as x1 and x2

787

"""

788

789

def minimum(x1, x2, out=None):

790

"""

791

Element-wise minimum of array elements.

792

793

Parameters:

794

x1, x2: array_like - Input arrays holding the elements to be compared

795

out: ndarray, optional - Output array of same shape as x1 and x2

796

"""

797

798

def fmax(x1, x2, out=None):

799

"""

800

Element-wise maximum of array elements.

801

802

Parameters:

803

x1, x2: array_like - Input arrays holding the elements to be compared

804

out: ndarray, optional - Output array of same shape as x1 and x2

805

"""

806

807

def fmin(x1, x2, out=None):

808

"""

809

Element-wise minimum of array elements.

810

811

Parameters:

812

x1, x2: array_like - Input arrays holding the elements to be compared

813

out: ndarray, optional - Output array of same shape as x1 and x2

814

"""

815

816

def heaviside(x1, x2, out=None):

817

"""

818

Compute the Heaviside step function.

819

820

Parameters:

821

x1: array_like - Input values

822

x2: array_like - Value of the function when x1 is 0

823

out: ndarray, optional - Output array of same shape as x1 and x2

824

"""

825

826

def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):

827

"""

828

Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.

829

830

Parameters:

831

x: array_like - Input data

832

copy: bool, optional - Whether to create a copy of x (default is True)

833

nan: int, float, optional - Value to be used to fill NaN values (default is 0.0)

834

posinf: int, float, optional - Value to be used to fill positive infinity values

835

neginf: int, float, optional - Value to be used to fill negative infinity values

836

"""

837

838

def real_if_close(a, tol=100):

839

"""

840

If complex input returns a real array if complex parts are close to zero.

841

842

Parameters:

843

a: array_like - Input array

844

tol: float - Tolerance in machine epsilons for the complex part of the elements in the array (default is 100)

845

"""

846

847

def interp(x, xp, fp, left=None, right=None, period=None):

848

"""

849

One-dimensional linear interpolation for monotonically increasing sample points.

850

851

Parameters:

852

x: array_like - x-coordinates at which to evaluate the interpolated values

853

xp: 1-D sequence of floats - x-coordinates of the data points, must be increasing

854

fp: 1-D sequence of float or complex - y-coordinates of the data points, same length as xp

855

left: optional float or complex corresponding to fp - Value to return for x < xp[0]

856

right: optional float or complex corresponding to fp - Value to return for x > xp[-1]

857

period: None or float, optional - A period for the x-coordinates

858

"""

859

860

def convolve(a, v, mode='full'):

861

"""

862

Returns the discrete convolution of two one-dimensional arrays.

863

864

Parameters:

865

a: (N,) array_like - First one-dimensional input array

866

v: (M,) array_like - Second one-dimensional input array

867

mode: {'full', 'valid', 'same'}, optional - Size of the output

868

"""

869

```

870

871

### Special Functions

872

873

Mathematical special functions for advanced computation.

874

875

```python { .api }

876

def i0(x):

877

"""

878

Modified Bessel function of the first kind, order 0.

879

880

Parameters:

881

x: array_like - Input array

882

"""

883

884

def sinc(x):

885

"""

886

Return the sinc function.

887

888

Parameters:

889

x: array_like - Input array

890

"""

891

```

892

893

### Floating Point Functions

894

895

Functions for manipulating floating-point number representation and properties.

896

897

```python { .api }

898

def signbit(x, out=None):

899

"""

900

Returns element-wise True where signbit is set (less than zero).

901

902

Parameters:

903

x: array_like - Input values

904

out: ndarray, optional - Output array of same shape as x

905

"""

906

907

def copysign(x1, x2, out=None):

908

"""

909

Change the sign of x1 to that of x2, element-wise.

910

911

Parameters:

912

x1: array_like - Values to change the sign of

913

x2: array_like - Values whose sign will be copied to x1

914

out: ndarray, optional - Output array of same shape as x1 and x2

915

"""

916

917

def frexp(x, out1=None, out2=None):

918

"""

919

Decompose the elements of x into mantissa and twos exponent.

920

921

Parameters:

922

x: array_like - Input array

923

out1: ndarray, optional - Output array for mantissa

924

out2: ndarray, optional - Output array for exponent

925

"""

926

927

def ldexp(x1, x2, out=None):

928

"""

929

Returns x1 * 2**x2, element-wise.

930

931

Parameters:

932

x1: array_like - Array of multipliers

933

x2: array_like, int - Array of twos exponents

934

out: ndarray, optional - Output array of same shape as x1 and x2

935

"""

936

937

def nextafter(x1, x2, out=None):

938

"""

939

Return the next floating-point value after x1 towards x2, element-wise.

940

941

Parameters:

942

x1: array_like - Values to find the next representable value of

943

x2: array_like - Direction where to look for the next representable value

944

out: ndarray, optional - Output array of same shape as x1 and x2

945

"""

946

```

947

948

### Rational Functions

949

950

Functions for working with rational numbers and number theory.

951

952

```python { .api }

953

def gcd(x1, x2, out=None):

954

"""

955

Returns the greatest common divisor of |x1| and |x2|.

956

957

Parameters:

958

x1, x2: array_like, int - Arrays of values

959

out: ndarray, optional - Output array of same shape as x1 and x2

960

"""

961

962

def lcm(x1, x2, out=None):

963

"""

964

Returns the lowest common multiple of |x1| and |x2|.

965

966

Parameters:

967

x1, x2: array_like, int - Arrays of values

968

out: ndarray, optional - Output array of same shape as x1 and x2

969

"""

970

```

971

972

### Window Functions

973

974

Functions for creating window functions commonly used in signal processing.

975

976

```python { .api }

977

def bartlett(M):

978

"""

979

Return the Bartlett window.

980

981

Parameters:

982

M: int - Number of points in the output window

983

"""

984

985

def blackman(M):

986

"""

987

Return the Blackman window.

988

989

Parameters:

990

M: int - Number of points in the output window

991

"""

992

993

def hamming(M):

994

"""

995

Return the Hamming window.

996

997

Parameters:

998

M: int - Number of points in the output window

999

"""

1000

1001

def hanning(M):

1002

"""

1003

Return the Hanning window.

1004

1005

Parameters:

1006

M: int - Number of points in the output window

1007

"""

1008

1009

def kaiser(M, beta):

1010

"""

1011

Return the Kaiser window.

1012

1013

Parameters:

1014

M: int - Number of points in the output window

1015

beta: float - Shape parameter for window

1016

"""

1017

```

1018

1019

## Usage Examples

1020

1021

```python

1022

import cupy as cp

1023

1024

# Basic mathematical operations

1025

x = cp.linspace(0, 2*cp.pi, 1000)

1026

y = cp.sin(x)

1027

z = cp.exp(x)

1028

1029

# Trigonometric functions

1030

angles = cp.array([0, cp.pi/4, cp.pi/2, cp.pi])

1031

sin_vals = cp.sin(angles)

1032

cos_vals = cp.cos(angles)

1033

1034

# Statistical operations

1035

data = cp.random.normal(0, 1, (1000, 1000))

1036

mean = cp.mean(data)

1037

std = cp.std(data)

1038

total = cp.sum(data)

1039

1040

# Element-wise operations

1041

a = cp.array([1, 4, 9, 16])

1042

sqrt_a = cp.sqrt(a)

1043

log_a = cp.log(a)

1044

1045

# Complex number operations

1046

complex_arr = cp.array([1+2j, 3+4j, 5+6j])

1047

magnitude = cp.abs(complex_arr)

1048

phase = cp.angle(complex_arr)

1049

```

1050

1051

Mathematical functions in CuPy provide comprehensive numerical computation capabilities optimized for GPU acceleration, enabling high-performance scientific computing with familiar NumPy interfaces while leveraging the parallel processing power of modern GPUs.