SingleElementSequence
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
วิธีการสืบทอด
จากคลาส java.lang.Object บูลีน | เท่ากับ (วัตถุ arg0) |
คลาสสุดท้าย<?> | รับคลาส () |
ภายใน | แฮชโค้ด () |
โมฆะสุดท้าย | แจ้ง () |
โมฆะสุดท้าย | แจ้งทั้งหมด () |
สตริง | toString () |
โมฆะสุดท้าย | รอสักครู่ (ยาว arg0, int arg1) |
โมฆะสุดท้าย | รอ (ยาว arg0) |
โมฆะสุดท้าย | รอ () |
จากอินเทอร์เฟซ java.lang.Iterable ความว่างเปล่าที่เป็นนามธรรม | forEach (ผู้บริโภค<? super T> arg0) |
นามธรรม Iterator<U ขยาย NdArray <T>> | ตัววนซ้ำ () |
ตัวแยกนามธรรม<U ขยาย NdArray <T>> | ตัวแยกสัญญาณ () |
วิธีการสาธารณะ
ส่งกลับแต่ละองค์ประกอบเป็นชิ้นใหม่
แตกต่างจากคอลเลกชัน Java ทั่วไป องค์ประกอบของ NdArraySequence
เป็นแบบชั่วคราว กล่าวคือ อินสแตนซ์ NdArray
ใหม่จะได้รับการจัดสรรสำหรับการวนซ้ำแต่ละครั้ง เพื่อปรับปรุงประสิทธิภาพ คุณสามารถรีไซเคิลอินสแตนซ์เดียวกันเพื่อดูองค์ประกอบทั้งหมดของลำดับนี้ได้ โดยใช้ DataBufferWindow
ในบางกรณี อาจเป็นการดีกว่าที่จะปิดใช้งานการปรับให้เหมาะสมดังกล่าวเพื่อให้แน่ใจว่าแต่ละองค์ประกอบที่ส่งคืนนั้นเป็นชิ้นใหม่ของอาร์เรย์ดั้งเดิม ตัวอย่างเช่น หากองค์ประกอบหนึ่งรายการขึ้นไปที่เยี่ยมชมต้องอยู่นอกขอบเขตของการวนซ้ำของลำดับ asSlices()
จะตรวจสอบให้แน่ใจว่าองค์ประกอบทั้งหมดที่ส่งคืนโดยลำดับนั้นเป็นอินสแตนซ์ที่ไม่ซ้ำกัน
final List<IntNdArray> vectors = new ArrayList<>();
IntNdArray matrix = NdArrays.ofInts(Shape.of(6, 6));
ndArray.elements(0).forEach(e -> vectors::add); // Not safe, as `e` might always be the same recycled instance
ndArray.elements(0).asSlices().forEach(e -> vectors::add); // Safe, each `e` is a distinct NdArray instance
การส่งคืน
- ลำดับที่ส่งคืนแต่ละองค์ประกอบที่วนซ้ำเป็นชิ้นใหม่
โมฆะสาธารณะ forEachIndexed (BiConsumer<long[], U> ผู้บริโภค)
ตัววนซ้ำสาธารณะ <U> ตัววนซ้ำ ()
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# SingleElementSequence\n\npublic final class **SingleElementSequence** \nA sequence of one single element \n\n### Public Constructors\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [SingleElementSequence](/jvm/api_docs/java/org/tensorflow/ndarray/impl/sequence/SingleElementSequence#SingleElementSequence(org.tensorflow.ndarray.impl.AbstractNdArray\u003cT, U\u003e))([AbstractNdArray](/jvm/api_docs/java/org/tensorflow/ndarray/impl/AbstractNdArray)\\\u003cT, U\\\u003e ndArray) |\n\n### Public Methods\n\n|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [NdArraySequence](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence)\\\u003cU\\\u003e | [asSlices](/jvm/api_docs/java/org/tensorflow/ndarray/impl/sequence/SingleElementSequence#asSlices())() Returns each element as a new slice. |\n| void | [forEachIndexed](/jvm/api_docs/java/org/tensorflow/ndarray/impl/sequence/SingleElementSequence#forEachIndexed(java.util.function.BiConsumer\u003clong[], U\u003e))(BiConsumer\\\u003clong\\[\\], U\\\u003e consumer) |\n| Iterator\\\u003cU\\\u003e | [iterator](/jvm/api_docs/java/org/tensorflow/ndarray/impl/sequence/SingleElementSequence#iterator())() |\n\n### Inherited Methods\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface [org.tensorflow.ndarray.NdArraySequence](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence) \n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [NdArraySequence](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence)\\\u003cU extends [NdArray](/jvm/api_docs/java/org/tensorflow/ndarray/NdArray)\\\u003cT\\\u003e\\\u003e | [asSlices](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence#asSlices())() Returns each element as a new slice. |\n| abstract void | [forEachIndexed](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence#forEachIndexed(java.util.function.BiConsumer\u003clong[], T\u003e))(BiConsumer\\\u003clong\\[\\], U extends [NdArray](/jvm/api_docs/java/org/tensorflow/ndarray/NdArray)\\\u003cT\\\u003e\\\u003e consumer) Visit each elements of this iteration and their respective coordinates. |\n\nFrom interface java.lang.Iterable \n\n|-----------------------------------------------------------------------------------------------------|-------------------------------------|\n| abstract void | forEach(Consumer\\\u003c? super T\\\u003e arg0) |\n| abstract Iterator\\\u003cU extends [NdArray](/jvm/api_docs/java/org/tensorflow/ndarray/NdArray)\\\u003cT\\\u003e\\\u003e | iterator() |\n| abstract Spliterator\\\u003cU extends [NdArray](/jvm/api_docs/java/org/tensorflow/ndarray/NdArray)\\\u003cT\\\u003e\\\u003e | spliterator() |\n\nPublic Constructors\n-------------------\n\n#### public\n**SingleElementSequence**\n([AbstractNdArray](/jvm/api_docs/java/org/tensorflow/ndarray/impl/AbstractNdArray)\\\u003cT, U\\\u003e ndArray)\n\n\u003cbr /\u003e\n\nPublic Methods\n--------------\n\n#### public [NdArraySequence](/jvm/api_docs/java/org/tensorflow/ndarray/NdArraySequence)\\\u003cU\\\u003e\n**asSlices**\n()\n\nReturns each element as a new slice.\n\nUnlike conventional Java collections, elements of a `NdArraySequence` are transient, i.e. new `NdArray`\ninstances are allocated for each iteration. To improve performance, the same instance can be recycled to view\nall elements of this sequence, using a [DataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow).\n\nIn some cases though, it might be preferable to disable such optimizations to ensure that each element returned is a\nnew slice of the original array. For example, if one or more elements visited must live beyond the scope of the sequence\niteration, `asSlices()` makes sure that all elements returned by the sequence are unique instances.\n\n final List\u003cIntNdArray\u003e vectors = new ArrayList\u003c\u003e();\n IntNdArray matrix = NdArrays.ofInts(Shape.of(6, 6));\n ndArray.elements(0).forEach(e -\u003e vectors::add); // Not safe, as `e` might always be the same recycled instance\n ndArray.elements(0).asSlices().forEach(e -\u003e vectors::add); // Safe, each `e` is a distinct NdArray instance\n \n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Returns\n\n- a sequence that returns each elements iterated as a new slice \n\n#### public void\n**forEachIndexed**\n(BiConsumer\\\u003clong\\[\\], U\\\u003e consumer)\n\n\u003cbr /\u003e\n\n#### public Iterator\\\u003cU\\\u003e\n**iterator**\n()\n\n\u003cbr /\u003e"]]