File tree Expand file tree Collapse file tree 2 files changed +54
-5
lines changed Expand file tree Collapse file tree 2 files changed +54
-5
lines changed Original file line number Diff line number Diff line change @@ -132,10 +132,10 @@ macro_rules! ndindex_with_array {
132
132
}
133
133
134
134
#[ inline]
135
- fn index_unchecked( & self , strides : & $ix_n) -> isize {
135
+ fn index_unchecked( & self , _strides : & $ix_n) -> isize {
136
136
$(
137
- stride_offset( self [ $index] , get!( strides , $index) ) +
138
- ) +
137
+ stride_offset( self [ $index] , get!( _strides , $index) ) +
138
+ ) *
139
139
0
140
140
}
141
141
}
@@ -157,7 +157,7 @@ macro_rules! ndindex_with_array {
157
157
self , strides. ndim( ) ) ;
158
158
$(
159
159
stride_offset( get!( self , $index) , get!( strides, $index) ) +
160
- ) +
160
+ ) *
161
161
0
162
162
}
163
163
}
@@ -179,7 +179,7 @@ macro_rules! ndindex_with_array {
179
179
self , strides. ndim( ) ) ;
180
180
$(
181
181
stride_offset( self [ $index] , get!( strides, $index) ) +
182
- ) +
182
+ ) *
183
183
0
184
184
}
185
185
}
@@ -188,6 +188,7 @@ macro_rules! ndindex_with_array {
188
188
}
189
189
190
190
ndindex_with_array ! {
191
+ [ 0 , Ix0 ]
191
192
[ 1 , Ix1 0 ]
192
193
[ 2 , Ix2 0 1 ]
193
194
[ 3 , Ix3 0 1 2 ]
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ extern crate ndarray;
3
3
4
4
use ndarray:: Array ;
5
5
use ndarray:: Ix3 ;
6
+ use ndarray:: IntoDimension ;
6
7
use ndarray:: ShapeBuilder ;
7
8
8
9
#[ test]
@@ -98,3 +99,50 @@ fn test_ixdyn_uget() {
98
99
}
99
100
assert_eq ! ( sum, 10. ) ;
100
101
}
102
+
103
+ #[ test]
104
+ fn test_0 ( ) {
105
+ let mut a = Array :: zeros ( vec ! [ ] ) ;
106
+ let z = vec ! [ ] . into_dimension ( ) ;
107
+ assert_eq ! ( a[ z. clone( ) ] , 0. ) ;
108
+ a[ [ ] ] = 1. ;
109
+ assert_eq ! ( a[ [ ] ] , 1. ) ;
110
+ assert_eq ! ( a. len( ) , 1 ) ;
111
+ assert_eq ! ( a. as_slice( ) . unwrap( ) , & [ 1. ] ) ;
112
+
113
+ let mut a = Array :: zeros ( vec ! [ ] . f ( ) ) ;
114
+ assert_eq ! ( a[ [ ] ] , 0. ) ;
115
+ a[ [ ] ] = 1. ;
116
+ assert_eq ! ( a[ [ ] ] , 1. ) ;
117
+ assert_eq ! ( a. len( ) , 1 ) ;
118
+ assert_eq ! ( a. as_slice( ) . unwrap( ) , & [ 1. ] ) ;
119
+ }
120
+
121
+ #[ test]
122
+ fn test_0_add ( ) {
123
+ let mut a = Array :: zeros ( vec ! [ ] ) ;
124
+ a += 1. ;
125
+ assert_eq ! ( a[ [ ] ] , 1. ) ;
126
+ a += 2. ;
127
+ assert_eq ! ( a[ [ ] ] , 3. ) ;
128
+ }
129
+
130
+ #[ test]
131
+ fn test_0_add_add ( ) {
132
+ let mut a = Array :: zeros ( vec ! [ ] ) ;
133
+ a += 1. ;
134
+ let mut b = Array :: zeros ( vec ! [ ] ) ;
135
+ b += 1. ;
136
+ a += & b;
137
+ assert_eq ! ( a[ [ ] ] , 2. ) ;
138
+ }
139
+
140
+ #[ test]
141
+ fn test_0_add_broad ( ) {
142
+ let mut b = Array :: from_vec ( vec ! [ 5. , 6. ] ) ;
143
+ let mut a = Array :: zeros ( vec ! [ ] ) ;
144
+ a += 1. ;
145
+ b += & a;
146
+ assert_eq ! ( b[ 0 ] , 6. ) ;
147
+ assert_eq ! ( b[ 1 ] , 7. ) ;
148
+ }
You can’t perform that action at this time.
0 commit comments