PyCMatrix 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,862 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyCMatrix
3
+ Version: 1.0.0
4
+ Summary: A Python matrix manipulation library
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Dynamic: license-file
9
+
10
+ # PyMat
11
+
12
+ A modular Python library for creating, manipulating, and performing mathematical operations on matrices.
13
+
14
+ **Version:** `1.0.0`
15
+ **Status:** Stable
16
+
17
+ ---
18
+
19
+ ## Features
20
+
21
+ PyMat provides a collection of tools for working with matrices:
22
+
23
+ * Matrix creation and constructors
24
+ * Matrix indexing and iteration
25
+ * Matrix addition and subtraction
26
+ * Matrix multiplication
27
+ * Scalar multiplication and division
28
+ * Element-wise multiplication
29
+ * Matrix powers
30
+ * Mathematical functions
31
+ * Aggregation and reduction operations
32
+ * Matrix norms
33
+ * Row and column manipulation
34
+ * Matrix reshaping and flattening
35
+ * Transpose
36
+ * Minors and cofactors
37
+ * Determinant
38
+ * Adjoint and inverse
39
+ * Matrix rank
40
+ * Linear-system solving
41
+ * Matrix property checks
42
+ * Approximate equality
43
+ * Random matrix generation
44
+ * Deep copying
45
+ * Input validation
46
+
47
+ ---
48
+
49
+ ## Installation
50
+
51
+ Clone the repository:
52
+
53
+ ```bash
54
+ git clone https://github.com/Github-Shashank/PyMat.git
55
+ cd PyMat
56
+ ```
57
+
58
+ Create and activate a virtual environment if desired:
59
+
60
+ ```bash
61
+ python -m venv .venv
62
+ ```
63
+
64
+ On Windows:
65
+
66
+ ```bash
67
+ .venv\Scripts\activate
68
+ ```
69
+
70
+ On Linux/macOS:
71
+
72
+ ```bash
73
+ source .venv/bin/activate
74
+ ```
75
+
76
+ Install PyMat:
77
+
78
+ ```bash
79
+ pip install -e .
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Quick Start
85
+
86
+ ```python
87
+ from matrix import Matrix
88
+
89
+ A = Matrix([
90
+ [1, 2],
91
+ [3, 4]
92
+ ])
93
+
94
+ B = Matrix([
95
+ [5, 6],
96
+ [7, 8]
97
+ ])
98
+
99
+ print(A)
100
+ print(B)
101
+ ```
102
+
103
+ ### Matrix arithmetic
104
+
105
+ ```python
106
+ print(A + B)
107
+ print(A - B)
108
+ print(A * B)
109
+ ```
110
+
111
+ `*` performs matrix multiplication when both operands are matrices.
112
+
113
+ Scalar multiplication is also supported:
114
+
115
+ ```python
116
+ print(A * 2)
117
+ print(2 * A)
118
+ ```
119
+
120
+ Scalar division:
121
+
122
+ ```python
123
+ print(A / 2)
124
+ ```
125
+
126
+ Negation:
127
+
128
+ ```python
129
+ print(-A)
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Indexing
135
+
136
+ Matrix elements are accessed using:
137
+
138
+ ```python
139
+ A[row, column]
140
+ ```
141
+
142
+ For example:
143
+
144
+ ```python
145
+ print(A[0, 1])
146
+ ```
147
+
148
+ Assigning an element:
149
+
150
+ ```python
151
+ A[0, 1] = 10
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Matrix Properties
157
+
158
+ ```python
159
+ print(A.order)
160
+ print(A.shape)
161
+ ```
162
+
163
+ Both return:
164
+
165
+ ```text
166
+ (rows, columns)
167
+ ```
168
+
169
+ Matrix classification properties include:
170
+
171
+ ```python
172
+ A.isSqrMatrix
173
+ A.isDiagMatrix
174
+ A.isRowMatrix
175
+ A.isColMatrix
176
+ A.isSclrMatrix
177
+ A.isIdntMatrix
178
+ A.isZeroMatrix
179
+ A.isSymtMatrix
180
+ A.isSkewSymtMatrix
181
+ ```
182
+
183
+ Invertibility-related properties:
184
+
185
+ ```python
186
+ A.isInvertible
187
+ A.isSingularMatrix
188
+ A.isNonSingularMatrix
189
+ ```
190
+
191
+ ---
192
+
193
+ ## Constructors
194
+
195
+ PyMat provides several class methods for creating matrices.
196
+
197
+ ### Ones
198
+
199
+ ```python
200
+ Matrix.one(3, 3)
201
+ ```
202
+
203
+ Creates a matrix filled with `1`.
204
+
205
+ ### Zeros
206
+
207
+ ```python
208
+ Matrix.zero(3, 3)
209
+ ```
210
+
211
+ Creates a matrix filled with `0`.
212
+
213
+ ### Identity
214
+
215
+ ```python
216
+ Matrix.identity(3)
217
+ ```
218
+
219
+ Creates a `3 × 3` identity matrix.
220
+
221
+ ### Constant
222
+
223
+ ```python
224
+ Matrix.constant(2, 3, 5)
225
+ ```
226
+
227
+ Creates a `2 × 3` matrix filled with `5`.
228
+
229
+ ### Diagonal
230
+
231
+ ```python
232
+ Matrix.diagonal([1, 2, 3])
233
+ ```
234
+
235
+ Creates a diagonal matrix.
236
+
237
+ ### Random
238
+
239
+ ```python
240
+ Matrix.random(3, 3)
241
+ ```
242
+
243
+ Creates a random matrix using PyMat's existing random constructor.
244
+
245
+ ### Uniform random
246
+
247
+ ```python
248
+ Matrix.random_uniform(3, 3, low=-1, high=1)
249
+ ```
250
+
251
+ Creates a matrix whose elements are uniformly distributed between `low` and `high`.
252
+
253
+ ### Seed
254
+
255
+ ```python
256
+ Matrix.seed(42)
257
+ ```
258
+
259
+ Sets the random generator seed used by PyMat's uniform random constructor.
260
+
261
+ ---
262
+
263
+ ## Matrix Transformation
264
+
265
+ ### Transpose
266
+
267
+ ```python
268
+ A.transpose
269
+ ```
270
+
271
+ Returns the transpose of `A`.
272
+
273
+ ### Flatten
274
+
275
+ ```python
276
+ A.flatten()
277
+ ```
278
+
279
+ Converts the matrix into a single-row matrix.
280
+
281
+ For example:
282
+
283
+ ```text
284
+ [1 2]
285
+ [3 4]
286
+ ```
287
+
288
+ becomes:
289
+
290
+ ```text
291
+ [1 2 3 4]
292
+ ```
293
+
294
+ ### Reshape
295
+
296
+ ```python
297
+ A.reshape(4, 1)
298
+ ```
299
+
300
+ Changes the matrix dimensions while preserving the element count.
301
+
302
+ The number of elements must remain unchanged.
303
+
304
+ ---
305
+
306
+ ## Row and Column Manipulation
307
+
308
+ Rows and columns can be inserted, deleted, retrieved, or swapped.
309
+
310
+ ```python
311
+ A.insertRow(...)
312
+ A.insertCol(...)
313
+ A.delRow(...)
314
+ A.delCol(...)
315
+ A.getRow(...)
316
+ A.getCol(...)
317
+ ```
318
+
319
+ Rows:
320
+
321
+ ```python
322
+ A.swapRows(0, 1)
323
+ ```
324
+
325
+ Columns:
326
+
327
+ ```python
328
+ A.swapCols(0, 1)
329
+ ```
330
+
331
+ By default, swapping returns a new matrix.
332
+
333
+ In-place swapping is also supported:
334
+
335
+ ```python
336
+ A.swapRows(0, 1, inplace=True)
337
+ A.swapCols(0, 1, inplace=True)
338
+ ```
339
+
340
+ ---
341
+
342
+ ## Element-wise Operations
343
+
344
+ Matrix multiplication and element-wise multiplication are different operations.
345
+
346
+ Element-wise multiplication:
347
+
348
+ ```python
349
+ A.elementwise_multiply(B)
350
+ ```
351
+
352
+ Each corresponding pair of elements is multiplied:
353
+
354
+ ```text
355
+ [a b] [x y] [a*x b*y]
356
+ [c d] × [z w] = [c*z d*w]
357
+ ```
358
+
359
+ The matrices must have the same dimensions.
360
+
361
+ ---
362
+
363
+ ## Applying Functions
364
+
365
+ PyMat provides a general `apply()` operation:
366
+
367
+ ```python
368
+ A.apply(function)
369
+ ```
370
+
371
+ Example:
372
+
373
+ ```python
374
+ A.apply(lambda x: x * x)
375
+ ```
376
+
377
+ This applies the function independently to every matrix element.
378
+
379
+ ---
380
+
381
+ ## Mathematical Functions
382
+
383
+ PyMat provides element-wise mathematical functions:
384
+
385
+ ```python
386
+ A.exp()
387
+ A.log()
388
+ A.sqrt()
389
+
390
+ A.abs()
391
+
392
+ A.sin()
393
+ A.cos()
394
+ A.tan()
395
+
396
+ A.sinh()
397
+ A.cosh()
398
+ A.tanh()
399
+ ```
400
+
401
+ For example:
402
+
403
+ ```python
404
+ A.sqrt()
405
+ ```
406
+
407
+ returns a matrix containing the square root of every element.
408
+
409
+ ---
410
+
411
+ ## Reductions
412
+
413
+ PyMat provides operations that reduce the entire matrix to a single value.
414
+
415
+ ### Sum
416
+
417
+ ```python
418
+ A.sum()
419
+ ```
420
+
421
+ ### Mean
422
+
423
+ ```python
424
+ A.mean()
425
+ ```
426
+
427
+ ### Minimum
428
+
429
+ ```python
430
+ A.min()
431
+ ```
432
+
433
+ ### Maximum
434
+
435
+ ```python
436
+ A.max()
437
+ ```
438
+
439
+ ### Product
440
+
441
+ ```python
442
+ A.prod()
443
+ ```
444
+
445
+ ---
446
+
447
+ ## Norm
448
+
449
+ The Frobenius norm of a matrix can be calculated using:
450
+
451
+ ```python
452
+ A.norm()
453
+ ```
454
+
455
+ The squared norm is available through:
456
+
457
+ ```python
458
+ A.norm_squared()
459
+ ```
460
+
461
+ For a matrix
462
+
463
+ ```text
464
+ [a b]
465
+ [c d]
466
+ ```
467
+
468
+ the squared Frobenius norm is:
469
+
470
+ ```text
471
+ a² + b² + c² + d²
472
+ ```
473
+
474
+ and the norm is:
475
+
476
+ ```text
477
+ √(a² + b² + c² + d²)
478
+ ```
479
+
480
+ ---
481
+
482
+ ## Matrix Operations
483
+
484
+ ### Minor
485
+
486
+ ```python
487
+ A.minor(row, column)
488
+ ```
489
+
490
+ Returns the minor associated with an element.
491
+
492
+ ### Cofactor
493
+
494
+ ```python
495
+ A.cofactor(row, column)
496
+ ```
497
+
498
+ Returns the corresponding cofactor.
499
+
500
+ ### Matrix of Minors
501
+
502
+ ```python
503
+ A.matrixOfMinors
504
+ ```
505
+
506
+ ### Matrix of Cofactors
507
+
508
+ ```python
509
+ A.matrixOfCofactors
510
+ ```
511
+
512
+ ### Determinant
513
+
514
+ ```python
515
+ A.determinant
516
+ ```
517
+
518
+ ### Trace
519
+
520
+ ```python
521
+ A.trace
522
+ ```
523
+
524
+ ### Adjoint
525
+
526
+ ```python
527
+ A.adjoint
528
+ ```
529
+
530
+ ### Inverse
531
+
532
+ ```python
533
+ A.inverse
534
+ ```
535
+
536
+ The inverse exists only for an invertible square matrix.
537
+
538
+ ---
539
+
540
+ ## Rank
541
+
542
+ The rank of a matrix can be calculated using:
543
+
544
+ ```python
545
+ A.rank()
546
+ ```
547
+
548
+ Example:
549
+
550
+ ```python
551
+ A = Matrix([
552
+ [1, 2],
553
+ [2, 4]
554
+ ])
555
+
556
+ print(A.rank())
557
+ ```
558
+
559
+ The rank is:
560
+
561
+ ```text
562
+ 1
563
+ ```
564
+
565
+ ---
566
+
567
+ ## Solving Linear Systems
568
+
569
+ PyMat can solve a system of linear equations represented as:
570
+
571
+ ```text
572
+ AX = B
573
+ ```
574
+
575
+ using:
576
+
577
+ ```python
578
+ A.solve(B)
579
+ ```
580
+
581
+ Example:
582
+
583
+ ```python
584
+ A = Matrix([
585
+ [2, 1],
586
+ [1, 3]
587
+ ])
588
+
589
+ B = Matrix([
590
+ [5],
591
+ [6]
592
+ ])
593
+
594
+ X = A.solve(B)
595
+
596
+ print(X)
597
+ ```
598
+
599
+ The coefficient matrix must be square and the right-hand side must have compatible dimensions.
600
+
601
+ ---
602
+
603
+ ## Approximate Equality
604
+
605
+ Exact equality:
606
+
607
+ ```python
608
+ A == B
609
+ ```
610
+
611
+ checks whether corresponding elements are exactly equal.
612
+
613
+ For floating-point calculations, approximate equality is available:
614
+
615
+ ```python
616
+ A.isApproxEqual(B)
617
+ ```
618
+
619
+ A custom tolerance can be supplied:
620
+
621
+ ```python
622
+ A.isApproxEqual(B, tolerance=1e-6)
623
+ ```
624
+
625
+ This is useful when numerical calculations produce small floating-point differences.
626
+
627
+ ---
628
+
629
+ ## Copying
630
+
631
+ To create an independent copy of a matrix:
632
+
633
+ ```python
634
+ B = A.copy()
635
+ ```
636
+
637
+ The copy is independent of the original matrix.
638
+
639
+ Changing `B` does not modify `A`.
640
+
641
+ ---
642
+
643
+ ## Iteration
644
+
645
+ A matrix can be iterated over:
646
+
647
+ ```python
648
+ for row in A:
649
+ print(row)
650
+ ```
651
+
652
+ The matrix's traversal functionality is also available through:
653
+
654
+ ```python
655
+ A.traverse
656
+ ```
657
+
658
+ ---
659
+
660
+ ## Matrix Power
661
+
662
+ Positive integer powers are supported:
663
+
664
+ ```python
665
+ A ** 2
666
+ ```
667
+
668
+ which performs:
669
+
670
+ ```text
671
+ A × A
672
+ ```
673
+
674
+ For example:
675
+
676
+ ```python
677
+ A ** 3
678
+ ```
679
+
680
+ calculates:
681
+
682
+ ```text
683
+ A × A × A
684
+ ```
685
+
686
+ ---
687
+
688
+ ## API Overview
689
+
690
+ ### Operators
691
+
692
+ | Operator | Operation |
693
+ | ------------ | --------------------- |
694
+ | `A + B` | Matrix addition |
695
+ | `A - B` | Matrix subtraction |
696
+ | `A * B` | Matrix multiplication |
697
+ | `A * scalar` | Scalar multiplication |
698
+ | `scalar * A` | Scalar multiplication |
699
+ | `A / scalar` | Scalar division |
700
+ | `-A` | Matrix negation |
701
+ | `A ** n` | Matrix power |
702
+ | `A == B` | Exact equality |
703
+
704
+ ### Core Properties
705
+
706
+ | Property | Purpose |
707
+ | ------------- | ------------------ |
708
+ | `order` | Matrix dimensions |
709
+ | `shape` | Alias for `order` |
710
+ | `transpose` | Transposed matrix |
711
+ | `traverse` | Matrix traversal |
712
+ | `determinant` | Matrix determinant |
713
+ | `trace` | Matrix trace |
714
+ | `adjoint` | Matrix adjoint |
715
+ | `inverse` | Matrix inverse |
716
+
717
+ ### Numerical Methods
718
+
719
+ | Method | Purpose |
720
+ | ------------------------ | --------------------------------- |
721
+ | `elementwise_multiply()` | Element-wise multiplication |
722
+ | `apply()` | Apply a function to every element |
723
+ | `exp()` | Element-wise exponential |
724
+ | `log()` | Element-wise logarithm |
725
+ | `sqrt()` | Element-wise square root |
726
+ | `abs()` | Element-wise absolute value |
727
+ | `sin()` | Element-wise sine |
728
+ | `cos()` | Element-wise cosine |
729
+ | `tan()` | Element-wise tangent |
730
+ | `sinh()` | Element-wise hyperbolic sine |
731
+ | `cosh()` | Element-wise hyperbolic cosine |
732
+ | `tanh()` | Element-wise hyperbolic tangent |
733
+ | `sum()` | Sum of all elements |
734
+ | `mean()` | Mean of all elements |
735
+ | `min()` | Minimum element |
736
+ | `max()` | Maximum element |
737
+ | `prod()` | Product of all elements |
738
+ | `norm_squared()` | Squared Frobenius norm |
739
+ | `norm()` | Frobenius norm |
740
+ | `rank()` | Matrix rank |
741
+ | `solve()` | Solve a linear system |
742
+
743
+ ---
744
+
745
+ ## Validation
746
+
747
+ PyMat provides validation helpers:
748
+
749
+ ```python
750
+ A.isValidIndex(...)
751
+ A.isEqualOrder(B)
752
+ A.isMultiplicable(B)
753
+ A.isApproxEqual(B)
754
+ ```
755
+
756
+ These can be used to validate matrix dimensions, indices, and numerical equality.
757
+
758
+ ---
759
+
760
+ ## Testing
761
+
762
+ PyMat includes a test suite covering the library's functionality.
763
+
764
+ Run the tests with:
765
+
766
+ ```bash
767
+ python -m unittest discover
768
+ ```
769
+
770
+ The current v1 implementation has:
771
+
772
+ ```text
773
+ 100 tests
774
+ 100 passed
775
+ 0 failed
776
+ ```
777
+
778
+ ---
779
+
780
+ ## Project Structure
781
+
782
+ ```text
783
+ PyMat/
784
+ ├── matrix/
785
+ │ ├── __init__.py
786
+ │ ├── arithmetic.py
787
+ │ ├── bool.py
788
+ │ ├── constructors.py
789
+ │ ├── exceptions.py
790
+ │ ├── manipulation.py
791
+ │ ├── matrix.py
792
+ │ ├── operations.py
793
+ │ └── validators.py
794
+
795
+ ├── tests/
796
+ │ └── test_matrix.py
797
+
798
+ ├── docs/
799
+ │ ├── api_reference.md
800
+ │ ├── arithmetic.md
801
+ │ ├── constructors.md
802
+ │ ├── manipulation.md
803
+ │ ├── operations.md
804
+ │ └── properties.md
805
+
806
+ ├── README.md
807
+ ├── LICENSE
808
+ ├── .gitignore
809
+ └── pyproject.toml
810
+ ```
811
+
812
+ ---
813
+
814
+ ## Design
815
+
816
+ PyMat is organized into separate modules so that different areas of matrix functionality remain independent.
817
+
818
+ ```text
819
+ matrix.py
820
+
821
+ ├── arithmetic.py
822
+ ├── constructors.py
823
+ ├── manipulation.py
824
+ ├── operations.py
825
+ ├── validators.py
826
+ └── bool.py
827
+ ```
828
+
829
+ The `Matrix` class provides the public interface while the individual modules contain the underlying functionality.
830
+
831
+ This structure makes PyMat easier to maintain, test, and extend.
832
+
833
+ ---
834
+
835
+ ## Documentation
836
+
837
+ Detailed documentation is available in the `docs/` directory:
838
+
839
+ * [API Reference](docs/api_reference.md)
840
+ * [Arithmetic](docs/arithmetic.md)
841
+ * [Constructors](docs/constructors.md)
842
+ * [Manipulation](docs/manipulation.md)
843
+ * [Operations](docs/operations.md)
844
+ * [Properties](docs/properties.md)
845
+
846
+ ---
847
+
848
+ ## Version
849
+
850
+ Current release:
851
+
852
+ ```text
853
+ PyMat 1.0.0
854
+ ```
855
+
856
+ PyMat 1.0 represents the first stable version of the library's public API.
857
+
858
+ ---
859
+
860
+ ## License
861
+
862
+ PyMat is distributed under the license included in the `LICENSE` file.