Skip to content

Commit eb41e69

Browse files
committed
fixed dtype errors - package works
1 parent aaa1600 commit eb41e69

File tree

4 files changed

+26
-36
lines changed

4 files changed

+26
-36
lines changed

numojo/core/array_creation_routines.mojo

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ fn arange[
3838
Error if both dtype and dtype are integers or if dtype is a float and dtype is an integer.
3939
4040
Parameters:
41-
dtype: Input datatype of the input values.
42-
dtype: Output datatype of the output NDArray.
41+
dtype: Datatype of the output array.
4342
4443
Args:
4544
start: Scalar[dtype] - Start value.
@@ -64,7 +63,7 @@ fn arange[
6463
)
6564
for idx in range(num):
6665
result.data[idx] = (
67-
start.cast[out_dtype]() + step.cast[out_dtype]() * idx
66+
start.cast[dtype]() + step.cast[dtype]() * idx
6867
)
6968

7069
return result
@@ -89,11 +88,10 @@ fn linspace[
8988
Function that computes a series of linearly spaced values starting from "start" to "stop" with given size. Wrapper function for _linspace_serial, _linspace_parallel.
9089
9190
Raises:
92-
Error if both dtype and dtype are integers or if dtype is a float and dtype is an integer.
91+
Error if dtype is an integer.
9392
9493
Parameters:
95-
dtype: Datatype of the input values.
96-
dtype: Datatype of the output NDArray.
94+
dtype: Datatype of the output array.
9795
9896
Args:
9997
start: Start value.
@@ -222,11 +220,10 @@ fn logspace[
222220
Generate a logrithmic spaced NDArray of `num` elements between `start` and `stop`. Wrapper function for _logspace_serial, _logspace_parallel functions.
223221
224222
Raises:
225-
Error if both dtype and dtype are integers or if dtype is a float and dtype is an integer.
223+
Error if dtype is an integer.
226224
227225
Parameters:
228-
dtype: Datatype of the input values.
229-
dtype: Datatype of the output NDArray.
226+
dtype: Datatype of the output array.
230227
231228
Args:
232229
start: The starting value of the NDArray.
@@ -363,11 +360,10 @@ fn geomspace[
363360
Generate a NDArray of `num` elements between `start` and `stop` in a geometric series.
364361
365362
Raises:
366-
Error if both dtype and dtype are integers or if dtype is a float and dtype is an integer.
363+
Error if dtype is an integer.
367364
368365
Parameters:
369366
dtype: Datatype of the input values.
370-
dtype: Datatype of the output NDArray.
371367
372368
Args:
373369
start: The starting value of the NDArray.

numojo/core/array_manipulation_routines.mojo

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn reshape[
7575
num_elements_new *= i
7676
ndim_new += 1
7777

78-
if array.ndshape._size != num_elements_new:
78+
if array.ndshape.ndsize != num_elements_new:
7979
raise Error("Cannot reshape: Number of elements do not match.")
8080

8181
var shape_new: List[Int] = List[Int]()
@@ -100,9 +100,9 @@ fn ravel[dtype: DType](inout array: NDArray[dtype], order: String = "C") raises:
100100
return
101101
else:
102102
if order == "C":
103-
reshape[dtype](array, array.ndshape._size, order="C")
103+
reshape[dtype](array, array.ndshape.ndsize, order="C")
104104
else:
105-
reshape[dtype](array, array.ndshape._size, order="F")
105+
reshape[dtype](array, array.ndshape.ndsize, order="F")
106106

107107

108108
fn where[
@@ -122,7 +122,7 @@ fn where[
122122
mask: A NDArray.
123123
124124
"""
125-
for i in range(x.ndshape._size):
125+
for i in range(x.ndshape.ndsize):
126126
if mask.data[i] == True:
127127
x.data.store(i, scalar)
128128

@@ -148,7 +148,7 @@ fn where[
148148
"""
149149
if x.ndshape != y.ndshape:
150150
raise Error("Shape mismatch error: x and y must have the same shape")
151-
for i in range(x.ndshape._size):
151+
for i in range(x.ndshape.ndsize):
152152
if mask.data[i] == True:
153153
x.data.store(i, y.data[i])
154154

@@ -172,6 +172,6 @@ fn flip[dtype: DType](array: NDArray[dtype]) raises -> NDArray[dtype]:
172172
var result: NDArray[dtype] = NDArray[dtype](
173173
shape=array.ndshape, order=array.order
174174
)
175-
for i in range(array.ndshape._size):
176-
result.data.store(i, array.data[array.ndshape._size - i - 1])
175+
for i in range(array.ndshape.ndsize):
176+
result.data.store(i, array.data[array.ndshape.ndsize - i - 1])
177177
return result

numojo/core/ndarray.mojo

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,17 +1792,13 @@ struct NDArray[dtype: DType = DType.float64](
17921792
"""
17931793
Itemwise equivelence between scalar and Array.
17941794
"""
1795-
var other_array: Self = NDArray[dtype](self.shape(), fill=other)
1796-
return math.equal[dtype](self, other_array)
17971795
return math.equal[dtype](self, other)
17981796

17991797
@always_inline("nodebug")
18001798
fn __ne__(self, other: SIMD[dtype, 1]) raises -> NDArray[DType.bool]:
18011799
"""
18021800
Itemwise nonequivelence.
18031801
"""
1804-
var other_array: Self = NDArray[dtype](self.shape(), fill=other)
1805-
return math.not_equal[dtype](self, other_array)
18061802
return math.not_equal[dtype](self, other)
18071803

18081804
@always_inline("nodebug")
@@ -1817,8 +1813,6 @@ struct NDArray[dtype: DType = DType.float64](
18171813
"""
18181814
Itemwise less than.
18191815
"""
1820-
var other_array: Self = NDArray[dtype](self.shape(), fill=other)
1821-
return math.less[dtype](self, other_array)
18221816
return math.less[dtype](self, other)
18231817

18241818
@always_inline("nodebug")

numojo/math/calculus/differentiation.mojo

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn gradient[
1919
dtype: DType
2020
](x: NDArray[dtype], spacing: Scalar[dtype]) raises -> NDArray[dtype]:
2121
"""
22-
Compute the integral of y over x using the trapezoidal rule.
22+
Compute the gradient of y over x using the trapezoidal rule.
2323
2424
Parameters:
2525
dtype: Input data type.
@@ -48,11 +48,11 @@ fn gradient[
4848
var space: NDArray[dtype] = core.arange[dtype](
4949
1, x.num_elements() + 1, step=spacing.cast[dtype]()
5050
)
51-
var hu: Scalar[out_dtype] = space.get_scalar(1)
52-
var hd: Scalar[out_dtype] = space.get_scalar(0)
51+
var hu: Scalar[dtype] = space.get_scalar(1)
52+
var hd: Scalar[dtype] = space.get_scalar(0)
5353
result.store(
5454
0,
55-
(x.get_scalar(1).cast[out_dtype]() - x.get_scalar(0).cast[out_dtype]())
55+
(x.get_scalar(1).cast[dtype]() - x.get_scalar(0).cast[dtype]())
5656
/ (hu - hd),
5757
)
5858

@@ -61,23 +61,23 @@ fn gradient[
6161
result.store(
6262
x.num_elements() - 1,
6363
(
64-
x.get_scalar(x.num_elements() - 1).cast[out_dtype]()
65-
- x.get_scalar(x.num_elements() - 2).cast[out_dtype]()
64+
x.get_scalar(x.num_elements() - 1).cast[dtype]()
65+
- x.get_scalar(x.num_elements() - 2).cast[dtype]()
6666
)
6767
/ (hu - hd),
6868
)
6969

7070
for i in range(1, x.num_elements() - 1):
71-
var hu: Scalar[out_dtype] = space.get_scalar(i + 1) - space.get_scalar(
71+
var hu: Scalar[dtype] = space.get_scalar(i + 1) - space.get_scalar(
7272
i
7373
)
74-
var hd: Scalar[out_dtype] = space.get_scalar(i) - space.get_scalar(
74+
var hd: Scalar[dtype] = space.get_scalar(i) - space.get_scalar(
7575
i - 1
7676
)
77-
var fi: Scalar[out_dtype] = (
78-
hd**2 * x.get_scalar(i + 1).cast[out_dtype]()
79-
+ (hu**2 - hd**2) * x.get_scalar(i).cast[out_dtype]()
80-
- hu**2 * x.get_scalar(i - 1).cast[out_dtype]()
77+
var fi: Scalar[dtype] = (
78+
hd**2 * x.get_scalar(i + 1).cast[dtype]()
79+
+ (hu**2 - hd**2) * x.get_scalar(i).cast[dtype]()
80+
- hu**2 * x.get_scalar(i - 1).cast[dtype]()
8181
) / (hu * hd * (hu + hd))
8282
result.store(i, fi)
8383

0 commit comments

Comments
 (0)