Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/NumSharp.Core/Selection/NDArray.Indexing.Masking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ public NDArray this[NDArray<bool> mask]
get => FetchIndices(this, np.nonzero(mask), null, true);
set
{
throw new NotImplementedException("Setter is not implemented yet");
if(mask.ndim == 1)
{
for (int i = 0; i < mask.size; i++)
{
if (mask.GetBoolean(i))
this[i] = value;
}
}
else
{
throw new NotImplementedException("Setter is not implemented yet");
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/NumSharp.UnitTest/Selection/NDArray.Indexing.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public void MaskSetter()
nd.Should().BeOfValues(-2, 2, -2, 4, -2, 6);
}

[TestMethod]
public void MaskSetter2D()
{
var nd = np.arange(15).reshape(5, 3);
var mask = new NDArray(new bool[] { true, false, true, false, true }).MakeGeneric<bool>();
nd[mask] = 99;
nd.Should().BeOfValues(99, 99, 99, 3, 4, 5, 99, 99, 99, 9, 10, 11, 99, 99, 99);
}

[Ignore("to do fix")]
[TestMethod]
public void MaskSetter3D()
{
var nd = np.arange(30).reshape(2, 3, 5);
var mask = new NDArray(new bool[] { true, true, false, false, true, true }).reshape(2, 3).MakeGeneric<bool>();
nd[mask] = 99;
}

[TestMethod]
public void Compare()
{
Expand Down